Jump to content

Detecting Nearby Mobs in SMP


Samalot

Recommended Posts

So, this is more of a brainstorm - I have some general idea about how I could accomplish some implementation of this. However, I am always keen to hear what people think and if they have any better/more sophisticated methods!

 

Item: A token which applies the swiftness potion buff when in close proximity (4 blocks) from a Mob.

 

player.addPotionEffect(new PotionEffect(Potion.moveSpeed.id, 50, 1));

 

Issues: The event I was going to use onPlayerUpdate(PlayerTickEvent event) is @SideOnly(Side.CLIENT)

 

My initial thought would be to just do the logic client-side and send a flag to the server (via a packet?) to apply the potion effect?

 

Or, maybe have an event which runs server-side? I can't seem to find a 'tick event' from the forge bus, but some research shows there may be one on the FML Bus (however most of this info is from around 2012, so it could be out-dated).

 

So my real question is - Do you think this is the right approach? Is sending a packet potentially tens of times every tick an issue? Or is there some other way I have completely missed?

 

Thanks in advance! 

 

Edit: Upon reflection, I realise that the title is pretty poor - my apologies.

Link to comment
Share on other sites

If this "token" is your own item, override

Item#onUpdate

. This is called once every tick while the item is in a player's inventory.

 

Otherwise

PlayerTickEvent

is the correct event to use. It's fired on both sides and not annotated with

@SideOnly

, I'm not sure why you thought it was.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

I removed the restriction and received an error, seems I interpreted it wrong! Thanks for the help.

 

The reason I cannot just use the onUpdate method is that the item has to also work from inside a 'token pouch'.

(I could always just write a bunch of if statements inside of the pouch code, but I thought this approach might be cleaner.)

 

EDIT:

 

Error = "java.lang.NoClassDefFoundError: net/minecraft/client/multiplayer/WorldClient"

Link to comment
Share on other sites

The reason I cannot just use the onUpdate method is that the item has to also work from inside a 'token pouch'.

(I could always just write a bunch of if statements inside of the pouch code, but I thought this approach might be cleaner.)

 

The pouch could simply propagate the update to its contents and still have each individual token handle its own effects.

 

This may be slightly cheaper than scanning the player's inventory from

PlayerTickEvent

.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Link to comment
Share on other sites

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.