Hi,
I want to cache an entity as a string to be able to create a copy of it later.
I have already searched a bit with Google and now I have the following code.
to get the string(works)
to create an entity from the string
Unfortunately, creating the entity does not work. No entity is created and there is no error message.
Is there a more elegant solution for this or a paper Function I don't know yet?
I would like to save everything(passengers(except players), items) when saving.
Thanks for your help
Richie
Sorry for my bad english
I want to cache an entity as a string to be able to create a copy of it later.
I have already searched a bit with Google and now I have the following code.
to get the string(works)
Java:
net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
CompoundTag compound = new CompoundTag();
nmsEntity.serializeEntity(compound);
CompoundTag compoundCopy = compound.copy();
forbiddenKeys.forEach(tag -> {
compoundCopy.remove(tag);
});
this.entity = compound.toString();
to create an entity from the string
Java:
public @Nullable Entity spawnEntity(Location location) throws CommandSyntaxException {
CompoundTag compound = TagParser.parseTag(entity);
CompoundTag compoundCopy = compound.copy();
Level worldServer = ((CraftWorld) location.getWorld()).getHandle();
net.minecraft.world.entity.Entity nmsEntity = EntityType.create(compoundCopy, worldServer).get();
nmsEntity.setPos(location.getX(), location.getY(), location.getZ());
return nmsEntity != null ? nmsEntity.getBukkitEntity() : null;
}
Unfortunately, creating the entity does not work. No entity is created and there is no error message.
Is there a more elegant solution for this or a paper Function I don't know yet?
I would like to save everything(passengers(except players), items) when saving.
Thanks for your help
Richie
Sorry for my bad english