From 55fe34e3038c524feb31c5d41813f1e69a0e009a Mon Sep 17 00:00:00 2001 From: Draylar Date: Sat, 29 May 2021 17:08:01 -0500 Subject: [PATCH] add support for getOrEmpty --- gradle.properties | 2 +- .../mixin/DefaultedRegistryDFUMixin.java | 23 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 65fa758..f592211 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.0 +mod_version=1.0.1 maven_group=draylar archives_base_name=budget-dfu diff --git a/src/main/java/draylar/budgetdfu/mixin/DefaultedRegistryDFUMixin.java b/src/main/java/draylar/budgetdfu/mixin/DefaultedRegistryDFUMixin.java index f68981b..a48edea 100644 --- a/src/main/java/draylar/budgetdfu/mixin/DefaultedRegistryDFUMixin.java +++ b/src/main/java/draylar/budgetdfu/mixin/DefaultedRegistryDFUMixin.java @@ -39,4 +39,27 @@ private Identifier remapRegistryRetrieval(Identifier id) { return id; } + + @ModifyVariable(method = "getOrEmpty", at = @At("HEAD"), index = 1) + private Identifier remapOptionalRegistryRetrieval(Identifier id) { + // If the ID passed in is null, return the default value of this registry. + if(id == null) { + return defaultId; + } + + @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; + } }