Preparing for AE update
This commit is contained in:
parent
d59e3b5d5e
commit
d1cce7764c
2 changed files with 152 additions and 140 deletions
|
@ -2,18 +2,10 @@ package cr0s.warpdrive.machines;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import appeng.api.IAEItemStack;
|
||||
import appeng.api.Util;
|
||||
import appeng.api.WorldCoord;
|
||||
import appeng.api.events.GridTileLoadEvent;
|
||||
import appeng.api.events.GridTileUnloadEvent;
|
||||
import appeng.api.me.tiles.IGridMachine;
|
||||
import appeng.api.me.tiles.ITileCable;
|
||||
import appeng.api.me.util.IGridInterface;
|
||||
import appeng.api.me.util.IMEInventoryHandler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockFluid;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -21,12 +13,18 @@ import net.minecraft.tileentity.TileEntity;
|
|||
import net.minecraft.world.ChunkCoordIntPair;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import cr0s.warpdrive.data.Vector3;
|
||||
import net.minecraftforge.fluids.IFluidBlock;
|
||||
import appeng.api.networking.IGrid;
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.storage.IMEInventoryHandler;
|
||||
import appeng.api.storage.data.IAEItemStack;
|
||||
import appeng.api.util.WorldCoord;
|
||||
import cr0s.warpdrive.PacketHandler;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.WarpDriveConfig;
|
||||
import cr0s.warpdrive.data.Vector3;
|
||||
|
||||
public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser implements IGridMachine, ITileCable
|
||||
public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser implements IGridNode, ITileCable
|
||||
{
|
||||
//FOR STORAGE
|
||||
private boolean silkTouch = false;
|
||||
|
@ -36,7 +34,7 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
private Vector3 minerVector;
|
||||
|
||||
Boolean powerStatus = false;
|
||||
private IGridInterface grid;
|
||||
private IGrid grid;
|
||||
private boolean isMEReady = false;
|
||||
|
||||
abstract boolean canSilkTouch();
|
||||
|
@ -64,21 +62,22 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
minerVector.translate(0.5);
|
||||
}
|
||||
|
||||
private List<ItemStack> getItemStackFromBlock(int i, int j, int k, int blockID, int blockMeta)
|
||||
private List<ItemStack> getItemStackFromBlock(int i, int j, int k, Block block, int blockMeta)
|
||||
{
|
||||
Block block = Block.blocksList[blockID];
|
||||
if (block == null)
|
||||
return null;
|
||||
if (silkTouch(blockID))
|
||||
|
||||
ArrayList<ItemStack> t = new ArrayList<ItemStack>();
|
||||
if (silkTouch(block))
|
||||
{
|
||||
if (block.canSilkHarvest(worldObj, null, i, j, k, blockMeta))
|
||||
{
|
||||
ArrayList<ItemStack> t = new ArrayList<ItemStack>();
|
||||
t.add(new ItemStack(blockID, 1, blockMeta));
|
||||
t.add(new ItemStack(block, 1, blockMeta));
|
||||
return t;
|
||||
}
|
||||
}
|
||||
return block.getBlockDropped(worldObj, i, j, k, blockMeta, fortuneLevel);
|
||||
t.add(new ItemStack(block.getItemDropped(blockMeta, new Random(), fortuneLevel), block.damageDropped(blockMeta), block.quantityDropped(blockMeta, fortuneLevel, new Random())));
|
||||
return t;
|
||||
}
|
||||
|
||||
protected boolean isOnEarth()
|
||||
|
@ -91,7 +90,7 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
|
||||
for(int i = 0; i < 6; i++) {
|
||||
Vector3 sideOffset = adjacentSideOffsets[i];
|
||||
result = worldObj.getBlockTileEntity(xCoord + sideOffset.intX(), yCoord + sideOffset.intY(), zCoord + sideOffset.intZ());
|
||||
result = worldObj.getTileEntity(xCoord + sideOffset.intX(), yCoord + sideOffset.intY(), zCoord + sideOffset.intZ());
|
||||
if (result != null && !(result instanceof TileEntityAbstractMiner) && (result instanceof IInventory)) {
|
||||
return (IInventory) result;
|
||||
}
|
||||
|
@ -164,13 +163,13 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
|
||||
protected int calculateBlockCost()
|
||||
{
|
||||
return calculateBlockCost(0);
|
||||
return calculateBlockCost(Blocks.air);
|
||||
}
|
||||
|
||||
protected int calculateBlockCost(int blockID)
|
||||
protected int calculateBlockCost(Block block)
|
||||
{
|
||||
int enPerBlock = isOnEarth() ? WarpDriveConfig.ML_EU_PER_BLOCK_EARTH : WarpDriveConfig.ML_EU_PER_BLOCK_SPACE;
|
||||
if(silkTouch(blockID))
|
||||
if (silkTouch(block))
|
||||
return (int) Math.round(enPerBlock * WarpDriveConfig.ML_EU_MUL_SILKTOUCH);
|
||||
return (int) Math.round(enPerBlock * (Math.pow(WarpDriveConfig.ML_EU_MUL_FORTUNE, fortune())));
|
||||
}
|
||||
|
@ -191,26 +190,26 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
return false;
|
||||
}
|
||||
|
||||
private boolean canDig(int blockID, int x, int y, int z) {// not used
|
||||
private boolean canDig(Block block, int x, int y, int z) {// not used
|
||||
// ignore air & fluids
|
||||
if (!WarpDriveConfig.isAirBlock(worldObj, blockID, x, y, z) && Block.blocksList[blockID] != null && !(Block.blocksList[blockID] instanceof BlockFluid)) {
|
||||
if (block == null || (worldObj.isAirBlock(x, y, z) || (block instanceof IFluidBlock))) {
|
||||
return false;
|
||||
}
|
||||
// check blacklist
|
||||
if (blockID == Block.bedrock) {
|
||||
if (block.isAssociatedBlock(Blocks.bedrock)) {
|
||||
return false;
|
||||
}
|
||||
if (WarpDriveConfig.forceFieldBlocks.contains(blockID)) {
|
||||
// isMining = false;
|
||||
if (WarpDriveConfig.forceFieldBlocks.contains(block)) {
|
||||
// isMining = false;
|
||||
return false;
|
||||
}
|
||||
// check whitelist
|
||||
// WarpDriveConfig.MinerOres.contains(blockID) then true ?
|
||||
else if (blockID == WarpDriveConfig.GT_Granite || blockID == WarpDriveConfig.GT_Ores || blockID == WarpDriveConfig.iridiumBlockID) {
|
||||
else if (block.isAssociatedBlock(WarpDrive.iridiumBlock)) {
|
||||
return true;
|
||||
}
|
||||
// check default
|
||||
else if ( (Block.blocksList[blockID] != null) && (Block.blocksList[blockID].blockResistance <= Block.obsidian.blockResistance) ) {
|
||||
else if (block.getExplosionResistance(null) <= Blocks.obsidian.getExplosionResistance(null)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
@ -228,21 +227,21 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
//worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F);
|
||||
}
|
||||
|
||||
private void mineBlock(Vector3 valuable,int blockID, int blockMeta)
|
||||
private void mineBlock(Vector3 valuable, Block block, int blockMeta)
|
||||
{
|
||||
laserBlock(valuable);
|
||||
worldObj.playAuxSFXAtEntity(null, 2001, valuable.intX(), valuable.intY(), valuable.intZ(), blockID + (blockMeta << 12));
|
||||
worldObj.playAuxSFXAtEntity(null, 2001, valuable.intX(), valuable.intY(), valuable.intZ(), (blockMeta << 12));
|
||||
worldObj.setBlockToAir(valuable.intX(), valuable.intY(), valuable.intZ());
|
||||
}
|
||||
|
||||
protected boolean harvestBlock(Vector3 valuable)
|
||||
{
|
||||
int blockID = worldObj.getBlockId(valuable.intX(), valuable.intY(), valuable.intZ());
|
||||
Block block = worldObj.getBlock(valuable.intX(), valuable.intY(), valuable.intZ());
|
||||
int blockMeta = worldObj.getBlockMetadata(valuable.intX(), valuable.intY(), valuable.intZ());
|
||||
if (blockID != Block.waterMoving && blockID != Block.waterStill && blockID != Block.lavaMoving && blockID != Block.lavaStill)
|
||||
if (!block.isAssociatedBlock(Blocks.water) && !block.isAssociatedBlock(Blocks.lava))
|
||||
{
|
||||
boolean didPlace = true;
|
||||
List<ItemStack> stacks = getItemStackFromBlock(valuable.intX(), valuable.intY(), valuable.intZ(), blockID, blockMeta);
|
||||
List<ItemStack> stacks = getItemStackFromBlock(valuable.intX(), valuable.intY(), valuable.intZ(), block, blockMeta);
|
||||
if (stacks != null)
|
||||
{
|
||||
for (ItemStack stack : stacks)
|
||||
|
@ -250,10 +249,10 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
didPlace = didPlace && dumpToInv(stack) == stack.stackSize;
|
||||
}
|
||||
}
|
||||
mineBlock(valuable,blockID,blockMeta);
|
||||
mineBlock(valuable, block, blockMeta);
|
||||
return didPlace;
|
||||
}
|
||||
else if (blockID == Block.waterMoving || blockID == Block.waterStill)
|
||||
else if (block.isAssociatedBlock(Blocks.water))
|
||||
// Evaporate water
|
||||
worldObj.playSoundEffect(valuable.intX() + 0.5D, valuable.intY() + 0.5D, valuable.intZ() + 0.5D, "random.fizz", 0.5F, 2.6F + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) * 0.8F);
|
||||
worldObj.setBlockToAir(valuable.intX(), valuable.intY(), valuable.intZ());
|
||||
|
@ -363,7 +362,7 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
|
||||
for(int i=0;i<6;i++)
|
||||
{
|
||||
result = worldObj.getBlockTileEntity(xCoord + xPos[i], yCoord + yPos[i], zCoord + zPos[i]);
|
||||
result = worldObj.getTileEntity(xCoord + xPos[i], yCoord + yPos[i], zCoord + zPos[i]);
|
||||
|
||||
if (result != null && result instanceof TileEntityParticleBooster)
|
||||
{
|
||||
|
|
|
@ -2,13 +2,14 @@ package cr0s.warpdrive.machines;
|
|||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import cr0s.warpdrive.data.Vector3;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.WarpDriveConfig;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
import cr0s.warpdrive.data.Vector3;
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
|
||||
public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
||||
Boolean active = false;
|
||||
|
@ -70,16 +71,16 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
return;
|
||||
}
|
||||
Vector3 pos = logs.get(logIndex);
|
||||
int blockID = worldObj.getBlockId(pos.intX(), pos.intY(), pos.intZ());
|
||||
Block block = worldObj.getBlock(pos.intX(), pos.intY(), pos.intZ());
|
||||
|
||||
if (mode == 1) {
|
||||
int cost = calculateBlockCost(blockID);
|
||||
int cost = calculateBlockCost(block);
|
||||
if (consumeEnergyFromBooster(cost, true)) {
|
||||
if (isLog(blockID) || (doLeaves && isLeaf(blockID))) {
|
||||
if (isLog(block) || (doLeaves && isLeaf(block))) {
|
||||
delayMul = 1;
|
||||
if (isRoomForHarvest()) {
|
||||
if (consumeEnergyFromBooster(cost, false)) {
|
||||
if (isLog(blockID)) {
|
||||
if (isLog(block)) {
|
||||
delayMul = 4;
|
||||
totalHarvested++;
|
||||
}
|
||||
|
@ -94,10 +95,10 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
logIndex++;
|
||||
}
|
||||
} else if(mode == 2) {
|
||||
int cost = calculateBlockCost(blockID);
|
||||
int cost = calculateBlockCost(block);
|
||||
if (consumeEnergyFromBooster(cost, true)) {
|
||||
if (isRoomForHarvest()) {
|
||||
if (blockID == WarpDriveConfig.IC2_RubberWood) {
|
||||
if (block.isAssociatedBlock(Block.getBlockFromItem(WarpDriveConfig.IC2_RubberWood.getItem()))) {
|
||||
int metadata = worldObj.getBlockMetadata(pos.intX(), pos.intY(), pos.intZ());
|
||||
if (metadata >= 2 && metadata <= 5) {
|
||||
WarpDrive.debugPrint("wetspot found");
|
||||
|
@ -115,7 +116,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
} else {
|
||||
delayMul = 1;
|
||||
}
|
||||
} else if(isLog(blockID)) {
|
||||
} else if (isLog(block)) {
|
||||
if (consumeEnergyFromBooster(cost, false)) {
|
||||
delayMul = 4;
|
||||
totalHarvested++;
|
||||
|
@ -123,7 +124,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
} else {
|
||||
return;
|
||||
}
|
||||
} else if(isLeaf(blockID)) {
|
||||
} else if (isLeaf(block)) {
|
||||
if (consumeEnergyFromBooster(cost, true)) {
|
||||
delayMul = 1;
|
||||
harvestBlock(pos);
|
||||
|
@ -142,12 +143,12 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
}
|
||||
}
|
||||
|
||||
private static boolean isLog(int blockID) {
|
||||
return WarpDriveConfig.minerLogs.contains(blockID);
|
||||
private static boolean isLog(Block block) {
|
||||
return WarpDriveConfig.minerLogs.contains(block);
|
||||
}
|
||||
|
||||
private static boolean isLeaf(int blockID) {
|
||||
return WarpDriveConfig.minerLeaves.contains(blockID);
|
||||
private static boolean isLeaf(Block block) {
|
||||
return WarpDriveConfig.minerLeaves.contains(block);
|
||||
}
|
||||
|
||||
private static void addTree(LinkedList<Vector3> list, Vector3 newTree) {
|
||||
|
@ -172,8 +173,8 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
|
||||
for(int x = xmin; x <= xmax; x++) {
|
||||
for(int z = zmin; z <= zmax; z++) {
|
||||
int blockID = worldObj.getBlockId(x, yCoord, z);
|
||||
if (isLog(blockID)) {
|
||||
Block block = worldObj.getBlock(x, yCoord, z);
|
||||
if (isLog(block)) {
|
||||
Vector3 pos = new Vector3(x, yCoord, z);
|
||||
logPositions.add(pos);
|
||||
scanNearby(logPositions, x, yCoord, z, 0);
|
||||
|
@ -188,8 +189,8 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
for(int dx : deltas) {
|
||||
for(int dy = 1; dy >= 0; dy--) {
|
||||
for(int dz : deltas) {
|
||||
int blockID = worldObj.getBlockId(x+dx, y+dy, z+dz);
|
||||
if (isLog(blockID) || (doLeaves && isLeaf(blockID))) {
|
||||
Block block = worldObj.getBlock(x + dx, y + dy, z + dz);
|
||||
if (isLog(block) || (doLeaves && isLeaf(block))) {
|
||||
Vector3 pos = new Vector3(x + dx, y + dy, z + dz);
|
||||
if (!current.contains(pos)) {
|
||||
addTree(current, pos);
|
||||
|
@ -237,7 +238,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
|
||||
// ComputerCraft IPeripheral methods implementation
|
||||
@Override
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) throws Exception {
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) {
|
||||
String methodName = methodsArray[method];
|
||||
if (methodName.equals("start")) {
|
||||
if (!active) {
|
||||
|
@ -306,8 +307,8 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
|
||||
//ABSTRACT LASER IMPLEMENTATION
|
||||
@Override
|
||||
protected boolean silkTouch(int blockID) {
|
||||
if (isLeaf(blockID)) {
|
||||
protected boolean silkTouch(Block block) {
|
||||
if (isLeaf(block)) {
|
||||
return silkTouchLeaves;
|
||||
}
|
||||
return silkTouch();
|
||||
|
@ -347,4 +348,16 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
protected float getColorB() {
|
||||
return 0.4f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSinkTier() {
|
||||
// TODO Auto-generated method stub
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSourceTier() {
|
||||
// TODO Auto-generated method stub
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue