add option to disable normal loot

This commit is contained in:
Jenny committed 2025-03-12 09:19:18 +01:00
1 parent 8e30a4cd8f
commit 3b115a1781
6 files changed
+58 -2

No files matched your search

@@ -22,6 +22,5 @@ public class Xp2Items {
MinecraftForge.EVENT_BUS.register(this);
ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ServerConfig.SPEC, "xp2items.toml");
}
}
@@ -12,10 +12,12 @@ public class ServerConfig {
public static final ForgeConfigSpec.ConfigValue<Integer> C_XP_AMOUNT;
public static final ForgeConfigSpec.ConfigValue<Integer> C_ITEM_AMOUNT;
public static final ForgeConfigSpec.ConfigValue<Boolean> C_DISABLE_LOOT_TABLES;
static {
C_XP_AMOUNT = BUILDER.comment("xp needed per loot drop, 0=per level").define("xp_amount", 25);
C_ITEM_AMOUNT = BUILDER.comment("items per loot drop").define("item_amount", 1);
C_DISABLE_LOOT_TABLES = BUILDER.comment("disable all loot tables").define("disable_loot_tables", false);
SPEC = BUILDER.build();
}
@@ -0,0 +1,21 @@
package com.jenny.xp2items.mixins;
import com.jenny.xp2items.config.ServerConfig;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.LootTable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(LootTable.class)
public class LootTableMixin {
@Inject(method = "getRandomItems(Lnet/minecraft/world/level/storage/loot/LootContext;)Lit/unimi/dsi/fastutil/objects/ObjectArrayList;", at = @At("RETURN"), cancellable = true)
private void getRandomItems(LootContext p_230923_, CallbackInfoReturnable<ObjectArrayList<ItemStack>> cir) {
if (ServerConfig.C_DISABLE_LOOT_TABLES.get()) {
cir.setReturnValue(new ObjectArrayList<>());
}
}
}
+15
View File
@@ -0,0 +1,15 @@
{
"required": true,
"minVersion": "0.8",
"package": "com.jenny.xp2items.mixins",
"compatibilityLevel": "JAVA_21",
"refmap": "xp2items.refmap.json",
"client": [
],
"injectors": {
"defaultRequire": 1
},
"mixins": [
"LootTableMixin"
]
}