Posted September 11, 20169 yr I'm learning modding minecraft with a "Super cheaty block" hehe. Basically what this block does is when right clicked with a dirt it should give a diamond or spawn it on the player's feet. I've already managed to add the block, spawn it with the /give command and give the diamond to the inventory if otherwise i'm spawning the diamond on the floor (code bellow) but it shows 2 diamonds on the floor and if relog or open a free slot it only show one diamond. public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, @Nullable ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { ItemStack reward = new ItemStack(Items.DIAMOND, 1); Item dirtItem = ItemBlock.getItemFromBlock(Blocks.DIRT); if (playerIn != null) { heldItem = playerIn.getHeldItem(EnumHand.MAIN_HAND); if (heldItem != null && dirtItem.equals(heldItem.getItem())) { heldItem.stackSize -= 1; if (!playerIn.inventory.addItemStackToInventory(reward)) { worldIn.spawnEntityInWorld(new EntityItem(worldIn, playerIn.posX, playerIn.posY, playerIn.posZ, reward)); } } } return true; }
September 11, 20169 yr 1. If you ever manipulate data - you do it on server (!world.isRemote). That includes giving items and spawning entities. http://mcforge.readthedocs.org/en/latest/concepts/sides/ 2. You can compare Items with "==". equals is usually discouraged (they are singletons). 1.7.10 is no longer supported by forge, you are on your own.
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.