Search in sources :

Example 1 with IMaterialDisplay

use of net.silentchaos512.gear.api.material.IMaterialDisplay in project Silent-Gear by SilentChaos512.

the class GearDisplayManager method getMaterials.

public static Collection<IMaterialDisplay> getMaterials() {
    synchronized (MATERIALS) {
        Collection<IMaterialDisplay> ret = new ArrayList<>();
        for (IMaterial material : MaterialManager.getValues()) {
            MaterialInstance mat = MaterialInstance.of(material);
            ret.add(mat.getDisplayProperties());
        }
        ret.addAll(MATERIALS.values());
        return ret;
    }
}
Also used : IMaterial(net.silentchaos512.gear.api.material.IMaterial) IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance)

Example 2 with IMaterialDisplay

use of net.silentchaos512.gear.api.material.IMaterialDisplay in project Silent-Gear by SilentChaos512.

the class GearDisplayManager method reloadMaterials.

private static void reloadMaterials(ResourceManager resourceManager) {
    Collection<ResourceLocation> resources = resourceManager.listResources(PATH_MATERIALS, s -> s.endsWith(".json"));
    if (resources.isEmpty())
        return;
    synchronized (MATERIALS) {
        SilentGear.LOGGER.info("Reloading material model files");
        MATERIALS.clear();
        String packName = "ERROR";
        for (ResourceLocation id : resources) {
            String path = id.getPath().substring(PATH_MATERIALS.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 material model {} as it's null or empty", name);
                } else {
                    IMaterialDisplay model = MaterialDisplay.deserialize(name, json);
                    MATERIALS.put(name, model);
                }
            } catch (IllegalArgumentException | JsonParseException ex) {
                SilentGear.LOGGER.error("Parsing error loading material model {}", name, ex);
                ERROR_LIST.add(String.format("material:%s (%s)", name, packName));
            } catch (IOException ex) {
                SilentGear.LOGGER.error("Could not read material model {}", name, ex);
                ERROR_LIST.add(String.format("material:%s (%s)", name, packName));
            }
        }
    }
}
Also used : IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) 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)

Example 3 with IMaterialDisplay

use of net.silentchaos512.gear.api.material.IMaterialDisplay in project Silent-Gear by SilentChaos512.

the class GearModelOverrideList method addWithBlendedColor.

private static void addWithBlendedColor(List<MaterialLayer> list, PartData part, MaterialInstance material, ItemStack stack) {
    IMaterialDisplay model = material.getDisplayProperties();
    GearType gearType = GearHelper.getType(stack);
    List<MaterialLayer> layers = model.getLayerList(gearType, part, material).getLayers();
    addColorBlendedLayers(list, part, stack, layers);
}
Also used : GearType(net.silentchaos512.gear.api.item.GearType) IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer)

Example 4 with IMaterialDisplay

use of net.silentchaos512.gear.api.material.IMaterialDisplay in project Silent-Gear by SilentChaos512.

the class CompoundPartModel method buildFakeModel.

private void buildFakeModel(Function<Material, TextureAtlasSprite> spriteGetter, ImmutableList.Builder<BakedQuad> builder, Transformation rotation, IMaterial material) {
    // This method will display an example item for items with no data (ie, for advancements)
    MaterialInstance mat = MaterialInstance.of(material);
    IMaterialDisplay model = mat.getDisplayProperties();
    MaterialLayer exampleMain = model.getLayerList(this.gearType, this.partType, mat).getFirstLayer();
    if (exampleMain != null) {
        builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, exampleMain.getTexture(this.texturePath, 0))), rotation, exampleMain.getColor()));
    }
    builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, new StaticLayer(PART_MARKER_TEXTURE).getTexture(this.gearType, 0))), rotation, Color.VALUE_WHITE));
}
Also used : IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer) IMaterial(net.silentchaos512.gear.api.material.IMaterial) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) LazyMaterialInstance(net.silentchaos512.gear.gear.material.LazyMaterialInstance) StaticLayer(net.silentchaos512.gear.api.material.StaticLayer)

Example 5 with IMaterialDisplay

use of net.silentchaos512.gear.api.material.IMaterialDisplay in project Silent-Gear by SilentChaos512.

the class FragmentModel method buildFakeModel.

private void buildFakeModel(Function<Material, TextureAtlasSprite> spriteGetter, ImmutableList.Builder<BakedQuad> builder, Transformation rotation, IMaterial material) {
    // This method will display an example item for items with no data (ie, for advancements)
    MaterialInstance mat = MaterialInstance.of(material);
    IMaterialDisplay model = mat.getDisplayProperties();
    MaterialLayer exampleMain = model.getLayerList(GearType.FRAGMENT, PartType.MAIN, mat).getFirstLayer();
    if (exampleMain != null) {
        builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, exampleMain.getTexture(GearType.FRAGMENT, 0))), rotation, exampleMain.getColor()));
    }
}
Also used : IMaterialDisplay(net.silentchaos512.gear.api.material.IMaterialDisplay) MaterialLayer(net.silentchaos512.gear.api.material.MaterialLayer) IMaterial(net.silentchaos512.gear.api.material.IMaterial) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) LazyMaterialInstance(net.silentchaos512.gear.gear.material.LazyMaterialInstance)

Aggregations

IMaterialDisplay (net.silentchaos512.gear.api.material.IMaterialDisplay)16 MaterialLayer (net.silentchaos512.gear.api.material.MaterialLayer)12 IMaterial (net.silentchaos512.gear.api.material.IMaterial)7 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)6 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)5 ResourceLocation (net.minecraft.resources.ResourceLocation)3 LazyMaterialInstance (net.silentchaos512.gear.gear.material.LazyMaterialInstance)3 StaticLayer (net.silentchaos512.gear.api.material.StaticLayer)2 PartType (net.silentchaos512.gear.api.part.PartType)2 PartTextures (net.silentchaos512.gear.client.model.PartTextures)2 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Resource (net.minecraft.server.packs.resources.Resource)1 GearType (net.silentchaos512.gear.api.item.GearType)1 IPartDisplay (net.silentchaos512.gear.api.part.IPartDisplay)1 ModResourceLocation (net.silentchaos512.gear.util.ModResourceLocation)1