diff options
Diffstat (limited to 'src/Java/powercrystals/minefactoryreloaded/farmables')
4 files changed, 270 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); + } +} diff --git a/src/Java/powercrystals/minefactoryreloaded/farmables/plantables/PlantableStandard.java b/src/Java/powercrystals/minefactoryreloaded/farmables/plantables/PlantableStandard.java new file mode 100644 index 0000000000..022d947150 --- /dev/null +++ b/src/Java/powercrystals/minefactoryreloaded/farmables/plantables/PlantableStandard.java @@ -0,0 +1,116 @@ +package powercrystals.minefactoryreloaded.farmables.plantables; + +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; +import net.minecraftforge.common.IPlantable; +import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.oredict.OreDictionary; +import powercrystals.minefactoryreloaded.api.IFactoryPlantable; +import powercrystals.minefactoryreloaded.api.ReplacementBlock; + +/* + * Used for directly placing blocks (ie saplings) and items (ie sugarcane). Pass in source ID to constructor, + * so one instance per source ID. + */ + +public class PlantableStandard implements IFactoryPlantable +{ + public static final int WILDCARD = OreDictionary.WILDCARD_VALUE; + + protected Item _seed; + protected Block _block; + protected ReplacementBlock _plantedBlock; + protected int _validMeta; + + public PlantableStandard(Block block) + { + this(Item.getItemFromBlock(block), block); + } + + public PlantableStandard(Block block, Block plantedBlock) + { + this(Item.getItemFromBlock(block), plantedBlock); + } + + public PlantableStandard(Item block, Block plantedBlock) + { + this(block, plantedBlock, WILDCARD); + } + + public PlantableStandard(Block block, int meta) + { + this(Item.getItemFromBlock(block), block, meta); + } + + public PlantableStandard(Block block, Block plantedBlock, int meta) + { + this(Item.getItemFromBlock(block), plantedBlock, meta); + } + + public PlantableStandard(Item block, Block plantedBlock, int validMeta) + { + this(block, plantedBlock, validMeta, new ReplacementBlock(plantedBlock)); + } + + public PlantableStandard(Item block, Block plantedBlock, int validMeta, int plantedMeta) + { + this(block, plantedBlock, validMeta, new ReplacementBlock(plantedBlock).setMeta(plantedMeta)); + } + + public PlantableStandard(Item block, Block plantedBlock, int validMeta, boolean useItemMeta) + { + this(block, plantedBlock, validMeta, new ReplacementBlock(plantedBlock).setMeta(useItemMeta)); + } + + public PlantableStandard(Item block, Block plantedBlock, int validMeta, ReplacementBlock repl) + { + _seed = block; + _block = plantedBlock; + _validMeta = validMeta; + _plantedBlock = repl; + } + + @Override + public boolean canBePlanted(ItemStack stack, boolean forFermenting) + { + return _validMeta == WILDCARD || stack.getItemDamage() == _validMeta; + } + + @Override + public boolean canBePlantedHere(World world, int x, int y, int z, ItemStack stack) + { + if (!world.isAirBlock(x, y, z)) + return false; + + Block groundId = world.getBlock(x, y - 1, z); + return (_block.canPlaceBlockAt(world, x, y, z) && _block.canReplace(world, x, y, z, 0, stack)) || + (_block instanceof IPlantable && groundId != null && + groundId.canSustainPlant(world, x, y, z, ForgeDirection.UP, (IPlantable)_block)); + } + + @Override + public void prePlant(World world, int x, int y, int z, ItemStack stack) + { + return; + } + + @Override + public void postPlant(World world, int x, int y, int z, ItemStack stack) + { + return; + } + + @Override + public ReplacementBlock getPlantedBlock(World world, int x, int y, int z, ItemStack stack) + { + return _plantedBlock; + } + + @Override + public Item getSeed() + { + return _seed; + } +} |