This repository has been archived by the owner on Jul 20, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for non-defaulted registries
- Loading branch information
Showing
3 changed files
with
65 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
src/main/java/draylar/budgetdfu/mixin/RegistryDFUMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters