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

Hello everyone:

I am having problems with adding and getting NBT tags off of a custom item.

When a BlockOre drops this item, a HarvestDropsEvent is fired:

@SubscribeEvent
public void GetCorrectOreDrops(HarvestDropsEvent event)
{
	if (event.block instanceof BlockOre)
	{

		//STOP NOW if Block is being silk touched
		if (event.isSilkTouching)
		{
			event.drops.clear();
			event.drops.add(Stack.S(event.block));
		}

		int nuggets = (event.world.rand.nextInt(16) + event.fortuneLevel * event.world.rand.nextInt(5) + 1);

		ItemStack stack = event.drops.get(0);
		stack = ORef.lumpOre.addOre((BlockOre) event.block, nuggets, stack);
		event.drops.set(0, stack);
		event.dropChance = 1.0F;
	}
}

 

This refers to a NBT adding script in the item (addOre):

public ItemStack addOre(BlockOre ore, int nuggets, ItemStack stack)
{
	NBTTagList taglist = (stack.stackTagCompound != null && stack.stackTagCompound.hasKey("Ores")) ? (NBTTagList) stack.stackTagCompound.getTag("BiggerDim") : new NBTTagList();
	NBTTagCompound tag = new NBTTagCompound();

	tag.setInteger("nuggets", nuggets);
	tag.setInteger("ore", ore.getIdFromBlock(ore));
	taglist.appendTag(tag);

	System.out.println(tag.getInteger("ore"));

	stack.stackTagCompound.setTag("Ores", taglist);

	return stack;
}

 

Whenever I harvest the block, the game crashes. What am I missing?

 

 

This helped me understand NBT greatly "

 

But the issue is you are forgetting to check to see if the itemstack has a NBTTagCompound

 

if (itemStack.stackTagCompound == null) {
		itemStack.setTagCompound(new NBTTagCompound());
	}

 

you are probably getting a crash of something being null right? Watch the video and all will be revealed to you. (also the posted code snippet is how you make sure not to get a crash trying to add to a null object)

  • Author

The actual crash comes from a ticking memory connection with a whole bunch of forge/minecraft code, but it is caused by a null pointer in

stack.stackTagCompound.setTag("Ores", taglist);

in the second code bit.

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.