use of shcm.shsupercm.fabric.citresewn.pack.ResewnItemModelIdentifier in project CITResewn by SHsuperCM.
the class ModelLoaderMixin method linkBakedCITItemModels.
@Inject(method = "upload", at = @At("RETURN"))
public void linkBakedCITItemModels(TextureManager textureManager, Profiler profiler, CallbackInfoReturnable<SpriteAtlasManager> cir) {
if (CITResewn.INSTANCE.activeCITs == null)
return;
profiler.push("citresewn_linking");
info("Linking baked models to CITItems...");
if (CITResewn.INSTANCE.activeCITs != null) {
for (CITItem citItem : CITResewn.INSTANCE.activeCITs.citItems.values().stream().flatMap(Collection::stream).distinct().collect(Collectors.toList())) {
for (Map.Entry<List<ModelOverride.Condition>, JsonUnbakedModel> citModelEntry : citItem.unbakedAssets.entrySet()) {
if (citModelEntry.getKey() == null) {
citItem.bakedModel = this.bakedModels.get(new ResewnItemModelIdentifier(citModelEntry.getValue().id));
} else {
BakedModel bakedModel = bakedModels.get(new ResewnItemModelIdentifier(citModelEntry.getValue().id));
if (bakedModel == null)
CITResewn.logWarnLoading("Skipping sub cit: Failed loading model for \"" + citModelEntry.getValue().id + "\" in " + citItem.pack.resourcePack.getName() + " -> " + citItem.propertiesIdentifier.getPath());
else
citItem.bakedSubModels.override(citModelEntry.getKey(), bakedModel);
}
}
citItem.unbakedAssets = null;
}
}
profiler.pop();
}
use of shcm.shsupercm.fabric.citresewn.pack.ResewnItemModelIdentifier in project CITResewn by SHsuperCM.
the class ModelLoaderMixin method addCITItemModels.
@Inject(method = "addModel", at = @At("TAIL"))
public void addCITItemModels(ModelIdentifier eventModelId, CallbackInfo ci) {
if (eventModelId != ModelLoader.MISSING_ID)
return;
if (CITResewn.INSTANCE.activeCITs == null)
return;
info("Loading CITItem models...");
CITResewn.INSTANCE.activeCITs.citItems.values().stream().flatMap(Collection::stream).distinct().forEach(citItem -> {
try {
citItem.loadUnbakedAssets(resourceManager);
for (JsonUnbakedModel unbakedModel : citItem.unbakedAssets.values()) {
ResewnItemModelIdentifier id = new ResewnItemModelIdentifier(unbakedModel.id);
this.unbakedModels.put(id, unbakedModel);
this.modelsToLoad.addAll(unbakedModel.getModelDependencies());
this.modelsToBake.put(id, unbakedModel);
}
} catch (Exception e) {
CITResewn.logErrorLoading(e.getMessage());
}
});
CITItem.GENERATED_SUB_CITS_SEEN.clear();
}
use of shcm.shsupercm.fabric.citresewn.pack.ResewnItemModelIdentifier in project CITResewn by SHsuperCM.
the class ModelLoaderMixin method forceLiteralResewnModelIdentifier.
@Inject(method = "loadModelFromJson", cancellable = true, at = @At("HEAD"))
public void forceLiteralResewnModelIdentifier(Identifier id, CallbackInfoReturnable<JsonUnbakedModel> cir) {
if (id instanceof ResewnItemModelIdentifier) {
InputStream is = null;
Resource resource = null;
try {
JsonUnbakedModel json = JsonUnbakedModel.deserialize(IOUtils.toString(is = (resource = resourceManager.getResource(id)).getInputStream(), StandardCharsets.UTF_8));
json.id = id.toString();
json.id = json.id.substring(0, json.id.length() - 5);
((JsonUnbakedModelAccessor) json).getTextureMap().replaceAll((layer, original) -> {
Optional<SpriteIdentifier> left = original.left();
if (left.isPresent()) {
String originalPath = left.get().getTextureId().getPath();
String[] split = originalPath.split("/");
if (originalPath.startsWith("./") || (split.length > 2 && split[1].equals("cit"))) {
Identifier resolvedIdentifier = CIT.resolvePath(id, originalPath, ".png", identifier -> resourceManager.containsResource(identifier));
if (resolvedIdentifier != null)
return Either.left(new SpriteIdentifier(left.get().getAtlasId(), new ResewnTextureIdentifier(resolvedIdentifier)));
}
}
return original;
});
Identifier parentId = ((JsonUnbakedModelAccessor) json).getParentId();
if (parentId != null) {
String[] parentIdPathSplit = parentId.getPath().split("/");
if (parentId.getPath().startsWith("./") || (parentIdPathSplit.length > 2 && parentIdPathSplit[1].equals("cit"))) {
parentId = CIT.resolvePath(id, parentId.getPath(), ".json", identifier -> resourceManager.containsResource(identifier));
if (parentId != null)
((JsonUnbakedModelAccessor) json).setParentId(new ResewnItemModelIdentifier(parentId));
}
}
json.getOverrides().replaceAll(override -> {
String[] modelIdPathSplit = override.getModelId().getPath().split("/");
if (override.getModelId().getPath().startsWith("./") || (modelIdPathSplit.length > 2 && modelIdPathSplit[1].equals("cit"))) {
Identifier resolvedOverridePath = CIT.resolvePath(id, override.getModelId().getPath(), ".json", identifier -> resourceManager.containsResource(identifier));
if (resolvedOverridePath != null)
return new ModelOverride(new ResewnItemModelIdentifier(resolvedOverridePath), override.streamConditions().collect(Collectors.toList()));
}
return override;
});
cir.setReturnValue(json);
} catch (Exception ignored) {
} finally {
IOUtils.closeQuietly(is, resource);
}
}
}
Aggregations