From 3b115a17817276a17f340a6c936b66bdb0a3393d Mon Sep 17 00:00:00 2001 From: Jenny Date: Wed, 12 Mar 2025 08:40:16 +0100 Subject: [PATCH] add option to disable normal loot --- build.gradle | 19 +++++++++++++++++ gradle.properties | 2 +- .../java/com/jenny/xp2items/Xp2Items.java | 1 - .../jenny/xp2items/config/ServerConfig.java | 2 ++ .../jenny/xp2items/mixins/LootTableMixin.java | 21 +++++++++++++++++++ src/main/resources/xp2items.mixins.json | 15 +++++++++++++ 6 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/jenny/xp2items/mixins/LootTableMixin.java create mode 100644 src/main/resources/xp2items.mixins.json diff --git a/build.gradle b/build.gradle index c59f898..2bfa673 100644 --- a/build.gradle +++ b/build.gradle @@ -1,3 +1,14 @@ +buildscript { + repositories { + // These repositories are only for Gradle plugins, put any other repositories in the repository block further below + maven { url = 'https://repo.spongepowered.org/repository/maven-public/' } + mavenCentral() + } + dependencies { + classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT' + } +} + plugins { id 'eclipse' id 'idea' @@ -5,6 +16,7 @@ plugins { id 'org.parchmentmc.librarian.forgegradle' version '1.+' } +apply plugin: 'org.spongepowered.mixin' group = mod_group_id version = mod_version @@ -107,6 +119,12 @@ minecraft { } } +mixin { + add sourceSets.main, "${mod_id}.refmap.json" + + config "${mod_id}.mixins.json" +} + // Include resources generated by data generators. sourceSets.main.resources { srcDir 'src/generated/resources' } @@ -129,6 +147,7 @@ dependencies { // then special handling is done to allow a setup of a vanilla dependency without the use of an external repository. minecraft "net.minecraftforge:forge:${minecraft_version}-${forge_version}" + annotationProcessor 'org.spongepowered:mixin:0.8.5:processor' // Example mod dependency with JEI - using fg.deobf() ensures the dependency is remapped to your development mappings // The JEI API is declared for compile time use, while the full JEI artifact is used at runtime // compileOnly fg.deobf("mezz.jei:jei-${mc_version}-common-api:${jei_version}") diff --git a/gradle.properties b/gradle.properties index 98038af..3ead030 100644 --- a/gradle.properties +++ b/gradle.properties @@ -38,7 +38,7 @@ mod_name=XP -> items # The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default. mod_license=All Rights Reserved # The mod version. See https://semver.org/ -mod_version=0.0.1 +mod_version=0.1.0 # The group ID for the mod. It is only important when publishing as an artifact to a Maven repository. # This should match the base package used for the mod sources. # See https://maven.apache.org/guides/mini/guide-naming-conventions.html diff --git a/src/main/java/com/jenny/xp2items/Xp2Items.java b/src/main/java/com/jenny/xp2items/Xp2Items.java index 470b3a8..c6924ec 100644 --- a/src/main/java/com/jenny/xp2items/Xp2Items.java +++ b/src/main/java/com/jenny/xp2items/Xp2Items.java @@ -22,6 +22,5 @@ public class Xp2Items { MinecraftForge.EVENT_BUS.register(this); ModLoadingContext.get().registerConfig(ModConfig.Type.COMMON, ServerConfig.SPEC, "xp2items.toml"); - } } diff --git a/src/main/java/com/jenny/xp2items/config/ServerConfig.java b/src/main/java/com/jenny/xp2items/config/ServerConfig.java index 656fb73..fcb225a 100644 --- a/src/main/java/com/jenny/xp2items/config/ServerConfig.java +++ b/src/main/java/com/jenny/xp2items/config/ServerConfig.java @@ -12,10 +12,12 @@ public class ServerConfig { public static final ForgeConfigSpec.ConfigValue C_XP_AMOUNT; public static final ForgeConfigSpec.ConfigValue C_ITEM_AMOUNT; + public static final ForgeConfigSpec.ConfigValue 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(); } diff --git a/src/main/java/com/jenny/xp2items/mixins/LootTableMixin.java b/src/main/java/com/jenny/xp2items/mixins/LootTableMixin.java new file mode 100644 index 0000000..eeed9b2 --- /dev/null +++ b/src/main/java/com/jenny/xp2items/mixins/LootTableMixin.java @@ -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> cir) { + if (ServerConfig.C_DISABLE_LOOT_TABLES.get()) { + cir.setReturnValue(new ObjectArrayList<>()); + } + } +} diff --git a/src/main/resources/xp2items.mixins.json b/src/main/resources/xp2items.mixins.json new file mode 100644 index 0000000..ddd3d5a --- /dev/null +++ b/src/main/resources/xp2items.mixins.json @@ -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" + ] +}