use of net.silentchaos512.gear.api.util.PartGearKey in project Silent-Gear by SilentChaos512.
the class TraitHelper method getTraits.
public static List<TraitInstance> getTraits(List<? extends IGearComponentInstance<?>> components, PartGearKey partKey, ItemStack gear) {
if (components.isEmpty()) {
return Collections.emptyList();
}
Map<ITrait, Integer> map = new LinkedHashMap<>();
Map<ITrait, Integer> countMatsWithTrait = new HashMap<>();
for (IGearComponentInstance<?> comp : components) {
for (TraitInstance inst : comp.getTraits(partKey, gear)) {
if (inst.conditionsMatch(partKey, gear, components)) {
map.merge(inst.getTrait(), inst.getLevel(), Integer::sum);
countMatsWithTrait.merge(inst.getTrait(), 1, Integer::sum);
}
}
}
ITrait[] keys = map.keySet().toArray(new ITrait[0]);
for (ITrait trait : keys) {
final int matsWithTrait = countMatsWithTrait.get(trait);
final float divisor = Math.max(components.size() / 2f, matsWithTrait);
final int value = Math.round(map.get(trait) / divisor);
map.put(trait, Mth.clamp(value, 1, trait.getMaxLevel()));
}
cancelTraits(map, keys);
// FIXME
// MinecraftForge.EVENT_BUS.post(new GetTraitsEvent(gear, materials, result));
List<TraitInstance> ret = new ArrayList<>();
map.forEach((trait, level) -> ret.add(TraitInstance.of(trait, level)));
return ret;
}
use of net.silentchaos512.gear.api.util.PartGearKey in project Silent-Gear by SilentChaos512.
the class TraitHelper method getTraits.
/**
* Gets a Map of Traits and levels from the parts, used to calculate trait levels and should not
* be used in most cases. Consider using {@link #getTraitLevel(ItemStack, ResourceLocation)} or
* {@link #hasTrait(ItemStack, ResourceLocation)} when appropriate.
*
* @param gear The item
* @param gearType The gear type
* @param parts The list of all parts used in constructing the gear.
* @return A Map of Traits to their levels
*/
public static Map<ITrait, Integer> getTraits(ItemStack gear, GearType gearType, PartDataList parts) {
if (parts.isEmpty() || (!gear.isEmpty() && GearHelper.isBroken(gear)))
return ImmutableMap.of();
Map<ITrait, Integer> result = new LinkedHashMap<>();
for (PartData part : parts) {
PartGearKey key = PartGearKey.of(gearType, part);
for (TraitInstance inst : part.getTraits(key, gear)) {
if (inst.conditionsMatch(key, gear, parts)) {
ITrait trait = inst.getTrait();
// Get the highest value in any part
result.merge(trait, inst.getLevel(), Integer::max);
}
}
}
ITrait[] keys = result.keySet().toArray(new ITrait[0]);
cancelTraits(result, keys);
MinecraftForge.EVENT_BUS.post(new GetTraitsEvent(gear, parts, result));
return result;
}
use of net.silentchaos512.gear.api.util.PartGearKey in project Silent-Gear by SilentChaos512.
the class BlueprintIngredient method getJeiHint.
@Override
public Optional<Component> getJeiHint() {
PartGearKey key = PartGearKey.of(this.gearType, this.partType);
MutableComponent keyText = new TextComponent(key.toString());
Component text = TextUtil.withColor(keyText, Color.DODGERBLUE);
return Optional.of(TextUtil.translate("jei", "blueprintType", text));
}
use of net.silentchaos512.gear.api.util.PartGearKey in project Silent-Gear by SilentChaos512.
the class PartMaterialIngredient method getJeiHint.
@Override
public Optional<Component> getJeiHint() {
MutableComponent text;
if (!this.categories.isEmpty()) {
MutableComponent cats = new TextComponent(categories.stream().map(IMaterialCategory::getName).collect(Collectors.joining(", ")));
text = TextUtil.withColor(cats, Color.INDIANRED);
} else {
MutableComponent any = new TextComponent("any");
text = TextUtil.withColor(any, Color.LIGHTGREEN);
}
PartGearKey key = PartGearKey.of(this.gearType, this.partType);
text.append(TextUtil.misc("spaceBrackets", key.toString()).withStyle(ChatFormatting.GRAY));
return Optional.of(TextUtil.translate("jei", "materialType", text));
}
use of net.silentchaos512.gear.api.util.PartGearKey in project Silent-Gear by SilentChaos512.
the class CompoundMaterial method getTraits.
@Override
public Collection<TraitInstance> getTraits(IMaterialInstance material, PartGearKey partKey, ItemStack gear) {
List<IMaterialInstance> materials = new ArrayList<>(getMaterials(material));
List<TraitInstance> traits = TraitHelper.getTraits(materials, partKey, ItemStack.EMPTY);
Collection<TraitInstance> ret = new ArrayList<>();
for (TraitInstance inst : traits) {
if (inst.conditionsMatch(partKey, ItemStack.EMPTY, materials)) {
ret.add(inst);
}
}
return ret;
}
Aggregations