Search in sources :

Example 1 with IPartData

use of net.silentchaos512.gear.api.part.IPartData in project Silent-Gear by SilentChaos512.

the class AbstractGearPart method getStatModifiers.

@Override
public Collection<StatInstance> getStatModifiers(IPartData part, PartType partType, StatGearKey key, ItemStack gear) {
    List<StatInstance> mods = new ArrayList<>(this.stats.get(key));
    GetStatModifierEvent event = new GetStatModifierEvent((PartData) part, (ItemStat) key.getStat(), mods);
    MinecraftForge.EVENT_BUS.post(event);
    return event.getModifiers();
}
Also used : GetStatModifierEvent(net.silentchaos512.gear.api.event.GetStatModifierEvent)

Example 2 with IPartData

use of net.silentchaos512.gear.api.part.IPartData in project Silent-Gear by SilentChaos512.

the class CompoundPart method getStatModifiers.

@Override
public Collection<StatInstance> getStatModifiers(IPartData part, PartType partType, StatGearKey key, ItemStack gear) {
    // Get the materials and all the stat modifiers they provide for this stat
    List<IMaterialInstance> materials = getMaterials(part);
    List<StatInstance> statMods = materials.stream().flatMap(m -> m.getStatModifiers(partType, key).stream()).collect(Collectors.toList());
    // Get any base modifiers for this part (could be none)
    statMods.addAll(this.stats.get(key));
    if (statMods.isEmpty()) {
        // No modifiers for this stat, so doing anything else is pointless
        return statMods;
    }
    GetStatModifierEvent event = new GetStatModifierEvent((PartData) part, (ItemStat) key.getStat(), statMods);
    MinecraftForge.EVENT_BUS.post(event);
    // Average together all modifiers of the same op. This makes things like rods with varying
    // numbers of materials more "sane".
    List<StatInstance> ret = new ArrayList<>(event.getModifiers());
    for (StatInstance.Operation op : StatInstance.Operation.values()) {
        Collection<StatInstance> modsForOp = ret.stream().filter(s -> s.getOp() == op).collect(Collectors.toList());
        if (modsForOp.size() > 1) {
            StatInstance mod = compressModifiers(modsForOp, op, key);
            ret.removeIf(inst -> inst.getOp() == op);
            ret.add(mod);
        }
    }
    // Synergy
    if (key.getStat().doesSynergyApply()) {
        final float synergy = SynergyUtils.getSynergy(this.partType, materials, getTraits(part, PartGearKey.of(gearType, partType), gear));
        if (!MathUtils.floatsEqual(synergy, 1.0f)) {
            final float multi = synergy - 1f;
            for (int i = 0; i < ret.size(); ++i) {
                StatInstance oldMod = ret.get(i);
                float value = oldMod.getValue();
                // Taking the abs of value times multi makes negative mods become less negative
                StatInstance newMod = oldMod.copySetValue(value + Math.abs(value) * multi);
                ret.remove(i);
                ret.add(i, newMod);
            }
        }
    }
    return ret;
}
Also used : JsonParseException(com.google.gson.JsonParseException) ResourceLocation(net.minecraft.resources.ResourceLocation) SilentGear(net.silentchaos512.gear.SilentGear) JsonObject(com.google.gson.JsonObject) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) GearHelper(net.silentchaos512.gear.util.GearHelper) MaterialManager(net.silentchaos512.gear.gear.material.MaterialManager) FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) PartGearKey(net.silentchaos512.gear.api.util.PartGearKey) Function(java.util.function.Function) ArrayList(java.util.ArrayList) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) IPartData(net.silentchaos512.gear.api.part.IPartData) GsonHelper(net.minecraft.util.GsonHelper) ColorUtils(net.silentchaos512.gear.client.util.ColorUtils) Nullable(javax.annotation.Nullable) StatInstance(net.silentchaos512.gear.api.stats.StatInstance) ItemStat(net.silentchaos512.gear.api.stats.ItemStat) Component(net.minecraft.network.chat.Component) StatGearKey(net.silentchaos512.gear.api.util.StatGearKey) MathUtils(net.silentchaos512.utils.MathUtils) Collection(java.util.Collection) SynergyUtils(net.silentchaos512.gear.util.SynergyUtils) Collectors(java.util.stream.Collectors) PartType(net.silentchaos512.gear.api.part.PartType) GearType(net.silentchaos512.gear.api.item.GearType) IMaterial(net.silentchaos512.gear.api.material.IMaterial) MinecraftForge(net.minecraftforge.common.MinecraftForge) List(java.util.List) IPartSerializer(net.silentchaos512.gear.api.part.IPartSerializer) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) MaterialList(net.silentchaos512.gear.api.material.MaterialList) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance) GetStatModifierEvent(net.silentchaos512.gear.api.event.GetStatModifierEvent) ItemStack(net.minecraft.world.item.ItemStack) TraitHelper(net.silentchaos512.gear.util.TraitHelper) CompoundPartItem(net.silentchaos512.gear.item.CompoundPartItem) Collections(java.util.Collections) GetStatModifierEvent(net.silentchaos512.gear.api.event.GetStatModifierEvent) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) ArrayList(java.util.ArrayList) StatInstance(net.silentchaos512.gear.api.stats.StatInstance)

