Search in sources :

Example 1 with Identifier

use of net.modificationstation.stationapi.api.registry.Identifier in project StationAPI by ModificationStation.

the class SpriteAtlasTexture method loadSprites.

private Collection<Sprite.Info> loadSprites(TexturePack resourceManager, Set<Identifier> ids) {
    ArrayList<CompletableFuture<Void>> list = new ArrayList<>();
    ConcurrentLinkedQueue<Sprite.Info> concurrentLinkedQueue = new ConcurrentLinkedQueue<>();
    for (Identifier identifier : ids) {
        if (MissingSprite.getMissingSpriteId().equals(identifier))
            continue;
        list.add(CompletableFuture.runAsync(() -> {
            Sprite.Info info3;
            Identifier identifier2 = this.getTexturePath(identifier);
            try (Resource resource = Resource.of(resourceManager.getResourceAsStream(ResourceManager.ASSETS.toPath(identifier2)))) {
                BufferedImage image = ImageIO.read(resource.getInputStream());
                AnimationResourceMetadata animationResourceMetadata = resource.getMetadata(AnimationResourceMetadata.READER);
                if (animationResourceMetadata == null)
                    animationResourceMetadata = AnimationResourceMetadata.EMPTY;
                Pair<Integer, Integer> pair = animationResourceMetadata.getResolution(image.getWidth(), image.getHeight());
                info3 = new Sprite.Info(identifier, pair.getFirst(), pair.getSecond(), animationResourceMetadata);
            } catch (RuntimeException runtimeException) {
                LOGGER.error("Unable to parse metadata from {} : {}", identifier2, runtimeException);
                return;
            } catch (IOException iOException) {
                LOGGER.error("Using missing texture, unable to load {} : {}", identifier2, iOException);
                return;
            }
            concurrentLinkedQueue.add(info3);
        }, Util.getMainWorkerExecutor()));
    }
    CompletableFuture.allOf(list.toArray(new CompletableFuture[0])).join();
    return concurrentLinkedQueue;
}
Also used : Resource(net.modificationstation.stationapi.api.client.resource.Resource) AnimationResourceMetadata(net.modificationstation.stationapi.api.client.resource.metadata.AnimationResourceMetadata) Identifier(net.modificationstation.stationapi.api.registry.Identifier) Pair(com.mojang.datafixers.util.Pair)

Example 2 with Identifier

use of net.modificationstation.stationapi.api.registry.Identifier in project StationAPI by ModificationStation.

the class JsonRecipesLoader method registerRecipe.

