Topic category: Help with MCreator software
Hello ! I wanted to ask how could one store an entity as a variable : for example for storing a target to make custom AI , or for long distance targets interactions , as there is no "Entity NBT" in mcreator!
More in depth : im trying to store a UUID (i think it's called like this?) of an entity (namely any mob/creature or the player found in a "For each entity as Entity iterator" block), for it to be called on each frame for the AI to pathfind to it, and have to only run one check for entity around the creature !
i can also code a little in Java, so if it's possible to do by modifying a few things in the generated code, i'm ok with it ! thank you very much for reading , and i hope you'll be able to help me !
I was looking into this, and I think you can do this using the
getUUID()
function or something like that. I don't know how to retrieve the entity later.yeah, it's what i tried so far, but there seems to be no real way to retrieve the entity out of that, unless doing a big loop through all of minecraft's current entities and doing a check to check if the uuid are mathcing, and if yes, storing the entity , but it seems a bit much ..
i would gladly have some help if someone know how to do it ! , i've also tried to do this :
world.getEntityFromUuid(UUID.fromString(entity.getPersistentData().getString("tagTargetUUID")));
as a custom code snippet, but it doesnt work, getting a cannot find symbol error with this function
What "cannot find symbol" error is it? You can p Roxanne import it.
It looks like ServerLevel (which implements LevelAccessor) has a method getEntity. It takes one argument of type UUID and returns an Entity. A UUID object can be created in a number of ways, including from a string. You could try that.
Late, but answering for the benefit of anyone else with the same problem.
Ther are plugins and custom code for getting the UUID from a mob. If you have either, then you can use the following to get an entity from the UUID:
Make a command. It should have a sole input of "single entity."
Then make its procedure. Make it do whatever you would like to do with the entity you have the UUID of, which will be provided as a command argument.
Wherever you would like to invoke this, use "create text with" and "run command" procedure blocks (or custom code) to make it run that command using the UUID you want as the target entity.
I've used this for one of my mods and it has worked out pretty well, although I have to create commands quite often.