Example 3 with IPartData

use of net.silentchaos512.gear.api.part.IPartData in project Silent-Gear by SilentChaos512.

the class CompoundPart method getTraits.

@Override
public Collection<TraitInstance> getTraits(IPartData part, PartGearKey partKey, ItemStack gear) {
    List<TraitInstance> ret = new ArrayList<>(super.getTraits(part, partKey, gear));
    List<IMaterialInstance> materials = getMaterials(part);
    for (TraitInstance inst : TraitHelper.getTraits(materials, partKey, gear)) {
        if (inst.conditionsMatch(partKey, gear, materials)) {
            ret.add(inst);
        }
    }
    return ret;
}
Also used : IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance) TraitInstance(net.silentchaos512.gear.api.traits.TraitInstance) ArrayList(java.util.ArrayList)

Example 4 with IPartData

use of net.silentchaos512.gear.api.part.IPartData in project Silent-Gear by SilentChaos512.

the class CompoundMaterialDisplay method getLayerColor.

@Override
public int getLayerColor(GearType gearType, IPartData part, IMaterialInstance materialIn, int layer) {
    List<MaterialLayer> layers = getLayerList(gearType, part, materialIn).getLayers();
    if (layer < layers.size()) {
        ItemStack stack = materialIn.getItem();
        if (stack.getItem() instanceof CompoundMaterialItem) {
            List<IMaterialInstance> subMaterials = CompoundMaterialItem.getSubMaterials(stack);
            int color = ColorUtils.getBlendedColor((CompoundMaterialItem) stack.getItem(), subMaterials, layer);
            // return layers.get(layer).getColor();
            return color;
        }
    }
    return Color.VALUE_WHITE;
}
Also used : ItemStack(net.minecraft.world.item.ItemStack) CompoundMaterialItem(net.silentchaos512.gear.item.CompoundMaterialItem)

Example 5 with IPartData

use of net.silentchaos512.gear.api.part.IPartData in project Silent-Gear by SilentChaos512.

the class GearData method writeConstructionParts.

