Jump to content

[Solved]Tile Entity Errors


ninjapancakes87

Recommended Posts

So I'm trying to make a portable chest (haversack) that functions the same as the alchemical bag from EE2/EE3.  When held, and right clicked, it opens a GUI.  I'm using a tile entity for this, and I've gotten tile entity's to work before.  However, now, I get this error:

 

2014-01-04 22:45:48 [iNFO] [sTDERR] java.lang.NullPointerException
2014-01-04 22:45:48 [iNFO] [sTDERR] 	at ninjapancakes87.civilwar.item.haversack.ContainerHaversack.<init>(ContainerHaversack.java:16)

This is the suspect line:

this.numRows = par2IInventory.getSizeInventory() / 9;

 

I have tried fixing this by hardcoding a number in, but this just leads to more problems, all dealing with the TileEntityHaversack class.  I made sure I called

GameRegistry.registerTileEntity(TileEntityHaversack.class, "Haversack");

in my load method.

Here is my TileEntity:

TileEntityHaversack:

 

package ninjapancakes87.civilwar.item.haversack;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;

public class TileEntityHaversack extends TileEntity implements IInventory{
private ItemStack[] chestContents = new ItemStack[27];

@Override
public ItemStack getStackInSlot(int par1) {
	return this.chestContents[par1];
}

@Override
public ItemStack decrStackSize(int par1, int par2) {
	if (this.chestContents[par1] != null)
        {
            ItemStack itemstack;

            if (this.chestContents[par1].stackSize <= par2)
            {
                itemstack = this.chestContents[par1];
                this.chestContents[par1] = null;
                this.onInventoryChanged();
                return itemstack;
            }
            else
            {
                itemstack = this.chestContents[par1].splitStack(par2);

                if (this.chestContents[par1].stackSize == 0)
                {
                    this.chestContents[par1] = null;
                }

                this.onInventoryChanged();
                return itemstack;
            }
        }
        else
        {
            return null;
        }
}

@Override
public ItemStack getStackInSlotOnClosing(int par1) {
	if (this.chestContents[par1] != null)
        {
            ItemStack itemstack = this.chestContents[par1];
            this.chestContents[par1] = null;
            return itemstack;
        }
        else
        {
            return null;
        }
}
@Override
public void setInventorySlotContents(int i, ItemStack par2ItemStack) {
	this.chestContents[i] = par2ItemStack;

        if (par2ItemStack != null && par2ItemStack.stackSize > this.getInventoryStackLimit())
        {
            par2ItemStack.stackSize = this.getInventoryStackLimit();
        }

        this.onInventoryChanged();		
}

@Override
public String getInvName() {
	return "Haversack";
}

@Override
public boolean isInvNameLocalized() {
	return false;
}

@Override
public int getInventoryStackLimit() {
	return 64;
}

@Override
public boolean isUseableByPlayer(EntityPlayer entityplayer) {
	return true;
}

@Override
public void openChest() {		
}

@Override
public void closeChest() {	
}

@Override
public boolean isItemValidForSlot(int i, ItemStack itemstack) {
	return true;
}
@Override
public int getSizeInventory() {
	return 27;
}
public void readFromNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.readFromNBT(par1NBTTagCompound);
        NBTTagList nbttaglist = par1NBTTagCompound.getTagList("Items");
        this.chestContents = new ItemStack[this.getSizeInventory()];

        for (int i = 0; i < nbttaglist.tagCount(); ++i)
        {
            NBTTagCompound nbttagcompound1 = (NBTTagCompound)nbttaglist.tagAt(i);
            int j = nbttagcompound1.getByte("Slot") & 255;

            if (j >= 0 && j < this.chestContents.length)
            {
                this.chestContents[j] = ItemStack.loadItemStackFromNBT(nbttagcompound1);
            }
        }
    }

    /**
     * Writes a tile entity to NBT.
     */
    public void writeToNBT(NBTTagCompound par1NBTTagCompound)
    {
        super.writeToNBT(par1NBTTagCompound);
        NBTTagList nbttaglist = new NBTTagList();

        for (int i = 0; i < this.chestContents.length; ++i)
        {
            if (this.chestContents[i] != null)
            {
                NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                nbttagcompound1.setByte("Slot", (byte)i);
                this.chestContents[i].writeToNBT(nbttagcompound1);
                nbttaglist.appendTag(nbttagcompound1);
            }
        }

        par1NBTTagCompound.setTag("Items", nbttaglist);
    }
}

 

Link to comment
Share on other sites

Suspect line is not in the class provided.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.