Manslaughter777 Posted October 6, 2015 Posted October 6, 2015 G' day Ive made an upgrade for the pickaxe where when you break a block, all surrounding blocks get broken too in a 3x3 area. This works but there is a problem. B S S B S S S S S B = bedrock S = stone Lets say I break the center block, all 9 blocks will break even though im using and iron pickaxe which cant break bedrock. What I need to happen is so that when I break the center block, it will only break the stone (or whatever other block an iron pick can break) butnot the bedrock. This is inside BlockBreakEvent int boxWidth = 3; double par1 = boxWidth / 2; for(int i = 0; i < boxWidth; i++) { for(int j = 0; j < boxWidth; j++) { for(int k = 0; k < boxWidth; k++) { Item heldItem = player.getHeldItem().getItem(); //if(player.getHeldItem().getItem().canHarvestBlock()) //System.out.println(heldItem.canHarvestBlock(target, player.getHeldItem())); int x1 = (int)(x - par1 + i); int y1 = (int)(y - par1 + j); int z1 = (int)(z - par1 + k); Block target = world.getBlock(x1, y1, z1); int targetMeta = world.getBlockMetadata(x1, y1, z1); if(heldItem.canHarvestBlock(target, player.getHeldItem())) { target.harvestBlock(world, player, x1, y1, z1, targetMeta); world.setBlockToAir(x1, y1, z1); } } } } That code still makes the bedrock break, however I have also tried the following which somewhat works: int boxWidth = 3; double par1 = boxWidth / 2; for(int i = 0; i < boxWidth; i++) { for(int j = 0; j < boxWidth; j++) { for(int k = 0; k < boxWidth; k++) { Item heldItem = player.getHeldItem().getItem(); //if(player.getHeldItem().getItem().canHarvestBlock()) //System.out.println(heldItem.canHarvestBlock(target, player.getHeldItem())); int x1 = (int)(x - par1 + i); int y1 = (int)(y - par1 + j); int z1 = (int)(z - par1 + k); Block target = world.getBlock(x1, y1, z1); int targetMeta = world.getBlockMetadata(x1, y1, z1); if(world.getBlock((x1, y1, z1) != Blocks.bedrock) { target.harvestBlock(world, player, x1, y1, z1, targetMeta); world.setBlockToAir(x1, y1, z1); } } } } This code DOES work. The pick does not break the bedrock but still breaks the stone. Only problem is that blocks like Obsidian which an iron pick cant mine can still get broken this way. What looking for is something that checks if the block at the coords at x y z can be broken with the held item, and if so break it, otherwise dont. Thnx Quote
thebest108 Posted October 6, 2015 Posted October 6, 2015 Block block = World.getBlockState(x,y,z).getBlock(); ItemStack itemstack = "Your pickaxe itemstack" Then its just itemstack.canDestroy(block) Quote "you seem to be THE best modder I've seen imo." ~spynathan ლ(́◉◞౪◟◉‵ლ
Manslaughter777 Posted October 6, 2015 Author Posted October 6, 2015 Block block = World.getBlockState(x,y,z).getBlock(); ItemStack itemstack = "Your pickaxe itemstack" Then its just itemstack.canDestroy(block) Hmm, i cant find any of those methods? Are they new in 1.8? cause im still on 1.7... Quote
Manslaughter777 Posted October 6, 2015 Author Posted October 6, 2015 I have found something that works but still not fully correct. int boxWidth = 3; double par1 = boxWidth / 2; for(int i = 0; i < boxWidth; i++) { for(int j = 0; j < boxWidth; j++) { for(int k = 0; k < boxWidth; k++) { Item heldItem = player.getHeldItem().getItem(); //if(player.getHeldItem().getItem().canHarvestBlock()) //System.out.println(heldItem.canHarvestBlock(target, player.getHeldItem())); int x1 = (int)(x - par1 + i); int y1 = (int)(y - par1 + j); int z1 = (int)(z - par1 + k); Block target = world.getBlock(x1, y1, z1); int targetMeta = world.getBlockMetadata(x1, y1, z1); if(ForgeHooks.canToolHarvestBlock(target, targetMeta, player.getHeldItem())) { target.harvestBlock(world, player, x1, y1, z1, targetMeta); world.setBlockToAir(x1, y1, z1); } } } } this seems to work fine only that for some reason dirt doesnt get destroyed??? Quote
Failender Posted October 6, 2015 Posted October 6, 2015 because dirt isnt something to get harvested by pickaxes..? Also dont its not Item#canHarvestBlock , its ItemStack#canHarvestBlock, are you sure u checked that with a ItemStack and not an item? Quote
statphantom Posted October 6, 2015 Posted October 6, 2015 I am still learning so cant help you 100% but one thing that might help is, ItemStack (from player.getHeldItem()) is your object of the item, your damage, your adjustments, your enchantments etc. Where the Item (player.getHeldItem().getItem()) is kinda like a reference to the Class that your held item is a part of, e.g. testing if it is an instanceof ItemTool. If I'm wrong correct me please. Quote
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.