diff --git a/gradle.properties b/gradle.properties index f592211..56cd64a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ yarn_mappings=1.16.5+build.9 loader_version=0.11.3 # Mod Properties -mod_version=1.0.1 +mod_version=1.0.2 maven_group=draylar archives_base_name=budget-dfu diff --git a/src/main/java/draylar/budgetdfu/mixin/RegistryDFUMixin.java b/src/main/java/draylar/budgetdfu/mixin/RegistryDFUMixin.java new file mode 100644 index 0000000..229863f --- /dev/null +++ b/src/main/java/draylar/budgetdfu/mixin/RegistryDFUMixin.java @@ -0,0 +1,62 @@ +package draylar.budgetdfu.mixin; + +import draylar.budgetdfu.BudgetDFU; +import net.minecraft.util.Identifier; +import net.minecraft.util.registry.DefaultedRegistry; +import net.minecraft.util.registry.Registry; +import org.jetbrains.annotations.Nullable; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyVariable; + +@Mixin(Registry.class) +public class RegistryDFUMixin { + + @ModifyVariable(method = "get(Lnet/minecraft/util/Identifier;)Ljava/lang/Object;", at = @At("HEAD"), index = 1) + private Identifier remapRegistryRetrieval(Identifier id) { + // If the ID passed in is null, return null. + if(id == null) { + return null; + } + + @Nullable Identifier direct = BudgetDFU.remapDirect((DefaultedRegistry) (Object) this, id); + + // If a direct Identifier remap was found, apply it now & return. + if(direct != null) { + return direct; + } + + // If a namespace remap is applicable, apply now & return. + String updatedNamespace = BudgetDFU.remapNamespace((DefaultedRegistry) (Object) this, id.getNamespace()); + if(updatedNamespace != null) { + return new Identifier(updatedNamespace, id.getPath()); + } + + return id; + } + + @ModifyVariable(method = "getOrEmpty(Lnet/minecraft/util/Identifier;)Ljava/util/Optional;", at = @At("HEAD"), index = 1) + private Identifier remapOptionalRegistryRetrieval(Identifier id) { + // If the ID passed in is null, return null. + if(id == null) { + return null; + } + + @Nullable Identifier direct = BudgetDFU.remapDirect((DefaultedRegistry) (Object) this, id); + + // If a direct Identifier remap was found, apply it now & return. + if(direct != null) { + return direct; + } + + // If a namespace remap is applicable, apply now & return. + String updatedNamespace = BudgetDFU.remapNamespace((DefaultedRegistry) (Object) this, id.getNamespace()); + if(updatedNamespace != null) { + return new Identifier(updatedNamespace, id.getPath()); + } + + return id; + } +} diff --git a/src/main/resources/budget-dfu.mixins.json b/src/main/resources/budget-dfu.mixins.json index 474121f..8b48dfd 100644 --- a/src/main/resources/budget-dfu.mixins.json +++ b/src/main/resources/budget-dfu.mixins.json @@ -4,7 +4,8 @@ "package": "draylar.budgetdfu.mixin", "compatibilityLevel": "JAVA_8", "mixins": [ - "DefaultedRegistryDFUMixin" + "DefaultedRegistryDFUMixin", + "RegistryDFUMixin" ], "client": [ ],