Preparing for AE update

This commit is contained in:
Francesco Macagno 2015-07-26 17:07:59 -07:00
parent d59e3b5d5e
commit d1cce7764c
2 changed files with 152 additions and 140 deletions

View file

@ -2,18 +2,10 @@ package cr0s.warpdrive.machines;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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.Block;
import net.minecraft.block.BlockFluid; import net.minecraft.init.Blocks;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -21,12 +13,18 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.ChunkCoordIntPair; import net.minecraft.world.ChunkCoordIntPair;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge; 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.PacketHandler;
import cr0s.warpdrive.WarpDrive; import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.WarpDriveConfig; 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 //FOR STORAGE
private boolean silkTouch = false; private boolean silkTouch = false;
@ -36,7 +34,7 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
private Vector3 minerVector; private Vector3 minerVector;
Boolean powerStatus = false; Boolean powerStatus = false;
private IGridInterface grid; private IGrid grid;
private boolean isMEReady = false; private boolean isMEReady = false;
abstract boolean canSilkTouch(); abstract boolean canSilkTouch();
@ -64,21 +62,22 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
minerVector.translate(0.5); 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) if (block == null)
return null; return null;
if (silkTouch(blockID))
ArrayList<ItemStack> t = new ArrayList<ItemStack>();
if (silkTouch(block))
{ {
if (block.canSilkHarvest(worldObj, null, i, j, k, blockMeta)) if (block.canSilkHarvest(worldObj, null, i, j, k, blockMeta))
{ {
ArrayList<ItemStack> t = new ArrayList<ItemStack>(); t.add(new ItemStack(block, 1, blockMeta));
t.add(new ItemStack(blockID, 1, blockMeta));
return t; 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() protected boolean isOnEarth()
@ -91,7 +90,7 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
for(int i = 0; i < 6; i++) { for(int i = 0; i < 6; i++) {
Vector3 sideOffset = adjacentSideOffsets[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)) { if (result != null && !(result instanceof TileEntityAbstractMiner) && (result instanceof IInventory)) {
return (IInventory) result; return (IInventory) result;
} }
@ -164,13 +163,13 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
protected int calculateBlockCost() 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; 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 * WarpDriveConfig.ML_EU_MUL_SILKTOUCH);
return (int) Math.round(enPerBlock * (Math.pow(WarpDriveConfig.ML_EU_MUL_FORTUNE, fortune()))); 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; 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 // 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; return false;
} }
// check blacklist // check blacklist
if (blockID == Block.bedrock) { if (block.isAssociatedBlock(Blocks.bedrock)) {
return false; return false;
} }
if (WarpDriveConfig.forceFieldBlocks.contains(blockID)) { if (WarpDriveConfig.forceFieldBlocks.contains(block)) {
// isMining = false; // isMining = false;
return false; return false;
} }
// check whitelist // check whitelist
// WarpDriveConfig.MinerOres.contains(blockID) then true ? // 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; return true;
} }
// check default // 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 true;
} }
return false; 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); //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); 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()); worldObj.setBlockToAir(valuable.intX(), valuable.intY(), valuable.intZ());
} }
protected boolean harvestBlock(Vector3 valuable) 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()); 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; 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) if (stacks != null)
{ {
for (ItemStack stack : stacks) for (ItemStack stack : stacks)
@ -250,11 +249,11 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
didPlace = didPlace && dumpToInv(stack) == stack.stackSize; didPlace = didPlace && dumpToInv(stack) == stack.stackSize;
} }
} }
mineBlock(valuable,blockID,blockMeta); mineBlock(valuable, block, blockMeta);
return didPlace; return didPlace;
} }
else if (blockID == Block.waterMoving || blockID == Block.waterStill) else if (block.isAssociatedBlock(Blocks.water))
// Evaporate 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.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()); worldObj.setBlockToAir(valuable.intX(), valuable.intY(), valuable.intZ());
return true; return true;
@ -363,7 +362,7 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
for(int i=0;i<6;i++) 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) if (result != null && result instanceof TileEntityParticleBooster)
{ {

View file

@ -2,13 +2,14 @@ package cr0s.warpdrive.machines;
import java.util.LinkedList; import java.util.LinkedList;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import cr0s.warpdrive.data.Vector3;
import cr0s.warpdrive.WarpDrive; import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.WarpDriveConfig; 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.lua.ILuaContext;
import dan200.computercraft.api.peripheral.IComputerAccess;
public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner { public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
Boolean active = false; Boolean active = false;
@ -36,14 +37,14 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
super(); super();
peripheralName = "treefarmLaser"; peripheralName = "treefarmLaser";
methodsArray = new String[] { methodsArray = new String[] {
"start", "start",
"stop", "stop",
"area", "area",
"leaves", "leaves",
"silkTouch", "silkTouch",
"silkTouchLeaves", "silkTouchLeaves",
"treetap", "treetap",
"state" "state"
}; };
} }
@ -70,16 +71,16 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
return; return;
} }
Vector3 pos = logs.get(logIndex); 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) { if (mode == 1) {
int cost = calculateBlockCost(blockID); int cost = calculateBlockCost(block);
if (consumeEnergyFromBooster(cost, true)) { if (consumeEnergyFromBooster(cost, true)) {
if (isLog(blockID) || (doLeaves && isLeaf(blockID))) { if (isLog(block) || (doLeaves && isLeaf(block))) {
delayMul = 1; delayMul = 1;
if (isRoomForHarvest()) { if (isRoomForHarvest()) {
if (consumeEnergyFromBooster(cost, false)) { if (consumeEnergyFromBooster(cost, false)) {
if (isLog(blockID)) { if (isLog(block)) {
delayMul = 4; delayMul = 4;
totalHarvested++; totalHarvested++;
} }
@ -94,10 +95,10 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
logIndex++; logIndex++;
} }
} else if(mode == 2) { } else if(mode == 2) {
int cost = calculateBlockCost(blockID); int cost = calculateBlockCost(block);
if (consumeEnergyFromBooster(cost, true)) { if (consumeEnergyFromBooster(cost, true)) {
if (isRoomForHarvest()) { 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()); int metadata = worldObj.getBlockMetadata(pos.intX(), pos.intY(), pos.intZ());
if (metadata >= 2 && metadata <= 5) { if (metadata >= 2 && metadata <= 5) {
WarpDrive.debugPrint("wetspot found"); WarpDrive.debugPrint("wetspot found");
@ -115,7 +116,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
} else { } else {
delayMul = 1; delayMul = 1;
} }
} else if(isLog(blockID)) { } else if (isLog(block)) {
if (consumeEnergyFromBooster(cost, false)) { if (consumeEnergyFromBooster(cost, false)) {
delayMul = 4; delayMul = 4;
totalHarvested++; totalHarvested++;
@ -123,7 +124,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
} else { } else {
return; return;
} }
} else if(isLeaf(blockID)) { } else if (isLeaf(block)) {
if (consumeEnergyFromBooster(cost, true)) { if (consumeEnergyFromBooster(cost, true)) {
delayMul = 1; delayMul = 1;
harvestBlock(pos); harvestBlock(pos);
@ -142,12 +143,12 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
} }
} }
private static boolean isLog(int blockID) { private static boolean isLog(Block block) {
return WarpDriveConfig.minerLogs.contains(blockID); return WarpDriveConfig.minerLogs.contains(block);
} }
private static boolean isLeaf(int blockID) { private static boolean isLeaf(Block block) {
return WarpDriveConfig.minerLeaves.contains(blockID); return WarpDriveConfig.minerLeaves.contains(block);
} }
private static void addTree(LinkedList<Vector3> list, Vector3 newTree) { 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 x = xmin; x <= xmax; x++) {
for(int z = zmin; z <= zmax; z++) { for(int z = zmin; z <= zmax; z++) {
int blockID = worldObj.getBlockId(x, yCoord, z); Block block = worldObj.getBlock(x, yCoord, z);
if (isLog(blockID)) { if (isLog(block)) {
Vector3 pos = new Vector3(x, yCoord, z); Vector3 pos = new Vector3(x, yCoord, z);
logPositions.add(pos); logPositions.add(pos);
scanNearby(logPositions, x, yCoord, z, 0); scanNearby(logPositions, x, yCoord, z, 0);
@ -188,8 +189,8 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
for(int dx : deltas) { for(int dx : deltas) {
for(int dy = 1; dy >= 0; dy--) { for(int dy = 1; dy >= 0; dy--) {
for(int dz : deltas) { for(int dz : deltas) {
int blockID = worldObj.getBlockId(x+dx, y+dy, z+dz); Block block = worldObj.getBlock(x + dx, y + dy, z + dz);
if (isLog(blockID) || (doLeaves && isLeaf(blockID))) { if (isLog(block) || (doLeaves && isLeaf(block))) {
Vector3 pos = new Vector3(x + dx, y + dy, z + dz); Vector3 pos = new Vector3(x + dx, y + dy, z + dz);
if (!current.contains(pos)) { if (!current.contains(pos)) {
addTree(current, pos); addTree(current, pos);
@ -237,7 +238,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
// ComputerCraft IPeripheral methods implementation // ComputerCraft IPeripheral methods implementation
@Override @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]; String methodName = methodsArray[method];
if (methodName.equals("start")) { if (methodName.equals("start")) {
if (!active) { if (!active) {
@ -306,8 +307,8 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
//ABSTRACT LASER IMPLEMENTATION //ABSTRACT LASER IMPLEMENTATION
@Override @Override
protected boolean silkTouch(int blockID) { protected boolean silkTouch(Block block) {
if (isLeaf(blockID)) { if (isLeaf(block)) {
return silkTouchLeaves; return silkTouchLeaves;
} }
return silkTouch(); return silkTouch();
@ -347,4 +348,16 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
protected float getColorB() { protected float getColorB() {
return 0.4f; 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;
}
} }