Search in sources :

Example 1 with GeometryModelTextureTable

use of gg.moonflower.pollen.pinwheel.api.common.texture.GeometryModelTextureTable in project pollen by MoonflowerTeam.

the class DeveloperHalo method registerTextures.

@Override
public void registerTextures(BiConsumer<ResourceLocation, GeometryModelTextureTable> textureConsumer) {
    this.halos.forEach((key, value) -> {
        textureConsumer.accept(new ResourceLocation(Pollen.MOD_ID, key), value.getTextureTable());
        textureConsumer.accept(new ResourceLocation(Pollen.MOD_ID, key + "_emissive"), new GeometryModelTextureTable(value.getTextureTable().getTextureDefinitions().entrySet().stream().collect(Collectors.<Map.Entry<String, GeometryModelTexture[]>, String, GeometryModelTexture[]>toMap(Map.Entry::getKey, entry -> {
            GeometryModelTexture[] textures = new GeometryModelTexture[entry.getValue().length];
            for (int i = 0; i < textures.length; i++) {
                GeometryModelTexture texture = entry.getValue()[i];
                textures[i] = GeometryModelTexture.texture(texture).setGlowing(true).build();
            }
            return textures;
        }))));
    });
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) JsonObject(com.google.gson.JsonObject) Entitlement(gg.moonflower.pollen.core.client.entitlement.Entitlement) GeometryModelTexture(gg.moonflower.pollen.pinwheel.api.common.texture.GeometryModelTexture) Pollen(gg.moonflower.pollen.core.Pollen) Collectors(java.util.stream.Collectors) ArrayEntry(gg.moonflower.pollen.core.client.screen.button.ArrayEntry) Consumer(java.util.function.Consumer) Nullable(org.jetbrains.annotations.Nullable) EntitlementEntry(gg.moonflower.pollen.core.client.screen.button.EntitlementEntry) TextComponent(net.minecraft.network.chat.TextComponent) Codec(com.mojang.serialization.Codec) Locale(java.util.Locale) Map(java.util.Map) GsonHelper(net.minecraft.util.GsonHelper) BiConsumer(java.util.function.BiConsumer) RecordCodecBuilder(com.mojang.serialization.codecs.RecordCodecBuilder) GeometryModelTextureTable(gg.moonflower.pollen.pinwheel.api.common.texture.GeometryModelTextureTable) ApiStatus(org.jetbrains.annotations.ApiStatus) GeometryModelTexture(gg.moonflower.pollen.pinwheel.api.common.texture.GeometryModelTexture) ResourceLocation(net.minecraft.resources.ResourceLocation) Map(java.util.Map) GeometryModelTextureTable(gg.moonflower.pollen.pinwheel.api.common.texture.GeometryModelTextureTable)

Example 2 with GeometryModelTextureTable

use of gg.moonflower.pollen.pinwheel.api.common.texture.GeometryModelTextureTable in project pollen by MoonflowerTeam.

the class Halo method registerTextures.

@Override
public void registerTextures(BiConsumer<ResourceLocation, GeometryModelTextureTable> textureConsumer) {
    textureConsumer.accept(this.getRegistryName(), this.data.getTextureTable());
    textureConsumer.accept(new ResourceLocation(this.getRegistryName().getNamespace(), this.getRegistryName().getPath() + "_emissive"), new GeometryModelTextureTable(this.data.getTextureTable().getTextureDefinitions().entrySet().stream().collect(Collectors.<Map.Entry<String, GeometryModelTexture[]>, String, GeometryModelTexture[]>toMap(Map.Entry::getKey, entry -> {
        GeometryModelTexture[] textures = new GeometryModelTexture[entry.getValue().length];
        for (int i = 0; i < textures.length; i++) {
            GeometryModelTexture texture = entry.getValue()[i];
            textures[i] = GeometryModelTexture.texture(texture).setGlowing(true).build();
        }
        return textures;
    }))));
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) Nullable(org.jetbrains.annotations.Nullable) Entitlement(gg.moonflower.pollen.core.client.entitlement.Entitlement) Codec(com.mojang.serialization.Codec) GeometryModelTexture(gg.moonflower.pollen.pinwheel.api.common.texture.GeometryModelTexture) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) GeometryModelTextureTable(gg.moonflower.pollen.pinwheel.api.common.texture.GeometryModelTextureTable) Collectors(java.util.stream.Collectors) ApiStatus(org.jetbrains.annotations.ApiStatus) GeometryModelTexture(gg.moonflower.pollen.pinwheel.api.common.texture.GeometryModelTexture) ResourceLocation(net.minecraft.resources.ResourceLocation) Map(java.util.Map) GeometryModelTextureTable(gg.moonflower.pollen.pinwheel.api.common.texture.GeometryModelTextureTable)

Example 3 with GeometryModelTextureTable

use of gg.moonflower.pollen.pinwheel.api.common.texture.GeometryModelTextureTable in project pollen by MoonflowerTeam.

the class LocalTextureTableLoader method reload.

