private Entity createEntity(MinecraftKey entityResource, NBTTagCompound optionalMeta) { // Note that the entity position is not set by this method Class<? extends Entity> entityClass = EntityTypes.b.get(entityResource); if (entityClass == null) { TerrainControl.log(LogMarker.WARN, "Unknown entity name: {}", entityResource); return null; } NBTTagCompound copy = optionalMeta == null ? new NBTTagCompound() : (NBTTagCompound) optionalMeta.clone(); copy.setString("id", entityResource.toString()); Entity entity = EntityTypes.a(copy, world); if (entity instanceof EntityInsentient) { ((EntityInsentient) entity).persistent = true; } return entity; }
@Override public void setBlock(int x, int y, int z, LocalMaterialData material, NamedBinaryTag tag) { setBlock(x, y, z, material); if (tag == null) return; // Convert NamedBinaryTag to a native nms tag NBTTagCompound nmsTag = NBTHelper.getNMSFromNBTTagCompound(tag); // Add the id and position to it nmsTag.setString("id", material.withDefaultBlockData().getName()); nmsTag.setInt("x", x); nmsTag.setInt("y", y); nmsTag.setInt("z", z); // Update to current Minecraft format (maybe we want to do this at // server startup instead, and then save the result?) nmsTag = this.dataConverter.a(DataConverterTypes.BLOCK_ENTITY, nmsTag, -1); // Add that data to the current tile entity in the world TileEntity tileEntity = world.getTileEntity(new BlockPosition(x, y, z)); if (tileEntity != null) { tileEntity.load(nmsTag); } else { TerrainControl.log(LogMarker.DEBUG, "Skipping tile entity with id {}, cannot be placed at {},{},{} on id {}", nmsTag.getString("id"), x, y, z, getMaterial(x, y, z)); } }