Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[SOLVED!] Spawning items from using an item on a block


RaTheBadger
 Share

Recommended Posts

Hello; I'm having a minor issue with my mod. There's an item in my mod, that when right clicked on a block will turn it into a different block. This works fine; however it also is set to spawn an item there. When it does this, it spawns both the actual item, and a sort of ghost entity of the item. How do I fix this?

Here's all the code used to do this.

    public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
    {
        MovingObjectPosition var4 = this.getMovingObjectPositionFromPlayer(par2World, par3EntityPlayer, true);

        if (var4 == null)
        {
            return par1ItemStack;
        }
        else
        {
            if (var4.typeOfHit == EnumMovingObjectType.TILE)
            {
                int var5 = var4.blockX;
                int var6 = var4.blockY;
                int var7 = var4.blockZ;

                if (!par2World.canMineBlock(par3EntityPlayer, var5, var6, var7))
                {
                    return par1ItemStack;
                }

                if (!par3EntityPlayer.canPlayerEdit(var5, var6, var7, var4.sideHit, par1ItemStack))
                {
                    return par1ItemStack;
                }

                if (par2World.getBlockId(var5, var6, var7) == ModAdamant.witherdirt.blockID)
                {
                    par2World.setBlockWithNotify(var5, var6, var7, Block.dirt.blockID);
                    par1ItemStack.damageItem(1, par3EntityPlayer);
                    par2World.spawnEntityInWorld(new EntityItem(par2World, var5, var6, var7, new ItemStack(ModAdamant.withershard)));
                }
            }

            return par1ItemStack;
        }
    }

Thanks for helping me :)

Link to comment
Share on other sites

Add [solved] to the beginning of the title at least, then people knows it's solved and people willing to help can skipp it while others having similar problems will find the solution faster when searching :)

If you guys dont get it.. then well ya.. try harder...

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
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.

 Share



×
×
  • Create New...

Important Information

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