Awsome Posted August 1, 2020 Posted August 1, 2020 I have a tileentity that stores a temperature value as a float. I need the temperature to get sent to the container so that it can update the GUI on the client. I know I need to use a custom packet in order to send the value over to the client, but I don't exactly know where I should recieve the packet. Quote
Yohann Posted August 1, 2020 Posted August 1, 2020 How do you store the float ? You absolutety need to use a custom packet ? In fact, without further details I would say maybe use the dataManager for client-side synchronization and override the writeAdditional and readAdditional methods to make your data persistent. Quote
Awsome Posted August 1, 2020 Author Posted August 1, 2020 (edited) The float value is stored inside of a custom capability that the tile entity has. I'll check out dataManager and see if I can use that instead. Link to source: TileEntity: https://github.com/Awsomekeldeo/TechMod/blob/1.15-port/src/main/java/awsome/techmod/tileentity/TEFirebox.java Container: https://github.com/Awsomekeldeo/TechMod/blob/1.15-port/src/main/java/awsome/techmod/inventory/container/ContainerFirebox.java GUI: https://github.com/Awsomekeldeo/TechMod/blob/1.15-port/src/main/java/awsome/techmod/gui/FireboxScreen.java Capability: -Registration: https://github.com/Awsomekeldeo/TechMod/blob/1.15-port/src/main/java/awsome/techmod/api/capability/energy/CapabilityHeat.java -Default Implementation: https://github.com/Awsomekeldeo/TechMod/blob/1.15-port/src/main/java/awsome/techmod/api/capability/impl/HeatHandler.java -Capability Interface: https://github.com/Awsomekeldeo/TechMod/blob/1.15-port/src/main/java/awsome/techmod/api/capability/energy/IHeat.java Edited August 1, 2020 by Awsome Posted links to source Quote
Awsome Posted August 1, 2020 Author Posted August 1, 2020 As far as I can tell dataManager seems to be used exclusively for entities. So I'm not quite sure that would work for what I'm doing. Quote
Yohann Posted August 1, 2020 Posted August 1, 2020 (edited) My mistake, I didn't properly read your post (it's late here!). So yes, you have to use the packets with capabilities. This time, if I correctly read your post you don't know where you should recieve the packet. I've never really done what you want to do, but I have some basics. You need to follow this in the documation. The principle is to create a class that gathers everything you need for the network A fast example : public class Packet { private float temperature; public Packet(int temperature_) { this.temperature = temperature_; } // "responsible for encoding the message" public static void encode(Packet packet, PacketBuffer buffer) { buffer.writeInt(packet.temperature); } // "responsible for decoding the message" public static Packet decode(PacketBuffer buffer) { int temperature = buffer.readInt(); Packet instance = new Packet(temperature); return instance; } // What's INSTANCE ? Check Getting Started in the doc public static void registerMessage() { INSTANCE.messageBuilder(Packet.class, 0) .encoder(Packet::encode) .decoder(Packet::decode) .consumer(Packet::handle) .add(); // "Registering Packets" section } // "responsible for handling the message" public static void handle(Packet msg, Supplier<NetworkEvent.Context> ctx) { ctx.get().enqueueWork(() -> { // Work that needs to be threadsafe (most work) EntityPlayerMP sender = ctx.get().getSender(); // the client that sent this packet // do stuff }); ctx.get().setPacketHandled(true); } } } There's probably some things missing, but this should help. EDIT : Oh, I forgot! You need to call registerMessage() in the setup function of your mod. Edited August 1, 2020 by Yohann buggy link Quote
poopoodice Posted August 1, 2020 Posted August 1, 2020 You don't really need a packet just to sync a float, just convert it to int (maybe times it by 100, I don't know) and use trackInt() or trackIntArray() in Container. Quote
Awsome Posted August 1, 2020 Author Posted August 1, 2020 (edited) oh yeah, I could do that since I'm rounding the temperature to 2 decimal places anyways and I'm already using trackIntArray to track the burn time of fuel in it's fuel slot Edited August 1, 2020 by Awsome Quote
Awsome Posted August 1, 2020 Author Posted August 1, 2020 thanks, that was exactly what I needed to do. The temperature reading now displays properly. Quote
Recommended Posts
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.