Started by
Darknessay
on
Topic category: Help with MCreator software
I mean not to do like:
1. Spawn entity
2. Set Var = Get nearest entity
But something like:
1. Set Var = Spawn entity
Or:
1. Spawn entity
2. Set Var = Get Last Spawned Entity
Maybe i just dont see this option, or is it impossible?
It usually isn't an issue, but I think I see what you mean. If you use the 'entity spawned' trigger in the entity itself, you don't have to worry about using nearest entity, but sometimes that isn't the best option depending on what you're trying to do.
But yeah, I mostly wind up using 'nearest entity' when targeting newly spawned entities, especially if I need to do modifications for vanilla entities.
Yes, i made an item that summons minions, and i have to add an NBT tag to newly summoned creature to set his owner, so after that i could easely pick each entity around, check it's owner and set their's attack target when the owner attacks somebody.
I made it this way(item right-click trigger):
https://imgur.com/gallery/9FGRFqP
But for some reason, if i try to get nearest in cube lesser than 64, the game crashes like because "no data exist"(no entity found, i think)
I already made another creature that morphs to another with setting its current HP to newly spawned entity(the main entity despawns, and after that, new entity spawns at its position, then i pick it by get nearest and set it's current HP to main entity's HP) - and it works fine with 2 or 4 blocks cube size parameter, never crashes. Exectly the same procedure works and doesnt works in different triggers. How can it be?
For some reason i added wait 1 tick in here, i even dont remember why. I guess I thought that this way "the entity will ALREADY exist" when I select it. It works now, it works without buggs or crashes, but i just dont like how un-logic it looks like and want to find the answer.
Here is the morphing entity function for comparison(entity tick):
https://imgur.com/gallery/1NbNleu
I even made the main entity despawn first, before getting its HP parameters, and it doesnt crash so i conclude that there is some cash info about it savings within the procedure.
An alternative would be to have a procedure that runs when the minion entity spawns, checks for the nearest summoner entity, and sets its NBT tag that way- but it still amounts to the same thing. I'm not sure if there's an easy way around this without some significant custom code. But yes, the delay isn't strictly necessary, and may actually be the source of the problem: the order of the code determines the step order within the tick, so the entity should already exist regardless. You may still want to add an if bracket that checks if an entity of the desired type exists within the box, just on the off-chance something goes wrong, in which case it won't trigger and crash the game.