Skip to content
This repository has been archived by the owner on Jul 20, 2021. It is now read-only.

Commit

Permalink
add support for non-defaulted registries
Browse files Browse the repository at this point in the history
  • Loading branch information
Draylar committed May 29, 2021
1 parent 55fe34e commit f125c89
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
62 changes: 62 additions & 0 deletions src/main/java/draylar/budgetdfu/mixin/RegistryDFUMixin.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
3 changes: 2 additions & 1 deletion src/main/resources/budget-dfu.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"package": "draylar.budgetdfu.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"DefaultedRegistryDFUMixin"
"DefaultedRegistryDFUMixin",
"RegistryDFUMixin"
],
"client": [
],
Expand Down

0 comments on commit f125c89

Please sign in to comment.