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

[1.7.2] How to do something when holding key?


Sokaya
 Share

Recommended Posts

Key event handlers.

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.

Link to comment
Share on other sites

Its amazing what kind of information you can convey in your opening post, and how a lack thereof doesn't result in useful replies.

 

Here's what I did when I needed key-up and key-down (specifically, a key bound to an existing option).

//client-side event handler
@SubscribeEvent
public void tickStart(TickEvent.ClientTickEvent event) {
	EntityPlayer player = Minecraft.getMinecraft().thePlayer;
	if(player != null) {
		int jumpKey = Minecraft.getMinecraft().gameSettings.keyBindJump.getKeyCode();
		boolean sendPacket = false;
		boolean state = false;
		if(jumpKey >= 0) {
			sendPacket = HazardsEventHandler.instance.setPlayerSwimming(player, Keyboard.isKeyDown(jumpKey));
			state = Keyboard.isKeyDown(jumpKey);
		}
		else {
			jumpKey = Minecraft.getMinecraft().gameSettings.keyBindJump.getKeyCode()+100;
			if(jumpKey >= 0) {
				sendPacket = HazardsEventHandler.instance.setPlayerSwimming(player, Mouse.isButtonDown(jumpKey));
				state = Keyboard.isKeyDown(jumpKey);
			}
		}
		if(sendPacket) {
			PacketBuffer out = new PacketBuffer(Unpooled.buffer());
			out.writeBoolean(state);
			CtoSMessage packet = new CtoSMessage(player.getUniqueID(), out);
			UndergroundBase.networkWrapper.sendToServer(packet);
		}
	}
}

You'll not that there are packets involved.

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.

Link to comment
Share on other sites

I do it like that:

	@SubscribeEvent
public void tickStart(TickEvent.ClientTickEvent event)
{
	EntityPlayer player = Minecraft.getMinecraft().thePlayer;

	if (player != null)
	{
		Entity ent = player.ridingEntity;
		boolean state = false;
		if (ent != null && ent instanceof EntityMyPig)
		{
			state = Keyboard.isKeyDown(ClientKeyHandler.up.getKeyCode()) || Keyboard.isKeyDown(ClientKeyHandler.down.getKeyCode());
			if(!state)
				Main.proxy.channel.sendToServer(PacketHandler.getPacket(1, Side.SERVER));
		}
	}
}

 

And my method isn't called:(

Link to comment
Share on other sites

ClientKeyHandler.up.getKeyCode()
ClientKeyHandler.down.getKeyCode()

 

Wut.

 

Actually KeyInputEvent fires for key-releases, but you need 1.7.10 for that (why are you not using that?).

 

I had some issues with that, actually.  And yes, 1.7.10 here.  Do you know if it was a specific Forge version?

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.

Link to comment
Share on other sites

I've been pretty lazy about updating my dev-environment-forge.  I was likely doing a lot of my screwing around with keyboard stuff on 1180 which would, in fact, not have that change. ;)

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.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Here is my configuration: % java -version java version "18.0.2" 2022-07-19 Java(TM) SE Runtime Environment (build 18.0.2+9-61) Java HotSpot(TM) 64-Bit Server VM (build 18.0.2+9-61, mixed mode, sharing) forge-1.19-41.1.0-mdk on macOS Monterey 12.5 I ran the command: ./gradlew genEclipseRuns and was hoping it will generate the Eclipse project files for me. The run log is at https://gist.github.com/arun-gupta/06b983a6976b4c0a0f510d0dc225ddd3 and the generated directory structure is at https://gist.github.com/arun-gupta/3f5bfc70ec5d3d903b0f97d42840abda. In previous versions (1.12-ish), it used to generate an eclipse directory but 1.19 does not seem to have it. I tried opening the top-level forge directory but Eclipse does not recognize it as a project as well. How do I open this project in Eclipse now?  
    • I didn't put in credentials, I used it only for testing installing forge. But still the problem mentioned above.
    • I am trying to use Forge 1.18.2, I have checked my firewall, redownloaded Forge, deleted the fml.toml file (which keeps reappearing) and looked at countless help pages. I am just trying to download and use forge so that I can play with my friends and it will not download. It tells me there may be an issue with the Java runtime config and that the exit code is one, and I have copied the exit code.   
    • Okay, i think i understand but im getting issues, i create another packet to sync entity to another players like this package com.naim.belloto.networking.packet; import com.naim.belloto.networking.handler.ClientSyncHandler; import net.minecraft.client.Minecraft; import net.minecraft.network.FriendlyByteBuf; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.fml.DistExecutor; import net.minecraftforge.network.NetworkEvent; import java.util.Objects; import java.util.function.Supplier; public class ClientSyncPacket { public ClientSyncPacket() { } public ClientSyncPacket(FriendlyByteBuf buf) { } public void toBytes(FriendlyByteBuf buf) { } public boolean handle(Supplier<NetworkEvent.Context> ctx) { NetworkEvent.Context context = ctx.get(); context.enqueueWork(() -> { assert Minecraft.getInstance().player != null; int idplayer = Minecraft.getInstance().player.getId(); DistExecutor.unsafeCallWhenOn(Dist.CLIENT,() -> () -> ClientSyncHandler.handlePacket(ctx, idplayer)); }); return true; } } And in the handler: public class ClientSyncHandler { public static boolean handlePacket(Supplier<NetworkEvent.Context> ctx, int idPlayer) { Minecraft.getInstance().level.getEntity(idPlayer); return true; } } But is not working :// 
  • Topics

×
×
  • Create New...

Important Information

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