Jump to content

[1.7.10] player.addItemStackToInventory not showing up until relogging


ashjack

Recommended Posts

I have been trying to make a vein mining tool, similar to the dark matter pickaxe from EE2, and my code will remove all the blocks in the vein, and should give them to the player, but the new blocks only show up when I save and quit the world, and reload it. I don't need to close Minecraft, just the world. I have a feeling it's something to do with the !world.isRemote check, but putting it on the outside causes a crash, so I have to put it inside. Here is my code:

 

public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int i, int j, int k, int l, float a, float b, float c)
{
	int veinSize = 0;
	Block originalBlock = null;
if(!world.isRemote)
{

	if(true)
	{
		AlchemicalExchange.log.info("Has Used Item");
		List<V3> vein = new ArrayList<V3>();
		originalBlock = world.getBlock(i, j, k);

		if(originalBlock instanceof BlockOre)
		{
			AlchemicalExchange.log.info("Block is an ore");
			vein.add(0, new V3(originalBlock, i, j, k));

			for(int x=0; x<vein.size(); x++)
			{
				AlchemicalExchange.log.info("Running for loop");
				if(vein.get(x) != null)
				{
					V3 adjBlock = new V3(vein.get(x).block, vein.get(x).x, vein.get(x).y, vein.get(x).z);

					AlchemicalExchange.log.info("Checking for adjacent ore block");
					/*X AXIS*/
					if(world.getBlock((int)adjBlock.x+1, (int)adjBlock.y, (int)adjBlock.z) == originalBlock)
					{
						vein.add(new V3(adjBlock.block, adjBlock.x+1, adjBlock.y, adjBlock.z));
						world.setBlockToAir((int)adjBlock.x+1, (int)adjBlock.y, (int)adjBlock.z);
						veinSize++;
						AlchemicalExchange.log.info("Found adjacent ore block on the X Axis (Right)");
					}
					if(world.getBlock((int)adjBlock.x-1, (int)adjBlock.y, (int)adjBlock.z) == originalBlock)
					{
						vein.add(new V3(adjBlock.block, adjBlock.x-1, adjBlock.y, adjBlock.z));
						world.setBlockToAir((int)adjBlock.x-1, (int)adjBlock.y, (int)adjBlock.z);
						veinSize++;
						AlchemicalExchange.log.info("Found adjacent ore block on the X Axis (Left)");
					}

					/*Y AXIS*/
					if(world.getBlock((int)adjBlock.x, (int)adjBlock.y+1, (int)adjBlock.z) == originalBlock)
					{
						vein.add(new V3(adjBlock.block, adjBlock.x, adjBlock.y+1, adjBlock.z));
						world.setBlockToAir((int)adjBlock.x, (int)adjBlock.y+1, (int)adjBlock.z);
						veinSize++;
						AlchemicalExchange.log.info("Found adjacent ore block on the Y Axis (Above)");
					}
					if(world.getBlock((int)adjBlock.x, (int)adjBlock.y-1, (int)adjBlock.z) == originalBlock)
					{
						vein.add(new V3(adjBlock.block, adjBlock.x, adjBlock.y-1, adjBlock.z));
						world.setBlockToAir((int)adjBlock.x, (int)adjBlock.y-1, (int)adjBlock.z);
						veinSize++;
						AlchemicalExchange.log.info("Found adjacent ore block on the Y Axis (Below)");
					}

					/*Z AXIS*/
					if(world.getBlock((int)adjBlock.x, (int)adjBlock.y, (int)adjBlock.z+1) == originalBlock)
					{
						vein.add(new V3(adjBlock.block, adjBlock.x, adjBlock.y, adjBlock.z+1));
						world.setBlockToAir((int)adjBlock.x, (int)adjBlock.y, (int)adjBlock.z+1);
						veinSize++;
						AlchemicalExchange.log.info("Found adjacent ore block on the Z Axis (Front)");
					}
					if(world.getBlock((int)adjBlock.x, (int)adjBlock.y, (int)adjBlock.z-1) == originalBlock)
					{
						vein.add(new V3(adjBlock.block, adjBlock.x, adjBlock.y, adjBlock.z-1));
						world.setBlockToAir((int)adjBlock.x, (int)adjBlock.y, (int)adjBlock.z-1);
						veinSize++;
						AlchemicalExchange.log.info("Found adjacent ore block on the Z Axis (Back)");
					}
				}
			}

			if(vein.size() == 1)
			{
				world.setBlockToAir(i, j, k);
				veinSize++;
			}
		}
	}
}
player.inventory.addItemStackToInventory(new ItemStack(originalBlock, veinSize, originalBlock.getDamageValue(world, i, j, k)));
return true;
}

Link to comment
Share on other sites

1. What is that 'if(true)'? (Do you know Basic Java?)

2. Are you meaning that the change doesn't get saved and reloaded?

I. Stellarium for Minecraft: Configurable Universe for Minecraft! (WIP)

II. Stellar Sky, Better Star Rendering&Sky Utility mod, had separated from Stellarium.

Link to comment
Share on other sites

I do know some Java, but I didn't know the name of the onItemUse function at the time, so I found a snipped online which included that bit, so I thought I needed it to be there.

 

What I mean about the change is that say there were three ores in a vein. When I use the item on it, the ores disappear, but I need to save and quit to menu, and reload the world to see the three ores in my inventory.

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.