use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.
the class CraftedMaterial method getStatKeys.
@Override
public Collection<StatGearKey> getStatKeys(IMaterialInstance material, PartType type) {
Collection<StatGearKey> ret = new LinkedHashSet<>(super.getStatKeys(material, type));
IMaterialInstance base = getBaseMaterial(material);
ret.addAll(base.getStatKeys(type));
return ret;
}
use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.
the class CompoundPartItem method getName.
@Override
public Component getName(ItemStack stack) {
PartData part = PartData.from(stack);
MaterialInstance material = getPrimaryMaterial(stack);
if (part != null && material != null) {
TranslatableComponent nameText = new TranslatableComponent(this.getDescriptionId() + ".nameProper", material.getDisplayName(partType, ItemStack.EMPTY));
int nameColor = Color.blend(part.getColor(ItemStack.EMPTY), Color.VALUE_WHITE, 0.25f) & 0xFFFFFF;
return TextUtil.withColor(nameText, nameColor);
}
return super.getName(stack);
}
use of net.silentchaos512.gear.api.part.PartType 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();
}
use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.
the class MaterialBuilder method trait.
public MaterialBuilder trait(PartType partType, DataResource<ITrait> trait, int level, ITraitCondition... conditions) {
ITraitInstance inst = TraitInstance.of(trait, level, conditions);
List<ITraitInstance> list = traits.computeIfAbsent(partType, pt -> new ArrayList<>());
list.add(inst);
return this;
}
use of net.silentchaos512.gear.api.part.PartType in project Silent-Gear by SilentChaos512.
the class MaterialBuilder method serialize.
@SuppressWarnings({ "OverlyComplexMethod", "OverlyLongMethod" })
public JsonObject serialize() {
validate();
JsonObject json = new JsonObject();
json.addProperty("type", this.serializer.getName().toString());
json.addProperty("simple", this.simple);
if (this.parent != null) {
json.addProperty("parent", this.parent.toString());
}
if (!this.loadConditions.isEmpty()) {
JsonArray array = new JsonArray();
for (ICondition condition : this.loadConditions) {
array.add(CraftingHelper.serialize(condition));
}
json.add("conditions", array);
}
JsonObject availability = new JsonObject();
if (this.tier >= 0) {
availability.addProperty("tier", this.tier);
if (!this.categories.isEmpty()) {
JsonArray array = new JsonArray();
for (IMaterialCategory category : this.categories) {
array.add(category.getName());
}
availability.add("categories", array);
}
availability.addProperty("visible", this.visible);
JsonArray array = new JsonArray();
for (String gearType : this.gearBlacklist) {
array.add(gearType);
}
availability.add("gear_blacklist", array);
availability.addProperty("can_salvage", this.canSalvage);
}
if (!availability.entrySet().isEmpty()) {
json.add("availability", availability);
}
JsonObject craftingItems = new JsonObject();
if (this.ingredient != Ingredient.EMPTY) {
craftingItems.add("main", this.ingredient.toJson());
}
if (!this.partSubstitutes.isEmpty()) {
JsonObject subs = new JsonObject();
this.partSubstitutes.forEach((type, ing) -> subs.add(SilentGear.shortenId(type.getName()), ing.toJson()));
craftingItems.add("subs", subs);
}
json.add("crafting_items", craftingItems);
if (this.name != null) {
json.add("name", Component.Serializer.toJsonTree(this.name));
}
if (this.namePrefix != null) {
json.add("name_prefix", Component.Serializer.toJsonTree(this.namePrefix));
}
if (!this.stats.isEmpty()) {
JsonObject statsJson = new JsonObject();
this.stats.forEach((partType, map) -> statsJson.add(SilentGear.shortenId(partType.getName()), map.serialize()));
json.add("stats", statsJson);
}
if (!this.traits.isEmpty()) {
JsonObject traitsJson = new JsonObject();
this.traits.forEach((partType, list) -> {
JsonArray array = new JsonArray();
list.forEach(t -> array.add(t.serialize()));
traitsJson.add(SilentGear.shortenId(partType.getName()), array);
});
json.add("traits", traitsJson);
}
json.add("model", serializeModel());
return json;
}
Aggregations