Jump to content

Recommended Posts

Posted

I want an item to do something when you left click it while pointing at the air. How would I do this? I tried subscribing to onEntitySwing, but that event seems to also fire even if you're pointing at a block or entity. I also tried checking if the player is looking at anything with Item.rayTrace, but the method always returns null somehow.
One way I've seen is subscribing to a clientside event, but from my understanding that would require a packet, and I'd like to limit that if possible. Is there any other way, or is that the best way?

Posted

Get over your fear of sending packets.  The server is never aware of a "left-click empty" event - that's even mentioned in the javadoc for the PlayerInteractEvent.LeftClickEmpty event. Your only option if you want to inform the server is to listen for that event on the client and send a packet.

  • Like 1
Posted

I mean, I already know how to send packets, I'm just not sure about the performance impact which, looking back, shouldn't really be that big even combined with the few other packets already in the mod. Oh well, I'll be looking into the event then.

Posted

The simple number of different packets in your mod has zero impact on performance.  What does impact performance is ensuring you don't send packets unnecessarily, and that you encode information in the packet efficiently - don't send more data than is needed to convey the message (extreme & simplistic example: don't use a double to send a boolean value).

  • Only send packets when you know the other side needs the information.
  • Encode any data needed properly, e.g. don't use NBT for network data, use the smallest data type that fully describes the information you're sending.

In your case, a simple packet sent when a player does a "left click air" action is no big deal. It doesn't even need any extra data encoded in it - whenever the server receives such a packet it has all the information it needs: "player X just did a left click air".

 

Posted (edited)

What exactly are you trying to achieve? Empty left click swing or left click and hold?

I can’t read.

 

Yes. You should check if the player is holding the item (however a hacked client can easily send a false packet even if the item is not held in hand; you should also perform a check on the server side).

Edited by DavidM
to -> the

Some tips:

Spoiler

Modder Support:

Spoiler

1. Do not follow tutorials on YouTube, especially TechnoVision (previously called Loremaster) and HarryTalks, due to their promotion of bad practice and usage of outdated code.

2. Always post your code.

3. Never copy and paste code. You won't learn anything from doing that.

4. 

Quote

Programming via Eclipse's hotfixes will get you nowhere

5. Learn to use your IDE, especially the debugger.

6.

Quote

The "picture that's worth 1000 words" only works if there's an obvious problem or a freehand red circle around it.

Support & Bug Reports:

Spoiler

1. Read the EAQ before asking for help. Remember to provide the appropriate log(s).

2. Versions below 1.11 are no longer supported due to their age. Update to a modern version of Minecraft to receive support.

 

 

Posted
16 minutes ago, ProspectPyxis said:

So since I want to only do something with the item if you're holding it, I'd check if the player is holding the item first before sending the packet, correct?

Check on both sides: on the client so you're not sending unnecessary packets, and on the server because rule #1 of multiplayer gaming is don't trust the client.

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.