Search in sources :

Example 41 with PartType

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) StatGearKey(net.silentchaos512.gear.api.util.StatGearKey)

Example 42 with PartType

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);
}
Also used : TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) PartData(net.silentchaos512.gear.gear.part.PartData) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) LazyMaterialInstance(net.silentchaos512.gear.gear.material.LazyMaterialInstance)

Example 43 with PartType

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();
}
Also used : PartType(net.silentchaos512.gear.api.part.PartType) ResourceLocation(net.minecraft.resources.ResourceLocation) SilentGear(net.silentchaos512.gear.SilentGear) ModContainer(net.minecraftforge.fml.ModContainer) java.util(java.util) CommandDispatcher(com.mojang.brigadier.CommandDispatcher) SharedSuggestionProvider(net.minecraft.commands.SharedSuggestionProvider) CommandSourceStack(net.minecraft.commands.CommandSourceStack) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) LocalDateTime(java.time.LocalDateTime) MaterialManager(net.silentchaos512.gear.gear.material.MaterialManager) NetworkDirection(net.minecraftforge.network.NetworkDirection) ResourceLocationArgument(net.minecraft.commands.arguments.ResourceLocationArgument) ServerPlayer(net.minecraft.server.level.ServerPlayer) PartData(net.silentchaos512.gear.gear.part.PartData) ITraitCondition(net.silentchaos512.gear.api.traits.ITraitCondition) ChatFormatting(net.minecraft.ChatFormatting) ITraitSerializer(net.silentchaos512.gear.api.traits.ITraitSerializer) PartManager(net.silentchaos512.gear.gear.part.PartManager) ClientOutputCommandPacket(net.silentchaos512.gear.network.ClientOutputCommandPacket) SuggestionProvider(com.mojang.brigadier.suggestion.SuggestionProvider) IGearPart(net.silentchaos512.gear.api.part.IGearPart) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) Component(net.minecraft.network.chat.Component) TraitManager(net.silentchaos512.gear.gear.trait.TraitManager) CommandContext(com.mojang.brigadier.context.CommandContext) SimpleTrait(net.silentchaos512.gear.gear.trait.SimpleTrait) Commands(net.minecraft.commands.Commands) ModList(net.minecraftforge.fml.ModList) AndTraitCondition(net.silentchaos512.gear.gear.trait.condition.AndTraitCondition) IModInfo(net.minecraftforge.forgespi.language.IModInfo) Collectors(java.util.stream.Collectors) StandardCharsets(java.nio.charset.StandardCharsets) Player(net.minecraft.world.entity.player.Player) PartType(net.silentchaos512.gear.api.part.PartType) IMaterial(net.silentchaos512.gear.api.material.IMaterial) Util(net.minecraft.Util) TextComponent(net.minecraft.network.chat.TextComponent) ITrait(net.silentchaos512.gear.api.traits.ITrait) java.io(java.io) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance) DateTimeFormatter(java.time.format.DateTimeFormatter) TraitSerializers(net.silentchaos512.gear.gear.trait.TraitSerializers) Network(net.silentchaos512.gear.network.Network) ItemStack(net.minecraft.world.item.ItemStack) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) ClickEvent(net.minecraft.network.chat.ClickEvent) IMaterial(net.silentchaos512.gear.api.material.IMaterial) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance)

Example 44 with PartType

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

Example 45 with PartType

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;
}
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)

Aggregations

PartType (net.silentchaos512.gear.api.part.PartType)37 ItemStack (net.minecraft.world.item.ItemStack)14 PartData (net.silentchaos512.gear.gear.part.PartData)14 StatInstance (net.silentchaos512.gear.api.stats.StatInstance)13 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)10 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)10 TextComponent (net.minecraft.network.chat.TextComponent)9 ResourceLocation (net.minecraft.resources.ResourceLocation)9 GearType (net.silentchaos512.gear.api.item.GearType)9 PartDataList (net.silentchaos512.gear.api.part.PartDataList)9 ItemStat (net.silentchaos512.gear.api.stats.ItemStat)9 Component (net.minecraft.network.chat.Component)8 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)8 IPartData (net.silentchaos512.gear.api.part.IPartData)8 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)8 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)7 StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)7 ArrayList (java.util.ArrayList)5 Collectors (java.util.stream.Collectors)5 MutableComponent (net.minecraft.network.chat.MutableComponent)5