Posted June 19, 201510 yr Hey ! I'm trying to make it so when you right click on a block with an empty hand, it goes in your inventory. The problem is that when I right click on a blue flower, it gives me a red flower. I know there are no more metadatas, but some properties. I would like to know how to get the color of the block I'm rightclicking on, and then convert it into an int so I can give it to my player. Here is my code: public void clickEnderman(BlockPos pos, EntityPlayer player, Block block, PlayerInteractEvent event){ if (isBlockEditable(block) == true && player.getCurrentEquippedItem() == null && (player.experienceLevel >= 1 || player.capabilities.isCreativeMode)){ player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(block, 1)); event.world.setBlockToAir(pos); player.addExperienceLevel(-1); } } Any help will be welcome !
June 19, 201510 yr Author getPickBlock requires a moving object position, and it can only be accessed from an item. I want all this stuff to work when the player doesn't have an item. Plus, I think it would be usefull to know how to get the damn colors from the block, I may need it some day. Anyway, if you know how to get a moving object position without an Item, it would be usefull too !
June 19, 201510 yr Try this player.inventory.setInventorySlotContents(player.inventory.currentItem, new ItemStack(block, 1, block.getMetaFromState(world.getBlockState(pos))));
June 19, 201510 yr What do you mean no accossiated item? You mean the ItemBlock just doesn't exist, or the item is unobtainable in vanilla
June 24, 201510 yr Author Thanks for these infos, they're duly noted. I don't allow BlockContainers to be picked up, so I don't have any problems, but it's good to know if i ever need to know how to pick up flowerpots, thanks !
June 24, 201510 yr Doors aren't BlockContainers, and they don't have an associated ItemBlock. So you'd have to rethink your logic (Hint: getPickBlock . Please use that, it is your only way to do it properly.. Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support. 1.12 -> 1.13 primer by williewillus. 1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support. http://www.howoldisminecraft1710.today/
June 24, 201510 yr Author I'm aware of that, there's a whole list of blocks I don't want the player to pick up (such a buttons, levers, and everything you need to right click on): public boolean isBlockEditable(Block block){ @SuppressWarnings("rawtypes") Class[] forbidden = {BlockDoor.class, BlockButton.class, BlockContainer.class, BlockCrops.class, BlockFenceGate.class, BlockPortal.class, BlockLiquid.class, BlockFire.class, BlockLever.class, BlockRedstoneDiode.class, BlockTrapDoor.class, BlockPistonExtension.class, BlockPistonBase.class, BlockDragonEgg.class, BlockWorkbench.class, BlockAnvil.class}; Boolean isblockeditable = true; for (int i=0; i<forbidden.length; i++){ if (forbidden[i].isInstance(block) || block == Blocks.obsidian || block == Blocks.bedrock || block == Blocks.bed) isblockeditable = false; } return isblockeditable; }
June 24, 201510 yr Author Yep, you're right. Here is what I did: player.inventory.setInventorySlotContents(player.inventory.currentItem, block.getPickBlock(new MovingObjectPosition(player), event.world, pos)); Thanks !
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.