Refactored laser tree farm and mining laser
Fixed layerOffset lost when reloading chunk/world Fixed quarry mining with random warmup Added guide message to laser tree farm Fixed tree farm exceptions on chunkloading Added planting to tree farm (not functional yet) Improved tree farm support for tightly packed trees Fixed tree farm support for IC2 rubber trees Updated mining laser API to be more 'state' oriented Improved tapping mode by breaking the normal rubber logs Updated tree farm scanning area to be above instead of same level Added tree farm scanning area visualisation
This commit is contained in:
parent
0541f2d678
commit
e10c56bb1f
5 changed files with 907 additions and 768 deletions
|
@ -1,7 +1,16 @@
|
|||
package cr0s.warpdrive.block;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.api.IBlockUpdateDetector;
|
||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public abstract class TileEntityAbstractBase extends TileEntity implements IBlockUpdateDetector {
|
||||
|
||||
|
@ -9,6 +18,119 @@ public abstract class TileEntityAbstractBase extends TileEntity implements IBloc
|
|||
public void updatedNeighbours() {
|
||||
}
|
||||
|
||||
protected boolean isOnEarth() {
|
||||
return worldObj.provider.dimensionId == 0;
|
||||
}
|
||||
|
||||
protected void updateMetadata(int metadata) {
|
||||
if (getBlockMetadata() != metadata) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, metadata, 2);
|
||||
}
|
||||
}
|
||||
|
||||
// Inventory management methods
|
||||
|
||||
public static ItemStack copyWithSize(ItemStack itemStack, int newSize) {
|
||||
ItemStack ret = itemStack.copy();
|
||||
ret.stackSize = newSize;
|
||||
return ret;
|
||||
}
|
||||
|
||||
protected IInventory getFirstConnectedInventory() {
|
||||
TileEntity result = null;
|
||||
|
||||
for(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
|
||||
result = worldObj.getTileEntity(xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ);
|
||||
if (result != null && (result instanceof IInventory)) {
|
||||
return (IInventory) result;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected boolean addToConnectedInventory(ItemStack itemStack) {
|
||||
List<ItemStack> stacks = new ArrayList<ItemStack>(1);
|
||||
stacks.add(itemStack);
|
||||
return addToConnectedInventory(stacks);
|
||||
}
|
||||
|
||||
protected boolean addToConnectedInventory(List<ItemStack> stacks) {
|
||||
boolean overflow = false;
|
||||
if (stacks != null) {
|
||||
int qtyLeft = 0;
|
||||
for (ItemStack stack : stacks) {
|
||||
qtyLeft = addToInventory(getFirstConnectedInventory(), stack);
|
||||
if (qtyLeft > 0) {
|
||||
if (WarpDriveConfig.LOGGING_COLLECTION) {
|
||||
WarpDrive.logger.info(this + " Overflow detected");
|
||||
}
|
||||
overflow = true;
|
||||
int transfer;
|
||||
while (qtyLeft > 0) {
|
||||
transfer = Math.min(qtyLeft, stack.getMaxStackSize());
|
||||
ItemStack dropItemStack = copyWithSize(stack, transfer);
|
||||
EntityItem itemEnt = new EntityItem(worldObj, xCoord + 0.5D, yCoord + 1.0D, zCoord + 0.5D, dropItemStack);
|
||||
worldObj.spawnEntityInWorld(itemEnt);
|
||||
qtyLeft -= transfer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return overflow;
|
||||
}
|
||||
|
||||
private int addToInventory(IInventory inventory, ItemStack itemStackSource) {
|
||||
if (itemStackSource == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int qtyLeft = itemStackSource.stackSize;
|
||||
int transfer;
|
||||
|
||||
if (inventory != null) {
|
||||
// fill existing stacks first
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
||||
if (!inventory.isItemValidForSlot(i, itemStackSource)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack itemStack = inventory.getStackInSlot(i);
|
||||
if (itemStack == null || !itemStack.isItemEqual(itemStackSource)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
transfer = Math.min(qtyLeft, itemStack.getMaxStackSize() - itemStack.stackSize);
|
||||
itemStack.stackSize += transfer;
|
||||
qtyLeft -= transfer;
|
||||
if (qtyLeft <= 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// put remaining in empty slot
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
||||
if (!inventory.isItemValidForSlot(i, itemStackSource)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack itemStack = inventory.getStackInSlot(i);
|
||||
if (itemStack != null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
transfer = Math.min(qtyLeft, itemStackSource.getMaxStackSize());
|
||||
ItemStack dest = copyWithSize(itemStackSource, transfer);
|
||||
inventory.setInventorySlotContents(i, dest);
|
||||
qtyLeft -= transfer;
|
||||
|
||||
if (qtyLeft <= 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return qtyLeft;
|
||||
}
|
||||
|
||||
protected static int toInt(double d) {
|
||||
return (int) Math.round(d);
|
||||
|
|
|
@ -2,10 +2,12 @@ package cr0s.warpdrive.block.collection;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
|
@ -15,11 +17,14 @@ import cr0s.warpdrive.WarpDrive;
|
|||
public class BlockLaserTreeFarm extends BlockContainer {
|
||||
private IIcon[] iconBuffer;
|
||||
public final static int ICON_IDLE = 0;
|
||||
public final static int ICON_FARNINGLOWPOWER = 1;
|
||||
public final static int ICON_FARMINGLOWPOWER = 1;
|
||||
public final static int ICON_FARMINGPOWERED = 2;
|
||||
// 3 & 4 are reserved
|
||||
private final static int ICON_BOTTOM = 5;
|
||||
private final static int ICON_TOP = 6;
|
||||
public final static int ICON_SCANNINGLOWPOWER = 3;
|
||||
public final static int ICON_SCANNINGPOWERED = 4;
|
||||
public final static int ICON_PLANTINGLOWPOWER = 5;
|
||||
public final static int ICON_PLANTINGPOWERED = 6;
|
||||
private final static int ICON_BOTTOM = 7;
|
||||
private final static int ICON_TOP = 8;
|
||||
|
||||
public BlockLaserTreeFarm() {
|
||||
super(Material.rock);
|
||||
|
@ -33,8 +38,12 @@ public class BlockLaserTreeFarm extends BlockContainer {
|
|||
public void registerBlockIcons(IIconRegister par1IconRegister) {
|
||||
iconBuffer = new IIcon[16];
|
||||
iconBuffer[ICON_IDLE ] = par1IconRegister.registerIcon("warpdrive:collection/laserTreeFarmSide_idle");
|
||||
iconBuffer[ICON_FARNINGLOWPOWER ] = par1IconRegister.registerIcon("warpdrive:collection/laserTreeFarmSide_farmingLowPower");
|
||||
iconBuffer[ICON_FARMINGLOWPOWER ] = par1IconRegister.registerIcon("warpdrive:collection/laserTreeFarmSide_farmingLowPower");
|
||||
iconBuffer[ICON_FARMINGPOWERED ] = par1IconRegister.registerIcon("warpdrive:collection/laserTreeFarmSide_farmingPowered");
|
||||
iconBuffer[ICON_SCANNINGLOWPOWER] = par1IconRegister.registerIcon("warpdrive:collection/laserTreeFarmSide_scanningLowPower");
|
||||
iconBuffer[ICON_SCANNINGPOWERED ] = par1IconRegister.registerIcon("warpdrive:collection/laserTreeFarmSide_scanningPowered");
|
||||
iconBuffer[ICON_PLANTINGLOWPOWER] = par1IconRegister.registerIcon("warpdrive:collection/laserTreeFarmSide_plantingLowPower");
|
||||
iconBuffer[ICON_PLANTINGPOWERED ] = par1IconRegister.registerIcon("warpdrive:collection/laserTreeFarmSide_plantingPowered");
|
||||
iconBuffer[ICON_BOTTOM ] = par1IconRegister.registerIcon("warpdrive:collection/laserTreeFarmBottom");
|
||||
iconBuffer[ICON_TOP ] = par1IconRegister.registerIcon("warpdrive:collection/laserTreeFarmTop");
|
||||
}
|
||||
|
@ -54,12 +63,12 @@ public class BlockLaserTreeFarm extends BlockContainer {
|
|||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World var1, int i) {
|
||||
public TileEntity createNewTileEntity(World world, int i) {
|
||||
return new TileEntityLaserTreeFarm();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int quantityDropped(Random par1Random) {
|
||||
public int quantityDropped(Random random) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
@ -67,7 +76,23 @@ public class BlockLaserTreeFarm extends BlockContainer {
|
|||
* Returns the item to drop on destruction.
|
||||
*/
|
||||
@Override
|
||||
public Item getItemDropped(int par1, Random par2Random, int par3) {
|
||||
public Item getItemDropped(int par1, Random random, int par3) {
|
||||
return Item.getItemFromBlock(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) {
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TileEntityLaserTreeFarm treeFarm = (TileEntityLaserTreeFarm)world.getTileEntity(x, y, z);
|
||||
|
||||
if (treeFarm != null && (entityPlayer.getHeldItem() == null)) {
|
||||
WarpDrive.addChatMessage(entityPlayer, treeFarm.getStatus());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -2,39 +2,28 @@ package cr0s.warpdrive.block.collection;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.IFluidBlock;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.block.TileEntityAbstractLaser;
|
||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||
import cr0s.warpdrive.data.Vector3;
|
||||
import cr0s.warpdrive.data.VectorI;
|
||||
import cr0s.warpdrive.network.PacketHandler;
|
||||
|
||||
public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser
|
||||
{
|
||||
//FOR STORAGE
|
||||
private boolean silkTouch = false;
|
||||
private int fortuneLevel = 0;
|
||||
|
||||
private Vector3 laserOutput;
|
||||
|
||||
abstract boolean canSilkTouch();
|
||||
abstract int minFortune();
|
||||
abstract int maxFortune();
|
||||
ForgeDirection laserOutputSide = ForgeDirection.UP;
|
||||
|
||||
abstract float getColorR();
|
||||
abstract float getColorG();
|
||||
abstract float getColorB();
|
||||
|
||||
public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser {
|
||||
// machine type
|
||||
protected ForgeDirection laserOutputSide = ForgeDirection.NORTH;
|
||||
|
||||
// machine state
|
||||
protected boolean enableSilktouch = false;
|
||||
|
||||
// pre-computation
|
||||
protected Vector3 laserOutput = null;
|
||||
|
||||
public TileEntityAbstractMiner() {
|
||||
super();
|
||||
}
|
||||
|
@ -44,251 +33,67 @@ public abstract class TileEntityAbstractMiner extends TileEntityAbstractLaser
|
|||
super.validate();
|
||||
laserOutput = new Vector3(this).translate(0.5D).translate(laserOutputSide, 0.5D);
|
||||
}
|
||||
|
||||
private List<ItemStack> getItemStackFromBlock(int i, int j, int k, Block block, int blockMeta)
|
||||
{
|
||||
if (block == null)
|
||||
return null;
|
||||
|
||||
ArrayList<ItemStack> t = new ArrayList<ItemStack>();
|
||||
if (silkTouch(block))
|
||||
{
|
||||
if (block.canSilkHarvest(worldObj, null, i, j, k, blockMeta))
|
||||
{
|
||||
t.add(new ItemStack(block, 1, blockMeta));
|
||||
return t;
|
||||
}
|
||||
|
||||
protected void stop() {
|
||||
if (WarpDriveConfig.LOGGING_COLLECTION) {
|
||||
WarpDrive.logger.info(this + " Stop requested");
|
||||
}
|
||||
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(ForgeDirection side : ForgeDirection.VALID_DIRECTIONS) {
|
||||
result = worldObj.getTileEntity(xCoord + side.offsetX, yCoord + side.offsetY, zCoord + side.offsetZ);
|
||||
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(Block block)
|
||||
{
|
||||
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 level)
|
||||
{
|
||||
try
|
||||
{
|
||||
fortuneLevel = clamp(minFortune(), maxFortune(), level);
|
||||
}
|
||||
catch(NumberFormatException e)
|
||||
{
|
||||
fortuneLevel = minFortune();
|
||||
}
|
||||
return fortune();
|
||||
}
|
||||
|
||||
//DATA RET
|
||||
|
||||
protected int calculateLayerCost()
|
||||
{
|
||||
return isOnEarth() ? WarpDriveConfig.MINING_LASER_PLANET_ENERGY_PER_LAYER : WarpDriveConfig.MINING_LASER_SPACE_ENERGY_PER_LAYER;
|
||||
}
|
||||
|
||||
protected int calculateBlockCost()
|
||||
{
|
||||
return calculateBlockCost(Blocks.air);
|
||||
}
|
||||
|
||||
protected int calculateBlockCost(Block block)
|
||||
{
|
||||
int enPerBlock = isOnEarth() ? WarpDriveConfig.MINING_LASER_PLANET_ENERGY_PER_BLOCK : WarpDriveConfig.MINING_LASER_SPACE_ENERGY_PER_BLOCK;
|
||||
if (silkTouch(block))
|
||||
return (int) Math.round(enPerBlock * WarpDriveConfig.MINING_LASER_SILKTOUCH_ENERGY_FACTOR);
|
||||
return (int) Math.round(enPerBlock * (Math.pow(WarpDriveConfig.MINING_LASER_FORTUNE_ENERGY_FACTOR, fortune())));
|
||||
}
|
||||
|
||||
protected boolean isRoomForHarvest()
|
||||
{
|
||||
IInventory inv = findChest();
|
||||
if(inv != null)
|
||||
{
|
||||
int size = inv.getSizeInventory();
|
||||
for(int i=0;i<size;i++)
|
||||
if(inv.getStackInSlot(i) == null)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean canDig(Block block, int x, int y, int z) {// not used, should be abstract
|
||||
return false;
|
||||
}
|
||||
|
||||
//MINING FUNCTIONS
|
||||
|
||||
protected void laserBlock(VectorI valuable)
|
||||
{
|
||||
float r = getColorR();
|
||||
float g = getColorG();
|
||||
float b = getColorB();
|
||||
PacketHandler.sendBeamPacket(worldObj, laserOutput, valuable.getBlockCenter(), r, g, b, 2 * WarpDriveConfig.MINING_LASER_MINE_DELAY_TICKS, 0, 50);
|
||||
//worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F);
|
||||
}
|
||||
|
||||
private void mineBlock(VectorI valuable, Block block, int blockMeta)
|
||||
{
|
||||
laserBlock(valuable);
|
||||
worldObj.playAuxSFXAtEntity(null, 2001, valuable.x, valuable.y, valuable.z, (blockMeta << 12));
|
||||
worldObj.setBlockToAir(valuable.x, valuable.y, valuable.z);
|
||||
}
|
||||
|
||||
protected boolean harvestBlock(VectorI valuable)
|
||||
{
|
||||
|
||||
protected void harvestBlock(VectorI valuable) {
|
||||
Block block = worldObj.getBlock(valuable.x, valuable.y, valuable.z);
|
||||
int blockMeta = worldObj.getBlockMetadata(valuable.x, valuable.y, valuable.z);
|
||||
if (!block.isAssociatedBlock(Blocks.water) && !block.isAssociatedBlock(Blocks.lava))
|
||||
{
|
||||
boolean didPlace = true;
|
||||
if (block != null && (block instanceof BlockLiquid)) {
|
||||
// Evaporate fluid
|
||||
worldObj.playSoundEffect(valuable.x + 0.5D, valuable.y + 0.5D, valuable.z + 0.5D, "random.fizz", 0.5F,
|
||||
2.6F + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) * 0.8F);
|
||||
} else {
|
||||
List<ItemStack> stacks = getItemStackFromBlock(valuable.x, valuable.y, valuable.z, block, blockMeta);
|
||||
if (stacks != null)
|
||||
{
|
||||
for (ItemStack stack : stacks)
|
||||
{
|
||||
didPlace = didPlace && dumpToInv(stack) == stack.stackSize;
|
||||
}
|
||||
if (addToConnectedInventory(stacks)) {
|
||||
stop();
|
||||
}
|
||||
mineBlock(valuable, block, blockMeta);
|
||||
return didPlace;
|
||||
}
|
||||
else if (block.isAssociatedBlock(Blocks.water)) {
|
||||
// Evaporate water
|
||||
worldObj.playSoundEffect(valuable.x + 0.5D, valuable.y + 0.5D, valuable.z + 0.5D, "random.fizz", 0.5F, 2.6F + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) * 0.8F);
|
||||
// standard harvest block effect
|
||||
worldObj.playAuxSFXAtEntity(null, 2001, valuable.x, valuable.y, valuable.z, Block.getIdFromBlock(block) + (blockMeta << 12));
|
||||
}
|
||||
worldObj.setBlockToAir(valuable.x, valuable.y, valuable.z);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected int dumpToInv(ItemStack item)
|
||||
{
|
||||
return putInChest(findChest(), item);
|
||||
}
|
||||
|
||||
private static int putInChest(IInventory inventory, ItemStack itemStackSource)
|
||||
{
|
||||
if (inventory == null || itemStackSource == null)
|
||||
{
|
||||
return 0;
|
||||
|
||||
private List<ItemStack> getItemStackFromBlock(int i, int j, int k, Block block, int blockMeta) {
|
||||
if (block == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int transferred = 0;
|
||||
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
||||
{
|
||||
if (!inventory.isItemValidForSlot(i, itemStackSource))
|
||||
{
|
||||
continue;
|
||||
if (enableSilktouch) {
|
||||
boolean isSilkHarvestable = false;
|
||||
try {
|
||||
isSilkHarvestable = block.canSilkHarvest(worldObj, null, i, j, k, blockMeta);
|
||||
} catch (Exception exception) {// protect in case the mined block is corrupted
|
||||
exception.printStackTrace();
|
||||
}
|
||||
|
||||
ItemStack itemStack = inventory.getStackInSlot(i);
|
||||
|
||||
if (itemStack == null || !itemStack.isItemEqual(itemStackSource))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int transfer = Math.min(itemStackSource.stackSize - transferred, itemStack.getMaxStackSize() - itemStack.stackSize);
|
||||
itemStack.stackSize += transfer;
|
||||
transferred += transfer;
|
||||
|
||||
if (transferred == itemStackSource.stackSize)
|
||||
{
|
||||
return transferred;
|
||||
if (isSilkHarvestable) {
|
||||
ArrayList<ItemStack> isBlock = new ArrayList<ItemStack>();
|
||||
isBlock.add(new ItemStack(block, 1, blockMeta));
|
||||
return isBlock;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++)
|
||||
{
|
||||
if (!inventory.isItemValidForSlot(i, itemStackSource))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack itemStack = inventory.getStackInSlot(i);
|
||||
|
||||
if (itemStack != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
int transfer = Math.min(itemStackSource.stackSize - transferred, itemStackSource.getMaxStackSize());
|
||||
ItemStack dest = copyWithSize(itemStackSource, transfer);
|
||||
inventory.setInventorySlotContents(i, dest);
|
||||
transferred += transfer;
|
||||
|
||||
if (transferred == itemStackSource.stackSize)
|
||||
{
|
||||
return transferred;
|
||||
}
|
||||
|
||||
try {
|
||||
return block.getDrops(worldObj, i, j, k, blockMeta, 0);
|
||||
} catch (Exception exception) {// protect in case the mined block is corrupted
|
||||
exception.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
return transferred;
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
silkTouch = tag.getBoolean("silkTouch");
|
||||
fortuneLevel = tag.getInteger("fortuneLevel");
|
||||
enableSilktouch = tag.getBoolean("enableSilktouch");
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag)
|
||||
{
|
||||
public void writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
tag.setBoolean("silkTouch", silkTouch);
|
||||
tag.setInteger("fortuneLevel", fortuneLevel);
|
||||
tag.setBoolean("enableSilktouch", enableSilktouch);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,41 +2,78 @@ package cr0s.warpdrive.block.collection;
|
|||
|
||||
import java.util.LinkedList;
|
||||
|
||||
import li.cil.oc.api.machine.Arguments;
|
||||
import li.cil.oc.api.machine.Callback;
|
||||
import li.cil.oc.api.machine.Context;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.IGrowable;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.common.IPlantable;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||
import cr0s.warpdrive.data.Vector3;
|
||||
import cr0s.warpdrive.data.VectorI;
|
||||
import cr0s.warpdrive.network.PacketHandler;
|
||||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
|
||||
public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
||||
private boolean active = false;
|
||||
private boolean breakLeaves = false;
|
||||
private boolean tapTrees = false;
|
||||
|
||||
private final int MODE_SCANNING = 0;
|
||||
private final int MODE_HARVESTING = 1;
|
||||
private final int MODE_TAPPING = 2;
|
||||
private int mode = 0;
|
||||
private boolean doLeaves = false;
|
||||
private boolean silkTouchLeaves = false;
|
||||
private boolean treeTap = false;
|
||||
private boolean isFarming() {
|
||||
return currentState != STATE_IDLE;
|
||||
}
|
||||
private final int STATE_IDLE = 0;
|
||||
private final int STATE_WARMUP = 1;
|
||||
private final int STATE_SCAN = 2;
|
||||
private final int STATE_HARVEST = 3;
|
||||
private final int STATE_TAP = 4;
|
||||
private final int STATE_PLANT = 5;
|
||||
private int currentState = STATE_IDLE;
|
||||
|
||||
private final int radiusDefault = 8;
|
||||
private final int scanWait = 40;
|
||||
private final int mineWait = 4;
|
||||
private int delayMul = 4;
|
||||
private boolean enoughPower = false;
|
||||
|
||||
private final int TREE_FARM_MAX_MEDIUMS_COUNT = 1;
|
||||
private final int TREE_FARM_MAX_LOG_DISTANCE = 200;
|
||||
|
||||
private final int TREE_FARM_WARMUP_DELAY_TICKS = 40;
|
||||
private final int TREE_FARM_SCAN_DELAY_TICKS = 40;
|
||||
private final int TREE_FARM_HARVEST_LOG_DELAY_TICKS = 4;
|
||||
private final int TREE_FARM_BREAK_LEAF_DELAY_TICKS = 4;
|
||||
private final int TREE_FARM_SILKTOUCH_LEAF_DELAY_TICKS = 4;
|
||||
private final int TREE_FARM_TAP_TREE_WET_DELAY_TICKS = 4;
|
||||
private final int TREE_FARM_TAP_TREE_DRY_DELAY_TICKS = 1;
|
||||
private final int TREE_FARM_PLANT_DELAY_TICKS = 1;
|
||||
private final int TREE_FARM_LOWPOWER_DELAY_TICKS = 40;
|
||||
|
||||
private final int TREE_FARM_ENERGY_PER_SURFACE = 1;
|
||||
private final int TREE_FARM_ENERGY_PER_WET_SPOT = 1;
|
||||
private final double TREE_FARM_ENERGY_PER_LOG = 1;
|
||||
private final double TREE_FARM_ENERGY_PER_LEAF = 1;
|
||||
private final double TREE_FARM_SILKTOUCH_ENERGY_FACTOR = 2.0D;
|
||||
private final int TREE_FARM_ENERGY_PER_SAPLING = 1;
|
||||
|
||||
private int delayTargetTicks = 0;
|
||||
|
||||
private int totalHarvested = 0;
|
||||
|
||||
private int scan = 0;
|
||||
private int radiusX = radiusDefault;
|
||||
private int radiusZ = radiusDefault;
|
||||
private boolean bScanOnReload = false;
|
||||
private int delayTicks = 0;
|
||||
|
||||
LinkedList<VectorI> logs;
|
||||
private int logIndex = 0;
|
||||
private final int RADIUS_DEFAULT = 8;
|
||||
private int radiusX = RADIUS_DEFAULT;
|
||||
private int radiusZ = RADIUS_DEFAULT;
|
||||
|
||||
LinkedList<VectorI> soils;
|
||||
private int soilIndex = 0;
|
||||
LinkedList<VectorI> valuables;
|
||||
private int valuableIndex = 0;
|
||||
|
||||
public TileEntityLaserTreeFarm() {
|
||||
super();
|
||||
|
@ -46,112 +83,317 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
"start",
|
||||
"stop",
|
||||
"radius",
|
||||
"leaves",
|
||||
"silkTouch",
|
||||
"silkTouchLeaves",
|
||||
"treetap",
|
||||
"state"
|
||||
"state",
|
||||
"breakLeaves",
|
||||
"silktouch",
|
||||
"tapTrees"
|
||||
});
|
||||
countMaxLaserMediums = TREE_FARM_MAX_MEDIUMS_COUNT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
||||
if (active) {
|
||||
scan++;
|
||||
if (mode == MODE_SCANNING) {
|
||||
if (scan >= scanWait) {
|
||||
scan = 0;
|
||||
logs = scanTrees();
|
||||
if (logs.size() > 0) {
|
||||
mode = treeTap ? MODE_TAPPING : MODE_HARVESTING;
|
||||
}
|
||||
logIndex = 0;
|
||||
if (FMLCommonHandler.instance().getEffectiveSide().isClient()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (bScanOnReload) {
|
||||
soils = scanSoils();
|
||||
valuables = scanTrees();
|
||||
bScanOnReload = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if (currentState == STATE_IDLE) {
|
||||
delayTicks = 0;
|
||||
delayTargetTicks = TREE_FARM_WARMUP_DELAY_TICKS;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_IDLE);
|
||||
return;
|
||||
}
|
||||
|
||||
delayTicks++;
|
||||
|
||||
// Scanning
|
||||
if (currentState == STATE_WARMUP) {
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_SCANNINGLOWPOWER);
|
||||
if (delayTicks >= delayTargetTicks) {
|
||||
delayTicks = 0;
|
||||
delayTargetTicks = TREE_FARM_SCAN_DELAY_TICKS;
|
||||
currentState = STATE_SCAN;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_SCANNINGLOWPOWER);
|
||||
return;
|
||||
}
|
||||
} else if (currentState == STATE_SCAN) {
|
||||
int energyCost = TREE_FARM_ENERGY_PER_SURFACE * (1 + 2 * radiusX) * (1 + 2 * radiusZ);
|
||||
if (delayTicks == 1) {
|
||||
if (WarpDriveConfig.LOGGING_COLLECTION) {
|
||||
WarpDrive.logger.debug("Scan pre-tick");
|
||||
}
|
||||
} else {
|
||||
if (scan >= mineWait * delayMul) {
|
||||
scan = 0;
|
||||
// check power level
|
||||
enoughPower = consumeEnergyFromLaserMediums(energyCost, true);
|
||||
if (!enoughPower) {
|
||||
currentState = STATE_WARMUP; // going back to warmup state to show the animation when it'll be back online
|
||||
delayTicks = 0;
|
||||
delayTargetTicks = TREE_FARM_LOWPOWER_DELAY_TICKS;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_SCANNINGLOWPOWER);
|
||||
return;
|
||||
} else {
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_SCANNINGPOWERED);
|
||||
}
|
||||
|
||||
// show current layer
|
||||
int age = Math.max(40, 2 * TREE_FARM_SCAN_DELAY_TICKS);
|
||||
double xmax = xCoord + radiusX + 1.0D;
|
||||
double xmin = xCoord - radiusX + 0.0D;
|
||||
double zmax = zCoord + radiusZ + 1.0D;
|
||||
double zmin = zCoord - radiusZ + 0.0D;
|
||||
double y = yCoord + worldObj.rand.nextInt(9);
|
||||
PacketHandler.sendBeamPacket(worldObj, new Vector3(xmin, y, zmin), new Vector3(xmax, y, zmin), 0.3F, 0.0F, 1.0F, age, 0, 50);
|
||||
PacketHandler.sendBeamPacket(worldObj, new Vector3(xmax, y, zmin), new Vector3(xmax, y, zmax), 0.3F, 0.0F, 1.0F, age, 0, 50);
|
||||
PacketHandler.sendBeamPacket(worldObj, new Vector3(xmax, y, zmax), new Vector3(xmin, y, zmax), 0.3F, 0.0F, 1.0F, age, 0, 50);
|
||||
PacketHandler.sendBeamPacket(worldObj, new Vector3(xmin, y, zmax), new Vector3(xmin, y, zmin), 0.3F, 0.0F, 1.0F, age, 0, 50);
|
||||
|
||||
} else if (delayTicks >= delayTargetTicks) {
|
||||
if (WarpDriveConfig.LOGGING_COLLECTION) {
|
||||
WarpDrive.logger.debug("Scan tick");
|
||||
}
|
||||
delayTicks = 0;
|
||||
|
||||
// consume power
|
||||
enoughPower = consumeEnergyFromLaserMediums(energyCost, false);
|
||||
if (!enoughPower) {
|
||||
delayTargetTicks = TREE_FARM_LOWPOWER_DELAY_TICKS;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_SCANNINGLOWPOWER);
|
||||
return;
|
||||
} else {
|
||||
delayTargetTicks = TREE_FARM_SCAN_DELAY_TICKS;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_SCANNINGPOWERED);
|
||||
}
|
||||
|
||||
// scan
|
||||
soils = scanSoils();
|
||||
soilIndex = 0;
|
||||
|
||||
valuables = scanTrees();
|
||||
valuableIndex = 0;
|
||||
if (valuables != null && valuables.size() > 0) {
|
||||
worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:hilaser", 4F, 1F);
|
||||
currentState = tapTrees ? STATE_TAP : STATE_HARVEST;
|
||||
delayTargetTicks = TREE_FARM_HARVEST_LOG_DELAY_TICKS;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_FARMINGPOWERED);
|
||||
return;
|
||||
|
||||
if (logIndex >= logs.size()) {
|
||||
mode = MODE_SCANNING;
|
||||
return;
|
||||
}
|
||||
VectorI pos = logs.get(logIndex);
|
||||
Block block = worldObj.getBlock(pos.x, pos.y, pos.z);
|
||||
} else if (soils != null && soils.size() > 0) {
|
||||
worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:hilaser", 4F, 1F);
|
||||
currentState = STATE_PLANT;
|
||||
delayTargetTicks = TREE_FARM_PLANT_DELAY_TICKS;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_PLANTINGPOWERED);
|
||||
return;
|
||||
|
||||
if (mode == MODE_HARVESTING) {
|
||||
int cost = calculateBlockCost(block);
|
||||
if (consumeEnergyFromLaserMediums(cost, true)) {
|
||||
if (isLog(block) || (doLeaves && isLeaf(block))) {
|
||||
delayMul = 1;
|
||||
if (isRoomForHarvest()) {
|
||||
if (consumeEnergyFromLaserMediums(cost, false)) {
|
||||
if (isLog(block)) {
|
||||
delayMul = 4;
|
||||
totalHarvested++;
|
||||
}
|
||||
harvestBlock(pos);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
logIndex++;
|
||||
}
|
||||
} else if (mode == MODE_TAPPING) {
|
||||
int cost = calculateBlockCost(block);
|
||||
if (consumeEnergyFromLaserMediums(cost, true)) {
|
||||
if (isRoomForHarvest()) {
|
||||
if (block.isAssociatedBlock(WarpDriveConfig.IC2_rubberWood)) {
|
||||
int metadata = worldObj.getBlockMetadata(pos.x, pos.y, pos.z);
|
||||
if (metadata >= 2 && metadata <= 5) {
|
||||
if (WarpDriveConfig.LOGGING_COLLECTION) {
|
||||
WarpDrive.logger.info("wetspot found");
|
||||
}
|
||||
if (consumeEnergyFromLaserMediums(cost, false)) {
|
||||
ItemStack resin = WarpDriveConfig.IC2_Resin.copy();
|
||||
resin.stackSize = (int) Math.round(Math.random() * 4);
|
||||
dumpToInv(resin);
|
||||
worldObj.setBlockMetadataWithNotify(pos.x, pos.y, pos.z, metadata + 6, 3);
|
||||
laserBlock(pos);
|
||||
totalHarvested++;
|
||||
delayMul = 4;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
delayMul = 1;
|
||||
}
|
||||
} else if (isLog(block)) {
|
||||
if (consumeEnergyFromLaserMediums(cost, false)) {
|
||||
delayMul = 4;
|
||||
totalHarvested++;
|
||||
harvestBlock(pos);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
} else if (isLeaf(block)) {
|
||||
if (consumeEnergyFromLaserMediums(cost, false)) {
|
||||
delayMul = 1;
|
||||
harvestBlock(pos);
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
logIndex++;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F);
|
||||
currentState = STATE_WARMUP;
|
||||
delayTargetTicks = TREE_FARM_WARMUP_DELAY_TICKS;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_SCANNINGLOWPOWER);
|
||||
}
|
||||
}
|
||||
} else if (currentState == STATE_HARVEST || currentState == STATE_TAP) {
|
||||
if (delayTicks >= delayTargetTicks) {
|
||||
if (WarpDriveConfig.LOGGING_COLLECTION) {
|
||||
WarpDrive.logger.debug("Harvest/tap tick");
|
||||
}
|
||||
delayTicks = 0;
|
||||
|
||||
// harvesting done => plant
|
||||
if (valuables == null || valuableIndex >= valuables.size()) {
|
||||
valuableIndex = 0;
|
||||
currentState = STATE_PLANT;
|
||||
delayTargetTicks = TREE_FARM_PLANT_DELAY_TICKS;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_PLANTINGPOWERED);
|
||||
return;
|
||||
}
|
||||
|
||||
// get current block
|
||||
VectorI valuable = valuables.get(valuableIndex);
|
||||
Block block = worldObj.getBlock(valuable.x, valuable.y, valuable.z);
|
||||
valuableIndex++;
|
||||
boolean isLog = isLog(block);
|
||||
boolean isLeaf = isLeaf(block);
|
||||
|
||||
// save the rubber producing blocks in tapping mode
|
||||
if (currentState == STATE_TAP) {
|
||||
if (block.isAssociatedBlock(WarpDriveConfig.IC2_rubberWood)) {
|
||||
int metadata = worldObj.getBlockMetadata(valuable.x, valuable.y, valuable.z);
|
||||
if (metadata >= 2 && metadata <= 5) {
|
||||
if (WarpDriveConfig.LOGGING_COLLECTION) {
|
||||
WarpDrive.logger.debug("Tap found rubber wood wetspot at " + valuable + " with metadata " + metadata);
|
||||
}
|
||||
|
||||
// consume power
|
||||
int energyCost = TREE_FARM_ENERGY_PER_WET_SPOT;
|
||||
enoughPower = consumeEnergyFromLaserMediums(energyCost, false);
|
||||
if (!enoughPower) {
|
||||
delayTargetTicks = TREE_FARM_LOWPOWER_DELAY_TICKS;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_FARMINGLOWPOWER);
|
||||
return;
|
||||
} else {
|
||||
delayTargetTicks = TREE_FARM_TAP_TREE_WET_DELAY_TICKS;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_FARMINGPOWERED);
|
||||
}
|
||||
|
||||
ItemStack resin = WarpDriveConfig.IC2_Resin.copy();
|
||||
resin.stackSize = (int) Math.round(Math.random() * 4);
|
||||
if (addToConnectedInventory(resin)) {
|
||||
stop();
|
||||
}
|
||||
totalHarvested += resin.stackSize;
|
||||
int age = Math.max(10, Math.round((4 + worldObj.rand.nextFloat()) * WarpDriveConfig.MINING_LASER_MINE_DELAY_TICKS));
|
||||
PacketHandler.sendBeamPacket(worldObj, laserOutput, new Vector3(valuable.x, valuable.y, valuable.z).translate(0.5D),
|
||||
0.8F, 0.8F, 0.2F, age, 0, 50);
|
||||
|
||||
worldObj.setBlockMetadataWithNotify(valuable.x, valuable.y, valuable.z, metadata + 6, 3);
|
||||
// done with this block
|
||||
return;
|
||||
} else if (metadata != 0 && metadata != 1) {
|
||||
delayTargetTicks = TREE_FARM_TAP_TREE_DRY_DELAY_TICKS;
|
||||
// done with this block
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isLog || (breakLeaves && isLeaf)) {// actually break the block?
|
||||
// consume power
|
||||
double energyCost = isLog ? TREE_FARM_ENERGY_PER_LOG : TREE_FARM_ENERGY_PER_LEAF;
|
||||
if (enableSilktouch) {
|
||||
energyCost *= TREE_FARM_SILKTOUCH_ENERGY_FACTOR;
|
||||
}
|
||||
enoughPower = consumeEnergyFromLaserMediums((int) Math.round(energyCost), false);
|
||||
if (!enoughPower) {
|
||||
delayTargetTicks = TREE_FARM_LOWPOWER_DELAY_TICKS;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_FARMINGLOWPOWER);
|
||||
return;
|
||||
} else {
|
||||
delayTargetTicks = isLog ? TREE_FARM_HARVEST_LOG_DELAY_TICKS : enableSilktouch ? TREE_FARM_SILKTOUCH_LEAF_DELAY_TICKS : TREE_FARM_BREAK_LEAF_DELAY_TICKS;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_FARMINGPOWERED);
|
||||
}
|
||||
|
||||
totalHarvested++;
|
||||
int age = Math.max(10, Math.round((4 + worldObj.rand.nextFloat()) * WarpDriveConfig.MINING_LASER_MINE_DELAY_TICKS));
|
||||
PacketHandler.sendBeamPacket(worldObj, laserOutput, new Vector3(valuable.x, valuable.y, valuable.z).translate(0.5D),
|
||||
0.2F, 0.7F, 0.4F, age, 0, 50);
|
||||
worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F);
|
||||
|
||||
harvestBlock(valuable);
|
||||
}
|
||||
}
|
||||
} else if (currentState == STATE_PLANT) {
|
||||
if (delayTicks >= delayTargetTicks) {
|
||||
if (WarpDriveConfig.LOGGING_COLLECTION) {
|
||||
WarpDrive.logger.debug("Plant final tick");
|
||||
}
|
||||
delayTicks = 0;
|
||||
|
||||
// planting done => scan
|
||||
if (soils == null || soilIndex >= soils.size()) {
|
||||
soilIndex = 0;
|
||||
currentState = STATE_SCAN;
|
||||
delayTargetTicks = TREE_FARM_SCAN_DELAY_TICKS;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_SCANNINGPOWERED);
|
||||
return;
|
||||
}
|
||||
|
||||
// get current block
|
||||
VectorI soil = soils.get(soilIndex);
|
||||
Block block = worldObj.getBlock(soil.x, soil.y, soil.z);
|
||||
soilIndex++;
|
||||
IInventory inventory = getFirstConnectedInventory();
|
||||
if (inventory == null) {
|
||||
currentState = STATE_WARMUP;
|
||||
delayTargetTicks = TREE_FARM_WARMUP_DELAY_TICKS;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_SCANNINGLOWPOWER);
|
||||
return;
|
||||
}
|
||||
|
||||
int slotIndex = 0;
|
||||
boolean found = false;
|
||||
int plantableCount = 0;
|
||||
ItemStack itemStack = null;
|
||||
while (slotIndex < inventory.getSizeInventory() && !found) {
|
||||
itemStack = inventory.getStackInSlot(slotIndex);
|
||||
if (itemStack != null) {
|
||||
WarpDrive.logger.debug("- " + slotIndex + ": " + itemStack + " => " + itemStack.getItem() + " Plantable: " + (itemStack.getItem() instanceof IPlantable) + " Growable: " + (itemStack.getItem() instanceof IGrowable));
|
||||
}
|
||||
if (itemStack == null || itemStack.stackSize <= 0 || !(itemStack.getItem() instanceof IPlantable)) {
|
||||
slotIndex++;
|
||||
continue;
|
||||
}
|
||||
plantableCount++;
|
||||
WarpDrive.logger.debug("IPlantable found: " + itemStack);
|
||||
|
||||
if (!block.canSustainPlant(worldObj, soil.x, soil.y, soil.z, ForgeDirection.UP, (IPlantable)itemStack.getItem())) {
|
||||
slotIndex++;
|
||||
continue;
|
||||
}
|
||||
|
||||
found = true;
|
||||
}
|
||||
|
||||
// no plantable found at all, back to scanning
|
||||
if (plantableCount <= 0) {
|
||||
currentState = STATE_SCAN;
|
||||
delayTargetTicks = TREE_FARM_SCAN_DELAY_TICKS;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_SCANNINGPOWERED);
|
||||
return;
|
||||
}
|
||||
|
||||
// no sapling found for this soil, moving on...
|
||||
if (!found || itemStack == null) {
|
||||
WarpDrive.logger.debug("No sapling found");
|
||||
return;
|
||||
}
|
||||
WarpDrive.logger.debug("Sapling found: " + itemStack);
|
||||
|
||||
// consume power
|
||||
double energyCost = TREE_FARM_ENERGY_PER_SAPLING;
|
||||
enoughPower = consumeEnergyFromLaserMediums((int) Math.round(energyCost), false);
|
||||
if (!enoughPower) {
|
||||
delayTargetTicks = TREE_FARM_LOWPOWER_DELAY_TICKS;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_PLANTINGLOWPOWER);
|
||||
return;
|
||||
} else {
|
||||
delayTargetTicks = TREE_FARM_PLANT_DELAY_TICKS;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_PLANTINGPOWERED);
|
||||
}
|
||||
|
||||
itemStack.stackSize--;
|
||||
if (itemStack.stackSize <= 0) {
|
||||
itemStack = null;
|
||||
}
|
||||
inventory.setInventorySlotContents(slotIndex, itemStack);
|
||||
|
||||
// totalPlanted++;
|
||||
int age = Math.max(10, Math.round((4 + worldObj.rand.nextFloat()) * WarpDriveConfig.MINING_LASER_MINE_DELAY_TICKS));
|
||||
PacketHandler.sendBeamPacket(worldObj, laserOutput, new Vector3(soil.x, soil.y + 1, soil.z).translate(0.5D),
|
||||
0.2F, 0.7F, 0.4F, age, 0, 50);
|
||||
worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void stop() {
|
||||
super.stop();
|
||||
currentState = STATE_IDLE;
|
||||
updateMetadata(BlockLaserTreeFarm.ICON_IDLE);
|
||||
}
|
||||
|
||||
private static boolean isSoil(Block block) {
|
||||
return WarpDriveConfig.BLOCKS_SOILS.contains(block);
|
||||
}
|
||||
|
||||
private static boolean isLog(Block block) {
|
||||
return WarpDriveConfig.BLOCKS_LOGS.contains(block);
|
||||
}
|
||||
|
@ -160,48 +402,90 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
return WarpDriveConfig.BLOCKS_LEAVES.contains(block);
|
||||
}
|
||||
|
||||
private static void addTree(LinkedList<VectorI> list, VectorI newTree) {
|
||||
if (WarpDriveConfig.LOGGING_COLLECTION) {
|
||||
WarpDrive.logger.info("Adding tree position:" + newTree.x + "," + newTree.y + "," + newTree.z);
|
||||
private LinkedList<VectorI> scanSoils() {
|
||||
int xmin = xCoord - radiusX;
|
||||
int xmax = xCoord + radiusX;
|
||||
int ymin = yCoord + 0;
|
||||
int ymax = yCoord + 8;
|
||||
int zmin = zCoord - radiusZ;
|
||||
int zmax = zCoord + radiusZ;
|
||||
|
||||
LinkedList<VectorI> soilPositions = new LinkedList<VectorI>();
|
||||
|
||||
for(int y = ymin; y <= ymax; y++) {
|
||||
for(int x = xmin; x <= xmax; x++) {
|
||||
for(int z = zmin; z <= zmax; z++) {
|
||||
if (worldObj.isAirBlock(x, y + 1, z)) {
|
||||
Block block = worldObj.getBlock(x, y, z);
|
||||
if (isSoil(block)) {
|
||||
VectorI pos = new VectorI(x, y, z);
|
||||
if (WarpDriveConfig.LOGGING_COLLECTION) {
|
||||
WarpDrive.logger.info("Found soil at " + x + "," + y + "," + z);
|
||||
}
|
||||
soilPositions.add(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
list.add(newTree);
|
||||
if (WarpDriveConfig.LOGGING_COLLECTION) {
|
||||
WarpDrive.logger.info("Found " + soilPositions.size() + " soils");
|
||||
}
|
||||
return soilPositions;
|
||||
}
|
||||
|
||||
private LinkedList<VectorI> scanTrees() {
|
||||
int xmax, zmax;
|
||||
int xmin, zmin;
|
||||
xmax = xCoord + radiusX;
|
||||
xmin = xCoord - radiusX;
|
||||
zmax = zCoord + radiusZ;
|
||||
zmin = zCoord - radiusZ;
|
||||
int xmin = xCoord - radiusX;
|
||||
int xmax = xCoord + radiusX;
|
||||
int ymin = yCoord + 1;
|
||||
int ymax = yCoord + 1 + (tapTrees ? 8 : 0);
|
||||
int zmin = zCoord - radiusZ;
|
||||
int zmax = zCoord + radiusZ;
|
||||
|
||||
LinkedList<VectorI> logPositions = new LinkedList<VectorI>();
|
||||
|
||||
for(int x = xmin; x <= xmax; x++) {
|
||||
for(int z = zmin; z <= zmax; z++) {
|
||||
Block block = worldObj.getBlock(x, yCoord, z);
|
||||
if (isLog(block)) {
|
||||
VectorI pos = new VectorI(x, yCoord, z);
|
||||
logPositions.add(pos);
|
||||
scanNearby(logPositions, x, yCoord, z, 0);
|
||||
for(int y = ymin; y <= ymax; y++) {
|
||||
WarpDrive.logger.info("Checking for tree base at altitude " + y);
|
||||
for(int x = xmin; x <= xmax; x++) {
|
||||
for(int z = zmin; z <= zmax; z++) {
|
||||
Block block = worldObj.getBlock(x, y, z);
|
||||
if (isLog(block)) {
|
||||
VectorI pos = new VectorI(x, y, z);
|
||||
if (!logPositions.contains(pos)) {
|
||||
if (WarpDriveConfig.LOGGING_COLLECTION) {
|
||||
WarpDrive.logger.info("Found tree base at " + x + "," + y + "," + z);
|
||||
}
|
||||
logPositions.add(pos);
|
||||
scanBranches(logPositions, x, y, z, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (WarpDriveConfig.LOGGING_COLLECTION) {
|
||||
WarpDrive.logger.info("Found " + logPositions.size() + " valuables");
|
||||
}
|
||||
return logPositions;
|
||||
}
|
||||
|
||||
private void scanNearby(LinkedList<VectorI> current, int x, int y, int z, int d) {
|
||||
private void scanBranches(LinkedList<VectorI> logPositions, int x, int y, int z, int distance) {
|
||||
int[] deltas = {0, -1, 1};
|
||||
for(int dx : deltas) {
|
||||
for(int dy = 1; dy >= 0; dy--) {
|
||||
for(int dz : deltas) {
|
||||
if (dx == 0 && dy == 0 && dz == 0) {
|
||||
continue;
|
||||
}
|
||||
Block block = worldObj.getBlock(x + dx, y + dy, z + dz);
|
||||
if (isLog(block) || (doLeaves && isLeaf(block))) {
|
||||
if (isLog(block) || (breakLeaves && isLeaf(block))) {
|
||||
VectorI pos = new VectorI(x + dx, y + dy, z + dz);
|
||||
if (!current.contains(pos)) {
|
||||
addTree(current, pos);
|
||||
if (d < 35) {
|
||||
scanNearby(current,x+dx,y+dy,z+dz,d+1);
|
||||
if (!logPositions.contains(pos)) {
|
||||
if (WarpDriveConfig.LOGGING_COLLECTION) {
|
||||
WarpDrive.logger.info("Found tree branch at " + pos.x + "," + pos.y + "," + pos.z + " from tree base at " + x + "," + y + "," + z);
|
||||
}
|
||||
logPositions.add(pos);
|
||||
if (distance < TREE_FARM_MAX_LOG_DISTANCE) {
|
||||
scanBranches(logPositions, pos.x, pos.y, pos.z, distance + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -215,10 +499,9 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
super.writeToNBT(tag);
|
||||
tag.setInteger("radiusX", radiusX);
|
||||
tag.setInteger("radiusZ", radiusZ);
|
||||
tag.setBoolean("doLeaves", doLeaves);
|
||||
tag.setBoolean("active", active);
|
||||
tag.setBoolean("treetap", treeTap);
|
||||
tag.setBoolean("silkTouchLeaves", silkTouchLeaves);
|
||||
tag.setBoolean("breakLeaves", breakLeaves);
|
||||
tag.setBoolean("tapTrees", tapTrees);
|
||||
tag.setInteger("currentState", currentState);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -226,23 +509,140 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
super.readFromNBT(tag);
|
||||
radiusX = tag.getInteger("radiusX");
|
||||
if (radiusX == 0) {
|
||||
radiusX = radiusDefault;
|
||||
radiusX = RADIUS_DEFAULT;
|
||||
}
|
||||
radiusX = clamp(WarpDriveConfig.TREE_FARM_MIN_RADIUS, WarpDriveConfig.TREE_FARM_MAX_RADIUS, radiusX);
|
||||
radiusZ = tag.getInteger("radiusZ");
|
||||
if (radiusZ == 0) {
|
||||
radiusZ = radiusDefault;
|
||||
radiusZ = RADIUS_DEFAULT;
|
||||
}
|
||||
radiusZ = clamp(WarpDriveConfig.TREE_FARM_MIN_RADIUS, WarpDriveConfig.TREE_FARM_MAX_RADIUS, radiusZ);
|
||||
|
||||
doLeaves = tag.getBoolean("doLeaves");
|
||||
active = tag.getBoolean("active");
|
||||
treeTap = tag.getBoolean("treetap");
|
||||
silkTouchLeaves = tag.getBoolean("silkTouchLeaves");
|
||||
breakLeaves = tag.getBoolean("breakLeaves");
|
||||
tapTrees = tag.getBoolean("tapTrees");
|
||||
currentState = tag.getInteger("currentState");
|
||||
if (currentState == STATE_HARVEST || currentState == STATE_TAP || currentState == STATE_PLANT) {
|
||||
bScanOnReload = true;
|
||||
}
|
||||
}
|
||||
|
||||
// OpenComputer callback methods
|
||||
// FIXME: implement OpenComputers...
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] start(Context context, Arguments arguments) {
|
||||
return start(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] stop(Context context, Arguments arguments) {
|
||||
stop();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] state(Context context, Arguments arguments) {
|
||||
return state(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] radius(Context context, Arguments arguments) {
|
||||
return radius(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] breakLeaves(Context context, Arguments arguments) {
|
||||
return breakLeaves(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] silktouch(Context context, Arguments arguments) {
|
||||
return silktouch(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] tapTrees(Context context, Arguments arguments) {
|
||||
return tapTrees(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
// Common OC/CC methods
|
||||
private Object[] start(Object[] arguments) {
|
||||
if (isFarming()) {
|
||||
return new Object[] { false, "Already started" };
|
||||
}
|
||||
|
||||
totalHarvested = 0;
|
||||
delayTicks = 0;
|
||||
currentState = STATE_WARMUP;
|
||||
return new Boolean[] { true };
|
||||
}
|
||||
|
||||
private Object[] state(Object[] arguments) {
|
||||
int energy = getEnergyStored();
|
||||
String status = getStatus();
|
||||
Integer retValuables, retValuablesIndex;
|
||||
if (isFarming()) {
|
||||
retValuables = valuables.size();
|
||||
retValuablesIndex = valuableIndex;
|
||||
|
||||
return new Object[] { status, isFarming(), energy, totalHarvested, retValuablesIndex, retValuables };
|
||||
}
|
||||
return new Object[] { status, isFarming(), energy, totalHarvested, 0, 0 };
|
||||
}
|
||||
|
||||
private Object[] radius(Object[] arguments) {
|
||||
try {
|
||||
if (arguments.length == 1) {
|
||||
radiusX = clamp(WarpDriveConfig.TREE_FARM_MIN_RADIUS, WarpDriveConfig.TREE_FARM_MAX_RADIUS, toInt(arguments[0]));
|
||||
radiusZ = radiusX;
|
||||
} else if (arguments.length == 2) {
|
||||
radiusX = clamp(WarpDriveConfig.TREE_FARM_MIN_RADIUS, WarpDriveConfig.TREE_FARM_MAX_RADIUS, toInt(arguments[0]));
|
||||
radiusZ = clamp(WarpDriveConfig.TREE_FARM_MIN_RADIUS, WarpDriveConfig.TREE_FARM_MAX_RADIUS, toInt(arguments[1]));
|
||||
}
|
||||
} catch(NumberFormatException exception) {
|
||||
radiusX = RADIUS_DEFAULT;
|
||||
radiusZ = RADIUS_DEFAULT;
|
||||
}
|
||||
return new Integer[] { radiusX , radiusZ };
|
||||
}
|
||||
|
||||
private Object[] breakLeaves(Object[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
try {
|
||||
breakLeaves = toBool(arguments[0]);
|
||||
} catch (Exception exception) {
|
||||
return new Object[] { breakLeaves };
|
||||
}
|
||||
}
|
||||
return new Object[] { breakLeaves };
|
||||
}
|
||||
|
||||
private Object[] silktouch(Object[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
try {
|
||||
enableSilktouch = toBool(arguments[0]);
|
||||
} catch (Exception exception) {
|
||||
return new Object[] { enableSilktouch };
|
||||
}
|
||||
}
|
||||
return new Object[] { enableSilktouch };
|
||||
}
|
||||
|
||||
private Object[] tapTrees(Object[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
try {
|
||||
tapTrees = toBool(arguments[0]);
|
||||
} catch (Exception exception) {
|
||||
return new Object[] { tapTrees };
|
||||
}
|
||||
}
|
||||
return new Object[] { tapTrees };
|
||||
}
|
||||
|
||||
// ComputerCraft IPeripheral methods implementation
|
||||
@Override
|
||||
|
@ -251,114 +651,70 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
|
|||
String methodName = getMethodName(method);
|
||||
|
||||
if (methodName.equals("start")) {
|
||||
if (!active) {
|
||||
mode = MODE_SCANNING;
|
||||
totalHarvested = 0;
|
||||
active = true;
|
||||
}
|
||||
return new Boolean[] { true };
|
||||
return start(arguments);
|
||||
|
||||
} else if (methodName.equals("stop")) {
|
||||
active = false;
|
||||
return new Boolean[] { false };
|
||||
|
||||
} else if (methodName.equals("radius")) {
|
||||
try {
|
||||
if (arguments.length == 1) {
|
||||
radiusX = clamp(WarpDriveConfig.TREE_FARM_MIN_RADIUS, WarpDriveConfig.TREE_FARM_MAX_RADIUS, toInt(arguments[0]));
|
||||
radiusZ = radiusX;
|
||||
} else if (arguments.length == 2) {
|
||||
radiusX = clamp(WarpDriveConfig.TREE_FARM_MIN_RADIUS, WarpDriveConfig.TREE_FARM_MAX_RADIUS, toInt(arguments[0]));
|
||||
radiusZ = clamp(WarpDriveConfig.TREE_FARM_MIN_RADIUS, WarpDriveConfig.TREE_FARM_MAX_RADIUS, toInt(arguments[1]));
|
||||
}
|
||||
} catch(NumberFormatException e) {
|
||||
radiusX = radiusDefault;
|
||||
radiusZ = radiusDefault;
|
||||
}
|
||||
return new Integer[] { radiusX , radiusZ };
|
||||
|
||||
} else if (methodName.equals("leaves")) {
|
||||
try {
|
||||
if (arguments.length > 0) {
|
||||
doLeaves = toBool(arguments[0]);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
|
||||
}
|
||||
return new Boolean[] { doLeaves };
|
||||
|
||||
} else if (methodName.equals("silkTouch")) {
|
||||
try {
|
||||
silkTouch(arguments[0]);
|
||||
} catch(Exception e) {
|
||||
silkTouch(false);
|
||||
}
|
||||
return new Object[] { silkTouch() };
|
||||
|
||||
} else if (methodName.equals("silkTouchLeaves")) {
|
||||
try {
|
||||
if (arguments.length >= 1) {
|
||||
silkTouchLeaves = toBool(arguments[0]);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
silkTouchLeaves = false;
|
||||
}
|
||||
return new Object[] { silkTouchLeaves };
|
||||
|
||||
} else if (methodName.equals("treetap")) {
|
||||
try {
|
||||
if (arguments.length >= 1) {
|
||||
treeTap = toBool(arguments[0]);
|
||||
}
|
||||
} catch(Exception e) {
|
||||
treeTap = false;
|
||||
}
|
||||
return new Object[] { treeTap };
|
||||
stop();
|
||||
return null;
|
||||
|
||||
} else if (methodName.equals("state")) {
|
||||
String state = active ? (mode == MODE_SCANNING ? "scanning" : (mode == MODE_HARVESTING ? "harvesting" : (mode == MODE_TAPPING ? "tapping" : "<invalid>" + mode))) : "inactive";
|
||||
return new Object[] { state, radiusX, radiusZ, energy(), totalHarvested };
|
||||
return state(arguments);
|
||||
|
||||
} else if (methodName.equals("radius")) {
|
||||
return radius(arguments);
|
||||
|
||||
} else if (methodName.equals("breakLeaves")) {
|
||||
return breakLeaves(arguments);
|
||||
|
||||
} else if (methodName.equals("silktouch")) {
|
||||
return silktouch(arguments);
|
||||
|
||||
} else if (methodName.equals("tapTrees")) {
|
||||
return tapTrees(arguments);
|
||||
}
|
||||
|
||||
return super.callMethod(computer, context, method, arguments);
|
||||
}
|
||||
|
||||
//ABSTRACT LASER IMPLEMENTATION
|
||||
@Override
|
||||
protected boolean silkTouch(Block block) {
|
||||
if (isLeaf(block)) {
|
||||
return silkTouchLeaves;
|
||||
public String getStatus() {
|
||||
int energy = getEnergyStored();
|
||||
String state = "IDLE (not farming)";
|
||||
if (currentState == STATE_IDLE) {
|
||||
state = "IDLE (not farming)";
|
||||
} else if (currentState == STATE_WARMUP) {
|
||||
state = "Warming up...";
|
||||
} else if (currentState == STATE_SCAN) {
|
||||
if (breakLeaves) {
|
||||
state = "Scanning all";
|
||||
} else {
|
||||
state = "Scanning logs";
|
||||
}
|
||||
} else if (currentState == STATE_HARVEST) {
|
||||
if (breakLeaves) {
|
||||
state = "Harvesting all";
|
||||
} else {
|
||||
state = "Harvesting logs";
|
||||
}
|
||||
if (enableSilktouch) {
|
||||
state = state + " with silktouch";
|
||||
}
|
||||
} else if (currentState == STATE_TAP) {
|
||||
if (breakLeaves) {
|
||||
state = "Tapping trees, harvesting all";
|
||||
} else {
|
||||
state = "Tapping trees, harvesting logs";
|
||||
}
|
||||
if (enableSilktouch) {
|
||||
state = state + " with silktouch";
|
||||
}
|
||||
} else if (currentState == STATE_PLANT) {
|
||||
state = "Planting trees";
|
||||
}
|
||||
return silkTouch();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canSilkTouch() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int minFortune() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int maxFortune() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getColorR() {
|
||||
return 0.2f;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getColorG() {
|
||||
return 0.7f;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getColorB() {
|
||||
return 0.4f;
|
||||
if (energy <= 0) {
|
||||
state = state + " - Out of energy";
|
||||
} else if (((currentState == STATE_SCAN) || (currentState == STATE_HARVEST) || (currentState == STATE_TAP)) && !enoughPower) {
|
||||
state = state + " - Not enough power";
|
||||
}
|
||||
return state;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,24 +2,18 @@ package cr0s.warpdrive.block.collection;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import li.cil.oc.api.machine.Arguments;
|
||||
import li.cil.oc.api.machine.Callback;
|
||||
import li.cil.oc.api.machine.Context;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockLiquid;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidRegistry;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.Optional;
|
||||
import cr0s.warpdrive.WarpDrive;
|
||||
import cr0s.warpdrive.block.TileEntityAbstractLaser;
|
||||
import cr0s.warpdrive.config.WarpDriveConfig;
|
||||
import cr0s.warpdrive.data.Vector3;
|
||||
import cr0s.warpdrive.data.VectorI;
|
||||
|
@ -27,14 +21,15 @@ import cr0s.warpdrive.network.PacketHandler;
|
|||
import dan200.computercraft.api.lua.ILuaContext;
|
||||
import dan200.computercraft.api.peripheral.IComputerAccess;
|
||||
|
||||
public class TileEntityMiningLaser extends TileEntityAbstractLaser {
|
||||
public class TileEntityMiningLaser extends TileEntityAbstractMiner {
|
||||
private final boolean canSilktouch = (WarpDriveConfig.MINING_LASER_SILKTOUCH_DEUTERIUM_L <= 0 || FluidRegistry.isFluidRegistered("deuterium"));
|
||||
|
||||
private boolean isMining() {
|
||||
return currentState != STATE_IDLE;
|
||||
}
|
||||
|
||||
private boolean isQuarry = false;
|
||||
private boolean enableSilktouch = false;
|
||||
private int layerOffset = 1;
|
||||
private boolean mineAllBlocks = true;
|
||||
|
||||
private int delayTicksWarmup = 0;
|
||||
private int delayTicksScan = 0;
|
||||
|
@ -52,23 +47,22 @@ public class TileEntityMiningLaser extends TileEntityAbstractLaser {
|
|||
private ArrayList<VectorI> valuablesInLayer = new ArrayList<VectorI>();
|
||||
private int valuableIndex = 0;
|
||||
|
||||
private int layerOffset = 1;
|
||||
|
||||
public TileEntityMiningLaser() {
|
||||
super();
|
||||
laserOutputSide = ForgeDirection.DOWN;
|
||||
peripheralName = "warpdriveMiningLaser";
|
||||
addMethods(new String[] {
|
||||
"mine",
|
||||
"start",
|
||||
"stop",
|
||||
"isMining",
|
||||
"quarry",
|
||||
"state",
|
||||
"offset"
|
||||
"offset",
|
||||
"onlyOres",
|
||||
"silktouch"
|
||||
});
|
||||
CC_scripts = Arrays.asList("mine", "stop");
|
||||
countMaxLaserMediums = WarpDriveConfig.MINING_LASER_MAX_MEDIUMS_COUNT;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void updateEntity() {
|
||||
super.updateEntity();
|
||||
|
@ -84,12 +78,10 @@ public class TileEntityMiningLaser extends TileEntityAbstractLaser {
|
|||
updateMetadata(BlockMiningLaser.ICON_IDLE);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
boolean isOnEarth = (worldObj.provider.dimensionId == 0);
|
||||
|
||||
Vector3 laserOutput = new Vector3(xCoord + 0.5D, yCoord, zCoord + 0.5D);
|
||||
|
||||
if (currentState == STATE_WARMUP) { // warming up
|
||||
|
||||
if (currentState == STATE_WARMUP) {
|
||||
delayTicksWarmup++;
|
||||
updateMetadata(BlockMiningLaser.ICON_SCANNINGLOWPOWER);
|
||||
if (delayTicksWarmup >= WarpDriveConfig.MINING_LASER_WARMUP_DELAY_TICKS) {
|
||||
|
@ -98,7 +90,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractLaser {
|
|||
updateMetadata(BlockMiningLaser.ICON_SCANNINGLOWPOWER);
|
||||
return;
|
||||
}
|
||||
} else if (currentState == STATE_SCANNING) { // scanning
|
||||
} else if (currentState == STATE_SCANNING) {
|
||||
delayTicksScan++;
|
||||
if (delayTicksScan == 1) {
|
||||
// check power level
|
||||
|
@ -165,7 +157,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractLaser {
|
|||
currentLayer--;
|
||||
}
|
||||
}
|
||||
} else if (currentState == STATE_MINING) { // mining
|
||||
} else if (currentState == STATE_MINING) {
|
||||
delayTicksMine++;
|
||||
if (delayTicksMine >= WarpDriveConfig.MINING_LASER_MINE_DELAY_TICKS) {
|
||||
delayTicksMine = 0;
|
||||
|
@ -192,7 +184,6 @@ public class TileEntityMiningLaser extends TileEntityAbstractLaser {
|
|||
updateMetadata(BlockMiningLaser.ICON_MININGPOWERED);
|
||||
}
|
||||
|
||||
// System.out.println("[ML] Mining: " + (valuableIndex + 1) + "/" + valuablesInLayer.size());
|
||||
VectorI valuable = valuablesInLayer.get(valuableIndex);
|
||||
valuableIndex++;
|
||||
|
||||
|
@ -211,22 +202,14 @@ public class TileEntityMiningLaser extends TileEntityAbstractLaser {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateMetadata(int metadata) {
|
||||
Block block = worldObj.getBlock(xCoord, yCoord, zCoord);
|
||||
if (block.isAssociatedBlock(WarpDrive.blockMiningLaser) && getBlockMetadata() != metadata) {
|
||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, metadata, 2);
|
||||
}
|
||||
}
|
||||
|
||||
private void stop() {
|
||||
if (WarpDriveConfig.LOGGING_COLLECTION) {
|
||||
WarpDrive.logger.info(this + " Stop requested");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void stop() {
|
||||
super.stop();
|
||||
currentState = STATE_IDLE;
|
||||
updateMetadata(BlockMiningLaser.ICON_IDLE);
|
||||
}
|
||||
|
||||
|
||||
private boolean canDig(Block block, int x, int y, int z) {
|
||||
// ignore air
|
||||
if (worldObj.isAirBlock(x, y, z)) {
|
||||
|
@ -250,168 +233,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractLaser {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void harvestBlock(VectorI valuable) {
|
||||
Block block = worldObj.getBlock(valuable.x, valuable.y, valuable.z);
|
||||
int blockMeta = worldObj.getBlockMetadata(valuable.x, valuable.y, valuable.z);
|
||||
if (block != null && (block instanceof BlockLiquid)) {
|
||||
// Evaporate fluid
|
||||
worldObj.playSoundEffect(valuable.x + 0.5D, valuable.y + 0.5D, valuable.z + 0.5D, "random.fizz", 0.5F,
|
||||
2.6F + (worldObj.rand.nextFloat() - worldObj.rand.nextFloat()) * 0.8F);
|
||||
} else {
|
||||
List<ItemStack> stacks = getItemStackFromBlock(valuable.x, valuable.y, valuable.z, block, blockMeta);
|
||||
if (stacks != null) {
|
||||
boolean overflow = false;
|
||||
int qtyLeft = 0;
|
||||
for (ItemStack stack : stacks) {
|
||||
qtyLeft = putInChest(findChest(), stack);
|
||||
if (qtyLeft > 0) {
|
||||
if (WarpDriveConfig.LOGGING_COLLECTION) {
|
||||
WarpDrive.logger.info(this + " Overflow detected");
|
||||
}
|
||||
overflow = true;
|
||||
int transfer;
|
||||
while (qtyLeft > 0) {
|
||||
transfer = Math.min(qtyLeft, stack.getMaxStackSize());
|
||||
ItemStack dropItemStack = copyWithSize(stack, transfer);
|
||||
EntityItem itemEnt = new EntityItem(worldObj, xCoord + 0.5D, yCoord + 1.0D, zCoord + 0.5D, dropItemStack);
|
||||
worldObj.spawnEntityInWorld(itemEnt);
|
||||
qtyLeft -= transfer;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (overflow) {
|
||||
stop();
|
||||
}
|
||||
}
|
||||
// standard harvest block effect
|
||||
worldObj.playAuxSFXAtEntity(null, 2001, valuable.x, valuable.y, valuable.z, Block.getIdFromBlock(block) + (blockMeta << 12));
|
||||
}
|
||||
worldObj.setBlockToAir(valuable.x, valuable.y, valuable.z);
|
||||
}
|
||||
|
||||
private IInventory findChest() {
|
||||
TileEntity result = null;
|
||||
result = worldObj.getTileEntity(xCoord + 1, yCoord, zCoord);
|
||||
if (result != null && result instanceof IInventory) {
|
||||
return (IInventory) result;
|
||||
}
|
||||
|
||||
result = worldObj.getTileEntity(xCoord - 1, yCoord, zCoord);
|
||||
if (result != null && result instanceof IInventory) {
|
||||
return (IInventory) result;
|
||||
}
|
||||
|
||||
result = worldObj.getTileEntity(xCoord, yCoord, zCoord + 1);
|
||||
if (result != null && result instanceof IInventory) {
|
||||
return (IInventory) result;
|
||||
}
|
||||
|
||||
result = worldObj.getTileEntity(xCoord, yCoord, zCoord - 1);
|
||||
if (result != null && result instanceof IInventory) {
|
||||
return (IInventory) result;
|
||||
}
|
||||
|
||||
result = worldObj.getTileEntity(xCoord, yCoord + 1, zCoord);
|
||||
if (result != null && result instanceof IInventory) {
|
||||
return (IInventory) result;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public List<ItemStack> getItemStackFromBlock(int i, int j, int k, Block block, int blockMeta) {
|
||||
|
||||
if (block == null) {
|
||||
return null;
|
||||
}
|
||||
if (enableSilktouch) {
|
||||
boolean isSilkHarvestable = false;
|
||||
try {
|
||||
isSilkHarvestable = block.canSilkHarvest(worldObj, null, i, j, k, blockMeta);
|
||||
} catch (Exception e) {// protect in case the mined block is
|
||||
// corrupted
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (isSilkHarvestable) {
|
||||
if (WarpDriveConfig.MINING_LASER_SILKTOUCH_DEUTERIUM_L <= 0) {
|
||||
ArrayList<ItemStack> isBlock = new ArrayList<ItemStack>();
|
||||
isBlock.add(new ItemStack(block, 1, blockMeta));
|
||||
return isBlock;
|
||||
} else {
|
||||
// TODO: implement fluid support through AE or tanks
|
||||
WarpDrive.logger.error("Fluids aren't supported yet, ML_DEUTERIUM_MUL_SILKTOUCH should be 0");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return block.getDrops(worldObj, i, j, k, blockMeta, 0);
|
||||
} catch (Exception e) {// protect in case the mined block is corrupted
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private int putInChest(IInventory inventory, ItemStack itemStackSource) {
|
||||
if (itemStackSource == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int qtyLeft = itemStackSource.stackSize;
|
||||
int transfer;
|
||||
|
||||
if (inventory != null) {
|
||||
// fill existing stacks first
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
||||
if (!inventory.isItemValidForSlot(i, itemStackSource)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack itemStack = inventory.getStackInSlot(i);
|
||||
if (itemStack == null || !itemStack.isItemEqual(itemStackSource)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
transfer = Math.min(qtyLeft, itemStack.getMaxStackSize() - itemStack.stackSize);
|
||||
itemStack.stackSize += transfer;
|
||||
qtyLeft -= transfer;
|
||||
if (qtyLeft <= 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
// put remaining in empty slot
|
||||
for (int i = 0; i < inventory.getSizeInventory(); i++) {
|
||||
if (!inventory.isItemValidForSlot(i, itemStackSource)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ItemStack itemStack = inventory.getStackInSlot(i);
|
||||
if (itemStack != null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
transfer = Math.min(qtyLeft, itemStackSource.getMaxStackSize());
|
||||
ItemStack dest = copyWithSize(itemStackSource, transfer);
|
||||
inventory.setInventorySlotContents(i, dest);
|
||||
qtyLeft -= transfer;
|
||||
|
||||
if (qtyLeft <= 0) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return qtyLeft;
|
||||
}
|
||||
|
||||
public static ItemStack copyWithSize(ItemStack itemStack, int newSize) {
|
||||
ItemStack ret = itemStack.copy();
|
||||
ret.stackSize = newSize;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
private void scanLayer() {
|
||||
// WarpDrive.logger.info("Scanning layer");
|
||||
valuablesInLayer.clear();
|
||||
|
@ -420,13 +242,13 @@ public class TileEntityMiningLaser extends TileEntityAbstractLaser {
|
|||
Block block;
|
||||
int xmax, zmax;
|
||||
int xmin, zmin;
|
||||
|
||||
|
||||
// Search for valuable blocks
|
||||
x = xCoord;
|
||||
z = zCoord;
|
||||
block = worldObj.getBlock(x, currentLayer, z);
|
||||
if (canDig(block, x, currentLayer, z)) {
|
||||
if (isQuarry || WarpDriveConfig.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
|
||||
if (mineAllBlocks || WarpDriveConfig.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
|
||||
valuablesInLayer.add(new VectorI(x, currentLayer, z));
|
||||
}
|
||||
}
|
||||
|
@ -440,7 +262,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractLaser {
|
|||
for (; x <= xmax; x++) {
|
||||
block = worldObj.getBlock(x, currentLayer, z);
|
||||
if (canDig(block, x, currentLayer, z)) {
|
||||
if (isQuarry || WarpDriveConfig.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
|
||||
if (mineAllBlocks || WarpDriveConfig.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
|
||||
valuablesInLayer.add(new VectorI(x, currentLayer, z));
|
||||
}
|
||||
}
|
||||
|
@ -450,7 +272,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractLaser {
|
|||
for (; z <= zmax; z++) {
|
||||
block = worldObj.getBlock(x, currentLayer, z);
|
||||
if (canDig(block, x, currentLayer, z)) {
|
||||
if (isQuarry || WarpDriveConfig.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
|
||||
if (mineAllBlocks || WarpDriveConfig.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
|
||||
valuablesInLayer.add(new VectorI(x, currentLayer, z));
|
||||
}
|
||||
}
|
||||
|
@ -460,7 +282,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractLaser {
|
|||
for (; x >= xmin; x--) {
|
||||
block = worldObj.getBlock(x, currentLayer, z);
|
||||
if (canDig(block, x, currentLayer, z)) {
|
||||
if (isQuarry || WarpDriveConfig.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
|
||||
if (mineAllBlocks || WarpDriveConfig.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
|
||||
valuablesInLayer.add(new VectorI(x, currentLayer, z));
|
||||
}
|
||||
}
|
||||
|
@ -470,7 +292,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractLaser {
|
|||
for (; z > zmin; z--) {
|
||||
block = worldObj.getBlock(x, currentLayer, z);
|
||||
if (canDig(block, x, currentLayer, z)) {
|
||||
if (isQuarry || WarpDriveConfig.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
|
||||
if (mineAllBlocks || WarpDriveConfig.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
|
||||
valuablesInLayer.add(new VectorI(x, currentLayer, z));
|
||||
}
|
||||
}
|
||||
|
@ -480,7 +302,7 @@ public class TileEntityMiningLaser extends TileEntityAbstractLaser {
|
|||
for (; x < xCoord; x++) {
|
||||
block = worldObj.getBlock(x, currentLayer, z);
|
||||
if (canDig(block, x, currentLayer, z)) {
|
||||
if (isQuarry || WarpDriveConfig.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
|
||||
if (mineAllBlocks || WarpDriveConfig.BLOCKS_ORES.contains(block)) {// Quarry collects all blocks or only collect valuables blocks
|
||||
valuablesInLayer.add(new VectorI(x, currentLayer, z));
|
||||
}
|
||||
}
|
||||
|
@ -491,92 +313,79 @@ public class TileEntityMiningLaser extends TileEntityAbstractLaser {
|
|||
WarpDrive.logger.info(this + " Found " + valuablesInLayer.size() + " valuables");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
super.readFromNBT(tag);
|
||||
layerOffset = tag.getInteger("layerOffset");
|
||||
mineAllBlocks = tag.getBoolean("mineAllBlocks");
|
||||
currentState = tag.getInteger("currentState");
|
||||
isQuarry = tag.getBoolean("isQuarry");
|
||||
currentLayer = tag.getInteger("currentLayer");
|
||||
enableSilktouch = tag.getBoolean("enableSilktouch");
|
||||
if (currentState == STATE_MINING) {
|
||||
scanLayer();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag) {
|
||||
super.writeToNBT(tag);
|
||||
tag.setInteger("layerOffset", layerOffset);
|
||||
tag.setBoolean("mineAllBlocks", mineAllBlocks);
|
||||
tag.setInteger("currentState", currentState);
|
||||
tag.setBoolean("isQuarry", isQuarry);
|
||||
tag.setInteger("currentLayer", currentLayer);
|
||||
tag.setBoolean("enableSilktouch", enableSilktouch);
|
||||
}
|
||||
|
||||
|
||||
// OpenComputer callback methods
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] mine(Context context, Arguments arguments) {
|
||||
return mine(argumentsOCtoCC(arguments));
|
||||
public Object[] start(Context context, Arguments arguments) {
|
||||
return start(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] stop(Context context, Arguments arguments) {
|
||||
stop();
|
||||
return null;
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] isMining(Context context, Arguments arguments) {
|
||||
return new Boolean[] { isMining() };
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] quarry(Context context, Arguments arguments) {
|
||||
return quarry(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] state(Context context, Arguments arguments) {
|
||||
return state(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] offset(Context context, Arguments arguments) {
|
||||
return offset(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
private Object[] mine(Object[] arguments) {
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] onlyOres(Context context, Arguments arguments) {
|
||||
return onlyOres(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
@Callback
|
||||
@Optional.Method(modid = "OpenComputers")
|
||||
public Object[] silktouch(Context context, Arguments arguments) {
|
||||
return silktouch(argumentsOCtoCC(arguments));
|
||||
}
|
||||
|
||||
// Common OC/CC methods
|
||||
private Object[] start(Object[] arguments) {
|
||||
if (isMining()) {
|
||||
return new Boolean[] { false };
|
||||
return new Object[] { false, "Already started" };
|
||||
}
|
||||
|
||||
isQuarry = false;
|
||||
|
||||
enableSilktouch &= canSilktouch;
|
||||
delayTicksWarmup = 0;
|
||||
currentState = STATE_WARMUP;
|
||||
currentLayer = yCoord - layerOffset - 1;
|
||||
enableSilktouch = (arguments.length == 1 && (WarpDriveConfig.MINING_LASER_SILKTOUCH_DEUTERIUM_L <= 0 || FluidRegistry.isFluidRegistered("deuterium")));
|
||||
return new Boolean[] { true };
|
||||
}
|
||||
|
||||
private Object[] quarry(Object[] arguments) {
|
||||
if (isMining()) {
|
||||
return new Boolean[] { false };
|
||||
}
|
||||
|
||||
isQuarry = true;
|
||||
delayTicksScan = 0;
|
||||
currentState = STATE_WARMUP;
|
||||
currentLayer = yCoord - layerOffset - 1;
|
||||
enableSilktouch = (arguments.length == 1 && (WarpDriveConfig.MINING_LASER_SILKTOUCH_DEUTERIUM_L <= 0 || FluidRegistry.isFluidRegistered("deuterium")));
|
||||
return new Boolean[] { true };
|
||||
}
|
||||
|
||||
|
||||
private Object[] state(Object[] arguments) {
|
||||
int energy = getEnergyStored();
|
||||
String status = getStatus();
|
||||
|
@ -584,52 +393,74 @@ public class TileEntityMiningLaser extends TileEntityAbstractLaser {
|
|||
if (isMining()) {
|
||||
retValuablesInLayer = valuablesInLayer.size();
|
||||
retValuablesMined = valuableIndex;
|
||||
|
||||
return new Object[] { status, energy, currentLayer, retValuablesMined, retValuablesInLayer };
|
||||
|
||||
return new Object[] { status, isMining(), energy, currentLayer, retValuablesMined, retValuablesInLayer };
|
||||
}
|
||||
return new Object[] { status, energy, currentLayer, 0, 0 };
|
||||
return new Object[] { status, isMining(), energy, currentLayer, 0, 0 };
|
||||
}
|
||||
|
||||
|
||||
private Object[] onlyOres(Object[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
try {
|
||||
mineAllBlocks = ! toBool(arguments[0]);
|
||||
} catch (Exception exception) {
|
||||
return new Object[] { !mineAllBlocks };
|
||||
}
|
||||
}
|
||||
return new Object[] { !mineAllBlocks };
|
||||
}
|
||||
|
||||
private Object[] offset(Object[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
try {
|
||||
layerOffset = Math.min(256, Math.abs(toInt(arguments[0])));
|
||||
} catch (Exception e) {
|
||||
} catch (Exception exception) {
|
||||
return new Integer[] { layerOffset };
|
||||
}
|
||||
}
|
||||
return new Integer[] { layerOffset };
|
||||
}
|
||||
|
||||
|
||||
private Object[] silktouch(Object[] arguments) {
|
||||
if (arguments.length == 1) {
|
||||
try {
|
||||
enableSilktouch = ! toBool(arguments[0]);
|
||||
} catch (Exception exception) {
|
||||
return new Object[] { enableSilktouch };
|
||||
}
|
||||
}
|
||||
return new Object[] { enableSilktouch };
|
||||
}
|
||||
|
||||
// ComputerCraft IPeripheral methods implementation
|
||||
@Override
|
||||
@Optional.Method(modid = "ComputerCraft")
|
||||
public Object[] callMethod(IComputerAccess computer, ILuaContext context, int method, Object[] arguments) {
|
||||
String methodName = getMethodName(method);
|
||||
|
||||
if (methodName.equals("mine")) {
|
||||
return mine(arguments);
|
||||
if (methodName.equals("start")) {
|
||||
return start(arguments);
|
||||
|
||||
} else if (methodName.equals("stop")) {
|
||||
stop();
|
||||
return null;
|
||||
|
||||
} else if (methodName.equals("isMining")) {
|
||||
return new Boolean[] { isMining() };
|
||||
|
||||
} else if (methodName.equals("quarry")) {
|
||||
return quarry(arguments);
|
||||
|
||||
} else if (methodName.equals("state")) { // State is: state, energy,
|
||||
// currentLayer, valuablesMined, valuablesInLayer = getMinerState()
|
||||
} else if (methodName.equals("state")) {
|
||||
return state(arguments);
|
||||
|
||||
} else if (methodName.equals("offset")) {
|
||||
return offset(arguments);
|
||||
|
||||
} else if (methodName.equals("onlyOres")) {
|
||||
return onlyOres(arguments);
|
||||
|
||||
} else if (methodName.equals("silktouch")) {
|
||||
return silktouch(arguments);
|
||||
}
|
||||
|
||||
return super.callMethod(computer, context, method, arguments);
|
||||
}
|
||||
|
||||
|
||||
public String getStatus() {
|
||||
int energy = getEnergyStored();
|
||||
String state = "IDLE (not mining)";
|
||||
|
@ -638,19 +469,19 @@ public class TileEntityMiningLaser extends TileEntityAbstractLaser {
|
|||
} else if (currentState == STATE_WARMUP) {
|
||||
state = "Warming up...";
|
||||
} else if (currentState == STATE_SCANNING) {
|
||||
if (isQuarry) {
|
||||
if (mineAllBlocks) {
|
||||
state = "Scanning all";
|
||||
} else {
|
||||
state = "Scanning ores";
|
||||
}
|
||||
} else if (currentState == STATE_MINING) {
|
||||
if (isQuarry) {
|
||||
if (mineAllBlocks) {
|
||||
state = "Mining all";
|
||||
} else {
|
||||
state = "Mining ores";
|
||||
}
|
||||
if (enableSilktouch) {
|
||||
state = state + " using Deuterium";
|
||||
state = state + " with silktouch";
|
||||
}
|
||||
}
|
||||
if (energy <= 0) {
|
||||
|
|
Loading…
Reference in a new issue