Jump to content

[1.12.2] Spawning EntityItems when Activating a Block


Recommended Posts

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

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