Posted April 29, 20205 yr I need to synchronize the angle in TE, the angle changes to the server, but not in the client. I don't need to save it in NBT. I used packets to send data from GUI to TE. But I need TE to send the packet to the TE client, how do I do that?
April 29, 20205 yr see: https://mcforge.readthedocs.io/en/latest/tileentities/tileentity/#synchronizing-the-data-to-the-client Edited April 29, 20205 yr by Niprow doc site I will make fun of you if you are not able to look into the (vanilla-) code.
April 29, 20205 yr Author @Nullable @Override public SUpdateTileEntityPacket getUpdatePacket() { CompoundNBT tag = new CompoundNBT(); write(tag); return new SUpdateTileEntityPacket(this.pos,0,tag); } @Override public CompoundNBT getUpdateTag() { return write(new CompoundNBT()); } @Override public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) { super.onDataPacket(net, pkt); readFromNBT(pkt.getNbtCompound()); BlockState state = this.world.getBlockState(this.pos); this.world.notifyBlockUpdate(this.pos, state, state, 3); } I used it, but nothing worked.
April 29, 20205 yr World#notifyBlockUpdate you can not call that in onDataPacket or getUpdatePacket I will make fun of you if you are not able to look into the (vanilla-) code.
April 29, 20205 yr @Override public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) { super.onDataPacket(net, pkt); readFromNBT(pkt.getNbtCompound()); BlockState state = this.world.getBlockState(this.pos); this.world.notifyBlockUpdate(this.pos, state, state, 3); } World#notifyBlockUpdate is used to notify a block update, not actually update the block on the client side. All you have to do is to read data packet in onDataPacket. Some tips: Spoiler Modder Support: Spoiler 1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code. 2. Always post your code. 3. Never copy and paste code. You won't learn anything from doing that. 4. Quote Programming via Eclipse's hotfixes will get you nowhere 5. Learn to use your IDE, especially the debugger. 6. Quote The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it. Support & Bug Reports: Spoiler 1. Read the EAQ before asking for help. Remember to provide the appropriate log(s). 2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.
April 29, 20205 yr Author I understand it, I thought it only synchronized what's in the read and write. @Nullable @Override public SUpdateTileEntityPacket getUpdatePacket() { CompoundNBT tag = new CompoundNBT(); tag.putInt(ANGLE_TAG,this.angle); return new SUpdateTileEntityPacket(this.pos,0,tag); } @Override public CompoundNBT getUpdateTag() { return write(new CompoundNBT()); } @Override public void onDataPacket(NetworkManager net, SUpdateTileEntityPacket pkt) { super.onDataPacket(net, pkt); BlockState state = this.world.getBlockState(this.pos); this.angle = pkt.getNbtCompound().getInt(ANGLE_TAG); this.world.notifyBlockUpdate(this.pos, state, state, 3); }
April 29, 20205 yr Author but the animation in the renderer is kind of jerky. matrixStackIn.rotate(Vector3f.YP.rotationDegrees(angle+partialTicks*2)); there's gotta be a smooth rotation, and it feels like the animation has 20 fps. public void updateAnimation() { this.angle += 2; if (this.angle > 358) { this.angle = 0; } spawnWaterParticles(this.world, pos, 0, this.angle); } public int getAngle(){ return this.angle; } Edited April 29, 20205 yr by AlexInCube
April 29, 20205 yr that is so because of the tick-rate in your tile entity (if you update it in ITickableTileEntity#tick) you could change it in Block#tickRate (maybe) Edited April 29, 20205 yr by Niprow how to change tick rate I will make fun of you if you are not able to look into the (vanilla-) code.
April 29, 20205 yr 6 minutes ago, Niprow said: you could change it in Block#tickRate (maybe) I will make fun of you if you are not able to look into the (vanilla-) code.
April 30, 20205 yr 9 hours ago, AlexInCube said: this.world.notifyBlockUpdate(this.pos, state, state, 3); You are still doing this. Don't do this on the client, as it does nothing (well it might do something, but definitely not what you are expecting). Only send a packet to update your tile entity if the angle changes. Don't do it every tick. If the angle is not unpredictable and only change as part of an animation, send a packet to the client when the animation starts and handle the animation on the client side. Some tips: Spoiler Modder Support: Spoiler 1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code. 2. Always post your code. 3. Never copy and paste code. You won't learn anything from doing that. 4. Quote Programming via Eclipse's hotfixes will get you nowhere 5. Learn to use your IDE, especially the debugger. 6. Quote The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it. Support & Bug Reports: Spoiler 1. Read the EAQ before asking for help. Remember to provide the appropriate log(s). 2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.
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.