Skip to content

Commit

Permalink
Implement harvesting barley with right click. Closes #420
Browse files Browse the repository at this point in the history
  • Loading branch information
alexbegt committed Jan 2, 2018
1 parent 4f33f57 commit 8a76abe
Showing 1 changed file with 58 additions and 0 deletions.
Expand Up @@ -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 BlockNaturaBarley extends BlockOverworldCrops
{
Expand Down Expand Up @@ -47,4 +55,54 @@ protected ItemStack getCrop()
return NaturaCommons.barley.copy();
}

@Override
public void onBlockClicked(World worldIn, BlockPos pos, EntityPlayer playerIn)
{
if (!worldIn.isRemote)
{
int age = worldIn.getBlockState(pos).getValue(AGE).intValue();

if (age == 3)
{
worldIn.setBlockState(pos, this.getDefaultState().withProperty(AGE, Integer.valueOf(1)), 3);

EntityItem entityitem = new EntityItem(worldIn, playerIn.posX, playerIn.posY - 1.0D, playerIn.posZ, NaturaCommons.barley.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 == 3)
{
if (worldIn.isRemote)
return true;

worldIn.setBlockState(pos, this.getDefaultState().withProperty(AGE, Integer.valueOf(1)), 3);

EntityItem entityitem = new EntityItem(worldIn, playerIn.posX, playerIn.posY - 1.0D, playerIn.posZ, NaturaCommons.barley.copy());

worldIn.spawnEntity(entityitem);

if (!(playerIn instanceof FakePlayer))
{
entityitem.onCollideWithPlayer(playerIn);
}

return true;
}

return false;
}

}

2 comments on commit 8a76abe

@ArticulatedDrunk
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks man, most people don't do stuff so quickly. I was wondering why this was ever removed in the first place though, or did something else add the functionality back then?

@alexbegt
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The functionality was added for cotton, but barley was a separate mod

Please sign in to comment.