private static void registerRecipe(URL recipe) {
    try {
        String rawId = new Gson().fromJson(new InputStreamReader(recipe.openStream()), JsonRecipeType.class).getType();
        Identifier recipeId;
        try {
            recipeId = Identifier.of(rawId);
        } catch (MissingModException e) {
            LOGGER.warn("Found an unknown recipe type " + rawId + ". Ignoring.");
            return;
        }
        JsonRecipesRegistry.INSTANCE.computeIfAbsent(recipeId, identifier -> new HashSet<>()).add(recipe);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
Also used : ResourceManager(net.modificationstation.stationapi.api.resource.ResourceManager) java.util(java.util) MissingModException(net.modificationstation.stationapi.api.util.exception.MissingModException) MODID(net.modificationstation.stationapi.api.StationAPI.MODID) Filters(net.modificationstation.stationapi.api.resource.Filters) EventListener(net.mine_diver.unsafeevents.listener.EventListener) java.net(java.net) java.io(java.io) ListenerPriority(net.mine_diver.unsafeevents.listener.ListenerPriority) EventBusPolicy(net.modificationstation.stationapi.api.mod.entrypoint.EventBusPolicy) LOGGER(net.modificationstation.stationapi.api.StationAPI.LOGGER) Gson(com.google.gson.Gson) PreInitEvent(net.modificationstation.stationapi.api.event.mod.PreInitEvent) Entrypoint(net.modificationstation.stationapi.api.mod.entrypoint.Entrypoint) Identifier(net.modificationstation.stationapi.api.registry.Identifier) JsonRecipesRegistry(net.modificationstation.stationapi.api.registry.JsonRecipesRegistry) Identifier(net.modificationstation.stationapi.api.registry.Identifier) MissingModException(net.modificationstation.stationapi.api.util.exception.MissingModException) Gson(com.google.gson.Gson)

Example 3 with Identifier

use of net.modificationstation.stationapi.api.registry.Identifier in project StationAPI by ModificationStation.

the class MainTest method onInitialize.

@EventListener
public void onInitialize(TagRegisterEvent event) {
    SLTest.LOGGER.info("==================================================================================================");
    Identifier oreDictToTest = Identifier.of("items/tools/pickaxes/");
    SLTest.LOGGER.info(oreDictToTest);
    Optional<Map<Identifier, List<TagEntry>>> predicates = TagRegistry.INSTANCE.getWithIdentifiers(oreDictToTest);
    if (predicates.isPresent()) {
        for (Identifier oreDictEntryObject : predicates.get().keySet()) {
            SLTest.LOGGER.info(oreDictEntryObject);
        }
    } else {
        throw new RuntimeException("Predicates are empty for " + oreDictToTest);
    }
    SLTest.LOGGER.info("==================================================================================================");
// block.mineableByTool("pickaxe*", 0);
}
Also used : Identifier(net.modificationstation.stationapi.api.registry.Identifier) TagEntry(net.modificationstation.stationapi.api.tags.TagEntry) EventListener(net.mine_diver.unsafeevents.listener.EventListener)

Example 4 with Identifier

use of net.modificationstation.stationapi.api.registry.Identifier in project StationAPI by ModificationStation.

the class SpriteAtlasTexture method stitch.

public Data stitch(TexturePack resourceManager, Stream<Identifier> idStream, Profiler profiler, int mipmapLevel) {
    int p;
    profiler.push("preparing");
    Set<Identifier> set = idStream.peek(identifier -> {
        if (identifier == null) {
            throw new IllegalArgumentException("Location cannot be null!");
        }
    }).collect(Collectors.toSet());
    int i = this.maxTextureSize;
    TextureStitcher textureStitcher = new TextureStitcher(i, i, mipmapLevel);
    int j = Integer.MAX_VALUE;
    int k = 1 << mipmapLevel;
    profiler.swap("extracting_frames");
    for (Sprite.Info info2 : this.loadSprites(resourceManager, set)) {
        j = Math.min(j, Math.min(info2.getWidth(), info2.getHeight()));
        int l = Math.min(Integer.lowestOneBit(info2.getWidth()), Integer.lowestOneBit(info2.getHeight()));
        if (l < k) {
            LOGGER.warn("Texture {} with size {}x{} limits mip level from {} to {}", info2.getId(), info2.getWidth(), info2.getHeight(), MathHelper.log2(k), MathHelper.log2(l));
            k = l;
        }
        textureStitcher.add(info2);
    }
    int m = Math.min(j, k);
    int n = MathHelper.log2(m);
    if (n < mipmapLevel) {
        LOGGER.warn("{}: dropping miplevel from {} to {}, because of minimum power of two: {}", this.id, mipmapLevel, n, m);
        p = n;
    } else {
        p = mipmapLevel;
    }
    profiler.swap("register");
    textureStitcher.add(MissingSprite.getMissingInfo());
    profiler.swap("stitching");
    try {
        textureStitcher.stitch();
    } catch (TextureStitcherCannotFitException textureStitcherCannotFitException) {
        CrashReport crashReport = CrashReport.create(textureStitcherCannotFitException, "Stitching");
        CrashReportSection crashReportSection = crashReport.addElement("Stitcher");
        crashReportSection.add("Sprites", textureStitcherCannotFitException.getSprites().stream().map(info -> String.format("%s[%dx%d]", info.getId(), info.getWidth(), info.getHeight())).collect(Collectors.joining(",")));
        crashReportSection.add("Max Texture Size", i);
        throw new CrashException(crashReport);
    }
    profiler.swap("loading");
    List<Sprite> list = this.loadSprites(resourceManager, textureStitcher, p);
    profiler.pop();
    return new Data(set, textureStitcher.getWidth(), textureStitcher.getHeight(), p, list);
}
Also used : ResourceManager(net.modificationstation.stationapi.api.resource.ResourceManager) CrashReportSection(net.modificationstation.stationapi.api.util.exception.CrashReportSection) java.awt.image(java.awt.image) java.util(java.util) MODID(net.modificationstation.stationapi.api.StationAPI.MODID) java.util.stream(java.util.stream) Environment(net.fabricmc.api.Environment) LOGGER(net.modificationstation.stationapi.impl.client.texture.StationRenderImpl.LOGGER) Resource(net.modificationstation.stationapi.api.client.resource.Resource) CrashException(net.modificationstation.stationapi.api.util.exception.CrashException) Lists(com.google.common.collect.Lists) TexturePack(net.minecraft.client.resource.TexturePack) Identifier(net.modificationstation.stationapi.api.registry.Identifier) EnvType(net.fabricmc.api.EnvType) Util(net.modificationstation.stationapi.api.util.Util) CrashReport(net.modificationstation.stationapi.api.util.exception.CrashReport) ApiStatus(org.jetbrains.annotations.ApiStatus) java.util.concurrent(java.util.concurrent) javax.imageio(javax.imageio) Pair(com.mojang.datafixers.util.Pair) MathHelper(net.modificationstation.stationapi.api.util.math.MathHelper) AnimationResourceMetadata(net.modificationstation.stationapi.api.client.resource.metadata.AnimationResourceMetadata) Nullable(org.jetbrains.annotations.Nullable) java.io(java.io) Profiler(net.modificationstation.stationapi.api.util.profiler.Profiler) SpriteFinderImpl(net.modificationstation.stationapi.impl.client.render.SpriteFinderImpl) RenderSystem(net.modificationstation.stationapi.impl.client.texture.RenderSystem) CrashException(net.modificationstation.stationapi.api.util.exception.CrashException) CrashReport(net.modificationstation.stationapi.api.util.exception.CrashReport) CrashReportSection(net.modificationstation.stationapi.api.util.exception.CrashReportSection) Identifier(net.modificationstation.stationapi.api.registry.Identifier)

Example 5 with Identifier

use of net.modificationstation.stationapi.api.registry.Identifier in project StationAPI by ModificationStation.

the class ModelOverride method matches.

boolean matches(ItemInstance stack, @Nullable ClientLevel world, @Nullable Living entity) {
    ItemBase item = stack.getType();
    Iterator<Entry<Identifier, Float>> var5 = this.predicateToThresholds.entrySet().iterator();
    Entry<Identifier, Float> entry;
    ModelPredicateProvider modelPredicateProvider;
    if (!var5.hasNext()) {
        return true;
    }
    entry = var5.next();
    modelPredicateProvider = ModelPredicateProviderRegistry.INSTANCE.get(item, entry.getKey());
    while (modelPredicateProvider != null && modelPredicateProvider.call(stack, world, entity) >= entry.getValue()) {
        if (!var5.hasNext()) {
            return true;
        }
        entry = var5.next();
        modelPredicateProvider = ModelPredicateProviderRegistry.INSTANCE.get(item, entry.getKey());
    }
    return false;
}
Also used : Identifier(net.modificationstation.stationapi.api.registry.Identifier) ItemBase(net.minecraft.item.ItemBase) ModelPredicateProvider(net.modificationstation.stationapi.api.client.model.item.ModelPredicateProvider)

Aggregations

Identifier (net.modificationstation.stationapi.api.registry.Identifier)5 Pair (com.mojang.datafixers.util.Pair)2 java.io (java.io)2 java.util (java.util)2 EventListener (net.mine_diver.unsafeevents.listener.EventListener)2 MODID (net.modificationstation.stationapi.api.StationAPI.MODID)2 Resource (net.modificationstation.stationapi.api.client.resource.Resource)2 AnimationResourceMetadata (net.modificationstation.stationapi.api.client.resource.metadata.AnimationResourceMetadata)2 ResourceManager (net.modificationstation.stationapi.api.resource.ResourceManager)2 Lists (com.google.common.collect.Lists)1 Gson (com.google.gson.Gson)1 java.awt.image (java.awt.image)1 java.net (java.net)1 java.util.concurrent (java.util.concurrent)1 java.util.stream (java.util.stream)1 javax.imageio (javax.imageio)1 EnvType (net.fabricmc.api.EnvType)1 Environment (net.fabricmc.api.Environment)1 ListenerPriority (net.mine_diver.unsafeevents.listener.ListenerPriority)1 TexturePack (net.minecraft.client.resource.TexturePack)1