Search in sources :

Example 1 with CIT

use of shcm.shsupercm.fabric.citresewn.pack.cits.CIT 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);
        }
    }
}
Also used : Either(com.mojang.datafixers.util.Either) UnbakedModel(net.minecraft.client.render.model.UnbakedModel) java.util(java.util) SpriteIdentifier(net.minecraft.client.util.SpriteIdentifier) BakedModel(net.minecraft.client.render.model.BakedModel) Inject(org.spongepowered.asm.mixin.injection.Inject) ResewnTextureIdentifier(shcm.shsupercm.fabric.citresewn.pack.ResewnTextureIdentifier) CallbackInfoReturnable(org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable) Resource(net.minecraft.resource.Resource) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) Mixin(org.spongepowered.asm.mixin.Mixin) CIT(shcm.shsupercm.fabric.citresewn.pack.cits.CIT) TextureManager(net.minecraft.client.texture.TextureManager) At(org.spongepowered.asm.mixin.injection.At) CITResewn.info(shcm.shsupercm.fabric.citresewn.CITResewn.info) CITItem(shcm.shsupercm.fabric.citresewn.pack.cits.CITItem) CITResewn(shcm.shsupercm.fabric.citresewn.CITResewn) ModelLoader(net.minecraft.client.render.model.ModelLoader) ResourceManager(net.minecraft.resource.ResourceManager) Final(org.spongepowered.asm.mixin.Final) ModelOverride(net.minecraft.client.render.model.json.ModelOverride) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) IOUtils(org.apache.commons.io.IOUtils) SpriteAtlasManager(net.minecraft.client.render.model.SpriteAtlasManager) ModelIdentifier(net.minecraft.client.util.ModelIdentifier) JsonUnbakedModel(net.minecraft.client.render.model.json.JsonUnbakedModel) Profiler(net.minecraft.util.profiler.Profiler) Identifier(net.minecraft.util.Identifier) Shadow(org.spongepowered.asm.mixin.Shadow) ModifyArg(org.spongepowered.asm.mixin.injection.ModifyArg) ResewnItemModelIdentifier(shcm.shsupercm.fabric.citresewn.pack.ResewnItemModelIdentifier) InputStream(java.io.InputStream) ResewnTextureIdentifier(shcm.shsupercm.fabric.citresewn.pack.ResewnTextureIdentifier) InputStream(java.io.InputStream) Resource(net.minecraft.resource.Resource) SpriteIdentifier(net.minecraft.client.util.SpriteIdentifier) SpriteIdentifier(net.minecraft.client.util.SpriteIdentifier) ResewnTextureIdentifier(shcm.shsupercm.fabric.citresewn.pack.ResewnTextureIdentifier) ModelIdentifier(net.minecraft.client.util.ModelIdentifier) Identifier(net.minecraft.util.Identifier) ResewnItemModelIdentifier(shcm.shsupercm.fabric.citresewn.pack.ResewnItemModelIdentifier) JsonUnbakedModel(net.minecraft.client.render.model.json.JsonUnbakedModel) ResewnItemModelIdentifier(shcm.shsupercm.fabric.citresewn.pack.ResewnItemModelIdentifier) ModelOverride(net.minecraft.client.render.model.json.ModelOverride) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with CIT

use of shcm.shsupercm.fabric.citresewn.pack.cits.CIT in project CITResewn by SHsuperCM.

the class ModelLoaderMixin method initCITs.

@Inject(method = "addModel", at = @At("TAIL"))
public void initCITs(ModelIdentifier eventModelId, CallbackInfo ci) {
    if (eventModelId != ModelLoader.MISSING_ID)
        return;
    if (CITResewn.INSTANCE.activeCITs != null) {
        info("Clearing active CITs..");
        CITResewn.INSTANCE.activeCITs.dispose();
        CITResewn.INSTANCE.activeCITs = null;
    }
    if (!CITResewnConfig.INSTANCE().enabled)
        return;
    info("Parsing CITs...");
    List<CITPack> parsedPacks = CITParser.parseCITs(resourceManager.streamResourcePacks().collect(Collectors.toCollection(ArrayList::new)));
    List<CIT> parsed = parsedPacks.stream().flatMap(pack -> pack.cits.stream()).collect(Collectors.toCollection(ArrayList::new));
    if (parsed.size() > 0) {
        info("Activating CITs...");
        CITResewn.INSTANCE.activeCITs = new ActiveCITs(parsedPacks, parsed);
    } else
        info("No cit packs found.");
}
Also used : ActiveCITs(shcm.shsupercm.fabric.citresewn.ActiveCITs) CITParser(shcm.shsupercm.fabric.citresewn.pack.CITParser) Inject(org.spongepowered.asm.mixin.injection.Inject) CITResewn(shcm.shsupercm.fabric.citresewn.CITResewn) Collection(java.util.Collection) ModelLoader(net.minecraft.client.render.model.ModelLoader) ResourceManager(net.minecraft.resource.ResourceManager) Final(org.spongepowered.asm.mixin.Final) Collectors(java.util.stream.Collectors) CITResewnConfig(shcm.shsupercm.fabric.citresewn.config.CITResewnConfig) ArrayList(java.util.ArrayList) CallbackInfo(org.spongepowered.asm.mixin.injection.callback.CallbackInfo) List(java.util.List) ModelIdentifier(net.minecraft.client.util.ModelIdentifier) Mixin(org.spongepowered.asm.mixin.Mixin) CITPack(shcm.shsupercm.fabric.citresewn.pack.CITPack) CIT(shcm.shsupercm.fabric.citresewn.pack.cits.CIT) Shadow(org.spongepowered.asm.mixin.Shadow) At(org.spongepowered.asm.mixin.injection.At) CITResewn.info(shcm.shsupercm.fabric.citresewn.CITResewn.info) ActiveCITs(shcm.shsupercm.fabric.citresewn.ActiveCITs) ArrayList(java.util.ArrayList) CITPack(shcm.shsupercm.fabric.citresewn.pack.CITPack) CIT(shcm.shsupercm.fabric.citresewn.pack.cits.CIT) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

Collectors (java.util.stream.Collectors)2 ModelLoader (net.minecraft.client.render.model.ModelLoader)2 ModelIdentifier (net.minecraft.client.util.ModelIdentifier)2 ResourceManager (net.minecraft.resource.ResourceManager)2 Final (org.spongepowered.asm.mixin.Final)2 Mixin (org.spongepowered.asm.mixin.Mixin)2 Shadow (org.spongepowered.asm.mixin.Shadow)2 At (org.spongepowered.asm.mixin.injection.At)2 Inject (org.spongepowered.asm.mixin.injection.Inject)2 CallbackInfo (org.spongepowered.asm.mixin.injection.callback.CallbackInfo)2 CITResewn (shcm.shsupercm.fabric.citresewn.CITResewn)2 CITResewn.info (shcm.shsupercm.fabric.citresewn.CITResewn.info)2 CIT (shcm.shsupercm.fabric.citresewn.pack.cits.CIT)2 Either (com.mojang.datafixers.util.Either)1 InputStream (java.io.InputStream)1 StandardCharsets (java.nio.charset.StandardCharsets)1 java.util (java.util)1 ArrayList (java.util.ArrayList)1 Collection (java.util.Collection)1 List (java.util.List)1