Jump to content

[1.7.10] need some help with BlockBreakEvent and harvesting blocks


Manslaughter777

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

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.