Jump to content

[1.12.2] [Solved] TileEntity: the validated object is null


Recommended Posts

Posted (edited)

I'm making a tile entity with a single slot and I'm getting this crash report whenever I open the inventory after placing the block down. If I place the block down and close the game then open it again and access the inventory, it is fine. I've looked but I can't find anything that would return null after I went through all my code and replaced all the itemstack = null with itemstack = ItemStack.Empty. 

Log:

  Reveal hidden contents

 

Tile Entity:

  Reveal hidden contents

 

 

GUI Container:

  Reveal hidden contents

 

I've gotten pretty good at reading stack traces but I'm stumped here

 

So from what I understand, the block is placed into the work, in which the constructor is run, which creates the slots and sets them to ItemStack.EMPTY based on the the source code.

Then the player rightclicks the block which opens the gui (all of this working) and then the game freezes and the game complains about something being null even though nothing was ever set to null in my code. This means that between 1.8 and 1.12.2 a change was made meaning that a stack must be initialized by the modder. Or maybe not considering that if the player placed down a block then closed and reloaded the save to then access the inventory, everything would work just as it is supposed to. This is an error that freezes the game then fixes itself on next boot. I have never in my life seen something like this

Edited by GooberGunter
Posted (edited)

Update: so i added the tileentity#clear method and that fixes it, but all it does is set the tile entities slots to EMPTY which the addSlotToContainer method already does.

//Tile Entity, slot 0, Slot ID: 0
		for(int y = 0; y < 1; y++) {
			for(int x = 0; x < 1; x++) {
				this.addSlotToContainer(new Slot(te, x + y, 78 + x * 18, 34 + y * 18));
				this.te.clear();
			}
		}

 

Edited by GooberGunter
Posted (edited)

So when I switched to the capability a couple of things changed. The display name, which I've put off to the side since its not a big concern right now. And more importantly, the dropInventoryItems function which requires IInventory as a parameter, which i originally had as the tile entity. Is there a method I can use to drop the items in the tile entity when it's broken? Also how would I then create a new slot in the Container without an IInventory?

Edited by GooberGunter
Posted (edited)

So on the other hand, when creating a slot in the GUI container on the server side, it needs a slot with an IInventory, which I don't have access to since the tile entity implements the new IItemHandler

Edited by GooberGunter
Posted

So I got the slot to work but now I have the following problem, I'm trying to figure it out but it's pretty tough

Stacktrace:

  Reveal hidden contents

Container:

  Reveal hidden contents

Tile Entity:

  Reveal hidden contents

 

Posted

Update: So I've fiddled around with things. And I have a couple of problems:

1. Hoppers don't send items into the object, I think this is a problem with the TIle Entity class

2. Whenever the player puts an object into the container's slot, the item isn't deleted from the player's inventory causing duplicating glitches

3. Whenever the object is shift clicked from the Tile Entity's inventory, the game crashes with the following error.

 

I'm not sure why I'm having all of these problems, the entity was working fine when it was implementing IInventory.

Error:

  Reveal hidden contents

Container:

  Reveal hidden contents

Tile entity class:

  Reveal hidden contents

 

Posted
  On 12/18/2017 at 2:12 AM, GooberGunter said:

So I found out that I'm supposed to use ItemHandler through the capability system, not through direct implementation. Is that right?

Expand  

That's correct. 

  • Like 1

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Posted (edited)

So then, the insertItem and extractItem methods are all ready to be used, nothing needs to be overwritten, I can just call the ItemStackHandler to insert and extract things in the GUI Container class?

 

And do I have to attach the Item Handler Capability in an event?

 

Edit: they are, nothing needs to be overwritten afaik, I can call the ItemStackHandle, now I don’t need to attach the capability

Edited by GooberGunter

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.