May 5, 20205 yr Author Now i have another problem: the registerMessage line is only without errors, if the constructor of the class has a PacketBuffer as argument. But the sendToServer makes a new instance of the class with empty brackets. How do i match this?
May 5, 20205 yr 55 minutes ago, Drachenbauer said: the registerMessage line is only without errors, if the constructor of the class has a PacketBuffer as argument. no 55 minutes ago, Drachenbauer said: But the sendToServer makes a new instance of the class with empty brackets. no 55 minutes ago, Drachenbauer said: How do i match this? you do not have to and you could just create a new constructor? please show your code Edited May 5, 20205 yr by Niprow I will make fun of you if you are not able to look into the (vanilla-) code.
May 5, 20205 yr Author For the event now i have this. @SubscribeEvent private void keyPressed (KeyInputEvent event) { GlazedTerracottaButtonPacketHandler.CHANNEL.sendToServer(new GlazedTerracottaButtonPacketHandler()); } how do i spicify this for my keybinding? It only should send the packet, if i press my choosen key ,but not at one of the others from the normal game-controls (wich are also keybindings). Edited May 5, 20205 yr by Drachenbauer
May 5, 20205 yr Oh where could forge hide key-bindings? Maybe in the class KeyBinding? and for clean code that could be a PacketHandler class with a Message class: public class PacketHandler { private static int IDs = 0; private static final String PROTOCOL_VERSION = "modid"; public static final SimpleChannel INSTANCE = NetworkRegistry.newSimpleChannel( new ResourceLocation("modid", "main"), () -> PROTOCOL_VERSION, PROTOCOL_VERSION::equals, PROTOCOL_VERSION::equals ); //called in pre_init public static void init() { INSTANCE.registerMessage(IDs++, Message.class, Message::decode, Message::encode, Message::consumer); } private static class Message { //some stuff protected static void consumer(Message chantal, Supplier<NetworkEvent.Context> justin) { //where you have to handle the stuff that contains chantal and maybe justin } protected static Message encode(PacketBuffer johan) { //where you get the stuff from johan and have to put it in your message return null; } protected static void decode(Message martin, PacketBuffer johan) { //where you have to write the stuff into johan out of martin } } } I will make fun of you if you are not able to look into the (vanilla-) code.
May 5, 20205 yr Author Now my KeyInputEvent looks like this: @SubscribeEvent private void keyPressed (KeyInputEvent event) { if(R_KEY.isPressed()) { GlazedTerracottaButtonPacketHandler.CHANNEL.sendToServer(new GlazedTerracottaButtonPacketHandler()); } } R_KEY is the name of my KeyBinding What must i put into the methods in your sample? And how do i make the pointed button-block react on this message? What must i call in here: context.get().enqueueWork(() -> { } ); to contact the block? Must i make a method in the block-class, that does something with the block and then call it in there? How do i make it only effect the block, i look at (crosshair on it, selection-box visible)? Edited May 6, 20205 yr by Drachenbauer
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.