Topic category: Help with Minecraft modding (Java Edition)
I have two procedures on my custom item: one that saves the mob NBT data when hit with the item and despawns the mob, and one that spawns the saved mob when right clicked on a block. Both procedures work fine until the spawning procedure gets to the last line of the custom code snippet that actually spawns the mob. No mob is spawned but other parts of the procedure work as intended.
Saving Procedure:
Custom code snippet:
itemstack.getOrCreateTag().put("entitySavedData", entity.saveWithoutId(new CompoundTag()));
Spawning Procedure:
Custom code snippet:
if (world instanceof ServerLevel _level) {
CompoundTag entityCompound = itemstack.getOrCreateTag().getCompound("entitySavedData");
Entity entityToSpawn = EntityType.loadEntityRecursive(entityCompound, _level, (e) -> {
e.setPos(x, y + 1, z);
e.setYRot(world.getRandom().nextFloat() * 360F);
return e;
});
_level.addFreshEntity(entityToSpawn);
}
Imgur link to all images: https://imgur.com/a/GYYTvtk