Posted May 3, 20205 yr I have a tile entity with a custom render that renders the item stored in the tile entity above the tile entity. The render works great, but I have a problem when I read from nbt, the item does not render until the slot is updated. I believe this is because I only send packets when onContentsChanged is called, and in addition to that, only when the worldObj is defined. when the read nbt function is called the world is not yet defined, so I need to somehow, schedule some kind of an update for later, when the world obj is defined. I know I could do this if the tile entity ticked, but I don't really want to make the tile entity tick just for this. tile entity class:https://github.com/hijackster99/Ancient-Relics/blob/master/src/main/java/com/hijackster99/tileentities/TileEntityPedestal.java main class:https://github.com/hijackster99/Ancient-Relics/blob/master/src/main/java/com/hijackster99/core/ARBase.java TER: https://github.com/hijackster99/Ancient-Relics/blob/master/src/main/java/com/hijackster99/tileentities/renderer/PedestalTER.java Packet Handler: https://github.com/hijackster99/Ancient-Relics/blob/master/src/main/java/com/hijackster99/core/ARPacketHandler.java
May 3, 20205 yr Override getUpdatePacket, getUpdateTag, and onDataPacket. These methods specifically exist to synchronize TE data to the client. 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.
May 3, 20205 yr Author I am not sure I 100% understand what is going on, but, I think I am supposed to send the update information in getUpdatePacket, which is recieved on client by onDataPacket, and handle updates that way. For clarity, is getUpdatePacket only called on the server then? And should I replace all of my existing packet things with this system? Thanks again.
May 3, 20205 yr Author Ok. SO i have it working. I used the getUpdateTag and handleUpdateTag methods to sync when the block is initially loaded, but I found that I still needed to use the packet handler for when the slot contents changed as it did not seem that I was able to call the getUpdateTag method manually and have it just work.
May 3, 20205 yr Howdy Your TE should have these methods in addition to your read and write method // When the world loads from disk, the server needs to send the TileEntity information to the client // it uses getUpdatePacket(), getUpdateTag(), onDataPacket(), and handleUpdateTag() to do this: // getUpdatePacket() and onDataPacket() are used for one-at-a-time TileEntity updates // getUpdateTag() and handleUpdateTag() are used by vanilla to collate together into a single chunk update packet @Override @Nullable public SUpdateTileEntityPacket getUpdatePacket() { CompoundNBT nbtTagCompound = new CompoundNBT(); write(nbtTagCompound); int tileEntityType = 42; // arbitrary number; only used for vanilla TileEntities. You can use it, or not, as you want. return new SUpdateTileEntityPacket(this.pos, tileEntityType, nbtTagCompound); } @Override public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) { read(pkt.getNbtCompound()); } /* Creates a tag containing all of the TileEntity information, used by vanilla to transmit from server to client */ @Override public CompoundNBT getUpdateTag() { CompoundNBT nbtTagCompound = new CompoundNBT(); write(nbtTagCompound); return nbtTagCompound; } /* Populates this TileEntity with information from the tag, used by vanilla to transmit from server to client */ @Override public void handleUpdateTag(CompoundNBT tag) { this.read(tag); } In addition, whenever your code changes the data in the TileEntity, you should call markDirty(). -TGG Edited May 3, 20205 yr by TheGreyGhost
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.