Jump to content

Recommended Posts

Posted

I have a custom pickaxe that mines the ore and all ores around it and I'm not sure how to account for Silk Touch.

Here is the code:

public boolean onBlockDestroyed(ItemStack par1ItemStack, World par2World, int par3, int x, int y, int z, EntityLivingBase par7EntityLivingBase)
    {
	super.onBlockDestroyed(par1ItemStack, par2World, par3, x, y, z, par7EntityLivingBase);
	if(!par7EntityLivingBase.isSneaking())
	{
		String st1 = Integer.toString(par2World.getBlockId(x, y, z));
		String st2 = st1 + ":" + Integer.toString(par2World.getBlockMetadata(x, y, z));
		if(Arrays.asList(this.ores).contains(st1) || Arrays.asList(this.ores).contains(st2))
		{
			//par2World.destroyBlock(x, y, z, true);
			this.repeatMine(par2World, x, y, z);
		}
	}
        return true;
    }

public void repeatMine(World world, int x, int y, int z)
{
	for(int i = -1; i <= 1; i++)
	{
		for(int j = -1; j <= 1; j++)
		{
			for(int k = -1; k <= 1; k++)
			{
				String st1 = Integer.toString(world.getBlockId(x + i, y + j, z + k));
				String st2 = st1 + ":" + Integer.toString(world.getBlockMetadata(x + i, y + j, z + k));
				if(Arrays.asList(this.ores).contains(st1) || Arrays.asList(this.ores).contains(st2))
				{
					world.destroyBlock(x + i, y + j, z + k, true);
					this.repeatMine(world, x + i, y + j, z + k);
				}
			}
		}
	}
}

width=320 height=64http://www.slothygaming.com/img/ota.png[/img]

If your grammar is shit and you blatantly don't know what you're doing, I will not help you.

Posted

Use

EnchantmentHelper#getEnchantmentLevel(enchId, itemStack)

where

enchId

is the ID of the enchantment (e.g. Enchantment#fortune#effectId) and

itemStack

is the ItemStack you want to check (in your case the stack passed as parameter in your method).

The method returns 0 if it isn't enchanted, else it returns the level of the enchantment.

Don't ask for support per PM! They'll get ignored! | If a post helped you, click the "Thank You" button at the top right corner of said post! |

mah twitter

This thread makes me sad because people just post copy-paste-ready code when it's obvious that the OP has little to no programming experience. This is not how learning works.

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.