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 I basically want to be able to put stuff on a block and take it back off (changing it's state).

Since I want to partially require different items/tools for that I'm using the onBlockActivated-Method:

@Override
public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    if (!facing.equals(EnumFacing.UP)) return false;
    ItemStack item = playerIn.getHeldItem(hand);
    if (item == null || item.isEmpty()) return false;
    Type type = state.getValue(VARIANT);
    if (item.getItem().getToolClasses(item).contains("shovel")) {
        if (type.equals(Type.CLEAN)) return false; // clean up cleaned
        if (type.equals(Type.HAYED)) { //take back clean wheat
            if (!worldIn.isRemote) {
                worldIn.setBlockState(pos, getStateFromMeta(Type.CLEAN.getMeta()));

                Renergy.l("Dropping Wheat");
                EntityItem recycle = new EntityItem(worldIn, hitX, hitY + 0.1, hitZ, new ItemStack(Items.WHEAT));
                recycle.setDefaultPickupDelay();
                worldIn.spawnEntity(recycle);

                worldIn.playSound(playerIn, hitX, hitY, hitZ, SoundEvents.BLOCK_GRASS_BREAK, SoundCategory.BLOCKS, 1f, 1f);
            }
            return true;
        }
      //More cases....

 

Now changing the BlockState and decreasing the item in hand (placing something on the block) works without any problems.

Taking the item back from the block (with a shovel in this case) however only changes the BlockState.

The item wont spawn, the sound wont play and what frustrates me the most is that there is absolutely no StackTrace whatsoever.

 

There seems to be a similar topic from about a year ago that sadly never got resolved, so I'm opening this topic.

 

I'm currently building against forge 2619

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.