bigbang Posted November 21, 2017 Posted November 21, 2017 (edited) ************SOLUTION************ The solution is LivingSpawnEvent.SpecialSpawn instead of EntityEvent, so proper event hook for animals spawn should look like this: @SubscribeEvent(priority = EventPriority.NORMAL) public void onEntitySpawn(SpecialSpawn e) { Entity squid = e.getEntity(); if (squid instanceof EntitySquid) { //do stuff } } ************QUESTION************ public class EventHandler { + + @SubscribeEvent(priority = EventPriority.NORMAL) + public void EntityJoinWorldEvent(EntityEvent e) { + Entity spawnedEntity = e.getEntity(); + if (spawnedEntity instanceof EntitySquid) { + System.out.println(spawnedEntity.getUniqueID()); + } + } } Hi, What I want to achieve is replace half of Squids on my custom mob. So everytime Squid is spawned I want to replace it with a chance of 50%. When I subscribed to EntityJoinWorldEvent I noticed that this event is fired multiple times for the same entity. My code is above, nothing too fancy, very simple handler. Here is console output, you can see the same UUID repeat over and over again (i colorcoded the same UUIDs). I expect EntityJoinWorldEvent should be fired once per entity. Edit: Maybe I should try onJoinWorldEvent(EntityJoinWorldEvent e) instead of EntityJoinWorldEvent(EntityEvent e), this could be my problem? Quote [00:41:53] [Server thread/INFO]: [STDOUT]: 2f0b34e7-f396-4ff4-b986-bfb65217d06a - Squid A[00:41:53] [Server thread/INFO]: [STDOUT]: f9b18086-201d-4986-a342-f356f403eba3 - Squid B[00:41:53] [Server thread/INFO]: [STDOUT]: 5baaec49-4bf2-4052-99a7-6e087d2eb15a - Squid C[00:41:53] [Server thread/INFO]: [STDOUT]: e5287093-dbdb-4286-bd5b-e9ab09ff7298 - Squid D[00:41:53] [Server thread/INFO]: [STDOUT]: 5dca64e1-557a-4860-ad3d-b34d72ad6412 - Squid E[00:41:53] [Server thread/INFO]: [STDOUT]: 4fc4b076-a626-41d2-9e96-8a88c9fc4796 - Squid F[00:41:53] [Server thread/INFO]: [STDOUT]: 2f0b34e7-f396-4ff4-b986-bfb65217d06a - Squid A[00:41:53] [Server thread/INFO]: [STDOUT]: f9b18086-201d-4986-a342-f356f403eba3 - Squid B[00:41:53] [Server thread/INFO]: [STDOUT]: 5baaec49-4bf2-4052-99a7-6e087d2eb15a - Squid C[00:41:53] [Server thread/INFO]: [STDOUT]: e5287093-dbdb-4286-bd5b-e9ab09ff7298 - Squid D[00:41:53] [Server thread/INFO]: [STDOUT]: 5dca64e1-557a-4860-ad3d-b34d72ad6412 - Squid E[00:41:53] [Server thread/INFO]: [STDOUT]: 4fc4b076-a626-41d2-9e96-8a88c9fc4796 - Squid F[00:41:53] [Server thread/INFO]: [STDOUT]: 2f0b34e7-f396-4ff4-b986-bfb65217d06a - Squid A[00:41:53] [Server thread/INFO]: [STDOUT]: f9b18086-201d-4986-a342-f356f403eba3 - Squid B[00:41:53] [Server thread/INFO]: [STDOUT]: 5baaec49-4bf2-4052-99a7-6e087d2eb15a - Squid C[00:41:53] [Server thread/INFO]: [STDOUT]: e5287093-dbdb-4286-bd5b-e9ab09ff7298 - Squid D[00:41:53] [Server thread/INFO]: [STDOUT]: 5dca64e1-557a-4860-ad3d-b34d72ad6412 - Squid E[00:41:53] [Server thread/INFO]: [STDOUT]: 4fc4b076-a626-41d2-9e96-8a88c9fc4796 - Squid F Edited November 22, 2017 by bigbang Quote
Ugdhar Posted November 21, 2017 Posted November 21, 2017 1 hour ago, bigbang said: Maybe I should try onJoinWorldEvent(EntityJoinWorldEvent e) instead of EntityJoinWorldEvent(EntityEvent e), this could be my problem? Try it, it sounds more logical (I haven't messed with entity joining events at all, so not sure myself), EntityEvent makes it sound like it will fire for ANYTHING related to entities, spawning, dying, joining the world, maybe even moving. The name of the method doesn't matter, it's having the @SubscribeEvent notation and the proper parameters that make it work. Quote
Differentiation Posted November 21, 2017 Posted November 21, 2017 2 hours ago, bigbang said: EntityJoinWorldEvent(EntityEvent e) EntityEvent fires for any updates with entities. 2 hours ago, bigbang said: onJoinWorldEvent(EntityJoinWorldEvent e) Yes, you should... Quote
bigbang Posted November 21, 2017 Author Posted November 21, 2017 So LivingSpawnEvent.CheckSpawn, LivingSpawnEvent.SpecialSpawn and EntityJoinWorldEvent should be called only once? I assume that the only exception may be EntityJoinWorldEvent, it seems like this event should be fired also on level load for already extisting entities. Quote
Differentiation Posted November 21, 2017 Posted November 21, 2017 (edited) 41 minutes ago, bigbang said: So LivingSpawnEvent.CheckSpawn, LivingSpawnEvent.SpecialSpawn and EntityJoinWorldEvent should be called only once? I assume that the only exception may be EntityJoinWorldEvent, it seems like this event should be fired also on level load for already extisting entities. If you want to check for when a squid spawns, use your initial code with LivingSpawnEvent. Edited November 21, 2017 by Differentiation Quote
bigbang Posted November 22, 2017 Author Posted November 22, 2017 I found the best solution which is SpecialSpawn event, problem was solved. Quote
Recommended Posts
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.