Search in sources :

Example 6 with GearType

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

the class EnchantmentTraitBuilder method serialize.

@Override
public JsonObject serialize() {
    if (this.enchantments.isEmpty()) {
        throw new IllegalStateException("Enchantment trait '" + this.traitId + "' has no enchantments");
    }
    JsonObject json = super.serialize();
    JsonObject enchantmentsJson = new JsonObject();
    this.enchantments.forEach(((gearType, enchants) -> {
        JsonArray array = new JsonArray();
        enchants.forEach(e -> array.add(e.serialize()));
        enchantmentsJson.add(gearType.getName(), array);
    }));
    json.add("enchantments", enchantmentsJson);
    return json;
}
Also used : Enchantment(net.minecraft.world.item.enchantment.Enchantment) ResourceLocation(net.minecraft.resources.ResourceLocation) GearType(net.silentchaos512.gear.api.item.GearType) LinkedHashMap(java.util.LinkedHashMap) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) List(java.util.List) ITrait(net.silentchaos512.gear.api.traits.ITrait) EnchantmentTrait(net.silentchaos512.gear.gear.trait.EnchantmentTrait) Map(java.util.Map) DataResource(net.silentchaos512.gear.util.DataResource) ArrayList(java.util.ArrayList) JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject)

Example 7 with GearType

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

the class TraitBuilder method withGearTypeCondition.

public TraitBuilder withGearTypeCondition(GearType first, GearType... rest) {
    if (rest.length > 0) {
        Collection<GearType> types = new ArrayList<>(rest.length + 1);
        types.add(first);
        Collections.addAll(types, rest);
        GearTypeTraitCondition[] values = types.stream().map(GearTypeTraitCondition::new).toArray(GearTypeTraitCondition[]::new);
        return withConditions(new OrTraitCondition(values));
    }
    return withConditions(new GearTypeTraitCondition(first));
}
Also used : GearType(net.silentchaos512.gear.api.item.GearType) OrTraitCondition(net.silentchaos512.gear.gear.trait.condition.OrTraitCondition) ArrayList(java.util.ArrayList) GearTypeTraitCondition(net.silentchaos512.gear.gear.trait.condition.GearTypeTraitCondition)

Example 8 with GearType

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

the class PartDisplay method getMostSpecificKey.

private PartGearKey getMostSpecificKey(GearType gearType) {
    PartGearKey key = PartGearKey.of(gearType, this.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 9 with GearType

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

the class TooltipHandler method getPartStatLines.

private static void getPartStatLines(ItemTooltipEvent event, ItemStack stack, PartData part) {
    GearType gearType = getPartGearType(part);
    TextListBuilder builder = new TextListBuilder();
    List<ItemStat> relevantStats = new ArrayList<>(part.getGearType().getRelevantStats());
    if (part.getGearType().isArmor() && relevantStats.contains(ItemStats.DURABILITY)) {
        int index = relevantStats.indexOf(ItemStats.DURABILITY);
        relevantStats.remove(ItemStats.DURABILITY);
        relevantStats.add(index, ItemStats.ARMOR_DURABILITY);
    }
    for (ItemStat stat : relevantStats) {
        Collection<StatInstance> modifiers = new ArrayList<>();
        for (StatInstance mod : part.getStatModifiers(StatGearKey.of(stat, gearType), ItemStack.EMPTY)) {
            if (mod.getOp() == StatInstance.Operation.AVG) {
                float computed = stat.compute(Collections.singleton(mod));
                modifiers.add(StatInstance.of(computed, StatInstance.Operation.AVG, mod.getKey()));
            } else {
                modifiers.add(mod);
            }
        }
        getStatTooltipLine(event, part.getType(), stat, modifiers).ifPresent(builder::add);
    }
    event.getToolTip().addAll(builder.build());
}
Also used : TextListBuilder(net.silentchaos512.gear.client.util.TextListBuilder) GearType(net.silentchaos512.gear.api.item.GearType) StatInstance(net.silentchaos512.gear.api.stats.StatInstance) ItemStat(net.silentchaos512.gear.api.stats.ItemStat)

Example 10 with GearType

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

the class TooltipHandler method onPartTooltip.

private static void onPartTooltip(ItemTooltipEvent event, ItemStack stack, PartData part) {
    if (event.getFlags().isAdvanced() && KeyTracker.isControlDown()) {
        event.getToolTip().add(new TextComponent("* Part ID: " + part.getId()).withStyle(ChatFormatting.DARK_GRAY));
        event.getToolTip().add(new TextComponent("* Part data pack: " + part.get().getPackName()).withStyle(ChatFormatting.DARK_GRAY));
    }
    if (!Config.Client.showPartTooltips.get()) {
        return;
    }
    // Type, tier
    event.getToolTip().add(TextUtil.withColor(part.getType().getDisplayName(part.getTier()), Color.AQUAMARINE));
    // Traits
    List<TraitInstance> traits = new ArrayList<>();
    for (TraitInstance traitInstance : part.getTraits()) {
        if (traitInstance.getTrait().showInTooltip(event.getFlags())) {
            traits.add(traitInstance);
        }
    }
    int numTraits = traits.size();
    int traitIndex = getTraitDisplayIndex(numTraits);
    int i = 0;
    for (TraitInstance inst : traits) {
        if (traitIndex < 0 || traitIndex == i) {
            inst.addInformation(event.getToolTip(), event.getFlags());
        }
        ++i;
    }
    // Stats
    if (KeyTracker.isControlDown()) {
        event.getToolTip().add(new TranslatableComponent("misc.silentgear.tooltip.stats").withStyle(ChatFormatting.GOLD).append(new TextComponent(" (Silent Gear)").withStyle(ChatFormatting.RESET).withStyle(ChatFormatting.ITALIC)));
        getPartStatLines(event, stack, part);
    } else {
        event.getToolTip().add(new TranslatableComponent("misc.silentgear.tooltip.ctrlForStats").withStyle(ChatFormatting.GOLD));
    }
    // Gear type blacklist?
    if (part.get() instanceof AbstractGearPart) {
        List<GearType> blacklist = ((AbstractGearPart) part.get()).getBlacklistedGearTypes();
        if (!blacklist.isEmpty()) {
            int index = (ClientTicks.ticksInGame() / 20) % blacklist.size();
            GearType gearType = blacklist.get(index);
            Component blacklistedType = gearType.getDisplayName();
            event.getToolTip().add(new TranslatableComponent("misc.silentgear.tooltip.blacklist", blacklistedType).withStyle(ChatFormatting.RED));
        }
    }
}
Also used : TextComponent(net.minecraft.network.chat.TextComponent) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) AbstractGearPart(net.silentchaos512.gear.gear.part.AbstractGearPart) GearType(net.silentchaos512.gear.api.item.GearType) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance) MutableComponent(net.minecraft.network.chat.MutableComponent) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Component(net.minecraft.network.chat.Component) TextComponent(net.minecraft.network.chat.TextComponent)

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