use of net.minecraft.nbt.JsonToNBT in project MCMOD-Industria by M-Marvin.
the class JigsawFileManager method loadListNBT.
@SuppressWarnings("deprecation")
private static ListNBT loadListNBT(ServerWorld world, ResourceLocation location) {
IResourceManager resourceManager = getResourceManager(world);
ResourceLocation resourcePath = new ResourceLocation(location.getNamespace(), "structures/" + location.getPath() + ".mcmeta");
try (IResource resource = resourceManager.getResource(resourcePath)) {
InputStream inputStream = resource.getInputStream();
String jsonString = IOUtils.toString(inputStream);
CompoundNBT fileNBT = new JsonToNBT(new StringReader(jsonString)).readStruct();
ListNBT list = fileNBT.getList("structures", 10);
return list;
} catch (FileNotFoundException e) {
return null;
} catch (Throwable throwable) {
Industria.LOGGER.error("Couldn't load Jigsaw-Structure-List {}: {}", location, throwable.toString());
throwable.printStackTrace();
return null;
}
}
use of net.minecraft.nbt.JsonToNBT in project BudschieMorphMod by Budschie.
the class MorphNBTHandler method apply.
@Override
protected void apply(Map<ResourceLocation, JsonElement> objectIn, IResourceManager resourceManagerIn, IProfiler profilerIn) {
HashMap<EntityType<?>, IMorphNBTHandler> nbtDataHandlers = new HashMap<>();
MorphManagerHandlers.FALLBACK.setDataHandlers(nbtDataHandlers);
objectIn.forEach((resourceLocation, json) -> {
try {
JsonObject jsonObject = json.getAsJsonObject();
String entityTypeString = jsonObject.get("entity_type").getAsString();
// Load in the entity type
final EntityType<?> entityType = ForgeRegistries.ENTITIES.getValue(new ResourceLocation(entityTypeString));
if (entityType == null)
LOGGER.warn("The entity ", entityTypeString, " doesn't exist. Please make sure to only load this when the mod for the entity is present. You can do this by putting this JSON file in \"data/<modname>/morph_nbt\".");
// Load in the tracked nbt keys as a NBTPath array
JsonElement tracked = jsonObject.get("tracked_nbt_keys");
final NBTPath[] trackedNbtKeys = new NBTPath[tracked == null ? 1 : tracked.getAsJsonArray().size() + 1];
if (tracked != null) {
for (int i = 0; i < tracked.getAsJsonArray().size(); i++) trackedNbtKeys[i] = NBTPath.valueOf(tracked.getAsJsonArray().get(i).getAsString());
}
trackedNbtKeys[trackedNbtKeys.length - 1] = new NBTPath("CustomName");
JsonElement defaultNBTObject = jsonObject.get("default_nbt");
final CompoundNBT defaultNBT = defaultNBTObject == null ? new CompoundNBT() : new JsonToNBT(new StringReader(defaultNBTObject.getAsString())).readStruct();
// Build SpecialDataHandler
JsonMorphNBTHandler nbtHandler = new JsonMorphNBTHandler(defaultNBT, trackedNbtKeys);
nbtDataHandlers.put(entityType, nbtHandler);
} catch (CommandSyntaxException e) {
e.printStackTrace();
}
});
MorphNBTHandlersLoadedEvent event = new MorphNBTHandlersLoadedEvent(nbtDataHandlers);
// Fire an event when we are finished...
MinecraftForge.EVENT_BUS.post(event);
}
Aggregations