Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

About the ghost item - Are you spawning it on server? This applies for the other methods you have tried too

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

  • Author
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

 

4 hours ago, lightningdragonx5 said:

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

Your code goes inside the if block since worldIn.isRemote() returns true if it's a client world.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.