Jump to content

Recommended Posts

Posted (edited)

So basically I'm trying to make a leaf block with fruit on it that, when right clicked:

 

1. gives the player the fruit item, or drops it at their feet if their inventory is full.

Not exactly sure how to do that nicely. Directly adding it to the player inventory (player.inventory.add) resulted in some really weird stuff going on. Something tells me that's not a method I should be using.

 

Spawning it as an EntityItem in the world spawns it as a ghost item that can't be picked up even if I stand on it, or drop other normal versions of the item right next to the ghost items. It also isn't destroyed by lava.

 

2. changes the leaf block into the version that doesn't have fruit (note that said version is a different block altogether).

For this I tried using worldIn.setBlockState but that doesn't actually do anything - the block blinks with the texture of the fruit-less version for a split second and then immediately turns back into the fruit version, which can be right-clicked once again for the same result.

 

How would I go about doing these?

 

Edited by lightningdragonx5
Posted
4 hours ago, lightningdragonx5 said:

Spawning it as an EntityItem in the world spawns it as a ghost item that can't be picked up even if I stand on it

Make sure you call World#isRemote to check whether you're working with a client "dummy" world. Normally you would do this kind of stuff on the server world, i.e. something like if(!world.isRemote()) .

Posted (edited)
15 hours ago, MichaelVitrio said:

Make sure you call World#isRemote to check whether you're working with a client "dummy" world. Normally you would do this kind of stuff on the server world, i.e. something like if(!world.isRemote()) .

I did. Below is my current code, what could I be doing wrong?

 

@Override
    public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
        if(!worldIn.isRemote)
        {
            return false;
        }

        System.out.println(this.fruit);

        EntityItem droppedFruit = new EntityItem(worldIn, pos.getX(), pos.getY(), pos.getZ(), new ItemStack(this.fruit, 1));
        worldIn.spawnEntity(droppedFruit);
        

        worldIn.setBlockState(pos, this.baseLeaves.getDefaultState());

        return true;
    }

 

Edited by lightningdragonx5

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.

Announcements



×
×
  • Create New...

Important Information

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