Cannot use 'caught' entity in fishing event
LadyCailinBot opened this issue · 6 comments
CMDHELPER-3157 - Reported by Алексей.Положенцев
'caught' value in player_fish cannot be used in any function that uses entity id
console(entity_spec(@event[caught])) will give you BadEntityException: That entity (UUID ab5574fa-d19f-4c5f-a6b7-0e683da09940) does not exist.
Althought set_timeout(50, closure(console(entity_spec(@event[caught]))) works fine.
Comment by PseudoKnight
So, functions that use entities get the entity from the world. Entities are not added to the world until after those events that can cancel their being added. This affects creature_spawn, item_spawn, player_fish, projectile_launch, and lightning_strike. I'm evaluating whether we can store the entity references temporarily in those events, but I'm pretty sure that would affect other systems, which I'd like to avoid. At one point I considered storing Entity references in Constructs that store UUIDs, but I'm not sure LadyCailin would like that. It could help some other instances where we make multiple changes to an entity, though.
Comment by PseudoKnight
Another way I could see it working is storing it in the CommandHelperEnvironment, as long as each entity event had a consistent way of getting the entity like with players.
Comment by PseudoKnight
Actually, given how functions get entities, I think you'd HAVE to either store it in some sort of Construct (maybe Minecraft constructs outside of Core? that or have Construct optionally store underlying object references) or in Static, like injectedPlayers. Environment is out of the question unless we modified all entity functions. Though it should be noted some entity functions will not work on an entity that is not in the world yet.
Comment by Алексей.Положенцев
If it's impossible, you can at least add some extra 'event data' (item array) or even make it mutable, so we don't even need to use nonexistent entity and still have chance to tune it as we want...
Comment by PseudoKnight
There are too many things that functions get/set for entities to include that in event and mutable data. There's nothing stopping you from modifying the entity a tick later, though. That's how everyone does it right now when needed. Even if I changed this, some functions would still need to be ran a tick later.
Comment by PseudoKnight
I ended up injecting the entity into a variable in Static, like how players are handled in some events. So you should be able to use almost all entity functions in events that spawn entities now. There are a few functions that require the entity to be spawned in first, though. If you run into any errors, let me know. My testing went really well.