@Override
public CompletableFuture<Void> reload(PreparableReloadListener.PreparationBarrier stage, ResourceManager resourceManager, ProfilerFiller preparationsProfiler, ProfilerFiller reloadProfiler, Executor backgroundExecutor, Executor gameExecutor) {
    return CompletableFuture.supplyAsync(() -> {
        Map<ResourceLocation, GeometryModelTextureTable> textureLocations = new HashMap<>();
        for (ResourceLocation textureTableLocation : resourceManager.listResources(this.folder, name -> name.endsWith(".json"))) {
            ResourceLocation textureTableName = new ResourceLocation(textureTableLocation.getNamespace(), textureTableLocation.getPath().substring(this.folder.length(), textureTableLocation.getPath().length() - 5));
            if (textureTableName.getPath().equals("hash_tables"))
                continue;
            try (Resource resource = resourceManager.getResource(textureTableLocation)) {
                textureLocations.put(textureTableName, GeometryModelParser.parseTextures(new InputStreamReader(resource.getInputStream())));
            } catch (Exception e) {
                LOGGER.error("Failed to load texture table '" + textureTableName + "'", e);
            }
        }
        LOGGER.info("Loaded " + textureLocations.size() + " model texture tables.");
        return textureLocations;
    }, backgroundExecutor).thenAcceptBothAsync(CompletableFuture.supplyAsync(() -> {
        Set<String> hashTables = new HashSet<>();
        for (String domain : resourceManager.getNamespaces()) {
            ResourceLocation hashTableLocation = new ResourceLocation(domain, this.folder + "hash_tables.json");
            if (!resourceManager.hasResource(hashTableLocation))
                continue;
            try (Resource resource = resourceManager.getResource(hashTableLocation)) {
                hashTables.addAll(Arrays.asList(GSON.fromJson(new InputStreamReader(resource.getInputStream()), String[].class)));
            } catch (Exception e) {
                LOGGER.error("Failed to load texture hash table for " + domain, e);
            }
        }
        LOGGER.info("Loaded " + hashTables.size() + " hash tables.");
        return hashTables.toArray(new String[0]);
    }, backgroundExecutor), (textureLocations, hashTables) -> {
        this.textures.clear();
        this.textures.putAll(textureLocations);
        this.hashTables = hashTables;
    }, gameExecutor).thenCompose(stage::wait);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) Resource(net.minecraft.server.packs.resources.Resource) Arrays(java.util.Arrays) ProfilerFiller(net.minecraft.util.profiling.ProfilerFiller) Executor(java.util.concurrent.Executor) ResourceManager(net.minecraft.server.packs.resources.ResourceManager) Set(java.util.Set) HashMap(java.util.HashMap) CompletableFuture(java.util.concurrent.CompletableFuture) InputStreamReader(java.io.InputStreamReader) GeometryModelParser(gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelParser) HashSet(java.util.HashSet) Consumer(java.util.function.Consumer) Nullable(org.jetbrains.annotations.Nullable) TextureTableLoader(gg.moonflower.pollen.pinwheel.api.client.texture.TextureTableLoader) Logger(org.apache.logging.log4j.Logger) Gson(com.google.gson.Gson) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) PreparableReloadListener(net.minecraft.server.packs.resources.PreparableReloadListener) GeometryModelTextureTable(gg.moonflower.pollen.pinwheel.api.common.texture.GeometryModelTextureTable) LogManager(org.apache.logging.log4j.LogManager) ApiStatus(org.jetbrains.annotations.ApiStatus) InputStreamReader(java.io.InputStreamReader) HashMap(java.util.HashMap) ResourceLocation(net.minecraft.resources.ResourceLocation) Resource(net.minecraft.server.packs.resources.Resource) GeometryModelTextureTable(gg.moonflower.pollen.pinwheel.api.common.texture.GeometryModelTextureTable) HashSet(java.util.HashSet)

Aggregations

GeometryModelTextureTable (gg.moonflower.pollen.pinwheel.api.common.texture.GeometryModelTextureTable)3 Map (java.util.Map)3 BiConsumer (java.util.function.BiConsumer)3 ResourceLocation (net.minecraft.resources.ResourceLocation)3 ApiStatus (org.jetbrains.annotations.ApiStatus)3 Nullable (org.jetbrains.annotations.Nullable)3 Codec (com.mojang.serialization.Codec)2 Entitlement (gg.moonflower.pollen.core.client.entitlement.Entitlement)2 GeometryModelTexture (gg.moonflower.pollen.pinwheel.api.common.texture.GeometryModelTexture)2 Consumer (java.util.function.Consumer)2 Collectors (java.util.stream.Collectors)2 Gson (com.google.gson.Gson)1 JsonObject (com.google.gson.JsonObject)1 RecordCodecBuilder (com.mojang.serialization.codecs.RecordCodecBuilder)1 Pollen (gg.moonflower.pollen.core.Pollen)1 ArrayEntry (gg.moonflower.pollen.core.client.screen.button.ArrayEntry)1 EntitlementEntry (gg.moonflower.pollen.core.client.screen.button.EntitlementEntry)1 TextureTableLoader (gg.moonflower.pollen.pinwheel.api.client.texture.TextureTableLoader)1 GeometryModelParser (gg.moonflower.pollen.pinwheel.api.common.geometry.GeometryModelParser)1 InputStreamReader (java.io.InputStreamReader)1