Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

NBT tags causing item rendering crash


Qwertygiy
 Share

Recommended Posts

I'm pretty new to using NBT data, and it's been months since I've been very active at making anything at all, so this is probably me missing something pretty obvious.

 

What I'm trying to do is make a custom record item that uses one item ID for multiple songs, and uses NBT data to store the song name for playing.

 

Here's my item class:

 

 

 

package kbi.disc.common;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;

import net.minecraft.block.Block;
import net.minecraft.block.BlockJukeBox;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemRecord;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.client.renderer.texture.IconRegister;


public class ItemKBIRecord extends ItemRecord
{
    public String recordName;
public String artistName;

    public ItemKBIRecord(int par1)
    {
        super(par1, "Blank");
        this.recordName = "Blank";
	this.artistName = "Qwertygiy";
        this.maxStackSize = 1;
        //this.setCreativeTab(EightBit.tabEightBit);
    }

public void updateIcons(IconRegister iconRegister)
{
		 iconIndex = iconRegister.registerIcon("MMD:Disc");
}


public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10)
{
	if (par3World.getBlockId(par4, par5, par6) == Block.jukebox.blockID && par3World.getBlockMetadata(par4, par5, par6) == 0)
	{
		if (par3World.isRemote)
		{
			return true;
		}
		else
		{
			((BlockJukeBox)Block.jukebox).insertRecord(par3World, par4, par5, par6, par1ItemStack);
			//par3World.playAuxSFXAtEntity((EntityPlayer)null, 1005, par4, par5, par6, this.itemID);
			par3World.playSoundEffect(par4, par5, par6, "kbi.disc." + par1ItemStack.stackTagCompound.getString("artist") + "." + par1ItemStack.stackTagCompound.getString("song"), 1.0F, 1.0F);
			--par1ItemStack.stackSize;
			return true;
		}
	}
	else
	{
		return false;
	}
}


public void addData(ItemStack is, String name, String author)
{
	if (is.stackTagCompound == null) {
		NBTTagCompound nbt = new NBTTagCompound();
		nbt.setString("author", author);
		nbt.setString("song", name);
		is.setTagCompound(nbt);
	}
}

@SideOnly(Side.CLIENT)
    public void addInformation(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, List par3List, boolean par4)
    {
	if(par1ItemStack.stackTagCompound != null)
	{
		//par3List.add(par1ItemStack.stackTagCompound.getString("artist"));
		par3List.add(par1ItemStack.stackTagCompound.getString("song"));
	}
	else
	{
		par3List.add("Error - Invalid NBT tags");
	}
    }

    @SideOnly(Side.CLIENT)
    public String getRecordTitle()
    {
	return recordName;
    }

@SideOnly(Side.CLIENT)
    public EnumRarity getRarity(ItemStack par1ItemStack)
    {
        return EnumRarity.rare;
    }

}

 

 

 

Here's the item declarations and such in the main mod file:

 

 

 

recordItem = new ItemKBIRecord(11111);

		ItemStack testDisc = new ItemStack(11111, 1, 0);
		recordItem.addData(testDisc, "Stewed", "Qwertygiy");

		GameRegistry.addRecipe(testDisc, new Object[] {
			"xxx", Character.valueOf('x'), Block.dirt
		});

 

 

 

I can see the non-crafted item with no NBT data in BEI just fine.  But when I try to craft it, I get this crash.

 

From Mojang error report

 

java.lang.NullPointerException
at net.minecraft.item.ItemStack.func_77954_c(ItemStack.java:138)
at net.minecraft.client.renderer.entity.RenderItem.func_77015_a(RenderItem.java:339)
at net.minecraft.client.renderer.entity.RenderItem.func_82406_b(RenderItem.java:443)
at net.minecraft.client.gui.inventory.GuiContainer.renderSlotItem(GuiContainer.java:456)
at net.minecraft.client.gui.inventory.GuiContainer.func_74192_a(GuiContainer.java:443)
at net.minecraft.client.gui.inventory.GuiContainer.func_73863_a(GuiContainer.java:146)
at net.minecraft.client.renderer.EntityRenderer.func_78480_b(EntityRenderer.java:1168)
at net.minecraft.client.Minecraft.func_71411_J(Minecraft.java:867)
at net.minecraft.client.Minecraft.run(Minecraft.java:756)
at java.lang.Thread.run(Unknown Source)

 

From Forge log:

 

2013-04-13 11:09:33 [iNFO] [sTDERR] net.minecraft.util.ReportedException: Rendering screen
2013-04-13 11:09:33 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.EntityRenderer.func_78480_b(EntityRenderer.java:1177)
2013-04-13 11:09:33 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.func_71411_J(Minecraft.java:867)
2013-04-13 11:09:33 [iNFO] [sTDERR] 	at net.minecraft.client.Minecraft.run(Minecraft.java:756)
2013-04-13 11:09:33 [iNFO] [sTDERR] 	at java.lang.Thread.run(Unknown Source)
2013-04-13 11:09:33 [iNFO] [sTDERR] Caused by: java.lang.NullPointerException
2013-04-13 11:09:33 [iNFO] [sTDERR] 	at net.minecraft.item.ItemStack.func_77954_c(ItemStack.java:138)
2013-04-13 11:09:33 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.entity.RenderItem.func_77015_a(RenderItem.java:339)
2013-04-13 11:09:33 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.entity.RenderItem.func_82406_b(RenderItem.java:443)
2013-04-13 11:09:33 [iNFO] [sTDERR] 	at net.minecraft.client.gui.inventory.GuiContainer.renderSlotItem(GuiContainer.java:456)
2013-04-13 11:09:33 [iNFO] [sTDERR] 	at net.minecraft.client.gui.inventory.GuiContainer.func_74192_a(GuiContainer.java:443)
2013-04-13 11:09:33 [iNFO] [sTDERR] 	at net.minecraft.client.gui.inventory.GuiContainer.func_73863_a(GuiContainer.java:146)
2013-04-13 11:09:33 [iNFO] [sTDERR] 	at net.minecraft.client.renderer.EntityRenderer.func_78480_b(EntityRenderer.java:1168)
2013-04-13 11:09:33 [iNFO] [sTDERR] 	... 3 more

 

So, can anyone help me with this?

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
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.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.