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,39 +13,45 @@ 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;
|
||||
private int fortuneLevel = 0;
|
||||
|
||||
|
||||
private TileEntityParticleBooster booster = null;
|
||||
private Vector3 minerVector;
|
||||
|
||||
|
||||
Boolean powerStatus = false;
|
||||
private IGridInterface grid;
|
||||
private IGrid grid;
|
||||
private boolean isMEReady = false;
|
||||
|
||||
|
||||
abstract boolean canSilkTouch();
|
||||
abstract int minFortune();
|
||||
abstract int maxFortune();
|
||||
abstract double laserBelow();
|
||||
|
||||
|
||||
abstract float getColorR();
|
||||
abstract float getColorG();
|
||||
abstract float getColorB();
|
||||
|
||||
|
||||
public TileEntityAbstractMiner()
|
||||
{
|
||||
super();
|
||||
fixMinerVector();
|
||||
}
|
||||
|
||||
|
||||
private void fixMinerVector()
|
||||
{
|
||||
if(minerVector == null)
|
||||
|
@ -63,70 +61,71 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
minerVector.z = zCoord;
|
||||
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()
|
||||
{
|
||||
return worldObj.provider.dimensionId == 0;
|
||||
}
|
||||
|
||||
|
||||
private IInventory findChest() {
|
||||
TileEntity result = null;
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
//GETTERSETTERS
|
||||
|
||||
|
||||
protected int fortune()
|
||||
{
|
||||
return fortuneLevel;
|
||||
}
|
||||
|
||||
|
||||
protected boolean silkTouch()
|
||||
{
|
||||
return silkTouch;
|
||||
}
|
||||
|
||||
|
||||
protected boolean silkTouch(int blockID)
|
||||
{
|
||||
return silkTouch();
|
||||
}
|
||||
|
||||
|
||||
protected boolean silkTouch(boolean b)
|
||||
{
|
||||
silkTouch = canSilkTouch() && b;
|
||||
return silkTouch();
|
||||
}
|
||||
|
||||
|
||||
protected boolean silkTouch(Object o)
|
||||
{
|
||||
return silkTouch(toBool(o));
|
||||
}
|
||||
|
||||
|
||||
protected int fortune(int f)
|
||||
{
|
||||
try
|
||||
|
@ -139,14 +138,14 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
}
|
||||
return fortune();
|
||||
}
|
||||
|
||||
|
||||
protected TileEntityParticleBooster booster()
|
||||
{
|
||||
if(booster == null)
|
||||
findFirstBooster();
|
||||
return booster;
|
||||
}
|
||||
|
||||
|
||||
protected int energy() {
|
||||
TileEntityParticleBooster te = booster();
|
||||
if (te != null) {
|
||||
|
@ -154,32 +153,32 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
//DATA RET
|
||||
|
||||
|
||||
protected int calculateLayerCost()
|
||||
{
|
||||
return isOnEarth() ? WarpDriveConfig.ML_EU_PER_LAYER_EARTH : WarpDriveConfig.ML_EU_PER_LAYER_SPACE;
|
||||
}
|
||||
|
||||
|
||||
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())));
|
||||
}
|
||||
|
||||
|
||||
protected boolean isRoomForHarvest()
|
||||
{
|
||||
if(isMEReady && grid != null)
|
||||
return true;
|
||||
|
||||
|
||||
IInventory inv = findChest();
|
||||
if(inv != null)
|
||||
{
|
||||
|
@ -191,33 +190,33 @@ 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;
|
||||
}
|
||||
|
||||
|
||||
//MINING FUNCTIONS
|
||||
|
||||
|
||||
protected void laserBlock(Vector3 valuable)
|
||||
{
|
||||
fixMinerVector();
|
||||
|
@ -227,22 +226,22 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
PacketHandler.sendBeamPacket(worldObj, minerVector, valuable.clone().translate(0.5D), r, g, b, 2 * WarpDriveConfig.ML_MINE_DELAY_TICKS, 0, 50);
|
||||
//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,16 +249,16 @@ 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)
|
||||
// Evaporate water
|
||||
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());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
protected int dumpToInv(ItemStack item)
|
||||
{
|
||||
if (grid != null)
|
||||
|
@ -267,7 +266,7 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
else
|
||||
return putInChest(findChest(), item);
|
||||
}
|
||||
|
||||
|
||||
private int putInGrid(ItemStack itemStackSource)
|
||||
{
|
||||
int transferred = 0;
|
||||
|
@ -344,7 +343,7 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
|
||||
return transferred;
|
||||
}
|
||||
|
||||
|
||||
protected boolean consumeEnergyFromBooster(int requiredEnergy, boolean simulate)
|
||||
{
|
||||
TileEntityParticleBooster te = booster();
|
||||
|
@ -353,18 +352,18 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
private TileEntityParticleBooster findFirstBooster()
|
||||
{
|
||||
TileEntity result;
|
||||
int[] xPos = {1,-1,0,0,0,0};
|
||||
int[] yPos = {0,0,-1,1,0,0};
|
||||
int[] zPos = {0,0,0,0,-1,1};
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
booster = (TileEntityParticleBooster) result;
|
||||
|
@ -374,7 +373,7 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
booster = null;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
protected void defineMiningArea(int xSize,int zSize)
|
||||
{
|
||||
int xmax, zmax, x1, x2, z1, z2;
|
||||
|
@ -406,10 +405,10 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
zmin = z2;
|
||||
zmax = z1;
|
||||
}
|
||||
|
||||
|
||||
defineMiningArea(xmin,zmin,xmax,zmax);
|
||||
}
|
||||
|
||||
|
||||
protected void defineMiningArea(int minX, int minZ, int maxX, int maxZ)
|
||||
{
|
||||
if(worldObj == null)
|
||||
|
@ -426,14 +425,14 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
maxChunk = b;
|
||||
refreshLoading(true);
|
||||
}
|
||||
|
||||
|
||||
private static ItemStack copyWithSize(ItemStack itemStack, int newSize)
|
||||
{
|
||||
ItemStack ret = itemStack.copy();
|
||||
ret.stackSize = newSize;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
//NBT DATA
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag)
|
||||
|
@ -441,13 +440,13 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
super.readFromNBT(tag);
|
||||
silkTouch = tag.getBoolean("silkTouch");
|
||||
fortuneLevel = tag.getInteger("fortuneLevel");
|
||||
|
||||
|
||||
minerVector.x = xCoord;
|
||||
minerVector.y = yCoord - (laserBelow());
|
||||
minerVector.z = zCoord;
|
||||
minerVector = minerVector.translate(0.5);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag)
|
||||
{
|
||||
|
@ -455,20 +454,20 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
tag.setBoolean("silkTouch", silkTouch);
|
||||
tag.setInteger("fortuneLevel", fortuneLevel);
|
||||
}
|
||||
|
||||
|
||||
//AE INTERFACE
|
||||
@Override
|
||||
public void setNetworkReady( boolean isReady )
|
||||
{
|
||||
isMEReady = isReady;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean isMachineActive()
|
||||
{
|
||||
return isMEReady;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public float getPowerDrainPerTick()
|
||||
{
|
||||
|
@ -512,7 +511,7 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
{
|
||||
return powerStatus;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public IGridInterface getGrid()
|
||||
{
|
||||
|
@ -524,7 +523,7 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
{
|
||||
grid = gi;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean coveredConnections()
|
||||
{
|
||||
|
@ -536,5 +535,5 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser im
|
|||
{
|
||||
return worldObj;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -2,55 +2,56 @@ 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;
|
||||
|
||||
|
||||
private int mode = 0;
|
||||
private boolean doLeaves = false;
|
||||
private boolean silkTouchLeaves = false;
|
||||
private boolean treeTap = false;
|
||||
|
||||
|
||||
private final int defSize = 8;
|
||||
private final int scanWait = 40;
|
||||
private final int mineWait = 4;
|
||||
private int delayMul = 4;
|
||||
|
||||
|
||||
private int totalHarvested=0;
|
||||
|
||||
|
||||
private int scan = 0;
|
||||
private int xSize = defSize;
|
||||
private int zSize = defSize;
|
||||
|
||||
|
||||
LinkedList<Vector3> logs;
|
||||
private int logIndex = 0;
|
||||
|
||||
|
||||
public TileEntityLaserTreeFarm() {
|
||||
super();
|
||||
peripheralName = "treefarmLaser";
|
||||
methodsArray = new String[] {
|
||||
"start",
|
||||
"stop",
|
||||
"area",
|
||||
"leaves",
|
||||
"silkTouch",
|
||||
"silkTouchLeaves",
|
||||
"treetap",
|
||||
"state"
|
||||
"start",
|
||||
"stop",
|
||||
"area",
|
||||
"leaves",
|
||||
"silkTouch",
|
||||
"silkTouchLeaves",
|
||||
"treetap",
|
||||
"state"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
|
||||
if (active) {
|
||||
scan++;
|
||||
if (mode == 0) {
|
||||
|
@ -64,22 +65,22 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
} else {
|
||||
if (scan >= mineWait * delayMul) {
|
||||
scan = 0;
|
||||
|
||||
|
||||
if (logIndex >= logs.size()) {
|
||||
mode = 0;
|
||||
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);
|
||||
|
@ -141,20 +142,20 @@ 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) {
|
||||
WarpDrive.debugPrint("Adding tree position:" + newTree.x + "," + newTree.y + "," + newTree.z);
|
||||
list.add(newTree);
|
||||
}
|
||||
|
||||
|
||||
private LinkedList<Vector3> scanTrees() {
|
||||
int xmax, zmax, x1, x2, z1, z2;
|
||||
int xmin, zmin;
|
||||
|
@ -167,13 +168,13 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
z2 = zCoord - zSize / 2;
|
||||
zmin = Math.min(z1, z2);
|
||||
zmax = Math.max(z1, z2);
|
||||
|
||||
|
||||
LinkedList<Vector3> logPositions = new LinkedList<Vector3>();
|
||||
|
||||
|
||||
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);
|
||||
|
@ -182,14 +183,14 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
}
|
||||
return logPositions;
|
||||
}
|
||||
|
||||
|
||||
private void scanNearby(LinkedList<Vector3> current, int x, int y, int z, int d) {
|
||||
int[] deltas = {0, -1, 1};
|
||||
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);
|
||||
|
@ -198,11 +199,11 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
|
@ -213,20 +214,20 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
tag.setBoolean("treetap", treeTap);
|
||||
tag.setBoolean("silkTouchLeaves", silkTouchLeaves);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
xSize = tag.getInteger("xSize");
|
||||
zSize = tag.getInteger("zSize");
|
||||
defineMiningArea(xSize,zSize);
|
||||
|
||||
|
||||
doLeaves = tag.getBoolean("doLeaves");
|
||||
active = tag.getBoolean("active");
|
||||
treeTap = tag.getBoolean("treetap");
|
||||
silkTouchLeaves = tag.getBoolean("silkTouchLeaves");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean shouldChunkLoad() {
|
||||
return active;
|
||||
|
@ -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) {
|
||||
|
@ -269,7 +270,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
doLeaves = toBool(arguments[0]);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
|
||||
|
||||
}
|
||||
return new Boolean[] { doLeaves };
|
||||
} else if (methodName.equals("silkTouch")) {
|
||||
|
@ -306,13 +307,13 @@ 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();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected boolean canSilkTouch() {
|
||||
return true;
|
||||
|
@ -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