Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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

Block block = World.getBlockState(x,y,z).getBlock();

ItemStack itemstack = "Your pickaxe itemstack"

 

Then its just itemstack.canDestroy(block)

"you seem to be THE best modder I've seen imo."

~spynathan

 

ლ(́◉◞౪◟◉‵ლ

  • Author

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

  • Author

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

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?

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.

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.