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



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Minecraft Version-1.16.5 Forge Version-36.2.0   Crash Log-  https://gist.github.com/keepinitreal247/05669330de1d11fba00d1cbe565f35b1 Debug Log-https://gist.github.com/keepinitreal247/af4304598bd4192be840e8c111af2c81
    • When I try to open forge with java it says unable to install java but I can open java itself just fine. I've tried deleting and redownloading both forge and java but nothing changed. I also tried opening it from my files and from my desktop but it still gave me the same message. I don't think I'm doing anything wrong, I just click on forge and pressed open with java and java opens but only to give me the message saying " unable to install java there are errors in the following switches".   (this is just a picture of what i got from google not my exact message)
    • This is the capability inject and provider for one of my capabilities. All of them are coded the exact same way. public class CapabilityDamageTypes { @CapabilityInject(IDamageTypes.class) public static Capability<IDamageTypes> DAMAGE_TYPES_CAPABILITY = null; public static void register() { CapabilityManager.INSTANCE.register(IDamageTypes.class, new Storage(), new Factory()); } private static class Storage implements Capability.IStorage<IDamageTypes> { @Nullable @Override public INBT writeNBT(Capability<IDamageTypes> capability, IDamageTypes instance, Direction side) { CompoundNBT tag = new CompoundNBT(); tag.putFloat("slash", instance.getSlashDamage()); tag.putFloat("impact", instance.getImpactDamage()); tag.putFloat("puncture", instance.getPunctureDamage()); tag.putFloat("fire", instance.getFireDamage()); tag.putFloat("lightning", instance.getLightningDamage()); tag.putFloat("ice", instance.getIceDamage()); tag.putFloat("dark", instance.getDarkDamage()); tag.putFloat("holy", instance.getHolyDamage()); tag.putFloat("magic", instance.getMagicDamage()); tag.putString("mobDamageType", instance.getMobDamageType()); return tag; } @Override public void readNBT(Capability<IDamageTypes> capability, IDamageTypes instance, Direction side, INBT nbt) { float slash = ((CompoundNBT) nbt).getFloat("slash"); float impact = ((CompoundNBT) nbt).getFloat("impact"); float puncture = ((CompoundNBT) nbt).getFloat("puncture"); float fire = ((CompoundNBT) nbt).getFloat("fire"); float lightning = ((CompoundNBT) nbt).getFloat("lightning"); float ice = ((CompoundNBT) nbt).getFloat("ice"); float dark = ((CompoundNBT) nbt).getFloat("dark"); float holy = ((CompoundNBT) nbt).getFloat("holy"); float magic = ((CompoundNBT) nbt).getFloat("magic"); String mobDamageType = ((CompoundNBT) nbt).getString("mobDamageType"); instance.setSlashDamage(slash); instance.setImpactDamage(impact); instance.setPunctureDamage(puncture); instance.setFireDamage(fire); instance.setLightningDamage(lightning); instance.setIceDamage(ice); instance.setDarkDamage(dark); instance.setHolyDamage(holy); instance.setMagicDamage(magic); instance.setMobDamageType(mobDamageType); } } private static class Factory implements Callable<IDamageTypes> { @Override public IDamageTypes call() throws Exception { return new DamageTypes(0, 0, 0, 0, 0, 0, 0, 0, 0, "IMPACT"); } } } package com.cwjn.hardstuckintegration.Capabilities.DamageTypes; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.Direction; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilitySerializable; import net.minecraftforge.common.util.LazyOptional; import javax.annotation.Nonnull; import javax.annotation.Nullable; public class DamageTypesProvider implements ICapabilitySerializable<CompoundNBT> { //private final DamageTypes damage = new DamageTypes(); //private final LazyOptional<IDamageTypes> damageOptional = LazyOptional.of(() -> damage); private DamageTypes damage; private LazyOptional<IDamageTypes> damageOptional; public void invalidate() { damageOptional.invalidate(); } public DamageTypesProvider(float I, float P, float S, float F, float L, float IC, float D, float H, float M, String mobDamageType) { damage = new DamageTypes(I, P, S, F, L, IC, D, H, M, mobDamageType); damageOptional = LazyOptional.of(() -> damage); } @Nonnull @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) { return cap == CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY ? damageOptional.cast() : LazyOptional.empty(); } @Override public CompoundNBT serializeNBT() { if (CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY == null) { return new CompoundNBT(); } else { return (CompoundNBT) CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY.writeNBT(damage, null); } } @Override public void deserializeNBT(CompoundNBT nbt) { if (CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY != null) { CapabilityDamageTypes.DAMAGE_TYPES_CAPABILITY.readNBT(damage, null, nbt); } } }  
    • I got it now I installed the java 16 jdk instead of 8. Now it works thanks!  
    • net.minecraft.ResourceLocationException: Non [a-z0-9/._-] character in path of location: minecraft:textures/models/armor/gold_layer_١.png     at net.minecraft.resources.ResourceLocation.<init>(ResourceLocation.java:37) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading}     at net.minecraft.resources.ResourceLocation.<init>(ResourceLocation.java:42) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading}     at net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer.getArmorResource(HumanoidArmorLayer.java:146) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer.m_117118_(HumanoidArmorLayer.java:60) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer.m_6494_(HumanoidArmorLayer.java:36) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.entity.layers.HumanoidArmorLayer.m_6494_(HumanoidArmorLayer.java:23) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.entity.LivingEntityRenderer.m_7392_(LivingEntityRenderer.java:126) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.entity.MobRenderer.m_7392_(SourceFile:45) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading}     at net.minecraft.client.renderer.entity.MobRenderer.m_7392_(SourceFile:18) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading}     at net.minecraft.client.renderer.entity.EntityRenderDispatcher.m_114384_(EntityRenderDispatcher.java:129) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.LevelRenderer.m_109517_(LevelRenderer.java:1280) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.LevelRenderer.m_109599_(LevelRenderer.java:1076) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.GameRenderer.m_109089_(GameRenderer.java:1050) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.renderer.GameRenderer.m_109093_(GameRenderer.java:830) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91383_(Minecraft.java:1039) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.Minecraft.m_91374_(Minecraft.java:659) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:accesstransformer:B,pl:runtimedistcleaner:A}     at net.minecraft.client.main.Main.main(Main.java:186) ~[client-1.17.1-20210706.113038-srg.jar%2353!:?] {re:classloading,pl:runtimedistcleaner:A}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:?] {}     at jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:78) ~[?:?] {}     at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:?] {}     at java.lang.reflect.Method.invoke(Method.java:567) ~[?:?] {}     at net.minecraftforge.fml.loading.targets.CommonClientLaunchHandler.lambda$launchService$0(CommonClientLaunchHandler.java:45) ~[fmlloader-1.17.1-37.0.126.jar%2322!:?] {}     at cpw.mods.modlauncher.LaunchServiceHandlerDecorator.launch(LaunchServiceHandlerDecorator.java:37) [modlauncher-9.0.7.jar%235!:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:53) [modlauncher-9.0.7.jar%235!:?] {}     at cpw.mods.modlauncher.LaunchServiceHandler.launch(LaunchServiceHandler.java:71) [modlauncher-9.0.7.jar%235!:?] {}     at cpw.mods.modlauncher.Launcher.run(Launcher.java:106) [modlauncher-9.0.7.jar%235!:?] {}     at cpw.mods.modlauncher.Launcher.main(Launcher.java:77) [modlauncher-9.0.7.jar%235!:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:26) [modlauncher-9.0.7.jar%235!:?] {}     at cpw.mods.modlauncher.BootstrapLaunchConsumer.accept(BootstrapLaunchConsumer.java:23) [modlauncher-9.0.7.jar%235!:?] {}     at cpw.mods.bootstraplauncher.BootstrapLauncher.main(BootstrapLauncher.java:90) [bootstraplauncher-0.1.17.jar:?] {}   (This the crash report(
  • Topics

  • Who's Online (See full list)

×
×
  • Create New...

Important Information

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