public static void writeConstructionParts(ItemStack gear, Collection<? extends IPartData> parts) {
    if (checkNonGearItem(gear, "writeConstructionParts"))
        return;
    CompoundTag tags = getData(gear, NBT_ROOT_CONSTRUCTION);
    ListTag tagList = new ListTag();
    // Mains must be first in the list!
    parts.stream().filter(p -> p.getType() == PartType.MAIN).map(p -> p.write(new CompoundTag())).forEach(tagList::add);
    // Write everything else in any order
    parts.stream().filter(p -> p.getType() != PartType.MAIN).map(p -> p.write(new CompoundTag())).forEach(tagList::add);
    tags.put(NBT_CONSTRUCTION_PARTS, tagList);
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) SilentGear(net.silentchaos512.gear.SilentGear) java.util(java.util) Tag(net.minecraft.nbt.Tag) PartDataList(net.silentchaos512.gear.api.part.PartDataList) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) CrashReportCategory(net.minecraft.CrashReportCategory) CuriosCompat(net.silentchaos512.gear.compat.curios.CuriosCompat) CompoundPart(net.silentchaos512.gear.gear.part.CompoundPart) PartData(net.silentchaos512.gear.gear.part.PartData) ICoreItem(net.silentchaos512.gear.api.item.ICoreItem) IPartData(net.silentchaos512.gear.api.part.IPartData) Config(net.silentchaos512.gear.config.Config) PartManager(net.silentchaos512.gear.gear.part.PartManager) StackList(net.silentchaos512.lib.collection.StackList) Mod(net.minecraftforge.fml.common.Mod) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) IGearPart(net.silentchaos512.gear.api.part.IGearPart) Nullable(javax.annotation.Nullable) NameUtils(net.silentchaos512.lib.util.NameUtils) ReportedException(net.minecraft.ReportedException) StatGearKey(net.silentchaos512.gear.api.util.StatGearKey) EnchantmentTrait(net.silentchaos512.gear.gear.trait.EnchantmentTrait) Predicate(java.util.function.Predicate) ModList(net.minecraftforge.fml.ModList) RecalculateStatsPacket(net.silentchaos512.gear.network.RecalculateStatsPacket) Player(net.minecraft.world.entity.player.Player) PartType(net.silentchaos512.gear.api.part.PartType) GearType(net.silentchaos512.gear.api.item.GearType) CompoundTag(net.minecraft.nbt.CompoundTag) ITrait(net.silentchaos512.gear.api.traits.ITrait) Color(net.silentchaos512.utils.Color) PlayerLoggedInEvent(net.minecraftforge.event.entity.player.PlayerEvent.PlayerLoggedInEvent) Network(net.silentchaos512.gear.network.Network) ItemStack(net.minecraft.world.item.ItemStack) TraitActionContext(net.silentchaos512.gear.api.traits.TraitActionContext) Level(net.minecraft.world.level.Level) CrashReport(net.minecraft.CrashReport) Mth(net.minecraft.util.Mth) net.silentchaos512.gear.api.stats(net.silentchaos512.gear.api.stats) CompoundPartItem(net.silentchaos512.gear.item.CompoundPartItem) ListTag(net.minecraft.nbt.ListTag) ListTag(net.minecraft.nbt.ListTag) CompoundTag(net.minecraft.nbt.CompoundTag)

Aggregations

IPartData (net.silentchaos512.gear.api.part.IPartData)5 ItemStack (net.minecraft.world.item.ItemStack)4 PartType (net.silentchaos512.gear.api.part.PartType)4 IMaterialInstance (net.silentchaos512.gear.api.material.IMaterialInstance)3 ArrayList (java.util.ArrayList)2 Nullable (javax.annotation.Nullable)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 SilentGear (net.silentchaos512.gear.SilentGear)2 GetStatModifierEvent (net.silentchaos512.gear.api.event.GetStatModifierEvent)2 GearType (net.silentchaos512.gear.api.item.GearType)2 ICoreItem (net.silentchaos512.gear.api.item.ICoreItem)2 PartDataList (net.silentchaos512.gear.api.part.PartDataList)2 TraitInstance (net.silentchaos512.gear.api.traits.TraitInstance)2 StatGearKey (net.silentchaos512.gear.api.util.StatGearKey)2 MaterialInstance (net.silentchaos512.gear.gear.material.MaterialInstance)2 PartData (net.silentchaos512.gear.gear.part.PartData)2 CompoundPartItem (net.silentchaos512.gear.item.CompoundPartItem)2 JsonObject (com.google.gson.JsonObject)1 JsonParseException (com.google.gson.JsonParseException)1 java.util (java.util)1