Search in sources :

Example 36 with GearType

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

the class TooltipHandler method getSubStatTooltipLine.

private static Optional<MutableComponent> getSubStatTooltipLine(ItemTooltipEvent event, PartType partType, ItemStat stat, GearType gearType, Collection<StatInstance> modifiers) {
    if (!modifiers.isEmpty()) {
        StatInstance inst = stat.computeForDisplay(0, gearType, modifiers);
        if (inst.shouldList(partType, stat, event.getFlags().isAdvanced())) {
            boolean isZero = inst.getValue() == 0;
            Color color = isZero ? MC_DARK_GRAY : Color.WHITE;
            MutableComponent nameStr = TextUtil.withColor(gearType.getDisplayName().copy(), color);
            int decimalPlaces = stat.isDisplayAsInt() && inst.getOp() != StatInstance.Operation.MUL1 && inst.getOp() != StatInstance.Operation.MUL2 ? 0 : 2;
            MutableComponent statListText = TextUtil.withColor(StatModifierMap.formatText(modifiers, stat, decimalPlaces), color);
            // Harvest level hints
            MutableComponent textWithAdditions = stat == ItemStats.HARVEST_LEVEL && modifiers.size() == 1 ? harvestLevelWithHint(statListText, inst.getValue()) : statListText;
            return Optional.of(new TranslatableComponent("stat.silentgear.displayFormat", nameStr, textWithAdditions));
        }
    }
    return Optional.empty();
}
Also used : MutableComponent(net.minecraft.network.chat.MutableComponent) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Color(net.silentchaos512.utils.Color) StatInstance(net.silentchaos512.gear.api.stats.StatInstance)

Example 37 with GearType

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

the class MaterialDisplay method getMostSpecificKey.

private PartGearKey getMostSpecificKey(GearType gearType, PartType partType) {
    PartGearKey key = PartGearKey.of(gearType, partType);
    if (map.containsKey(key)) {
        return key;
    }
    PartGearKey parent = key.getParent();
    while (parent != null) {
        if (map.containsKey(parent)) {
            return parent;
        }
        parent = parent.getParent();
    }
    // No match
    return key;
}
Also used : PartGearKey(net.silentchaos512.gear.api.util.PartGearKey)

Example 38 with GearType

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

the class GearModel method buildFakeModel.

private void buildFakeModel(Function<Material, TextureAtlasSprite> spriteGetter, ImmutableList.Builder<BakedQuad> builder, Transformation rotation, IMaterial material) {
    // This method will display an example tool for items with no data (ie, for advancements)
    MaterialInstance mat = MaterialInstance.of(material);
    IMaterialDisplay model = mat.getDisplayProperties();
    if (!gearType.isArmor()) {
        MaterialLayer exampleRod = model.getLayerList(this.gearType, PartType.ROD, mat).getFirstLayer();
        if (exampleRod != null) {
            builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, exampleRod.getTexture(gearType, 0))), rotation, exampleRod.getColor()));
        }
    }
    MaterialLayer exampleMain = model.getLayerList(this.gearType, PartType.MAIN, mat).getFirstLayer();
    if (exampleMain != null) {
        builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, exampleMain.getTexture(gearType, 0))), rotation, exampleMain.getColor()));
    }
    if (gearType.matches(GearType.RANGED_WEAPON)) {
        MaterialLayer exampleBowstring = model.getLayerList(this.gearType, PartType.CORD, mat).getFirstLayer();
        if (exampleBowstring != null) {
            builder.addAll(getQuadsForSprite(0, spriteGetter.apply(new Material(InventoryMenu.BLOCK_ATLAS, exampleBowstring.getTexture(gearType, 0))), rotation, exampleBowstring.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)

Example 39 with GearType

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

the class PartGearKey method read.

public static PartGearKey read(String key) {
    String[] parts = key.split("/");
    if (parts.length != 2) {
        throw new JsonParseException("invalid key: " + key);
    }
    PartType partType = PartType.getNonNull(Objects.requireNonNull(SilentGear.getIdWithDefaultNamespace(parts[0])));
    if (partType.isInvalid()) {
        throw new JsonParseException("Unknown part type: " + parts[0]);
    }
    GearType gearType = GearType.get(parts[1]);
    if (gearType.isInvalid()) {
        throw new JsonParseException("Unknown gear type: " + parts[1]);
    }
    return new PartGearKey(gearType, partType);
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) GearType(net.silentchaos512.gear.api.item.GearType) JsonParseException(com.google.gson.JsonParseException)

Example 40 with GearType

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

the class StatGearKey method read.

@Nullable
public static StatGearKey read(String key) {
    String[] parts = key.split("/");
    if (parts.length > 2) {
        throw new JsonParseException("invalid key: " + key);
    }
    ItemStat stat = ItemStats.getRegistry().getValue(SilentGear.getIdWithDefaultNamespace(parts[0]));
    if (stat == null) {
        return null;
    }
    GearType gearType;
    if (parts.length > 1) {
        gearType = GearType.get(parts[1]);
        if (gearType.isInvalid()) {
            throw new JsonParseException("Unknown gear type: " + parts[1]);
        }
    } else {
        gearType = GearType.ALL;
    }
    return new StatGearKey(stat, gearType);
}
Also used : GearType(net.silentchaos512.gear.api.item.GearType) JsonParseException(com.google.gson.JsonParseException) ItemStat(net.silentchaos512.gear.api.stats.ItemStat) IItemStat(net.silentchaos512.gear.api.stats.IItemStat) Nullable(javax.annotation.Nullable)

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