Search in sources :

Example 1 with BarrelSkin

use of com.latmod.yabba.api.BarrelSkin in project YABBA by LatvianModder.

the class YabbaClient method loadModelsAndSkins.

public static void loadModelsAndSkins() {
    TEXTURES.clear();
    MODELS.clear();
    SKINS.clear();
    ALL_MODELS.clear();
    ALL_SKINS.clear();
    IResourceManager manager = ClientUtils.MC.getResourceManager();
    for (String domain : manager.getResourceDomains()) {
        try {
            for (IResource resource : manager.getAllResources(new ResourceLocation(domain, "yabba_models/_index.json"))) {
                for (JsonElement element : DataReader.get(resource).json().getAsJsonArray()) {
                    try {
                        JsonObject modelFile = DataReader.get(manager.getResource(new ResourceLocation(domain, "yabba_models/" + element.getAsString() + ".json"))).json().getAsJsonObject();
                        BarrelModel model = new BarrelModel(new ResourceLocation(domain, element.getAsString()), modelFile);
                        MODELS.put(model.id, model);
                        for (TextureSet textureSet : model.textures.values()) {
                            TEXTURES.addAll(textureSet.getTextures());
                        }
                    } catch (Exception ex1) {
                    }
                }
            }
        } catch (Exception ex) {
            if (!(ex instanceof FileNotFoundException)) {
                ex.printStackTrace();
            }
        }
        try {
            for (IResource resource : manager.getAllResources(new ResourceLocation(domain, "yabba_models/_skins.json"))) {
                parseSkinsJson(DataReader.get(resource).json().getAsJsonArray());
                VARIABLES.clear();
            }
        } catch (Exception ex) {
            if (!(ex instanceof FileNotFoundException)) {
                ex.printStackTrace();
            }
        }
    }
    for (Fluid fluid : FluidRegistry.getRegisteredFluids().values()) {
        FluidStack stack = new FluidStack(fluid, 1000);
        String displayName = stack.getLocalizedName();
        Color4I color = Color4I.rgba(fluid.getColor(stack));
        if (color.equals(Color4I.WHITE)) {
            color = Icon.EMPTY;
        }
        ResourceLocation still = fluid.getStill(stack);
        BarrelSkin skin = new BarrelSkin(fluid.getName() + "_still", TextureSet.of("all=" + still));
        skin.displayName = StringUtils.translate("lang.fluid.still", displayName);
        skin.color = color;
        skin.layer = BlockRenderLayer.TRANSLUCENT;
        REGISTER_SKIN.addSkin(skin);
        ResourceLocation flowing = fluid.getFlowing(stack);
        if (!still.equals(flowing)) {
            skin = new BarrelSkin(fluid.getName() + "_flowing", TextureSet.of("up&down=" + still + ",all=" + flowing));
            skin.displayName = StringUtils.translate("lang.fluid.flowing", displayName);
            skin.color = color;
            skin.layer = BlockRenderLayer.TRANSLUCENT;
            REGISTER_SKIN.addSkin(skin);
        }
    }
    new YabbaSkinsEvent(REGISTER_SKIN).post();
    for (BarrelSkin skin : SKINS.values()) {
        if (skin.displayName.isEmpty() && skin.state != CommonUtils.AIR_STATE) {
            try {
                skin.displayName = new ItemStack(skin.state.getBlock(), 1, skin.state.getBlock().getMetaFromState(skin.state)).getDisplayName();
            } catch (Exception ex) {
            }
        }
        if (skin.displayName.isEmpty() || skin.displayName.contains("air")) {
            skin.displayName = "";
        }
        if (skin.icon.isEmpty()) {
            skin.icon = ItemIcon.getItemIcon(((BlockItemBarrel) YabbaItems.ITEM_BARREL).createStack(YabbaItems.ITEM_BARREL.getDefaultState(), BarrelLook.get(Yabba.MOD_ID + ":block", skin.id), Tier.WOOD));
        }
    }
    ALL_MODELS.addAll(MODELS.values());
    DEFAULT_MODEL = MODELS.get(BarrelLook.DEFAULT_MODEL_ID);
    if (DEFAULT_MODEL == null) {
        DEFAULT_MODEL = ALL_MODELS.isEmpty() ? null : ALL_MODELS.get(0);
    }
    Yabba.LOGGER.info("Models: " + ALL_MODELS.size());
    if (FTBLibConfig.debugging.print_more_info) {
        for (BarrelModel model : ALL_MODELS) {
            Yabba.LOGGER.info("-- " + model.id + " :: " + model);
        }
    }
    ALL_SKINS.addAll(SKINS.values());
    ALL_SKINS.sort(StringUtils.ID_COMPARATOR);
    DEFAULT_SKIN = SKINS.get(BarrelLook.DEFAULT_SKIN_ID);
    if (DEFAULT_SKIN == null) {
        DEFAULT_SKIN = ALL_SKINS.isEmpty() ? null : ALL_SKINS.get(0);
    }
    Yabba.LOGGER.info("Skins: " + ALL_SKINS.size());
    if (FTBLibConfig.debugging.print_more_info) {
        for (BarrelSkin skin : ALL_SKINS) {
            Yabba.LOGGER.info("-- " + skin.id + " :: " + skin);
        }
    }
    for (BarrelModel model : ALL_MODELS) {
        model.icon = ItemIcon.getItemIcon(((BlockItemBarrel) YabbaItems.ITEM_BARREL).createStack(YabbaItems.ITEM_BARREL.getDefaultState(), BarrelLook.get(model.id, ""), Tier.WOOD));
    }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) Fluid(net.minecraftforge.fluids.Fluid) FileNotFoundException(java.io.FileNotFoundException) JsonObject(com.google.gson.JsonObject) Color4I(com.feed_the_beast.ftblib.lib.icon.Color4I) YabbaSkinsEvent(com.latmod.yabba.api.YabbaSkinsEvent) FileNotFoundException(java.io.FileNotFoundException) TextureSet(com.feed_the_beast.ftblib.lib.util.misc.TextureSet) JsonElement(com.google.gson.JsonElement) ResourceLocation(net.minecraft.util.ResourceLocation) IResourceManager(net.minecraft.client.resources.IResourceManager) ItemStack(net.minecraft.item.ItemStack) IResource(net.minecraft.client.resources.IResource) BarrelSkin(com.latmod.yabba.api.BarrelSkin) BlockItemBarrel(com.latmod.yabba.block.BlockItemBarrel)

