Skip to content

Instantly share code, notes, and snippets.

@Robijnvogel
Created January 13, 2017 02:59
Show Gist options
  • Save Robijnvogel/d6e4ac43513c18e042533b22375f5a36 to your computer and use it in GitHub Desktop.
Save Robijnvogel/d6e4ac43513c18e042533b22375f5a36 to your computer and use it in GitHub Desktop.
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) {
//Check if the metadata value is 0 -- we don't want the user to replace Ancient Fabric
if (heldItem != null && state.getValue(TYPE) != 1) {
Block block = Block.getBlockFromItem(heldItem.getItem());
if (!state.isNormalCube() || block instanceof BlockContainer || block == this || player.isSneaking()) {
return false;
}
if (!world.isRemote) {
if (!player.capabilities.isCreativeMode) {
heldItem.stackSize--;
}
world.setBlockState(pos, block.getStateForPlacement(world, pos, side, hitX, hitY, hitZ, 0, player)); //these parameters actually might not really be the right ones
}
return true;
}
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment