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.

[1.7.10] player.addItemStackToInventory not showing up until relogging

Featured Replies

Posted

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

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.

  • Author

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.

  • Author

Removing the if(true) changes nothing, so I'm going to assume that piece of code was useless.

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.