use of net.silentchaos512.gear.api.traits.TraitInstance in project Silent-Gear by SilentChaos512.
the class CompoundPart method getTraits.
@Override
public Collection<TraitInstance> getTraits(IPartData part, PartGearKey partKey, ItemStack gear) {
List<TraitInstance> ret = new ArrayList<>(super.getTraits(part, partKey, gear));
List<IMaterialInstance> materials = getMaterials(part);
for (TraitInstance inst : TraitHelper.getTraits(materials, partKey, gear)) {
if (inst.conditionsMatch(partKey, gear, materials)) {
ret.add(inst);
}
}
return ret;
}
use of net.silentchaos512.gear.api.traits.TraitInstance in project Silent-Gear by SilentChaos512.
the class TooltipHandler method addJeiSearchTerms.
private static void addJeiSearchTerms(ItemTooltipEvent event, MaterialInstance material) {
// Add search terms to allow advanced filtering in JEI (requires the
// `SearchAdvancedTooltips` JEI config to be set)
StringBuilder b = new StringBuilder();
for (IMaterialCategory category : material.getCategories()) {
b.append(category.getName()).append(" ");
}
Collection<String> traits = new HashSet<>();
for (PartType partType : material.getPartTypes()) {
b.append(partType.getDisplayName(0).getString()).append(" ");
for (TraitInstance trait : material.getTraits(partType)) {
traits.add(trait.getTrait().getDisplayName(0).getString());
}
}
for (String str : traits) {
b.append(str).append(" ");
}
event.getToolTip().add(new TextComponent(b.toString().toLowerCase(Locale.ROOT)).withStyle(ChatFormatting.DARK_GRAY).withStyle(ChatFormatting.ITALIC));
}
use of net.silentchaos512.gear.api.traits.TraitInstance in project Silent-Gear by SilentChaos512.
the class TooltipHandler method getMaterialTraitLines.
private static void getMaterialTraitLines(ItemTooltipEvent event, PartType partType, MaterialInstance material) {
Collection<TraitInstance> traits = material.getTraits(partType);
if (traits.isEmpty())
return;
MutableComponent header = TextUtil.misc("tooltip.traits").withStyle(ChatFormatting.GOLD);
if (!KeyTracker.isDisplayTraitsDown()) {
MutableComponent keyHint = TextUtil.withColor(TextUtil.keyBinding(KeyTracker.DISPLAY_TRAITS), Color.AQUAMARINE);
header.append(" ").append(keyHint);
}
event.getToolTip().add(header);
TextListBuilder builder = new TextListBuilder();
for (TraitInstance trait : traits) {
builder.add(trait.getDisplayName());
// Trait description and conditions
if (event.getFlags().isAdvanced() || KeyTracker.isDisplayTraitsDown()) {
builder.indent();
builder.add(trait.getTrait().getDescription(trait.getLevel()).withStyle(ChatFormatting.DARK_GRAY));
if (!trait.getConditions().isEmpty()) {
builder.add(TextUtil.withColor(trait.getConditionsText(), ChatFormatting.DARK_GRAY));
}
builder.unindent();
}
}
event.getToolTip().addAll(builder.build());
}
use of net.silentchaos512.gear.api.traits.TraitInstance 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));
}
}
}
use of net.silentchaos512.gear.api.traits.TraitInstance in project Silent-Gear by SilentChaos512.
the class SynergyUtils method getSynergy.
public static float getSynergy(PartType partType, List<? extends IMaterialInstance> materials, Collection<TraitInstance> traits) {
if (materials.isEmpty()) {
return 1;
}
// First, we add a bonus for the number of unique materials
double synergy = getBaseSynergy(materials);
// Second, reduce synergy for differences in certain properties
IMaterialInstance primary = materials.get(0);
final double primaryRarity = primary.getStat(partType, ItemStats.RARITY);
final double maxRarity = materials.stream().mapToDouble(m -> m.getStat(partType, ItemStats.RARITY)).max().orElse(0);
final int maxTier = materials.stream().mapToInt(m -> m.getTier(partType)).max().orElse(0);
for (IMaterialInstance material : getUniques(materials)) {
if (maxRarity > 0) {
float rarity = material.getStat(partType, ItemStats.RARITY);
synergy -= 0.005 * Math.abs(primaryRarity - rarity);
}
if (maxTier > 0) {
int tier = material.getTier(partType);
synergy -= 0.08 * Math.abs(maxTier - tier);
}
}
// Synergy traits
for (TraitInstance trait : traits) {
if (trait.getTrait() instanceof SynergyTrait) {
synergy = ((SynergyTrait) trait.getTrait()).apply(synergy, trait.getLevel());
}
}
return (float) Mth.clamp(synergy, MIN_VALUE, MAX_VALUE);
}
Aggregations