Skip to content

Commit

Permalink
fix: fix mod compat
Browse files Browse the repository at this point in the history
  • Loading branch information
CallMeEchoCodes committed Jul 27, 2024
1 parent 8570e37 commit 806568a
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package dev.callmeecho.globalize.main;

import net.minecraft.resource.ResourcePackProvider;

public interface ResourcePackManagerAccessor {
void globalize$addProvider(ResourcePackProvider provider);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package dev.callmeecho.globalize.mixin;

import com.google.common.collect.ImmutableSet;
import dev.callmeecho.globalize.main.ResourcePackManagerAccessor;
import net.minecraft.resource.ResourcePackManager;
import net.minecraft.resource.ResourcePackProvider;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Mutable;
import org.spongepowered.asm.mixin.Shadow;

import java.util.Set;

@Mixin(ResourcePackManager.class)
public class ResourcePackManagerMixin implements ResourcePackManagerAccessor {
@Mutable
@Shadow @Final public Set<ResourcePackProvider> providers;

@Override
public void globalize$addProvider(ResourcePackProvider provider) {
this.providers = ImmutableSet.<ResourcePackProvider>builder().addAll(this.providers).add(provider).build();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package dev.callmeecho.globalize.mixin;

import com.llamalad7.mixinextras.injector.ModifyReturnValue;
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import dev.callmeecho.globalize.main.Globalize;
import dev.callmeecho.globalize.main.ResourcePackManagerAccessor;
import net.minecraft.resource.*;
import net.minecraft.util.path.SymlinkFinder;
import org.spongepowered.asm.mixin.Mixin;
Expand All @@ -11,12 +15,13 @@

@Mixin(VanillaDataPackProvider.class)
public class VanillaDataPackProviderMixin {
@Redirect(method = "createManager(Lnet/minecraft/world/level/storage/LevelStorage$Session;)Lnet/minecraft/resource/ResourcePackManager;", at = @At(value = "INVOKE", target = "Lnet/minecraft/resource/VanillaDataPackProvider;createManager(Ljava/nio/file/Path;Lnet/minecraft/util/path/SymlinkFinder;)Lnet/minecraft/resource/ResourcePackManager;"))
private static ResourcePackManager createManager(Path dataPacksPath, SymlinkFinder symlinkFinder) {
return new ResourcePackManager(
new VanillaDataPackProvider(symlinkFinder),
new FileResourcePackProvider(dataPacksPath, ResourceType.SERVER_DATA, ResourcePackSource.WORLD, symlinkFinder),
new FileResourcePackProvider(Globalize.dataPackFolder, ResourceType.SERVER_DATA, ResourcePackSource.WORLD, symlinkFinder)
);
@WrapOperation(
method = "createManager(Lnet/minecraft/world/level/storage/LevelStorage$Session;)Lnet/minecraft/resource/ResourcePackManager;",
at = @At(value = "INVOKE", target = "Lnet/minecraft/resource/VanillaDataPackProvider;createManager(Ljava/nio/file/Path;Lnet/minecraft/util/path/SymlinkFinder;)Lnet/minecraft/resource/ResourcePackManager;")
)
private static ResourcePackManager createManager(Path dataPacksPath, SymlinkFinder symlinkFinder, Operation<ResourcePackManager> original) {
ResourcePackManager value = original.call(dataPacksPath, symlinkFinder);
((ResourcePackManagerAccessor)value).globalize$addProvider(new FileResourcePackProvider(Globalize.dataPackFolder, ResourceType.SERVER_DATA, ResourcePackSource.WORLD, symlinkFinder));
return value;
}
}
6 changes: 3 additions & 3 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
"description": "Global datapacks for modpacks",
"authors": ["CallMeEcho"],
"contact": {
"homepage": "https://github.com/CallMeEchoCodes/Bombastic",
"sources": "https://github.com/CallMeEchoCodes/Bombastic",
"issues": "https://github.com/CallMeEchoCodes/Bombastic/issues"
"homepage": "https://github.com/SpiritGameStudios/Globalize",
"sources": "https://github.com/SpiritGameStudios/Globalize",
"issues": "https://github.com/SpiritGameStudios/Globalize/issues"
},
"license": "MPL-2.0",
"environment": "*",
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/globalize.accesswidener
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
accessWidener v2 named
accessible field net/minecraft/resource/ResourcePackManager providers Ljava/util/Set;
1 change: 1 addition & 0 deletions src/main/resources/globalize.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"compatibilityLevel": "JAVA_21",
"package": "dev.callmeecho.globalize.mixin",
"mixins": [
"ResourcePackManagerMixin",
"VanillaDataPackProviderMixin"
],
"client": [
Expand Down

0 comments on commit 806568a

Please sign in to comment.