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

In 1.10 I stored item information in the onItemUse function to nbt to save the progress of a certain action.

 

 @NotNull
    @Override
    public EnumActionResult onItemUse(
                                       final ItemStack stack,
                                       final EntityPlayer playerIn,
                                       final World worldIn,
                                       final BlockPos pos,
                                       final EnumHand hand,
                                       final EnumFacing facing,
                                       final float hitX,
                                       final float hitY,
                                       final float hitZ)
    {
        if (!stack.hasTagCompound())
        {
            stack.setTagCompound(new NBTTagCompound());
        }
        final NBTTagCompound compound = stack.getTagCompound();

        if (!compound.hasKey("pos1"))
        {
            BlockPosUtil.writeToNBT(compound, "pos1", pos);
            if (worldIn.isRemote)
            {
                LanguageHandler.sendPlayerLocalizedMessage(playerIn, "item.scepterSteel.point");
            }
            return EnumActionResult.SUCCESS;
        }
        else if (!compound.hasKey("pos2"))
        {
            @NotNull final BlockPos pos1 = BlockPosUtil.readFromNBT(compound, "pos1");
            @NotNull final BlockPos pos2 = pos;
            if (pos2.distanceSq(pos1) > 0)
            {
                BlockPosUtil.writeToNBT(compound, "pos2", pos2);
                if (worldIn.isRemote)
                {
                    LanguageHandler.sendPlayerLocalizedMessage(playerIn, "item.scepterSteel.point2");
                }
                return EnumActionResult.SUCCESS;
            }
            if (worldIn.isRemote)
            {
                LanguageHandler.sendPlayerLocalizedMessage(playerIn, "item.scepterSteel.samePoint");
            }
            return EnumActionResult.FAIL;
        }
        else
        {
            @NotNull final BlockPos pos1 = BlockPosUtil.readFromNBT(compound, "pos1");
            @NotNull final BlockPos pos2 = BlockPosUtil.readFromNBT(compound, "pos2");
            if (!worldIn.isRemote)
            {
                saveStructure(worldIn, pos1, pos2, playerIn);
            }
            compound.removeTag("pos1");
            compound.removeTag("pos2");
            return EnumActionResult.SUCCESS;
        }
    }

 

 

In 1.10 though, the onItemUse does not offer the itemStack and the position variable at the same time.

 

I tried this but it won't work:

 

@NotNull
    @Override
    public EnumActionResult onItemUse(
                                       final EntityPlayer playerIn,
                                       final World worldIn,
                                       final BlockPos pos,
                                       final EnumHand hand,
                                       final EnumFacing facing,
                                       final float hitX,
                                       final float hitY,
                                       final float hitZ)
    {
        ItemStack stack = playerIn.getActiveItemStack();
        if (!stack.hasTagCompound())
        {
            stack.setTagCompound(new NBTTagCompound());
        }
        final NBTTagCompound compound = stack.getTagCompound();

        if (!compound.hasKey("pos1"))
        {
            BlockPosUtil.writeToNBT(compound, "pos1", pos);
            if (worldIn.isRemote)
            {
                LanguageHandler.sendPlayerLocalizedMessage(playerIn, "item.scepterSteel.point");
            }
            return EnumActionResult.SUCCESS;
        }
        else if (!compound.hasKey("pos2"))
        {
            @NotNull final BlockPos pos1 = BlockPosUtil.readFromNBT(compound, "pos1");
            @NotNull final BlockPos pos2 = pos;
            if (pos2.distanceSq(pos1) > 0)
            {
                BlockPosUtil.writeToNBT(compound, "pos2", pos2);
                if (worldIn.isRemote)
                {
                    LanguageHandler.sendPlayerLocalizedMessage(playerIn, "item.scepterSteel.point2");
                }
                return EnumActionResult.SUCCESS;
            }
            if (worldIn.isRemote)
            {
                LanguageHandler.sendPlayerLocalizedMessage(playerIn, "item.scepterSteel.samePoint");
            }
            return EnumActionResult.FAIL;
        }
        else
        {
            @NotNull final BlockPos pos1 = BlockPosUtil.readFromNBT(compound, "pos1");
            @NotNull final BlockPos pos2 = BlockPosUtil.readFromNBT(compound, "pos2");
            if (!worldIn.isRemote)
            {
                saveStructure(worldIn, pos1, pos2, playerIn);
            }
            compound.removeTag("pos1");
            compound.removeTag("pos2");
            return EnumActionResult.SUCCESS;
        }
    }

 

What can I do to make it work again?

 

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.