Jump to content

[1.10.2] Ghost itens spawn


gabrielbl

Recommended Posts

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;
}

 

Link to comment
Share on other sites

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.