Posted July 22, 201510 yr So i've started Forge coding for a couple weeks now, and I've been getting into Key Inputs, with handlers and all that. Recently, i've been trying to develop a keyinput where you click a key, and you would get a certain effect. When I did use the player.addPotionEffect() method though, the client only visualizes the effect, but doesn't actually work. Here's a snippet of my code: @SubscribeEvent public void onKeyInput(InputEvent.KeyInputEvent event) { EntityPlayer play = Minecraft.getMinecraft().thePlayer; if(testKey.ping.isPressed()) { buttonPress = true; if(play!=null){ if(XPowerFlask.ability==0) { play.addPotionEffect(new PotionEffect(Potion.damageBoost.getId(), 1000, 2)); In addition, I'd like to create a cooldown on the effect. Every time I add the onUpdate() method though, the ability works, then the cooldown just never seems to actually work. Thanks in advance! http://driesgames.game-server.cc//banner.png[/img] Java, Hosting Servers and Videos...
July 24, 201510 yr Author Forgive me if I sound like a beginner here, but I've looked at the SimpleNetworkWrapper, and i've played around a little with the Packeting, but how do I use the IMessage class I've made in order to return a Potion effect? http://driesgames.game-server.cc//banner.png[/img] Java, Hosting Servers and Videos...
July 24, 201510 yr Author Don't I have to put something within the FromBytes or ToBytes methods of the IMessage declaring the buf to be writing the potion effect to be sent, though? http://driesgames.game-server.cc//banner.png[/img] Java, Hosting Servers and Videos...
July 24, 201510 yr Basically, on your keyInput method, instead of checking if the player should get the effect and giving it to them on the client side, as soon as you determine that the button is pressed, send a packet. You technically don't need to send any information here, unless you want to use the same packet type for multiple key presses, in which case you would send something to define which key is pressed. Then, in the packet handler, define what should happen based on what key is pressed. The reason you don't send the potion effect in the packet, or send really any information in the packet other than that the key was pressed is because it's bad practice to trust the client. For instance, if you want to give jump boost when you hit the key and the player is holding a custom item, you could just send a packet to the server saying to give the player a jump boost, but what if the player isn't actually holding the item, the client just thinks it is due to being out of sync or through an exploit? It's always better to just send that the player wants the effect(as in the key is pressed) and then the server will determine if the player should have it, and then give it to the player.
July 24, 201510 yr Hi YOu might find this tutorial project useful https://github.com/TheGreyGhost/MinecraftByExample Look at MBE60 for network messages to do this sort of thing (send a message to the server in response to a button click) -TGG
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.