diff options
author | Draknyte1 <Draknyte1@hotmail.com> | 2017-01-17 19:41:46 +1000 |
---|---|---|
committer | Draknyte1 <Draknyte1@hotmail.com> | 2017-01-17 19:41:46 +1000 |
commit | 5834a266fdf425ad56558db71691f9b3b0df5e31 (patch) | |
tree | eb2123fde62da27795417fbe9b6afcd31b383adf /src/Java/powercrystals/minefactoryreloaded/farmables/harvestables | |
parent | 289e41515842ec89d01bfa593504163f75d0950c (diff) | |
download | GT5-Unofficial-5834a266fdf425ad56558db71691f9b3b0df5e31.tar.gz GT5-Unofficial-5834a266fdf425ad56558db71691f9b3b0df5e31.tar.bz2 GT5-Unofficial-5834a266fdf425ad56558db71691f9b3b0df5e31.zip |
% Tried to improve the logic for the Tree Farmer, to support Forestry 4.
% Moved COFH API related files.
+ Added a child mod, for misc handling.
$$ Borrowed some code from MFR, to attempt forestry support. (Credit left, will re-do if I even get it working).
Diffstat (limited to 'src/Java/powercrystals/minefactoryreloaded/farmables/harvestables')
3 files changed, 154 insertions, 0 deletions
diff --git a/src/Java/powercrystals/minefactoryreloaded/farmables/harvestables/HarvestableShearable.java b/src/Java/powercrystals/minefactoryreloaded/farmables/harvestables/HarvestableShearable.java new file mode 100644 index 0000000000..1719ae2486 --- /dev/null +++ b/src/Java/powercrystals/minefactoryreloaded/farmables/harvestables/HarvestableShearable.java @@ -0,0 +1,50 @@ +package powercrystals.minefactoryreloaded.farmables.harvestables; + +import java.util.*; + +import net.minecraft.block.Block; +import net.minecraft.init.Items; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.common.IShearable; +import powercrystals.minefactoryreloaded.api.HarvestType; + +public class HarvestableShearable extends HarvestableStandard +{ + public HarvestableShearable(Block block, HarvestType harvestType) + { + super(block, harvestType); + } + + public HarvestableShearable(Block block) + { + super(block); + } + + @Override + public List<ItemStack> getDrops(World world, Random rand, Map<String, Boolean> settings, int x, int y, int z) + { + Block block = world.getBlock(x, y, z); + if (settings.get("silkTouch") == Boolean.TRUE) + { + if (block instanceof IShearable) + { + ItemStack stack = new ItemStack(Items.shears, 1, 0); + if (((IShearable)block).isShearable(stack, world, x, y, z)) + { + return ((IShearable)block).onSheared(stack, world, x, y, z, 0); + } + } + if (Item.getItemFromBlock(block) != null) + { + ArrayList<ItemStack> drops = new ArrayList<ItemStack>(); + int meta = block.getDamageValue(world, x, y, z); + drops.add(new ItemStack(block, 1, meta)); + return drops; + } + } + + return block.getDrops(world, x, y, z, world.getBlockMetadata(x, y, z), 0); + } +} diff --git a/src/Java/powercrystals/minefactoryreloaded/farmables/harvestables/HarvestableStandard.java b/src/Java/powercrystals/minefactoryreloaded/farmables/harvestables/HarvestableStandard.java new file mode 100644 index 0000000000..eeab615ed8 --- /dev/null +++ b/src/Java/powercrystals/minefactoryreloaded/farmables/harvestables/HarvestableStandard.java @@ -0,0 +1,71 @@ +package powercrystals.minefactoryreloaded.farmables.harvestables; + +import java.util.*; + +import net.minecraft.block.Block; +import net.minecraft.init.Blocks; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import powercrystals.minefactoryreloaded.api.HarvestType; +import powercrystals.minefactoryreloaded.api.IFactoryHarvestable; + +public class HarvestableStandard implements IFactoryHarvestable +{ + private Block _block; + private HarvestType _harvestType; + + public HarvestableStandard(Block block, HarvestType harvestType) + { + if (block == Blocks.air) + throw new IllegalArgumentException("Passed air FactoryHarvestableStandard"); + + _block = block; + _harvestType = harvestType; + } + + public HarvestableStandard(Block block) + { + this(block, HarvestType.Normal); + } + + @Override + public Block getPlant() + { + return _block; + } + + @Override + public HarvestType getHarvestType() + { + return _harvestType; + } + + @Override + public boolean breakBlock() + { + return true; + } + + @Override + public boolean canBeHarvested(World world, Map<String, Boolean> harvesterSettings, int x, int y, int z) + { + return true; + } + + @Override + public List<ItemStack> getDrops(World world, Random rand, Map<String, Boolean> harvesterSettings, int x, int y, int z) + { + return world.getBlock(x, y, z).getDrops(world, x, y, z, world.getBlockMetadata(x, y, z), 0); + } + + @Override + public void preHarvest(World world, int x, int y, int z) + { + } + + @Override + public void postHarvest(World world, int x, int y, int z) + { + world.notifyBlocksOfNeighborChange(x, y, z, getPlant()); + } +} diff --git a/src/Java/powercrystals/minefactoryreloaded/farmables/harvestables/HarvestableTreeLeaves.java b/src/Java/powercrystals/minefactoryreloaded/farmables/harvestables/HarvestableTreeLeaves.java new file mode 100644 index 0000000000..eaa23bd847 --- /dev/null +++ b/src/Java/powercrystals/minefactoryreloaded/farmables/harvestables/HarvestableTreeLeaves.java @@ -0,0 +1,33 @@ +package powercrystals.minefactoryreloaded.farmables.harvestables; + +import net.minecraft.block.Block; +import net.minecraft.world.World; +import powercrystals.minefactoryreloaded.api.HarvestType; + +public class HarvestableTreeLeaves extends HarvestableShearable +{ + public HarvestableTreeLeaves(Block block) + { + super(block, HarvestType.TreeLeaf); + } + + @Override + public void postHarvest(World world, int x, int y, int z) + { + Block id = getPlant(); + + notifyBlock(world, x, y - 1, z, id); + notifyBlock(world, x - 1, y, z, id); + notifyBlock(world, x + 1, y, z, id); + notifyBlock(world, x, y, z - 1, id); + notifyBlock(world, x, y, z + 1, id); + notifyBlock(world, x, y + 1, z, id); + } + + protected void notifyBlock(World world, int x, int y, int z, Block id) + { + Block block = world.getBlock(x, y, z); + if (!block.isLeaves(world, x, y, z)) + world.notifyBlockOfNeighborChange(x, y, z, id); + } +} |