Search in sources :

Example 16 with PartType

use of net.silentchaos512.gear.api.part.PartType 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 17 with PartType

use of net.silentchaos512.gear.api.part.PartType 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 18 with PartType

use of net.silentchaos512.gear.api.part.PartType 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 19 with PartType

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

the class IStatModProvider method getStatUnclamped.

default float getStatUnclamped(D instance, PartType partType, StatGearKey key, ItemStack gear) {
    ItemStat stat = ItemStats.get(key.getStat());
    if (stat == null)
        return key.getStat().getDefaultValue();
    Collection<StatInstance> mods = getStatModifiers(instance, partType, key, gear);
    return stat.compute(stat.getBaseValue(), false, key.getGearType(), mods);
}
Also used : StatInstance(net.silentchaos512.gear.api.stats.StatInstance) ItemStat(net.silentchaos512.gear.api.stats.ItemStat)

Example 20 with PartType

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

the class PartGearKey method fromNetwork.

public static PartGearKey fromNetwork(FriendlyByteBuf buf) {
    GearType gearType = GearType.get(buf.readUtf());
    PartType partType = Objects.requireNonNull(PartType.get(buf.readResourceLocation()));
    return of(gearType, partType);
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) GearType(net.silentchaos512.gear.api.item.GearType)

Aggregations

PartType (net.silentchaos512.gear.api.part.PartType)37 ItemStack (net.minecraft.world.item.ItemStack)14 PartData (net.silentchaos512.gear.gear.part.PartData)14 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)13 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)10 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)10 TextComponent (net.minecraft.network.chat.TextComponent)9 ResourceLocation (net.minecraft.resources.ResourceLocation)9 GearType (net.silentchaos512.gear.api.item.GearType)9 PartDataList (net.silentchaos512.gear.api.part.PartDataList)9 ItemStat (net.silentchaos512.gear.api.stats.ItemStat)9 Component (net.minecraft.network.chat.Component)8 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)8 IPartData (net.silentchaos512.gear.api.part.IPartData)8 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)8 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)7 StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)7 ArrayList (java.util.ArrayList)5 Collectors (java.util.stream.Collectors)5 MutableComponent (net.minecraft.network.chat.MutableComponent)5