Search in sources :

Example 26 with GearType

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);
    }
}
Also used : GearType(net.silentchaos512.gear.api.item.GearType) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem)

Example 27 with GearType

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);
}
Also used : GearType(net.silentchaos512.gear.api.item.GearType)

Example 28 with GearType

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;
}
Also used : JsonArray(com.google.gson.JsonArray) IMaterialCategory(net.silentchaos512.gear.api.material.IMaterialCategory) JsonObject(com.google.gson.JsonObject) ICondition(net.minecraftforge.common.crafting.conditions.ICondition)

Example 29 with GearType

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);
}
Also used : MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance)

Example 30 with GearType

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;
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) JsonObject(com.google.gson.JsonObject) WielderEffectTrait(net.silentchaos512.gear.gear.trait.WielderEffectTrait) ArrayList(java.util.ArrayList) GearType(net.silentchaos512.gear.api.item.GearType) LinkedHashMap(java.util.LinkedHashMap) JsonArray(com.google.gson.JsonArray) List(java.util.List) ITrait(net.silentchaos512.gear.api.traits.ITrait) ITraitSerializer(net.silentchaos512.gear.api.traits.ITraitSerializer) Map(java.util.Map) DataResource(net.silentchaos512.gear.util.DataResource) MobEffect(net.minecraft.world.effect.MobEffect) JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject)

Aggregations

GearType (net.silentchaos512.gear.api.item.GearType)25 ItemStack (net.minecraft.world.item.ItemStack)9 PartType (net.silentchaos512.gear.api.part.PartType)9 ArrayList (java.util.ArrayList)8 ResourceLocation (net.minecraft.resources.ResourceLocation)8 JsonObject (com.google.gson.JsonObject)6 StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)6 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)6 JsonArray (com.google.gson.JsonArray)5 List (java.util.List)5 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)5 PartGearKey (net.silentchaos512.gear.api.util.PartGearKey)5 JsonParseException (com.google.gson.JsonParseException)4 IMaterial (net.silentchaos512.gear.api.material.IMaterial)4 MaterialLayer (net.silentchaos512.gear.api.material.MaterialLayer)4 IPartData (net.silentchaos512.gear.api.part.IPartData)4 ItemStat (net.silentchaos512.gear.api.stats.ItemStat)4 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)4 ITrait (net.silentchaos512.gear.api.traits.ITrait)4 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)4