Search in sources :

Example 1 with IPartDisplay

use of net.silentchaos512.gear.api.part.IPartDisplay in project Silent-Gear by SilentChaos512.

the class GearModel method getTextures.

@SuppressWarnings("OverlyComplexMethod")
@Override
public Collection<Material> getTextures(IModelConfiguration owner, Function<ResourceLocation, UnbakedModel> modelGetter, Set<Pair<String, String>> missingTextureErrors) {
    Set<Material> ret = new HashSet<>();
    ret.add(new Material(InventoryMenu.BLOCK_ATLAS, SilentGear.getId("item/error")));
    // Generic built-in textures
    for (PartTextures tex : PartTextures.getTextures(this.gearType)) {
        int animationFrames = tex.isAnimated() ? item.getAnimationFrames() : 1;
        for (int i = 0; i < animationFrames; ++i) {
            MaterialLayer layer = new MaterialLayer(tex, Color.VALUE_WHITE);
            ret.add(getTexture(layer, i, false));
            ret.add(getTexture(layer, 0, true));
        }
    }
    // Custom textures
    for (IMaterialDisplay materialDisplay : GearDisplayManager.getMaterials()) {
        for (PartType partType : PartType.getValues()) {
            if (item.hasTexturesFor(partType)) {
                for (MaterialLayer layer : materialDisplay.getLayerList(gearType, partType, LazyMaterialInstance.of(materialDisplay.getMaterialId()))) {
                    int animationFrames = layer.isAnimated() ? item.getAnimationFrames() : 1;
                    ret.addAll(this.getTexturesForAllFrames(layer, animationFrames, false));
                    ret.addAll(this.getTexturesForAllFrames(layer, 1, true));
                }
            }
        }
    }
    for (IPartDisplay partDisplay : GearDisplayManager.getParts()) {
        for (MaterialLayer layer : partDisplay.getLayers(gearType, FakePartData.of(PartType.NONE))) {
            int animationFrames = layer.isAnimated() ? item.getAnimationFrames() : 1;
            ret.addAll(this.getTexturesForAllFrames(layer, animationFrames, false));
            ret.addAll(this.getTexturesForAllFrames(layer, animationFrames, true));
        }
    }
    if (GearModelOverrideList.isDebugLoggingEnabled()) {
        SilentGear.LOGGER.info("Textures for gear model '{}' ({})", getTexturePath(false), this.gearType.getName());
        for (Material mat : ret) {
            SilentGear.LOGGER.info("- {}", mat.texture());
        }
    }
    return ret;
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) PartTextures(net.silentchaos512.gear.client.model.PartTextures) IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) IPartDisplay(net.silentchaos512.gear.api.part.IPartDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer) IMaterial(net.silentchaos512.gear.api.material.IMaterial)

Example 2 with IPartDisplay

use of net.silentchaos512.gear.api.part.IPartDisplay in project Silent-Gear by SilentChaos512.

the class GearModelOverrideList method addSimplePartLayers.

private static void addSimplePartLayers(List<MaterialLayer> list, PartData part, ItemStack stack) {
    IPartDisplay model = GearDisplayManager.get(part.get());
    if (model != null) {
        GearType gearType = GearHelper.getType(stack);
        List<MaterialLayer> layers = model.getLayers(gearType, part).getLayers();
        addColorBlendedLayers(list, part, stack, layers);
    }
}
Also used : GearType(net.silentchaos512.gear.api.item.GearType) IPartDisplay(net.silentchaos512.gear.api.part.IPartDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer)

Example 3 with IPartDisplay

use of net.silentchaos512.gear.api.part.IPartDisplay in project Silent-Gear by SilentChaos512.

the class GearDisplayManager method reloadParts.

private static void reloadParts(ResourceManager resourceManager) {
    Collection<ResourceLocation> resources = resourceManager.listResources(PATH_PARTS, s -> s.endsWith(".json"));
    if (resources.isEmpty())
        return;
    synchronized (PARTS) {
        SilentGear.LOGGER.info("Reloading part model files");
        PARTS.clear();
        String packName = "ERROR";
        for (ResourceLocation id : resources) {
            String path = id.getPath().substring(PATH_PARTS.length() + 1, id.getPath().length() - ".json".length());
            ResourceLocation name = new ResourceLocation(id.getNamespace(), path);
            try (Resource iresource = resourceManager.getResource(id)) {
                packName = iresource.getSourceName();
                JsonObject json = GsonHelper.fromJson(GSON, IOUtils.toString(iresource.getInputStream(), StandardCharsets.UTF_8), JsonObject.class);
                if (json == null) {
                    SilentGear.LOGGER.error("Could not load part model {} as it's null or empty", name);
                } else {
                    IPartDisplay model = PartDisplay.deserialize(name, json);
                    PARTS.put(name, model);
                }
            } catch (IllegalArgumentException | JsonParseException ex) {
                SilentGear.LOGGER.error("Parsing error loading part model {}", name, ex);
                ERROR_LIST.add(String.format("part:%s (%s)", name, packName));
            } catch (IOException ex) {
                SilentGear.LOGGER.error("Could not read part model {}", name, ex);
                ERROR_LIST.add(String.format("part:%s (%s)", name, packName));
            }
        }
    }
}
Also used : IPartDisplay(net.silentchaos512.gear.api.part.IPartDisplay) ResourceLocation(net.minecraft.resources.ResourceLocation) Resource(net.minecraft.server.packs.resources.Resource) JsonObject(com.google.gson.JsonObject) IOException(java.io.IOException) JsonParseException(com.google.gson.JsonParseException)

Aggregations

IPartDisplay (net.silentchaos512.gear.api.part.IPartDisplay)3 MaterialLayer (net.silentchaos512.gear.api.material.MaterialLayer)2 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1 IOException (java.io.IOException)1 ResourceLocation (net.minecraft.resources.ResourceLocation)1 Resource (net.minecraft.server.packs.resources.Resource)1 GearType (net.silentchaos512.gear.api.item.GearType)1 IMaterial (net.silentchaos512.gear.api.material.IMaterial)1 IMaterialDisplay (net.silentchaos512.gear.api.material.IMaterialDisplay)1 PartType (net.silentchaos512.gear.api.part.PartType)1 PartTextures (net.silentchaos512.gear.client.model.PartTextures)1