use of de.budschie.bmorph.morph.fallback.IMorphNBTHandler 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