Posted April 1, 20178 yr 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 April 1, 20178 yr 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.