Jump to content

[1.7.2] Blocks not completely updating (setBlock - method)


triplec0re

Recommended Posts

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;
		}

Link to comment
Share on other sites

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.

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.