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.

Featured Replies

Posted

I've been looking around and from everything I've seen there used to be a forge wiki page on it but there no long is. Do I have to set up a whole packet handler like this http://www.minecraftforge.net/forum/index.php?topic=20135.0 and all the keyhandler stuff, or is there an easier way to do it?

Looking around the closest thing I could find was this http://www.minecraftforge.net/forum/index.php?topic=25751.msg131395#msg131395 but like I said, I'm not sure.

 

Basically my question is how should I make a keybinding and all needed things for that in 1.10.2?

My IGN is TheUnderTaker11, but when I tried to sign up for this site it would not send the email... So yea now I have to use this account.

Its actually pretty simple, you can see how im doing it here to enable jetpack flight

https://github.com/abused/Tech-Expansion/blob/master/src/main/java/abused_master/TechExpansion/registry/KeybindHandler.java

and then i call

KeybindHandler.init();

in the preInit in my client proxy, using it is easy too how im doing it is checking if its being used as so:

if(KeybindHandler.keybind.isKeyDown()) {
        }

  • Author

Okay thank you, whew I was hoping I wasn't going to have to go through all that packet handler stuff just to have a keybind!

 

[EDIT] So question, what situation could I call that in though? It seems like it would need a point of reference, so do I have to call it on the clientside? Or could I call it somewhere like in the PlayerTick event?

My IGN is TheUnderTaker11, but when I tried to sign up for this site it would not send the email... So yea now I have to use this account.

Okay thank you, whew I was hoping I wasn't going to have to go through all that packet handler stuff just to have a keybind!

You usually need to use packets with keybinds. Keybinds are only client-side, so if you want to affect something on the server you need to send a packet.

 

[EDIT] So question, what situation could I call that in though? It seems like it would need a point of reference, so do I have to call it on the clientside? Or could I call it somewhere like in the PlayerTick event?

 

Keybinds should be registered client-side only during preinit. You call

Keybinding#isKeyDown()

on the client whenever you want to know if the bound key/s are pressed.

 

@abused_master

This will not work on a dedicated server, you need to use packets to turn the jetpack on/off server-side.

  • Author

So then it is clientside only, and I do need packets. In that case, could I use the link given in my OP to set up the packets, or is there a better tutorial I could use?

My IGN is TheUnderTaker11, but when I tried to sign up for this site it would not send the email... So yea now I have to use this account.

So then it is clientside only, and I do need packets. In that case, could I use the link given in my OP to set up the packets, or is there a better tutorial I could use?

 

That tutorial looks fine to me. The Forge RTD SimplImpl tutorial has nicer formatting IMO though.

  • Author

Okay so now I'm really confused. So I got two questions now.

 

import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.util.IThreadListener;
import net.minecraft.util.text.TextComponentString;
import net.minecraft.world.WorldServer;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

public class SendTeleportPlayer implements IMessage{

private int Distance;

public SendTeleportPlayer() { }

    public SendTeleportPlayer(int distance) {
        this.Distance = distance;
    }
@Override
public void fromBytes(ByteBuf buf)
{
	Distance = buf.readInt();
}

@Override
public void toBytes(ByteBuf buf)
{
	buf.writeInt(Distance);
}

public static class Handler implements IMessageHandler<SendTeleportPlayer, IMessage> {
    
    @Override
    public IMessage onMessage(SendTeleportPlayer message, MessageContext ctx) {
        IThreadListener mainThread = (WorldServer) ctx.getServerHandler().playerEntity.worldObj; // or Minecraft.getMinecraft() on the client
        mainThread.addScheduledTask(new Runnable() {
            @Override
            public void run() {
            	EntityPlayerMP serverPlayer = ctx.getServerHandler().playerEntity;
            	serverPlayer.addChatMessage(new TextComponentString("*Sigh*, "+message.Distance));
            }
        });
        return null; // no response
    }
}
}

 

 

My first question is, when it says "//or Minecraft.getMinecraft() on the client" does it mean when I'm sending it from the client, or when it's being run on the client? It never really said.

 

Second question is, where do I even put the code I want to actually do stuff? When it is in the run() like I have it now, I just get an error saying

Cannot refer to the non-final local variable ctx defined in an enclosing scope

and the same thing for the message#Distance.

 

For context my end goal is for this to "teleport" or move the player in the direction he is looking when he hits a keybind. Sure I could change the distance if I wanted but the actual info in the packet sends is arbitrary for what I want. I just need it to know a player hit the key and check a capability on the player.

My IGN is TheUnderTaker11, but when I tried to sign up for this site it would not send the email... So yea now I have to use this account.

My first question is, when it says "//or Minecraft.getMinecraft() on the client" does it mean when I'm sending it from the client, or when it's being run on the client? It never really said.

 

"Use Minecraft.getMinecraft() on the client."

"Minecraft is a Client-Side-Only class."

 

Hmmmmmmmm

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

My first question is, when it says "//or Minecraft.getMinecraft() on the client" does it mean when I'm sending it from the client, or when it's being run on the client? It never really said.

 

"Use Minecraft.getMinecraft() on the client."

"Minecraft is a Client-Side-Only class."

 

Hmmmmmmmm

What I am saying is that the packet, since it is a keybind, will be sent from the client to the server. There could be situations when you send a packet from server to client. I am asking for clarification on which one I should use. Does the context come from the client that sent it, hence I would have to use Minecraft.getMinecraft(), or is the context gotten from the server where the actual stuff should happen, and I'm supposed to assume the server already knows what player sent it?

My IGN is TheUnderTaker11, but when I tried to sign up for this site it would not send the email... So yea now I have to use this account.

Minecraft is a client side only class, you CANNOT use it on the server, not even in a packet handler.

 

The code in the example is a server side packet handler, which is what you want. The comment is for going the other way.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

Alright thank you for explaining that. Now my second question still stands, where to I do the actual stuff? I feel like making those variables final is a pretty bad idea.

My IGN is TheUnderTaker11, but when I tried to sign up for this site it would not send the email... So yea now I have to use this account.

A final method parameter is just one that you agree not to modify.  It's perfectly safe to make cxt final.

https://github.com/Draco18s/ReasonableRealism/blob/master/src/main/java/com/draco18s/ores/networking/ServerOreCartHandler.java#L30

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

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.