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

How do i make a block do stuff, if i aim at it and press a specific key on keyboard?


Drachenbauer
 Share

Recommended Posts

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 by Niprow

 I will make fun of you if you are not able to look into the (vanilla-) code.

Link to comment
Share on other sites

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 by Drachenbauer
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by Drachenbauer
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.