use of net.silentchaos512.gear.api.item.GearType in project Silent-Gear by SilentChaos512.
the class WielderEffectTrait method onUpdate.
@Override
public void onUpdate(TraitActionContext context, boolean isEquipped) {
if (!isEquipped || context.getPlayer() == null || context.getPlayer().tickCount % 10 != 0)
return;
GearType gearType = ((ICoreItem) context.getGear().getItem()).getGearType();
for (Map.Entry<String, List<PotionData>> entry : potions.entrySet()) {
String type = entry.getKey();
List<PotionData> list = entry.getValue();
applyEffects(context, gearType, type, list);
}
}
use of net.silentchaos512.gear.api.item.GearType in project Silent-Gear by SilentChaos512.
the class AttributeTrait method gearMatchesKey.
private static boolean gearMatchesKey(ItemStack gear, String key, String slotType) {
String[] parts = key.split("/");
if (parts.length > 2) {
// Invalid key
return false;
}
GearType gearType = GearHelper.getType(gear);
return gearType.matches(parts[0]) && (parts.length < 2 || slotType.equals(parts[1])) && GearHelper.isValidSlot(gear, slotType);
}
use of net.silentchaos512.gear.api.item.GearType 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;
}
use of net.silentchaos512.gear.api.item.GearType in project Silent-Gear by SilentChaos512.
the class PartMaterialIngredient method test.
@Override
public boolean test(@Nullable ItemStack stack) {
if (stack == null || stack.isEmpty())
return false;
MaterialInstance material = MaterialInstance.from(stack);
if (material == null)
return false;
int tier = material.getTier(this.partType);
return material.get().isCraftingAllowed(material, partType, gearType) && (categories.isEmpty() || material.hasAnyCategory(categories)) && tierMatches(tier);
}
use of net.silentchaos512.gear.api.item.GearType in project Silent-Gear by SilentChaos512.
the class PotionTraitBuilder method serialize.
@Override
public JsonObject serialize() {
if (this.potions.isEmpty()) {
throw new IllegalStateException("Potion effect trait '" + this.traitId + "' has no effects");
}
JsonObject json = super.serialize();
JsonObject effectsJson = new JsonObject();
this.potions.forEach(((gearType, effects) -> {
JsonArray array = new JsonArray();
effects.forEach(e -> array.add(e.serialize()));
effectsJson.add(gearType.getName(), array);
}));
json.add("potion_effects", effectsJson);
return json;
}
Aggregations