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

Hey,

 

I just started modding Minecraft. I want to create a pickaxe, which - on rightclick - harvests more than one block. Unfortunately I encountered two problems. The main problem is that the blocks get set to air, but you are still colliding with them. If I leave the world and rejoin, the blocks are reset to what they were  before (dirt, stone, whatever). The second problem is that  the block, the player is hovering over with his mouse, doesn't become air. 

 

Could you maybe take a look at my code (this is only for the player looking south)? I don't see any mistake, but maybe you do.

 

	@Override
public ItemStack onItemRightClick(ItemStack par1ItemStack, World w, EntityPlayer player)
{
	Minecraft mc = Minecraft.getMinecraft();
	int x1;
	int y1;
	int z1;
	int damage = 0;
	if(mc.objectMouseOver != null)
	{
		x1 = mc.objectMouseOver.blockX;
		y1 = mc.objectMouseOver.blockY;
		z1 = mc.objectMouseOver.blockZ;
		if((MathHelper.floor_double((double)((player.rotationYaw * 4F) / 360F) + 0.5D) & 3) == 0)
		{
			for(int xvar = x1-1; xvar < x1+2; xvar++)
			{
				for(int yvar = y1-1; yvar < y1+2; yvar++)
				{
					for(int zvar = z1; zvar < z1+4; zvar++)
					{
						Block block = w.getBlock(xvar, yvar, zvar);
						if(!block.isAir(w, xvar, yvar, zvar) && block.canHarvestBlock(player, w.getBlockMetadata(xvar, yvar, zvar)) && block.getMaterial() != Material.water && block.getMaterial() != Material.lava)
						{
							block.harvestBlock(w, player, xvar, yvar, zvar, w.getBlockMetadata(xvar, yvar, zvar));
							w.setBlockToAir(xvar, yvar, zvar);
							player.addExhaustion(-0.025F);
							damage+=5;

						}								
					}
				}
			}
			par1ItemStack.damageItem(damage, player);
			return par1ItemStack;
		}

  • Author

I did not intend to make it work on a server. Just want to become familiar with all the classes and methods. But it may be helpful in future, so thanks for that tip. And one more question there: How am I supposed to get the coordinates of the block the player is aiming at then?

 

I added the if-condition !w.isRemote() and surprisingly it does work now, although I do not really understand why, because this  condition should not change the field "isRemote" at all.

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.