Skip to content

Commit

Permalink
feat(enchantment): LevelBasedValue.Sum
Browse files Browse the repository at this point in the history
  • Loading branch information
lainio24 committed Jan 19, 2025
1 parent b3b5364 commit 2865b5a
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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<LevelBasedValue> values) implements LevelBasedValue {

public static final MapCodec<Sum> 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<Sum> codec() { return CODEC; }

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <https://www.gnu.org/licenses/>.
*/

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<MapCodec<? extends LevelBasedValue>> TYPES = DeferredRegister.create(Registries.ENCHANTMENT_LEVEL_BASED_VALUE_TYPE, ArnicaLib.MOD_ID);

public static final DeferredHolder<MapCodec<? extends LevelBasedValue>, MapCodec<HLevelBasedValue.Sum>> SUM = TYPES.register("sum", () -> HLevelBasedValue.Sum.CODEC);

}

0 comments on commit 2865b5a

Please sign in to comment.