Jump to content

Recommended Posts

Posted

I can't really see an obvious way to tell how the entity was created. The spawn egg class (ItemMonsterPlacer) calls the code that creates the entity but doesn't seem to make any special call or post any particular event.

 

I guess you could create a Capability for entities and replace the vanilla spawn eggs ((or maybe intercept the use of the spawn egg with an item use event) with your own version that not only creates the entity but also updates the Capability to indicate it was created by the spawn egg.

  • Like 1

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted
19 hours ago, jabelar said:

I can't really see an obvious way to tell how the entity was created. The spawn egg class (ItemMonsterPlacer) calls the code that creates the entity but doesn't seem to make any special call or post any particular event.

 

I guess you could create a Capability for entities and replace the vanilla spawn eggs ((or maybe intercept the use of the spawn egg with an item use event) with your own version that not only creates the entity but also updates the Capability to indicate it was created by the spawn egg.

Hmm, yeah that's what I was thinking too. Since the mod I'm working on is only for single player, I was thinking of getting the player's item in hand and see if the player right clicked using the correct egg and if the corresponding entity spawned in the correct location. 

Posted

Yes, you could do something like that. Anything that somehow ties the use of the spawn egg to the creation of the entity. I suppose you could make use of the fact that entities have a field for the ticksExisted (or something like that) so when a spawn egg is finished being used you could check area for any of the same entity type that have only existed for a tick or less. 

  • Like 1

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted

I'm assuming there's a particular reason for wanting to use EntityJoinWorldEvent?

 

Depending on what you're wanting to do, you could hook into LivingEntityUseItemEvent, and test for the spawn egg item.

 

But it all depends on what you're trying to do :)

  • Like 1
Posted
13 hours ago, jabelar said:

Yes, you could do something like that. Anything that somehow ties the use of the spawn egg to the creation of the entity. I suppose you could make use of the fact that entities have a field for the ticksExisted (or something like that) so when a spawn egg is finished being used you could check area for any of the same entity type that have only existed for a tick or less. 

Thank you that's very useful. I thought I had to keep track of the entity's life span on my own and I wasn't looking forward to that :D

 

6 hours ago, G-Rath said:

I'm assuming there's a particular reason for wanting to use EntityJoinWorldEvent?

 

Depending on what you're wanting to do, you could hook into LivingEntityUseItemEvent, and test for the spawn egg item.

 

But it all depends on what you're trying to do :)

Yeah I'm trying to cancel certain mob spawns in certain dimensions but I want mobs spawned from eggs to not be affected by this. 

Posted
1 minute ago, ReadySetPawn said:

Yeah I'm trying to cancel certain mob spawns in certain dimensions but I want mobs spawned from eggs to not be affected by this. 

I think the only tricky thing is I'm not sure the exact timing and order of these various events -- you need to tag the entity with the Capability at the time of creation but before the join event if possible. If the join event happens before the capability is fully applied you might need to using a living update event instead.

 

There is possibly an entirely different approach. There is a CheckSpawn event which is used whenever a natural spawn is being considered by the server. I don't believe check spawn is called when using a spawn egg. So you may not have to tag the entities at all, just intercept the check spawn event and return false for those you don't want to spawn in that dimension and spawn eggs should continue to work normally.

  • Like 1

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted
4 minutes ago, jabelar said:

I think the only tricky thing is I'm not sure the exact timing and order of these various events -- you need to tag the entity with the Capability at the time of creation but before the join event if possible. If the join event happens before the capability is fully applied you might need to using a living update event instead.

 

There is possibly an entirely different approach. There is a CheckSpawn event which is used whenever a natural spawn is being considered by the server. I don't believe check spawn is called when using a spawn egg. So you may not have to tag the entities at all, just intercept the check spawn event and return false for those you don't want to spawn in that dimension and spawn eggs should continue to work normally.

Hmm yea I'm liking the idea of not having the natural mobs spawn at all in the first place. Definitely going to look into the CheckSpawn event you're talking about. 

Posted
Just now, ReadySetPawn said:

Hmm yea I'm liking the idea of not having the natural mobs spawn at all in the first place. Definitely going to look into the CheckSpawn event you're talking about. 

You don't have to cancel all spawns. You can check for what is trying to spawn, what dimension you're in and return false if you don't want it to spawn. You should have full control of spawning through that event.

  • Like 1

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Posted
6 minutes ago, jabelar said:

You don't have to cancel all spawns. You can check for what is trying to spawn, what dimension you're in and return false if you don't want it to spawn. You should have full control of spawning through that event.

Thank you very much that worked brilliantly! And I noticed this also makes it so that the /summon command isn't broken either. 

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.