diff --git a/src/main/java/org/auioc/mcmod/arnicalib/game/enchantment/HLevelBasedValue.java b/src/main/java/org/auioc/mcmod/arnicalib/game/enchantment/HLevelBasedValue.java new file mode 100644 index 0000000..61ea64e --- /dev/null +++ b/src/main/java/org/auioc/mcmod/arnicalib/game/enchantment/HLevelBasedValue.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2025 AUIOC.ORG + * + * This file is part of ArnicaLib, a mod made for Minecraft. + * + * ArnicaLib is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +package org.auioc.mcmod.arnicalib.game.enchantment; + +import com.mojang.serialization.MapCodec; +import com.mojang.serialization.codecs.RecordCodecBuilder; +import net.minecraft.world.item.enchantment.LevelBasedValue; + +import java.util.List; + +/** + * @author LainIO24 + * @since 7.0.0 + */ +public interface HLevelBasedValue extends LevelBasedValue { + + static Sum sum(LevelBasedValue... values) { + return new Sum(List.of(values)); + } + + record Sum(List values) implements LevelBasedValue { + + public static final MapCodec CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group( + LevelBasedValue.CODEC.listOf().fieldOf("values").forGetter(o -> o.values) + ).apply(instance, Sum::new) + ); + + public static Sum of(LevelBasedValue... values) { + return new Sum(List.of(values)); + } + + @Override + public float calculate(int level) { + float r = 0.0F; + for (var i : values) { + r += i.calculate(level); + } + return r; + } + + @Override + public MapCodec codec() { return CODEC; } + + } + +} diff --git a/src/main/java/org/auioc/mcmod/arnicalib/mod/Initialization.java b/src/main/java/org/auioc/mcmod/arnicalib/mod/Initialization.java index 6cb4dfb..3dd43db 100644 --- a/src/main/java/org/auioc/mcmod/arnicalib/mod/Initialization.java +++ b/src/main/java/org/auioc/mcmod/arnicalib/mod/Initialization.java @@ -24,6 +24,7 @@ import net.neoforged.fml.loading.FMLEnvironment; import net.neoforged.neoforge.common.NeoForge; import org.auioc.mcmod.arnicalib.ArnicaLib; +import org.auioc.mcmod.arnicalib.mod.enchantment.AHLevelBasedValues; import org.auioc.mcmod.arnicalib.mod.loot.AHLootItemConditions; public class Initialization { @@ -43,6 +44,7 @@ public static void init() { private static void modSetup() { AHLootItemConditions.TYPES.register(modEventBus); + AHLevelBasedValues.TYPES.register(modEventBus); // AHGlobalLootModifiers.GLOBAL_LOOT_MODIFIERS.register(modEventBus); // AHLootItemFunctions.LOOT_FUNCTION_TYPES.register(modEventBus); // HTags.init(); diff --git a/src/main/java/org/auioc/mcmod/arnicalib/mod/enchantment/AHLevelBasedValues.java b/src/main/java/org/auioc/mcmod/arnicalib/mod/enchantment/AHLevelBasedValues.java new file mode 100644 index 0000000..d41f575 --- /dev/null +++ b/src/main/java/org/auioc/mcmod/arnicalib/mod/enchantment/AHLevelBasedValues.java @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2025 AUIOC.ORG + * + * This file is part of ArnicaLib, a mod made for Minecraft. + * + * ArnicaLib is free software: you can redistribute it and/or modify it under + * the terms of the GNU General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along with + * this program. If not, see . + */ + +package org.auioc.mcmod.arnicalib.mod.enchantment; + +import com.mojang.serialization.MapCodec; +import net.minecraft.core.registries.Registries; +import net.minecraft.world.item.enchantment.LevelBasedValue; +import net.neoforged.neoforge.registries.DeferredHolder; +import net.neoforged.neoforge.registries.DeferredRegister; +import org.auioc.mcmod.arnicalib.ArnicaLib; +import org.auioc.mcmod.arnicalib.game.enchantment.HLevelBasedValue; + +public class AHLevelBasedValues { + + public static final DeferredRegister> TYPES = DeferredRegister.create(Registries.ENCHANTMENT_LEVEL_BASED_VALUE_TYPE, ArnicaLib.MOD_ID); + + public static final DeferredHolder, MapCodec> SUM = TYPES.register("sum", () -> HLevelBasedValue.Sum.CODEC); + +}