use of net.silentchaos512.gear.api.traits.ITrait in project Silent-Gear by SilentChaos512.
the class PartBuilder method trait.
public PartBuilder trait(DataResource<ITrait> trait, int level, ITraitCondition... conditions) {
ITraitInstance inst = TraitInstance.of(trait, level, conditions);
this.traits.add(inst);
return this;
}
use of net.silentchaos512.gear.api.traits.ITrait in project Silent-Gear by SilentChaos512.
the class GearClientHelper method addTraitsInfo.
private static void addTraitsInfo(ItemStack stack, List<Component> tooltip, GearTooltipFlag flag) {
Map<ITrait, Integer> traits = TraitHelper.getCachedTraits(stack);
List<ITrait> visibleTraits = new ArrayList<>();
for (ITrait t : traits.keySet()) {
if (t != null && t.showInTooltip(flag)) {
visibleTraits.add(t);
}
}
int traitIndex = getTraitDisplayIndex(visibleTraits.size(), flag);
MutableComponent textTraits = TextUtil.withColor(misc("tooltip.traits"), Color.GOLD);
if (traitIndex < 0) {
if (!Config.Client.vanillaStyleTooltips.get()) {
tooltip.add(textTraits);
}
}
int i = 0;
for (ITrait trait : visibleTraits) {
if (traitIndex < 0 || traitIndex == i) {
final int level = traits.get(trait);
trait.addInformation(level, tooltip, flag, text -> {
if (Config.Client.vanillaStyleTooltips.get()) {
return TextUtil.withColor(new TextComponent(TextListBuilder.VANILLA_BULLET + " "), Color.GRAY).append(text);
}
if (traitIndex >= 0) {
return textTraits.append(TextUtil.withColor(new TextComponent(": "), ChatFormatting.GRAY).append(text));
}
return new TextComponent(TextListBuilder.BULLETS[0] + " ").append(text);
});
}
++i;
}
}
use of net.silentchaos512.gear.api.traits.ITrait in project Silent-Gear by SilentChaos512.
the class TraitSerializers method write.
@SuppressWarnings("unchecked")
public static <T extends ITrait> void write(T trait, FriendlyByteBuf buffer) {
ResourceLocation id = trait.getId();
ResourceLocation type = trait.getSerializer().getName();
log(() -> "write " + id + " (type " + type + ")");
buffer.writeResourceLocation(id);
buffer.writeResourceLocation(type);
ITraitSerializer<T> serializer = (ITraitSerializer<T>) trait.getSerializer();
serializer.write(buffer, trait);
}
use of net.silentchaos512.gear.api.traits.ITrait in project Silent-Gear by SilentChaos512.
the class MaterialRatioTraitCondition method matches.
@Override
public boolean matches(ITrait trait, PartGearKey key, ItemStack gear, List<? extends IGearComponentInstance<?>> components) {
int count = 0;
for (IGearComponentInstance<?> comp : components) {
Collection<TraitInstance> traits = comp.getTraits(key, gear);
for (TraitInstance inst : traits) {
if (inst.getTrait() == trait) {
++count;
break;
}
}
}
float ratio = (float) count / components.size();
return ratio >= this.requiredRatio;
}
use of net.silentchaos512.gear.api.traits.ITrait in project Silent-Gear by SilentChaos512.
the class TraitsCommand method getMaterialsWithTrait.
private static String getMaterialsWithTrait(ITrait trait) {
StringBuilder str = new StringBuilder();
boolean foundAny = false;
for (IMaterial material : MaterialManager.getValues(false)) {
MaterialInstance instance = MaterialInstance.of(material);
Collection<PartType> typesWithTrait = new ArrayList<>();
for (PartType partType : PartType.getValues()) {
Collection<TraitInstance> traits = instance.getTraits(partType);
for (TraitInstance inst : traits) {
if (inst.getTrait().equals(trait) && material.isVisible(partType)) {
typesWithTrait.add(partType);
break;
}
}
}
if (!typesWithTrait.isEmpty()) {
if (foundAny) {
str.append(", ");
}
foundAny = true;
str.append("**").append(instance.getDisplayName(PartType.MAIN).getString()).append("**").append(" _(").append(typesWithTrait.stream().map(pt -> pt.getDisplayName(0).getString()).collect(Collectors.joining(", "))).append(")_");
}
}
return str.toString();
}
Aggregations