Jump to content

[1.7.2] How to do something when holding key?


Sokaya

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.

Announcements



×
×
  • Create New...

Important Information

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