Search in sources :

Example 1 with Resource

use of net.minecraft.resource.Resource in project MiniMap by pl3xgaming.

the class Texture method initialize.

public static void initialize() {
    REGISTERED_TEXTURES.forEach(texture -> {
        try {
            Resource resource = texture.resource();
            if (resource.hasMetadata()) {
                texture.meta = texture.load(resource);
            } else {
                texture.meta = new AnimationMetadata();
            }
            MiniMap.LOG.info("Loaded texture " + texture.identifier);
        } catch (IOException e) {
            e.printStackTrace();
        }
    });
}
Also used : AnimationMetadata(net.pl3x.minimap.gui.texture.meta.AnimationMetadata) Resource(net.minecraft.resource.Resource) IOException(java.io.IOException)

Example 2 with Resource

use of net.minecraft.resource.Resource in project fabricskyboxes by AMereBagatelle.

the class SkyboxResourceListener method reload.

@Override
public void reload(ResourceManager manager) {
    SkyboxManager skyboxManager = SkyboxManager.getInstance();
    // clear registered skyboxes on reload
    skyboxManager.clearSkyboxes();
    // load new skyboxes
    Collection<Identifier> resources = manager.findResources("sky", (string) -> string.endsWith(".json"));
    for (Identifier id : resources) {
        Resource resource;
        try {
            resource = manager.getResource(id);
            try {
                JsonObject json = GSON.fromJson(new InputStreamReader(resource.getInputStream()), JsonObject.class);
                objectWrapper.setFocusedObject(json);
                AbstractSkybox skybox = this.parseSkyboxJson(id);
                if (skybox != null) {
                    skyboxManager.addSkybox(skybox);
                }
            } finally {
                try {
                    resource.close();
                } catch (IOException e) {
                    FabricSkyBoxesClient.getLogger().error("Error closing resource " + id.toString());
                    e.printStackTrace();
                }
            }
        } catch (IOException e) {
            FabricSkyBoxesClient.getLogger().error("Error reading skybox " + id.toString());
            e.printStackTrace();
        }
    }
}
Also used : Identifier(net.minecraft.util.Identifier) AbstractSkybox(io.github.amerebagatelle.fabricskyboxes.skyboxes.AbstractSkybox) InputStreamReader(java.io.InputStreamReader) SkyboxManager(io.github.amerebagatelle.fabricskyboxes.SkyboxManager) Resource(net.minecraft.resource.Resource) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException)

Example 3 with Resource

use of net.minecraft.resource.Resource 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 4 with Resource

use of net.minecraft.resource.Resource in project MiniMap by pl3xgaming.

the class Cursor method initialize.

public static void initialize() {
    REGISTERED_CURSORS.forEach(cursor -> {
        try {
            Resource resource = cursor.resource();
            if (resource.hasMetadata()) {
                cursor.meta = cursor.load(resource);
            } else {
                cursor.meta = new CursorMetadata();
            }
            cursor.texture.meta = new AnimationMetadata(cursor.meta.width(), cursor.meta.height(), cursor.meta.frames(), cursor.meta.frametime());
            MiniMap.LOG.info("Loaded mouse cursor " + cursor.identifier);
        } catch (IOException e) {
            e.printStackTrace();
        }
    });
}
Also used : AnimationMetadata(net.pl3x.minimap.gui.texture.meta.AnimationMetadata) Resource(net.minecraft.resource.Resource) CursorMetadata(net.pl3x.minimap.gui.texture.meta.CursorMetadata) IOException(java.io.IOException)

Example 5 with Resource

use of net.minecraft.resource.Resource in project tweed-api by Siphalor.

the class ConfigLoader method loadConfigs.

/**
 * Reloads all matching {@link ConfigFile}s.
 * @param resourceManager the current {@link ResourceManager}
 * @param environment the current environment
 * @param scope the definition scope
 */
public static void loadConfigs(ResourceManager resourceManager, ConfigEnvironment environment, ConfigScope scope) {
    Collection<ConfigFile> configFiles = TweedRegistry.getConfigFiles();
    for (ConfigFile configFile : configFiles) {
        configFile.reset(environment, scope);
        configFile.load(readMainConfigFile(configFile), environment, scope, ConfigOrigin.MAIN);
        updateMainConfigFile(configFile, environment, scope);
        try {
            List<Resource> resources = resourceManager.getAllResources(configFile.getFileIdentifier());
            for (Resource resource : resources) {
                configFile.load(resource, environment, scope, ConfigOrigin.DATAPACK);
            }
        } catch (Exception ignored) {
        }
        configFile.finishReload(environment, scope);
        if (ConfigEnvironment.SERVER.contains(environment)) {
            configFile.syncToClients(ConfigEnvironment.SYNCED, scope, ConfigOrigin.DATAPACK);
        }
    }
}
Also used : Resource(net.minecraft.resource.Resource)

Aggregations

Resource (net.minecraft.resource.Resource)5 IOException (java.io.IOException)3 Identifier (net.minecraft.util.Identifier)2 AnimationMetadata (net.pl3x.minimap.gui.texture.meta.AnimationMetadata)2 JsonObject (com.google.gson.JsonObject)1 Either (com.mojang.datafixers.util.Either)1 SkyboxManager (io.github.amerebagatelle.fabricskyboxes.SkyboxManager)1 AbstractSkybox (io.github.amerebagatelle.fabricskyboxes.skyboxes.AbstractSkybox)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 StandardCharsets (java.nio.charset.StandardCharsets)1 java.util (java.util)1 Collectors (java.util.stream.Collectors)1 BakedModel (net.minecraft.client.render.model.BakedModel)1 ModelLoader (net.minecraft.client.render.model.ModelLoader)1 SpriteAtlasManager (net.minecraft.client.render.model.SpriteAtlasManager)1 UnbakedModel (net.minecraft.client.render.model.UnbakedModel)1 JsonUnbakedModel (net.minecraft.client.render.model.json.JsonUnbakedModel)1 ModelOverride (net.minecraft.client.render.model.json.ModelOverride)1 TextureManager (net.minecraft.client.texture.TextureManager)1