hotrods20 Posted May 18, 2014 Posted May 18, 2014 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); } } } } } Quote http://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.
SanAndreaP Posted May 19, 2014 Posted May 19, 2014 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. Quote 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.
Recommended Posts
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.