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

[1.8]How to edit two tile entities[Solved]


Atijaf
 Share

Recommended Posts

I have a two Tile Entities that links with one another when the correct coordinate item is placed inside.

The item holds the block pos location.

 

TileEntity1 - the item inside points to TileEntity2

TileEntity2 - the item inside points to TileEntity1

 

They have to point to each other for them to be linked.

 

 

So the question... I need to update TileEntity2 when I remove TileEntity1's item so that they aren't linked anymore, but I can't access TileEntity2's location when TileEntity1's item doesn't exist. (the item that points to TileEntity2)

 

Can I instead use Container#slotClick to obtain the item the player removed and update TileEntity2?

Or should I avoid using the container to do this?

 

Hope this makes sense...

Link to comment
Share on other sites

Currently working on it now.  Thanks:)  I believe this is exactly what I needed to know.

 

One more thing.  Is #setInventorySlotContents called when the game loads the world?

 

.. Two more things.  If I use #markDirty() on server side, must I do that on client as well?

Link to comment
Share on other sites

Thanks!  Gosh I keep running into bugs and this last one stumped me.

 

I have an item that is stored within a TE.  The itemstack, it is associated with, contains NBT int and whenever the block is right clicked, that int is reduced by 20.  (I say right click just to simplify.  I actually do something else, but the point stays the same)  The action is only done serverSide and I thought that setting nbt data syncs between server and client, regardless of what side the nbt data was set.

 

The reason I know it isn't syncing on client side is when I open my gui, i step through the process, check the inventory slot for that itemstack, and the int hasn't changed.  If i'm on the server side, it has changed.

 

Does itemstack NBT data sync automatically if it's not in the player's inventory?  I'll figure out what I'm doing wrong, but just need to understand that.

 

Thanks for all the help!

Link to comment
Share on other sites

The action is only done serverSide and I thought that setting nbt data syncs between server and client, regardless of what side the nbt data was set.

No, ItemStack NBT data only syncs automatically if you set it server side, and only when it is accessed in an inventory using a Container class. NEVER set NBT data (or any other data) client side.

 

Does your TileEntity-based GUI use a Container? If so, as diesieben said you should be able to manually call #detectAndSendChanges, but that's called automatically every update tick from EntityPlayerMP, so you shouldn't have to... I suspect there is probably something else going on in your code; do you have an online repository or other way to view your code?

 

Also, I would not recommend using #setInventorySlotContents when reading your inventory from NBT. Usually this method implementation calls #markDirty() which may or may not iterate through the inventory contents. While you won't crash or anything like that, it's still much better, imo, to just set the inventory slot value directly with array access.

Link to comment
Share on other sites

Everything is done server side and only the required information is send to the client.  Though, I'm not in the container when i edit the itemstack's nbt.  I think I'm going to send a packet to the client side.  If that doesn't work, I'm going to reevaluate and redo the code with the now better understanding I have.

 

Thanks again:)

 

I'm sure I'll be back...

Link to comment
Share on other sites

Reevaluated and redid much of the code.  Works :D

 

By redoing the code, i removed a TON of nonsense, but the best part is that I didn't even have to use packets.  I overrid #markDirty() and it synced for both sides.  Thanks to all that helped!

 

Instead of one tile entity determining a few variables of the other tile entity, I have them act independently (ALMOST!)

 

I use to use a boolean to determine if they needed updating, but that caused a ton of resources being used (Called markdirty every tick... AND IT ALSO DIDN'T WORK)

I now use an int.  It'll return 0 if player placed item and 1 if player removed item from inventory. (That takes care of the source tile entity)

 

Now.. It'll return 2 if nothing has changed and then it'll check if it's linked.  If so, double check to see if it is truly linked (Do some of the math), and if it isn't truly linked (Target TE isn't correct), set linked to false and a few other variables...

 

I know I didn't have to write that, but I wasn't even sure if I quite understood it:p  Mainly just excited after the many hours spent on it, and after redoing it, figuring it out after a few hours was just thrilling.

 

THANKS A TON!

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.