diff options
Diffstat (limited to 'src/Java/gtPlusPlus/xmod')
8 files changed, 526 insertions, 62 deletions
diff --git a/src/Java/gtPlusPlus/xmod/forestry/Forestry.java b/src/Java/gtPlusPlus/xmod/forestry/Forestry.java new file mode 100644 index 0000000000..b21d9a154d --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/forestry/Forestry.java @@ -0,0 +1,127 @@ +package gtPlusPlus.xmod.forestry; + +import static cpw.mods.fml.common.registry.GameRegistry.findBlock; +import static cpw.mods.fml.common.registry.GameRegistry.findItem; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.xmod.forestry.trees.ForestryLeaf; +import gtPlusPlus.xmod.forestry.trees.ForestrySapling; +import net.minecraft.block.Block; +import net.minecraft.item.Item; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; + +import cofh.mod.ChildMod; +import cpw.mods.fml.common.*; +import cpw.mods.fml.common.Mod.CustomProperty; +import cpw.mods.fml.common.Mod.EventHandler; +import cpw.mods.fml.common.event.FMLInitializationEvent; +import cpw.mods.fml.common.event.FMLPostInitializationEvent; + +@ChildMod(parent = CORE.MODID, mod = @Mod(modid = "Gregtech++|CompatForestry", +name = "GT++ Compat: Forestry", +version = CORE.VERSION, +dependencies = "after:Miscutils;after:Forestry", +customProperties = @CustomProperty(k = "cofhversion", v = "true"))) +public class Forestry { + + private static final String name = "Forestry"; + + @EventHandler + public void load(FMLInitializationEvent e) { + + try { + initForestry(); + } catch (Throwable $) { + ModContainer This = FMLCommonHandler.instance().findContainerFor(this); + LogManager.getLogger(This.getModId()).log(Level.ERROR, "There was a problem loading " + This.getName(), $); + } + } + + private static void initForestry() { + + Item item; + + item = findItem(name, "sapling"); + Block block = findBlock(name, "saplingGE"); + if (item != null && block != null) { + ForestrySapling sapling = new ForestrySapling(item, block); + //MFRRegistry.registerPlantable(sapling); + //MFRRegistry.registerFertilizable(sapling); + } else + //Utils.LOG_WARNING("Forestry sapling/block null!"); + + block = findBlock(name, "soil"); + if (block != null) { + //ForestryBogEarth bog = new ForestryBogEarth(block); + //MFRRegistry.registerPlantable(bog); + //MFRRegistry.registerFertilizable(bog); + //MFRRegistry.registerHarvestable(bog); + //MFRRegistry.registerFruit(bog); + } else + //Utils.LOG_WARNING("Forestry bog earth null!"); + + for (int i = 1; true; ++i) { + block = findBlock(name, "log" + i); + l: if (block == null) { + if (i > 1) + Utils.LOG_WARNING("Forestry logs null at " + i + "."); + else { + block = findBlock(name, "logs"); + if (block != null) { + break l; + } + Utils.LOG_WARNING("Forestry logs null!"); + } + break; + } + //MFRRegistry.registerHarvestable(new HarvestableWood(block)); + //MFRRegistry.registerFruitLogBlock(block); + } + + for (int i = 1; true; ++i) { + block = findBlock(name, "fireproofLog" + i); + l: if (block == null) { + if (i > 1) + Utils.LOG_WARNING("Forestry logs null at " + i + "."); + else { + block = findBlock(name, "logsFireproof"); + if (block != null) { + break l; + } + Utils.LOG_WARNING("Forestry logs null!"); + } + break; + } + //MFRRegistry.registerHarvestable(new HarvestableWood(block)); + //MFRRegistry.registerFruitLogBlock(block); + } + + block = findBlock(name, "leaves"); + if (block != null) { + ForestryLeaf leaf = new ForestryLeaf(block); + //MFRRegistry.registerFertilizable(leaf); + //MFRRegistry.registerHarvestable(leaf); + //MFRRegistry.registerFruit(leaf); + } else + Utils.LOG_WARNING("Forestry leaves null!"); + + block = findBlock(name, "pods"); + item = findItem(name, "grafterProven"); + if (block != null) { + //ForestryPod pod = new ForestryPod(block, item); + //MFRRegistry.registerFertilizable(pod); + //MFRRegistry.registerHarvestable(pod); + //MFRRegistry.registerFruit(pod); + } else + Utils.LOG_WARNING("Forestry pods null!"); + } + + @EventHandler + public static void postInit(FMLPostInitializationEvent e) { + //MFRRegistry.registerLiquidDrinkHandler("bioethanol", new DrinkHandlerBiofuel()); + //TileEntityUnifier.updateUnifierLiquids(); + } + +} diff --git a/src/Java/gtPlusPlus/xmod/forestry/trees/ForestryLeaf.java b/src/Java/gtPlusPlus/xmod/forestry/trees/ForestryLeaf.java new file mode 100644 index 0000000000..e2550f4643 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/forestry/trees/ForestryLeaf.java @@ -0,0 +1,160 @@ +package gtPlusPlus.xmod.forestry.trees; + +import java.util.*; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.world.World; +import powercrystals.minefactoryreloaded.api.*; +import powercrystals.minefactoryreloaded.farmables.harvestables.HarvestableTreeLeaves; +import forestry.api.arboriculture.*; +import forestry.api.genetics.*; + + +public class ForestryLeaf extends HarvestableTreeLeaves implements IFactoryFruit +{ + private ITreeRoot root; + private ReplacementBlock repl; + protected Item _item; + + public ForestryLeaf(Block block) + { + super(block); + root = (ITreeRoot)AlleleManager.alleleRegistry.getSpeciesRoot("rootTrees"); + repl = EmptyReplacement.INSTANCE; + _item = Item.getItemFromBlock(block); + } + + @Override + public boolean canBePicked(World world, int x, int y, int z) + { + TileEntity te = world.getTileEntity(x, y, z); + if (te instanceof IFruitBearer) + { + IFruitBearer fruit = (IFruitBearer)te; + return fruit.getRipeness() >= 0.99f; + } + return false; + } + + public boolean canFertilize(World world, int x, int y, int z) + { + return !canBePicked(world, x, y, z); + } + + public boolean fertilize(World world, Random rand, int x, int y, int z) + { + TileEntity te = world.getTileEntity(x, y, z); + if (te instanceof IFruitBearer) + { + IFruitBearer fruit = (IFruitBearer)te; + fruit.addRipeness(1f); + return true; + } + return false; + } + + @Override + public ReplacementBlock getReplacementBlock(World world, int x, int y, int z) + { + return repl; + } + + @Override + public void prePick(World world, int x, int y, int z) + { + } + + @Override // HARVESTER + public List<ItemStack> getDrops(World world, Random rand, Map<String, Boolean> settings, int x, int y, int z) + { + ITree tree = getTree(world, x, y, z); + if (tree == null) + return null; + + ArrayList<ItemStack> prod = new ArrayList<ItemStack>(); + + float modifier = 1f; + if (settings.get("silkTouch") == Boolean.TRUE) + { + ItemStack item = new ItemStack(_item); + NBTTagCompound tag = new NBTTagCompound(); + tree.writeToNBT(tag); + item.setTagCompound(tag); + prod.add(item); + } + else + { + boolean hasMate = tree.getMate() != null; + for (ITree s : getSaplings(tree, world, x, y, z, modifier)) + if (s != null) { + if ((hasMate && !s.isGeneticEqual(tree)) || rand.nextInt(32) == 0) + if (rand.nextBoolean()) + prod.add(root.getMemberStack(s, EnumGermlingType.POLLEN.ordinal())); + + prod.add(root.getMemberStack(s, EnumGermlingType.SAPLING.ordinal())); + } + + getFruits(world, x, y, z, tree, prod); + } + + return prod; + } + + + private static ITree[] getSaplings(ITree tree, World world, int x, int y, int z, float modifier) { + return tree.getSaplings(world, null, x, y, z, modifier); + } + + @Override // FRUIT PICKER + public List<ItemStack> getDrops(World world, Random rand, int x, int y, int z) + { + ITree tree = getTree(world, x, y, z); + if (tree == null) + return null; + + ArrayList<ItemStack> prod = new ArrayList<ItemStack>(); + getFruits(world, x, y, z, tree, prod); + return prod; + } + + private ITree getTree(World world, int x, int y, int z) + { + TileEntity te = world.getTileEntity(x, y, z); + if (te instanceof IPollinatable) { + IIndividual t = ((IPollinatable)te).getPollen(); + if (t instanceof ITree) + return (ITree)t; + } + return null; + } + + private void getFruits(World world, int x, int y, int z, ITree tree, ArrayList<ItemStack> prod) + { + TileEntity te = world.getTileEntity(x, y, z); + if (te instanceof IFruitBearer) + { + IFruitBearer fruit = (IFruitBearer)te; + if (fruit.hasFruit()) + { + //int period = tree.getGenome().getFruitProvider().getRipeningPeriod(); + //ItemStack[] o = tree.produceStacks(world, x, y, z, (int)(fruit.getRipeness() * period + 0.1f)); + prod.addAll(fruit.pickFruit(null)); + } + } + } + + @Override + public void postPick(World world, int x, int y, int z) + { + TileEntity te = world.getTileEntity(x, y, z); + if (te instanceof IFruitBearer) + { + IFruitBearer fruit = (IFruitBearer)te; + fruit.addRipeness(-fruit.getRipeness()); + } + } +} diff --git a/src/Java/gtPlusPlus/xmod/forestry/trees/ForestrySapling.java b/src/Java/gtPlusPlus/xmod/forestry/trees/ForestrySapling.java new file mode 100644 index 0000000000..7c81ea0928 --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/forestry/trees/ForestrySapling.java @@ -0,0 +1,55 @@ +package gtPlusPlus.xmod.forestry.trees; + +import java.util.Random; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import powercrystals.minefactoryreloaded.api.ReplacementBlock; +import powercrystals.minefactoryreloaded.farmables.plantables.PlantableStandard; +import forestry.api.arboriculture.ITreeRoot; +import forestry.api.genetics.AlleleManager; + +public class ForestrySapling extends PlantableStandard +{ + private ITreeRoot root; + + public ForestrySapling(Item item, Block block) + { + super(item, block, WILDCARD, null); + root = (ITreeRoot)AlleleManager.alleleRegistry.getSpeciesRoot("rootTrees"); + _plantedBlock = new ReplacementBlock((Block)null) { + @Override + public boolean replaceBlock(World world, int x, int y, int z, ItemStack stack) { + return root.plantSapling(world, root.getMember(stack), null, x, y, z); + } + }; + } + + public Block getPlant() + { + return _block; + } + + @Override + public boolean canBePlantedHere(World world, int x, int y, int z, ItemStack stack) + { + if (!world.isAirBlock(x, y, z)) + return false; + + return root.getMember(stack).canStay(world, x, y, z); + } + + public boolean canFertilize(World world, int x, int y, int z) + { + return true; + } + + public boolean fertilize(World world, Random rand, int x, int y, int z) + { + Block block = world.getBlock(x, y, z); + root.getTree(world, x, y, z).getTreeGenerator(world, x, y, z, true).generate(world, rand, x, y, z); + return world.getBlock(x, y, z) != block; + } +} diff --git a/src/Java/gtPlusPlus/xmod/forestry/trees/TreefarmManager.java b/src/Java/gtPlusPlus/xmod/forestry/trees/TreefarmManager.java index ba8ffd8284..8fe3f62f23 100644 --- a/src/Java/gtPlusPlus/xmod/forestry/trees/TreefarmManager.java +++ b/src/Java/gtPlusPlus/xmod/forestry/trees/TreefarmManager.java @@ -63,7 +63,17 @@ public class TreefarmManager { public static boolean isWoodLog(Block log){ String tTool = log.getHarvestTool(0); - return OrePrefixes.log.contains(new ItemStack(log, 1))&& ((tTool != null) && (tTool.equals("axe"))) || (log.getMaterial() == Material.wood); + + if (log == Blocks.log || log == Blocks.log2){ + return true; + } + + //IC2 Rubber Tree Compat + if (log.getClass().getName().toLowerCase().contains("rubwood")){ + return true; + } + + return OrePrefixes.log.contains(new ItemStack(log, 1))&& ((tTool != null) && (tTool.equals("axe"))) || (log.getMaterial() != Material.wood) ? false : (OrePrefixes.fence.contains(new ItemStack(log, 1)) ? false : true); } public static boolean isLeaves(Block log){ @@ -88,7 +98,7 @@ public class TreefarmManager { } public static boolean isFenceBlock(Block fence){ - return (fence == Blocks.fence ? true : (fence == Blocks.fence_gate ? true : (fence == Blocks.nether_brick_fence ? true : false))); + return (fence == Blocks.fence ? true : (fence == Blocks.fence_gate ? true : (fence == Blocks.nether_brick_fence ? true : (OrePrefixes.fence.contains(new ItemStack(fence, 1)) ? true : false)))); } public static boolean isAirBlock(Block air){ @@ -96,6 +106,12 @@ public class TreefarmManager { if (air.getLocalizedName().toLowerCase().contains("air")){ return true; } + + if (air.getClass().getName().toLowerCase().contains("residual") || air.getClass().getName().toLowerCase().contains("heat")){ + return true; + } + + //Utils.LOG_INFO("Found "+air.getLocalizedName()); return (air == Blocks.air ? true : (air instanceof BlockAir ? true : false)); } diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntity_Cable.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntity_Cable.java index 53865da327..1e88135e94 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntity_Cable.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntity_Cable.java @@ -17,7 +17,7 @@ import ic2.api.energy.tile.IEnergySink; import java.util.ArrayList; import java.util.Arrays; -import api.cofh.energy.IEnergyReceiver; +import cofh.energy.IEnergyReceiver; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.tileentity.TileEntity; diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntity_SuperConductor.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntity_SuperConductor.java index 8e7cc778bd..23c1f3e47f 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntity_SuperConductor.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/GregtechMetaPipeEntity_SuperConductor.java @@ -18,7 +18,7 @@ import ic2.api.energy.tile.IEnergySink; import java.util.ArrayList; import java.util.Arrays; -import api.cofh.energy.IEnergyReceiver; +import cofh.energy.IEnergyReceiver; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.tileentity.TileEntity; diff --git a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaPipeEntityBase_Cable.java b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaPipeEntityBase_Cable.java index 4daa150889..0e7d7f30da 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaPipeEntityBase_Cable.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/api/metatileentity/implementations/base/GregtechMetaPipeEntityBase_Cable.java @@ -22,7 +22,7 @@ import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Arrays; -import api.cofh.energy.IEnergyReceiver; +import cofh.energy.IEnergyReceiver; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLivingBase; import net.minecraft.item.ItemStack; diff --git a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntityTreeFarm.java b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntityTreeFarm.java index a03e4c3952..0587c26b85 100644 --- a/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntityTreeFarm.java +++ b/src/Java/gtPlusPlus/xmod/gregtech/common/tileentities/machines/multi/GregtechMetaTileEntityTreeFarm.java @@ -11,8 +11,10 @@ import gregtech.api.metatileentity.implementations.*; import gregtech.api.objects.GT_ItemStack; import gregtech.api.objects.GT_RenderedTexture; import gregtech.api.util.GT_Recipe; +import gregtech.api.util.GT_Utility; import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.item.ItemUtils; +import gtPlusPlus.core.util.math.MathUtils; import gtPlusPlus.xmod.forestry.trees.TreefarmManager; import gtPlusPlus.xmod.gregtech.common.blocks.textures.TexturesGtBlock; @@ -35,6 +37,9 @@ public class GregtechMetaTileEntityTreeFarm extends GT_MetaTileEntity_MultiBlock public ArrayList<GT_MetaTileEntity_TieredMachineBlock> mCasings = new ArrayList(); /* private */ private int treeCheckTicks = 0; + /* private */ private int plantSaplingTicks = 0; + /* private */ private int cleanupTicks = 0; + /* private */ private boolean canChop = false; public GregtechMetaTileEntityTreeFarm(final int aID, final String aName, final String aNameRegional) { super(aID, aName, aNameRegional); @@ -275,44 +280,83 @@ public class GregtechMetaTileEntityTreeFarm extends GT_MetaTileEntity_MultiBlock //Tree Manager + private void tickTrees(){ + if (treeCheckTicks > 200){ + treeCheckTicks = 0; + } + else { + treeCheckTicks++; + } + } + + private void tickSaplings(){ + if (plantSaplingTicks > 200){ + plantSaplingTicks = 0; + } + else { + plantSaplingTicks++; + } + } + + private void tickCleanup(){ + if (cleanupTicks > 600){ + cleanupTicks = 0; + } + else { + cleanupTicks++; + } + } + + private void tickHandler(){ + //Count Sapling Timer + tickSaplings(); + //Count Tree Cutting Timer + tickTrees(); + //Tick Cleanup script Timer. + tickCleanup(); + } + + @Override public void onPostTick(final IGregTechTileEntity aBaseMetaTileEntity, final long aTick) { if (aBaseMetaTileEntity.isServerSide()) { - - //Check Inventory slots [1] + //Check Inventory slots [1] - Find a valid Buzzsaw Blade or a Saw try { Utils.LOG_INFO(mInventory[1].getDisplayName()); } catch (NullPointerException t){} - //Update Tick Timer Last - Do Not move up the call stack - if (treeCheckTicks > 100){ - treeCheckTicks = 0; - } - else { - treeCheckTicks++; - } - - //Set Machine State - if (treeCheckTicks == 100){ - mMachine = checkMachine(aBaseMetaTileEntity, mInventory[1]); - - //If Machine can work and it's only one of two times a second this will tick, tick. - if (mMachine){ + //If Machine can work and it's only once every 5 seconds this will tick. + if (mMachine){ + //Set Machine State + if (treeCheckTicks == 200){ + //mMachine = checkMachine(aBaseMetaTileEntity, mInventory[1]); Utils.LOG_INFO("Looking For Trees - Serverside | "+treeCheckTicks); + //Find wood to Cut findLogs(aBaseMetaTileEntity); - - cleanUp(aBaseMetaTileEntity); - + } + } + else { + if (plantSaplingTicks == 100){ + Utils.LOG_INFO("Looking For space to plant saplings - Serverside | "+plantSaplingTicks); + //Plant Some Saplings plantSaplings(aBaseMetaTileEntity); - + } + else if (plantSaplingTicks == 200){ + Utils.LOG_INFO("Looking For Saplings to grow - Serverside | "+plantSaplingTicks); + //Try Grow some Saplings findSaplings(aBaseMetaTileEntity); + //Set can work state + mMachine = true; } - } - - - - + } + //Call Cleanup Task last, before ticking. + if (cleanupTicks == 600){ + Utils.LOG_INFO("Looking For rubbish to cleanup - Serverside | "+cleanupTicks); + cleanUp(aBaseMetaTileEntity); + } + //Tick TE + tickHandler(); } //Client Side - do nothing @@ -377,6 +421,7 @@ public class GregtechMetaTileEntityTreeFarm extends GT_MetaTileEntity_MultiBlock } } } + mMachine = false; if (logsCut > 0) cleanUp(aBaseMetaTileEntity); //Utils.LOG_INFO("general failure | maybe there is no logs, not an error. | cut:"+logsCut ); @@ -444,60 +489,98 @@ public class GregtechMetaTileEntityTreeFarm extends GT_MetaTileEntity_MultiBlock for (int j = -7; j <= 7; j++) { int h = 1; - if (TreefarmManager.isAirBlock(aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j))){ - for (ItemStack n : r){ - if (n != null){ - if (OrePrefixes.sapling.contains(n) || n.getDisplayName().toLowerCase().contains("sapling")){ - Utils.LOG_INFO(""+n.getDisplayName()); - - int posX, posY, posZ; - posX = aBaseMetaTileEntity.getXCoord()+xDir+i; - posY = aBaseMetaTileEntity.getYCoord()+h; - posZ = aBaseMetaTileEntity.getZCoord()+zDir+j; - - //Works for everything but forestry saplings - TODO - Block saplingToPlace = Block.getBlockFromItem(n.getItem()); - - //If sapling block is not null - if (saplingToPlace != null){ - //Plant Sapling - world.setBlock(posX, posY, posZ, saplingToPlace); - world.setBlockMetadataWithNotify(posX, posY, posZ, n.getItemDamage(), 4); - //Deplete Input stack - depleteInput(n); + if ((i != -7 && i != 7) && (j != -7 && j != 7)) { + if (TreefarmManager.isAirBlock(aBaseMetaTileEntity.getBlockOffset(xDir + i, h, zDir + j))){ + //Utils.LOG_INFO("Found air"); + if (r.size() > 0){ + Utils.LOG_INFO("r was not null. "+r.size()); + for (ItemStack n : r){ + Utils.LOG_INFO("found "+n.getDisplayName()); + if (OrePrefixes.sapling.contains(n) || n.getDisplayName().toLowerCase().contains("sapling")){ + //Utils.LOG_INFO(""+n.getDisplayName()); + + int posX, posY, posZ; + posX = aBaseMetaTileEntity.getXCoord()+xDir+i; + posY = aBaseMetaTileEntity.getYCoord()+h; + posZ = aBaseMetaTileEntity.getZCoord()+zDir+j; + + //Works for everything but forestry saplings - TODO + Block saplingToPlace; + + if (n.getClass().getName().toLowerCase().contains("forestry")){ + Utils.LOG_INFO("It's a forestry sapling, trying magic."); + saplingToPlace = Block.getBlockFromItem(ItemUtils.getItem("Forestry:saplingGE")); + + } + else { + saplingToPlace = Block.getBlockFromItem(n.getItem()); + } + + + //If sapling block is not null + if (saplingToPlace != null){ + Utils.LOG_INFO("Placing Sapling Block."); + //Plant Sapling + world.setBlock(posX, posY, posZ, saplingToPlace); + world.setBlockMetadataWithNotify(posX, posY, posZ, n.getItemDamage(), 4); + //Deplete Input stack + depleteInput(n); + r = getStoredInputs(); + break; + } + Utils.LOG_INFO(n.getDisplayName()+" did not have a valid block."); + } + else { + Utils.LOG_INFO("item was not a sapling"); } } } + else{ + Utils.LOG_INFO("Input stack empty or null"); + } } - } + else { + Utils.LOG_INFO("No space for sapling, no air."); + } + } + } } Utils.LOG_INFO("Tried to grow saplings: | "+saplings ); return true; } - private Block findAirForSaplingToGrow(){ - return null; - } - private boolean cutLog(final World world, final int x, final int y, final int z){ Utils.LOG_INFO("Cutting Log"); try { //Get Log. final Block block = world.getBlock(x, y, z); //Add the stack to the bus. - addOutput(ItemUtils.getSimpleStack(block)); - //Update bus contents. - updateSlots(); - //Remove drop that was added to the bus. - world.setBlockToAir(x, y, z); - return true; + + ItemStack outputStack = ItemUtils.getSimpleStack(block); + if (outputStack != null){ + Utils.LOG_INFO("Adding 1x "+outputStack.getDisplayName()); + addOutput(outputStack); + //Update bus contents. + updateSlots(); + //Remove drop that was added to the bus. + world.setBlockToAir(x, y, z); + return true; + } + } catch (NullPointerException e){} return false; } public static boolean applyBonemeal(World world, int intX, int intY, int intZ){ Block block = world.getBlock(intX, intY, intZ); + int chance = MathUtils.randInt(0, 10); + + //Random Growth + if (chance < 8){ + return false; + } + EntityPlayer player = FakePlayerFactory.getMinecraft((WorldServer)world); if (!world.isRemote){ if (enableTreeFarmerParticles){ @@ -586,4 +669,27 @@ public class GregtechMetaTileEntityTreeFarm extends GT_MetaTileEntity_MultiBlock return getSides(aColor); } + + public boolean depleteInputEx(ItemStack aStack) { + if (GT_Utility.isStackInvalid(aStack)) return false; + + Utils.LOG_INFO("Taking one sapling away from in input bus."); + + for (GT_MetaTileEntity_Hatch_InputBus tHatch : this.mInputBusses) { + tHatch.mRecipeMap = getRecipeMap(); + if (isValidMetaTileEntity(tHatch)) { + for (int i = tHatch.getBaseMetaTileEntity().getSizeInventory() - 1; i >= 0; --i) { + if ((!(GT_Utility.areStacksEqual(aStack, tHatch.getBaseMetaTileEntity().getStackInSlot(i)))) || (tHatch.getBaseMetaTileEntity().getStackInSlot(0).stackSize < aStack.stackSize)){ + continue; + } + tHatch.getBaseMetaTileEntity().decrStackSize(0,1); + return true; + } + } + + } + + return false; + } + }
\ No newline at end of file |