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;
}
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));
}
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;
}
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());
}
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));
}
}
}
Aggregations