From 429e1540cda78958f13b518817dc3da999a923ea Mon Sep 17 00:00:00 2001 From: alexbegt Date: Sat, 21 Oct 2017 14:49:27 -0400 Subject: [PATCH] Add back right click harvesting on cotton crops. Closes #400 --- gradle.properties | 2 +- .../block/crops/BlockNaturaCotton.java | 57 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 87f8276a..90a8ca7d 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ mod_version=4.3.0 minecraft_version=1.12 minecraft_version_patch=1.12.2 -forge_version=14.23.0.2493 +forge_version=14.23.0.2515 mappings_version=snapshot_20170927 mantle_version=1.3.+ diff --git a/src/main/java/com/progwml6/natura/overworld/block/crops/BlockNaturaCotton.java b/src/main/java/com/progwml6/natura/overworld/block/crops/BlockNaturaCotton.java index 66903244..286388b4 100644 --- a/src/main/java/com/progwml6/natura/overworld/block/crops/BlockNaturaCotton.java +++ b/src/main/java/com/progwml6/natura/overworld/block/crops/BlockNaturaCotton.java @@ -6,7 +6,15 @@ import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyInteger; import net.minecraft.block.state.BlockStateContainer; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.util.EnumFacing; +import net.minecraft.util.EnumHand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraftforge.common.util.FakePlayer; public class BlockNaturaCotton extends BlockOverworldCrops { @@ -47,4 +55,53 @@ protected ItemStack getCrop() return NaturaCommons.cotton.copy(); } + @Override + public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn) + { + if (!worldIn.isRemote) + { + int age = worldIn.getBlockState(pos).getValue(AGE).intValue(); + + if (age == 4) + { + worldIn.setBlockState(pos, this.getDefaultState().withProperty(AGE, Integer.valueOf(2)), 3); + + EntityItem entityitem = new EntityItem(worldIn, playerIn.posX, playerIn.posY - 1.0D, playerIn.posZ, NaturaCommons.cotton.copy()); + + worldIn.spawnEntity(entityitem); + + if (!(playerIn instanceof FakePlayer)) + { + entityitem.onCollideWithPlayer(playerIn); + } + } + } + } + + @Override + public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) + { + int age = state.getValue(AGE).intValue(); + + if (age == 4) + { + if (worldIn.isRemote) + return true; + + worldIn.setBlockState(pos, this.getDefaultState().withProperty(AGE, Integer.valueOf(2)), 3); + + EntityItem entityitem = new EntityItem(worldIn, playerIn.posX, playerIn.posY - 1.0D, playerIn.posZ, NaturaCommons.cotton.copy()); + + worldIn.spawnEntity(entityitem); + + if (!(playerIn instanceof FakePlayer)) + { + entityitem.onCollideWithPlayer(playerIn); + } + return true; + } + + return false; + } + }