Search in sources :

Example 1 with GearType

use of net.silentchaos512.gear.api.item.GearType 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 2 with GearType

use of net.silentchaos512.gear.api.item.GearType in project Silent-Gear by SilentChaos512.

the class CompoundPart method getRandomMaterials.

private List<MaterialInstance> getRandomMaterials(GearType gearType, int count, int tier) {
    // Excludes children, will select a random child material (if appropriate) below
    List<IMaterial> matsOfTier = MaterialManager.getValues(tier == 0).stream().map(MaterialInstance::of).filter(m -> tier < 0 || tier == m.getTier(this.partType)).filter(m -> m.allowedInPart(this.partType) && m.isCraftingAllowed(this.partType, gearType)).map(MaterialInstance::get).collect(Collectors.toList());
    if (!matsOfTier.isEmpty()) {
        List<MaterialInstance> ret = new ArrayList<>();
        for (int i = 0; i < count; ++i) {
            IMaterial material = matsOfTier.get(SilentGear.RANDOM.nextInt(matsOfTier.size()));
            ret.add(getRandomChildMaterial(material));
        }
        return ret;
    }
    if (tier == -1) {
        // Something went wrong...
        return Collections.emptyList();
    }
    // No materials of tier? Select randoms of any tier.
    return getRandomMaterials(gearType, count, -1);
}
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) IMaterial(net.silentchaos512.gear.api.material.IMaterial) ArrayList(java.util.ArrayList) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance)

Example 3 with GearType

use of net.silentchaos512.gear.api.item.GearType in project Silent-Gear by SilentChaos512.

the class CompoundPart method randomizeData.

@Override
public PartData randomizeData(GearType gearType, int tier) {
    for (ItemStack stack : this.getIngredient().getItems()) {
        if (stack.getItem() instanceof CompoundPartItem) {
            int materialCount = getRandomMaterialCount(partType);
            List<MaterialInstance> materials = getRandomMaterials(gearType, materialCount, tier);
            ItemStack craftingItem = ((CompoundPartItem) stack.getItem()).create(materials);
            return PartData.of(this, craftingItem);
        }
    }
    return super.randomizeData(gearType, tier);
}
Also used : CompoundPartItem(net.silentchaos512.gear.item.CompoundPartItem) ItemStack(net.minecraft.world.item.ItemStack) MaterialInstance(net.silentchaos512.gear.gear.material.MaterialInstance) IMaterialInstance(net.silentchaos512.gear.api.material.IMaterialInstance)

Example 4 with GearType

use of net.silentchaos512.gear.api.item.GearType in project Silent-Gear by SilentChaos512.

the class EnchantmentTrait method onRecalculatePost.

@Override
public void onRecalculatePost(TraitActionContext context) {
    ItemStack gear = context.getGear();
    GearType gearType = GearHelper.getType(gear);
    int traitLevel = context.getTraitLevel();
    enchantments.forEach((type, list) -> {
        if (gearType.matches(type)) {
            addEnchantments(gear, traitLevel, list);
        }
    });
}
Also used : GearType(net.silentchaos512.gear.api.item.GearType) ItemStack(net.minecraft.world.item.ItemStack)

Example 5 with GearType

use of net.silentchaos512.gear.api.item.GearType in project Silent-Gear by SilentChaos512.

the class NBTTrait method onGearCrafted.

@Override
public void onGearCrafted(TraitActionContext context) {
    ItemStack gear = context.getGear();
    GearType gearType = GearHelper.getType(gear);
    int traitLevel = context.getTraitLevel();
    data.forEach((type, list) -> {
        if (gearType.matches(type) || "all".equals(type)) {
            list.stream().filter(e -> e.level == traitLevel).forEach(e -> gear.getOrCreateTag().merge(e.data));
        }
    });
}
Also used : ResourceLocation(net.minecraft.resources.ResourceLocation) SilentGear(net.silentchaos512.gear.SilentGear) TagParser(net.minecraft.nbt.TagParser) GearHelper(net.silentchaos512.gear.util.GearHelper) HashMap(java.util.HashMap) FriendlyByteBuf(net.minecraft.network.FriendlyByteBuf) ArrayList(java.util.ArrayList) GearType(net.silentchaos512.gear.api.item.GearType) List(java.util.List) CompoundTag(net.minecraft.nbt.CompoundTag) ITraitSerializer(net.silentchaos512.gear.api.traits.ITraitSerializer) Map(java.util.Map) GsonHelper(net.minecraft.util.GsonHelper) ItemStack(net.minecraft.world.item.ItemStack) TraitActionContext(net.silentchaos512.gear.api.traits.TraitActionContext) com.google.gson(com.google.gson) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) GearType(net.silentchaos512.gear.api.item.GearType) ItemStack(net.minecraft.world.item.ItemStack)

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