Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

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

Featured Replies

  • 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?

 

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.

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

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.

  • 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 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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.