Jump to content

Pick block with metadata


ARavinMadMonkey

Recommended Posts

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?

 

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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));
}	

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.