Search in sources :

Example 11 with GearType

use of net.silentchaos512.gear.api.item.GearType in project Silent-Gear by SilentChaos512.

the class CompoundMaterialDisplay method getLayerColor.

@Override
public int getLayerColor(GearType gearType, IPartData part, IMaterialInstance materialIn, int layer) {
    List<MaterialLayer> layers = getLayerList(gearType, part, materialIn).getLayers();
    if (layer < layers.size()) {
        ItemStack stack = materialIn.getItem();
        if (stack.getItem() instanceof CompoundMaterialItem) {
            List<IMaterialInstance> subMaterials = CompoundMaterialItem.getSubMaterials(stack);
            int color = ColorUtils.getBlendedColor((CompoundMaterialItem) stack.getItem(), subMaterials, layer);
            // return layers.get(layer).getColor();
            return color;
        }
    }
    return Color.VALUE_WHITE;
}
Also used : ItemStack(net.minecraft.world.item.ItemStack) CompoundMaterialItem(net.silentchaos512.gear.item.CompoundMaterialItem)

Example 12 with GearType

use of net.silentchaos512.gear.api.item.GearType in project Silent-Gear by SilentChaos512.

the class GearModelLoader method read.

@Override
public GearModel read(JsonDeserializationContext deserializationContext, JsonObject modelContents) {
    ItemTransforms cameraTransforms = deserializationContext.deserialize(modelContents.get("display"), ItemTransforms.class);
    if (cameraTransforms == null) {
        cameraTransforms = ItemTransforms.NO_TRANSFORMS;
    }
    String gearTypeStr = GsonHelper.getAsString(modelContents, "gear_type");
    GearType gearType = GearType.get(gearTypeStr);
    if (gearType.isInvalid()) {
        throw new NullPointerException("Unknown gear type: " + gearTypeStr);
    }
    String texturePath = GsonHelper.getAsString(modelContents, "texture_path", gearType.getName());
    String brokenTexturePath = GsonHelper.getAsString(modelContents, "broken_texture_path", gearType.getName());
    Collection<PartType> brokenTextureTypes = new ArrayList<>();
    JsonArray brokenTypesJson = GsonHelper.getAsJsonArray(modelContents, "broken_texture_types", null);
    if (brokenTypesJson != null) {
        for (JsonElement element : brokenTypesJson) {
            ResourceLocation id = SilentGear.getIdWithDefaultNamespace(element.getAsString());
            if (id != null) {
                PartType type = PartType.get(id);
                if (type != null) {
                    brokenTextureTypes.add(type);
                } else {
                    SilentGear.LOGGER.error("Unknown part type '{}' in model {}", id, this.getName());
                }
            }
        }
    }
    GearModel model = new GearModel(cameraTransforms, gearType, texturePath, brokenTexturePath, brokenTextureTypes);
    MODELS.add(model);
    return model;
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) JsonArray(com.google.gson.JsonArray) GearType(net.silentchaos512.gear.api.item.GearType) JsonElement(com.google.gson.JsonElement) ResourceLocation(net.minecraft.resources.ResourceLocation) ArrayList(java.util.ArrayList) ItemTransforms(net.minecraft.client.renderer.block.model.ItemTransforms)

Example 13 with GearType

use of net.silentchaos512.gear.api.item.GearType 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 14 with GearType

use of net.silentchaos512.gear.api.item.GearType in project Silent-Gear by SilentChaos512.

the class CompoundPartModelLoader method read.

@Override
public CompoundPartModel read(JsonDeserializationContext deserializationContext, JsonObject modelContents) {
    ItemTransforms cameraTransforms = deserializationContext.deserialize(modelContents.get("display"), ItemTransforms.class);
    if (cameraTransforms == null) {
        cameraTransforms = ItemTransforms.NO_TRANSFORMS;
    }
    GearType gearType = GearType.fromJson(modelContents, "gear_type");
    PartType partType = PartType.fromJson(modelContents, "part_type");
    String subPath = GsonHelper.getAsString(modelContents, "texture_path", gearType.getName());
    List<ResourceLocation> extras = new ArrayList<>();
    if (modelContents.has("extra_layers") && modelContents.get("extra_layers").isJsonArray()) {
        JsonArray array = modelContents.getAsJsonArray("extra_layers");
        array.forEach(e -> extras.add(new ResourceLocation(e.getAsString())));
    }
    CompoundPartModel model = new CompoundPartModel(cameraTransforms, gearType, partType, subPath, extras);
    MODELS.add(model);
    return model;
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) JsonArray(com.google.gson.JsonArray) GearType(net.silentchaos512.gear.api.item.GearType) ResourceLocation(net.minecraft.resources.ResourceLocation) ArrayList(java.util.ArrayList) ItemTransforms(net.minecraft.client.renderer.block.model.ItemTransforms)

Example 15 with GearType

use of net.silentchaos512.gear.api.item.GearType 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)

Aggregations

GearType (net.silentchaos512.gear.api.item.GearType)25 ItemStack (net.minecraft.world.item.ItemStack)9 PartType (net.silentchaos512.gear.api.part.PartType)9 ArrayList (java.util.ArrayList)8 ResourceLocation (net.minecraft.resources.ResourceLocation)8 JsonObject (com.google.gson.JsonObject)6 StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)6 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)6 JsonArray (com.google.gson.JsonArray)5 List (java.util.List)5 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)5 PartGearKey (net.silentchaos512.gear.api.util.PartGearKey)5 JsonParseException (com.google.gson.JsonParseException)4 IMaterial (net.silentchaos512.gear.api.material.IMaterial)4 MaterialLayer (net.silentchaos512.gear.api.material.MaterialLayer)4 IPartData (net.silentchaos512.gear.api.part.IPartData)4 ItemStat (net.silentchaos512.gear.api.stats.ItemStat)4 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)4 ITrait (net.silentchaos512.gear.api.traits.ITrait)4 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)4