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'm tracing some issues I have placing a block that has Meta-data.

I'm using this library for reference: forgeSrc-1.11.2-13.20.0.2262.jar. For the sake of this post I updated to the most recent MDK just before posting.

 

The problem seem to originate in the referenced library net.minecraft.item.ItemBlock.class in function onItemUse().

Spoiler

public EnumActionResult onItemUse(EntityPlayer player, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ)
    {
        IBlockState iblockstate = worldIn.getBlockState(pos);
        Block block = iblockstate.getBlock();

        if (!block.isReplaceable(worldIn, pos))
        {
            pos = pos.offset(facing);
        }

        ItemStack itemstack = player.getHeldItem(hand);

        if (!itemstack.isEmpty() && player.canPlayerEdit(pos, facing, itemstack) && worldIn.mayPlace(this.block, pos, false, facing, (Entity)null))
        {
            int i = this.getMetadata(itemstack.getMetadata());
            IBlockState iblockstate1 = this.block.getStateForPlacement(worldIn, pos, facing, hitX, hitY, hitZ, i, player, hand);

            if (placeBlockAt(itemstack, player, worldIn, pos, facing, hitX, hitY, hitZ, iblockstate1))
            {
                SoundType soundtype = worldIn.getBlockState(pos).getBlock().getSoundType(worldIn.getBlockState(pos), worldIn, pos, player);
                worldIn.playSound(player, pos, soundtype.getPlaceSound(), SoundCategory.BLOCKS, (soundtype.getVolume() + 1.0F) / 2.0F, soundtype.getPitch() * 0.8F);
                itemstack.shrink(1);
            }

            return EnumActionResult.SUCCESS;
        }
        else
        {
            return EnumActionResult.FAIL;
        }
    }

 

As you see the function does

 

 ItemStack itemstack = player.getHeldItem(hand);

 

and then 

 

 int i = this.getMetadata(itemstack.getMetadata());

 

The problem here is that this.getMetadata() has two different calltypes (net.minecraft.item.item.class)

Spoiler

public int getMetadata(int damage)
    {
        return 0;
    }

 

// (...) AND

 

public int getMetadata(ItemStack stack)
    {
        return stack.itemDamage;
    }

 

 

Now, seeing as

 itemstack.getMetadata()

returns the actual meta-data of the item as an int, the code

 int i = this.getMetadata(itemstack.getMetadata());

will ALWAYS return 0 as it calls

 public int getMetadata(int damage).

 

This causes the problem I have that whenever I have one of my added blocks with meta-data as an item, and right-click to place it as a block, the placed block is always default (0) meta-variant.

 

If this was intentional behaviour it seems strange to call itemstack.getMetadata() in the first place. It feels like the variable decleration should be int i = itemstack.getMetadata(); or possibly public int getMetadata(int damage) { return damage; }.

 

Does anyone have any information on something I might be doing wrong here? I Am fairly new to modding in minecraft so I might just be missing something.

Edited by CovexLy

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.