Added planting to laser tree farm

This commit is contained in:
LemADEC 2016-01-17 03:13:32 +01:00
parent b38aadc48c
commit 0f4ec6bd16

View file

@ -11,7 +11,6 @@ import li.cil.oc.api.machine.Context;
import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Optional; import cpw.mods.fml.common.Optional;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.IGrowable;
import net.minecraft.inventory.IInventory; import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -236,7 +235,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
int metadata = worldObj.getBlockMetadata(valuable.x, valuable.y, valuable.z); int metadata = worldObj.getBlockMetadata(valuable.x, valuable.y, valuable.z);
if (metadata >= 2 && metadata <= 5) { if (metadata >= 2 && metadata <= 5) {
if (WarpDriveConfig.LOGGING_COLLECTION) { if (WarpDriveConfig.LOGGING_COLLECTION) {
WarpDrive.logger.debug("Tap found rubber wood wetspot at " + valuable + " with metadata " + metadata); WarpDrive.logger.info("Tap found rubber wood wetspot at " + valuable + " with metadata " + metadata);
} }
// consume power // consume power
@ -329,19 +328,31 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
boolean found = false; boolean found = false;
int plantableCount = 0; int plantableCount = 0;
ItemStack itemStack = null; ItemStack itemStack = null;
Block plant = null;
int plantMetadata = -1;
while (slotIndex < inventory.getSizeInventory() && !found) { while (slotIndex < inventory.getSizeInventory() && !found) {
itemStack = inventory.getStackInSlot(slotIndex); itemStack = inventory.getStackInSlot(slotIndex);
if (itemStack != null) { if (itemStack == null || itemStack.stackSize <= 0) {
WarpDrive.logger.debug("- " + slotIndex + ": " + itemStack + " => " + itemStack.getItem() + " Plantable: " + (itemStack.getItem() instanceof IPlantable) + " Growable: " + (itemStack.getItem() instanceof IGrowable)); slotIndex++;
continue;
} }
if (itemStack == null || itemStack.stackSize <= 0 || !(itemStack.getItem() instanceof IPlantable)) { Block blockFromItem = Block.getBlockFromItem(itemStack.getItem());
if (!(itemStack.getItem() instanceof IPlantable) && !(blockFromItem instanceof IPlantable)) {
slotIndex++; slotIndex++;
continue; continue;
} }
plantableCount++; plantableCount++;
WarpDrive.logger.debug("IPlantable found: " + itemStack); IPlantable plantable = (IPlantable)((itemStack.getItem() instanceof IPlantable) ? itemStack.getItem() : blockFromItem);
plant = plantable.getPlant(worldObj, soil.x, soil.y + 1, soil.z);
plantMetadata = plantable.getPlantMetadata(worldObj, soil.x, soil.y + 1, soil.z);
if (plantMetadata == 0 && itemStack.getItemDamage() != 0) {
plantMetadata = itemStack.getItemDamage();
}
if (WarpDriveConfig.LOGGING_COLLECTION) {
WarpDrive.logger.info("Slot " + slotIndex + " as " + itemStack + " which plantable " + plantable + " as block " + plant + ":" + plantMetadata);
}
if (!block.canSustainPlant(worldObj, soil.x, soil.y, soil.z, ForgeDirection.UP, (IPlantable)itemStack.getItem())) { if (!block.canSustainPlant(worldObj, soil.x, soil.y, soil.z, ForgeDirection.UP, plantable)) {
slotIndex++; slotIndex++;
continue; continue;
} }
@ -362,7 +373,6 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
WarpDrive.logger.debug("No sapling found"); WarpDrive.logger.debug("No sapling found");
return; return;
} }
WarpDrive.logger.debug("Sapling found: " + itemStack);
// consume power // consume power
double energyCost = TREE_FARM_ENERGY_PER_SAPLING; double energyCost = TREE_FARM_ENERGY_PER_SAPLING;
@ -387,6 +397,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
PacketHandler.sendBeamPacket(worldObj, laserOutput, new Vector3(soil.x, soil.y + 1, soil.z).translate(0.5D), 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); 0.2F, 0.7F, 0.4F, age, 0, 50);
worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F); worldObj.playSoundEffect(xCoord + 0.5f, yCoord, zCoord + 0.5f, "warpdrive:lowlaser", 4F, 1F);
worldObj.setBlock(soil.x, soil.y + 1, soil.z, plant, plantMetadata, 3);
} }
} }
} }
@ -429,7 +440,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
if (isSoil(block)) { if (isSoil(block)) {
VectorI pos = new VectorI(x, y, z); VectorI pos = new VectorI(x, y, z);
if (WarpDriveConfig.LOGGING_COLLECTION) { if (WarpDriveConfig.LOGGING_COLLECTION) {
WarpDrive.logger.info("Found soil at " + x + "," + y + "," + z); // WarpDrive.logger.info("Found soil at " + x + "," + y + "," + z);
} }
soilPositions.add(pos); soilPositions.add(pos);
} }
@ -473,7 +484,7 @@ public class TileEntityLaserTreeFarm extends TileEntityAbstractMiner {
if (logPositions.size() > 0) { if (logPositions.size() > 0) {
HashSet<Block> whitelist = (HashSet<Block>) Dictionary.BLOCKS_LOGS.clone(); HashSet<Block> whitelist = (HashSet<Block>) Dictionary.BLOCKS_LOGS.clone();
if (breakLeaves) { if (breakLeaves) {
// whitelist.addAll(WarpDriveConfig.BLOCKS_LEAVES); whitelist.addAll(Dictionary.BLOCKS_LEAVES);
} }
logPositions = getConnectedBlocks(worldObj, logPositions, UP_DIRECTIONS, whitelist, WarpDriveConfig.TREE_FARM_MAX_LOG_DISTANCE + laserMediumCount * WarpDriveConfig.TREE_FARM_MAX_LOG_DISTANCE_PER_MEDIUM); logPositions = getConnectedBlocks(worldObj, logPositions, UP_DIRECTIONS, whitelist, WarpDriveConfig.TREE_FARM_MAX_LOG_DISTANCE + laserMediumCount * WarpDriveConfig.TREE_FARM_MAX_LOG_DISTANCE_PER_MEDIUM);
} }