Jump to content

Recommended Posts

Posted

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! :D

width=700 height=100http://driesgames.game-server.cc//banner.png[/img]

Java, Hosting Servers and Videos...

Posted

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.

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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