Posted August 7, 201411 yr Hey all, I'm having some trouble trying to get my metadata block to respond to the pick block function. After doing some searching I came across the method getBlockPicked? I cannot for the life of me get it to work though. I've also tried looking at vanilla code but I cant see anything. Could someone help me out?
August 8, 201411 yr Author I dont quite know what you mean, I tried looking for a ForgeHooks.onPickBlock but I cant seem to find anything.
August 8, 201411 yr Hi Cut and paste from my install... ForgeHooks:: /** * Called when a player uses 'pick block', calls new Entity and Block hooks. */ public static boolean onPickBlock(MovingObjectPosition target, EntityPlayer player, World world) { ItemStack result = null; boolean isCreative = player.capabilities.isCreativeMode; if (target.typeOfHit == MovingObjectType.BLOCK) { int x = target.blockX; int y = target.blockY; int z = target.blockZ; Block block = world.getBlock(x, y, z); if (block.isAir(world, x, y, z)) { return false; } result = block.getPickBlock(target, world, x, y, z); } else { if (target.typeOfHit != MovingObjectType.ENTITY || target.entityHit == null || !isCreative) { return false; } result = target.entityHit.getPickedResult(target); } if (result == null) { return false; } for (int x = 0; x < 9; x++) { ItemStack stack = player.inventory.getStackInSlot(x); if (stack != null && stack.isItemEqual(result) && ItemStack.areItemStackTagsEqual(stack, result)) { player.inventory.currentItem = x; return true; } } if (!isCreative) { return false; } int slot = player.inventory.getFirstEmptyStack(); if (slot < 0 || slot >= 9) { slot = player.inventory.currentItem; } player.inventory.setInventorySlotContents(slot, result); player.inventory.currentItem = slot; return true; } If that doesn't give you the clues you need, show us your code and an explanation of the problem (what you expect vs what you actually get), see if we can help -TGG
August 8, 201411 yr Author Okay, so I have 6 different types of bookcase, each with their own texture and metadata, but whenever I pick block on any of them, I always get the one with a metadata of 0. I have tried these two methods: public ItemStack onPickBlock(Block block, int i, int meta) { if(meta == 0) { return new ItemStack(AdvAes.blockBookshelves, 0, 3); } else return new ItemStack(AdvAes.blockBookshelves, 0, 5); } public ItemStack getPickBlock(Block block, int i, int meta) { if(meta == 0) { return new ItemStack(AdvAes.blockBookshelves, 0, 3); } else return new ItemStack(AdvAes.blockBookshelves, 0, 5); } I intentionally messed up the metadata numbers just for testing. However with both of these , where I should not be given the metadata of 0 at all, I still get the bookshelf with 0. EDIT: I have also now tried public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) { Item item = getItem(world, x, y , z); Block block = Block.getBlockFromItem(item); return new ItemStack(item, 1, block.getDamageValue(world, x, y, z)); } public ItemStack getPickBlock(MovingObjectPosition target, World world, int x, int y, int z) { Item item = getItem(world, x, y , z); if(item == null) { return null; } Block block = item instanceof ItemBlock && !isFlowerPot() ? Block.getBlockFromItem(item) : this; return new ItemStack(item, 1, block.getDamageValue(world, x, y, z)); }
August 8, 201411 yr Hi Where (which class) have you put those methods? I don't recognise them? Are you sure they get called at all? (Have you tried putting a breakpoint or System.out.println("here"); in there?) And why are you returning an ItemStack with a stack size of 0? -TGG
August 8, 201411 yr Author Im putting them in the class that relates to the block blockBookshelves = new Bookshelves().setBlockName("Bookshelf"); So they're going in Bookshelves.class. (I have added some more methods that I tried in the previous post, I didn't see that you replied.
August 8, 201411 yr If you mean you want to pick the block with metadata as an ItemBlock with damage, you should return the metadata in the damageDropped function, if that doesn't work, make custom class extending ItemBlock with damage to denote Block's metadata
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.