Example 2 with BarrelSkin

use of com.latmod.yabba.api.BarrelSkin in project YABBA by LatvianModder.

the class YabbaClient method parseSkinsJson.

private static void parseSkinsJson(JsonArray array) {
    for (JsonElement element : array) {
        try {
            if (!element.isJsonObject()) {
                continue;
            }
            JsonObject json = element.getAsJsonObject();
            if (json.has("add")) {
                ResourceLocation id = new ResourceLocation(parseVariableString(json.get("add").getAsString()));
                TextureSet textures;
                if (json.has("textures")) {
                    textures = TextureSet.of(parseVariableString(json.get("textures").getAsString()));
                } else {
                    textures = TextureSet.of("all=" + id.getResourceDomain() + ":blocks/" + id.getResourcePath());
                }
                BarrelSkin skin = new BarrelSkin(id.toString(), textures);
                if (json.has("name")) {
                    skin.displayName = JsonUtils.deserializeTextComponent(json.get("name")).getFormattedText();
                }
                if (json.has("icon")) {
                    skin.icon = Icon.getIcon(json.get("icon"));
                }
                if (json.has("layer")) {
                    skin.layer = ClientUtils.BLOCK_RENDER_LAYER_NAME_MAP.get(json.get("layer").getAsString());
                }
                if (json.has("color")) {
                    skin.color = Color4I.fromJson(json.get("color"));
                }
                skin.state = CommonUtils.getStateFromName(json.has("state") ? parseVariableString(json.get("state").getAsString()) : skin.id);
                REGISTER_SKIN.addSkin(skin);
            } else if (json.has("set")) {
                VARIABLES.put(parseVariableString(json.get("set").getAsString()), parseVariableString(json.get("value").getAsString()));
            } else if (json.has("for")) {
                JsonArray a = json.get("for").getAsJsonArray();
                if (a.size() == 3) {
                    String key = a.get(0).getAsString();
                    for (List<String> value : getIterator(a.get(1))) {
                        if (value.size() == 1) {
                            VARIABLES.put(key, parseVariableString(value.get(0)));
                        } else {
                            for (int i = 0; i < value.size(); i++) {
                                VARIABLES.put(key + "" + i, parseVariableString(value.get(i)));
                            }
                        }
                        parseSkinsJson(JsonUtils.toArray(a.get(2)));
                    }
                }
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}
Also used : JsonArray(com.google.gson.JsonArray) TextureSet(com.feed_the_beast.ftblib.lib.util.misc.TextureSet) JsonElement(com.google.gson.JsonElement) ResourceLocation(net.minecraft.util.ResourceLocation) JsonObject(com.google.gson.JsonObject) FileNotFoundException(java.io.FileNotFoundException) BarrelSkin(com.latmod.yabba.api.BarrelSkin)

Example 3 with BarrelSkin

use of com.latmod.yabba.api.BarrelSkin in project YABBA by LatvianModder.

the class ForestryIntegration method registerSkins.

@SubscribeEvent
public static void registerSkins(YabbaSkinsEvent event) {
    Yabba.LOGGER.info("Loading Forestry Integration");
    for (IWoodType type : TreeManager.woodAccess.getRegisteredWoodTypes()) {
        if (!(type instanceof EnumVanillaWoodType)) {
            try {
                BarrelSkin skin = new BarrelSkin(OtherMods.FORESTRY + ":planks_" + type.getName(), TextureSet.of("all=" + type.getPlankTexture()));
                try {
                    skin.state = TreeManager.woodAccess.getBlock(type, WoodBlockKind.PLANKS, false);
                } catch (Exception ex1) {
                }
                skin.displayName = TreeManager.woodAccess.getStack(type, WoodBlockKind.PLANKS, false).getDisplayName();
                event.addSkin(skin);
                skin = new BarrelSkin(OtherMods.FORESTRY + ":log_" + type.getName(), TextureSet.of("up&down=" + type.getHeartTexture() + ",all=" + type.getBarkTexture()));
                try {
                    skin.state = TreeManager.woodAccess.getBlock(type, WoodBlockKind.LOG, false);
                } catch (Exception ex1) {
                }
                skin.displayName = TreeManager.woodAccess.getStack(type, WoodBlockKind.LOG, false).getDisplayName();
                event.addSkin(skin);
            } catch (Exception ex) {
            }
        }
    }
}
Also used : IWoodType(forestry.api.arboriculture.IWoodType) EnumVanillaWoodType(forestry.api.arboriculture.EnumVanillaWoodType) BarrelSkin(com.latmod.yabba.api.BarrelSkin) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 4 with BarrelSkin

use of com.latmod.yabba.api.BarrelSkin in project YABBA by LatvianModder.

the class BakedBarrelBlockModel method get.

private BarrelModelVariant get(BarrelLook key) {
    if (key == BarrelLook.DEFAULT && defaultModelVariant != null) {
        return defaultModelVariant;
    }
    BarrelModelVariant variant = map.get(key);
    if (variant == null) {
        List<List<BakedQuad>> quads = new ArrayList<>(ModelRotation.values().length);
        BarrelModel model = key.getModel();
        BarrelSkin skin = key.getSkin();
        model.textureMap.put("skin", skin.spriteSet);
        for (ModelRotation rotation : ModelRotation.values()) {
            quads.add(model.buildModel(format, rotation, skin));
        }
        List<BakedQuad> itemQuads = model.buildItemModel(format, skin);
        variant = new BarrelModelVariant(quads, new BakedBarrelItemModel(getParticleTexture(), itemQuads.isEmpty() ? quads.get(0) : itemQuads));
        map.put(key, variant);
        if (key == BarrelLook.DEFAULT) {
            defaultModelVariant = variant;
        }
        if (FTBLibConfig.debugging.print_more_info) {
            Yabba.LOGGER.info("Created cached model for " + model.id + ":" + skin.id);
        }
    }
    return variant;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) ModelRotation(net.minecraft.client.renderer.block.model.ModelRotation) ArrayList(java.util.ArrayList) ItemOverrideList(net.minecraft.client.renderer.block.model.ItemOverrideList) ArrayList(java.util.ArrayList) List(java.util.List) BarrelSkin(com.latmod.yabba.api.BarrelSkin)

Example 5 with BarrelSkin

use of com.latmod.yabba.api.BarrelSkin in project YABBA by LatvianModder.

the class BakedBarrelBlockModel method getQuads.

@Override
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
    if (state instanceof IExtendedBlockState) {
        IExtendedBlockState statex = (IExtendedBlockState) state;
        BarrelLook look = statex.getValue(BlockAdvancedBarrelBase.LOOK);
        if (look == null) {
            look = BarrelLook.DEFAULT;
        }
        BarrelModel model = look.getModel();
        BarrelSkin skin = look.getSkin();
        if (MinecraftForgeClient.getRenderLayer() == ClientUtils.getStrongest(model.layer, skin.layer)) {
            return get(BarrelLook.get(model.id, skin.id)).getQuads(state.getValue(BlockAdvancedBarrelBase.ROTATION).getModelRotationIndexFromFacing(state.getValue(BlockHorizontal.FACING)));
        }
    }
    return Collections.emptyList();
}
Also used : IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) BarrelLook(com.latmod.yabba.util.BarrelLook) BarrelSkin(com.latmod.yabba.api.BarrelSkin)

Aggregations

BarrelSkin (com.latmod.yabba.api.BarrelSkin)5 TextureSet (com.feed_the_beast.ftblib.lib.util.misc.TextureSet)2 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 FileNotFoundException (java.io.FileNotFoundException)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 Color4I (com.feed_the_beast.ftblib.lib.icon.Color4I)1 JsonArray (com.google.gson.JsonArray)1 YabbaSkinsEvent (com.latmod.yabba.api.YabbaSkinsEvent)1 BlockItemBarrel (com.latmod.yabba.block.BlockItemBarrel)1 BarrelLook (com.latmod.yabba.util.BarrelLook)1 EnumVanillaWoodType (forestry.api.arboriculture.EnumVanillaWoodType)1 IWoodType (forestry.api.arboriculture.IWoodType)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)1 ItemOverrideList (net.minecraft.client.renderer.block.model.ItemOverrideList)1 ModelRotation (net.minecraft.client.renderer.block.model.ModelRotation)1 IResource (net.minecraft.client.resources.IResource)1 IResourceManager (net.minecraft.client.resources.IResourceManager)1