-
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.
- Loading branch information
1 parent
7fefe83
commit 91e5e15
Showing
14 changed files
with
358 additions
and
34 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
17 changes: 17 additions & 0 deletions
17
src/main/java/fr/firstmegagame4/env/json/impl/resource/EntryListDuckInterface.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,17 @@ | ||
package fr.firstmegagame4.env.json.impl.resource; | ||
|
||
import net.minecraft.resource.InputSupplier; | ||
import net.minecraft.resource.ResourcePack; | ||
import net.minecraft.util.Identifier; | ||
|
||
import java.io.InputStream; | ||
import java.util.Map; | ||
|
||
public interface EntryListDuckInterface { | ||
|
||
Identifier env_json$getEnvJsonIdentifier(); | ||
|
||
Map<ResourcePack, InputSupplier<InputStream>> env_json$getEnvJsonResources(); | ||
|
||
void env_json$putEnvJsonSource(ResourcePack resourcePack, InputSupplier<InputStream> inputSupplier); | ||
} |
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
11 changes: 11 additions & 0 deletions
11
src/main/java/fr/firstmegagame4/env/json/impl/resource/ResourceResult.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,11 @@ | ||
package fr.firstmegagame4.env.json.impl.resource; | ||
|
||
import net.minecraft.resource.InputSupplier; | ||
import net.minecraft.resource.ResourcePack; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import java.io.InputStream; | ||
|
||
@ApiStatus.Internal | ||
public record ResourceResult(ResourcePack pack, InputSupplier<InputStream> supplier, int packIndex) { | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/fr/firstmegagame4/env/json/impl/resource/ResultAccess.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,17 @@ | ||
package fr.firstmegagame4.env.json.impl.resource; | ||
|
||
import net.minecraft.resource.InputSupplier; | ||
import net.minecraft.resource.ResourcePack; | ||
import org.jetbrains.annotations.ApiStatus; | ||
|
||
import java.io.InputStream; | ||
|
||
@ApiStatus.Internal | ||
public interface ResultAccess { | ||
|
||
ResourcePack invokePack(); | ||
|
||
InputSupplier<InputStream> invokeSupplier(); | ||
|
||
int invokePackIndex(); | ||
} |
54 changes: 54 additions & 0 deletions
54
src/main/java/fr/firstmegagame4/env/json/mixin/EntryListMixin.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,54 @@ | ||
package fr.firstmegagame4.env.json.mixin; | ||
|
||
import fr.firstmegagame4.env.json.impl.EnvJsonUtils; | ||
import fr.firstmegagame4.env.json.impl.resource.EntryListDuckInterface; | ||
import it.unimi.dsi.fastutil.objects.Object2ObjectArrayMap; | ||
import net.minecraft.resource.InputSupplier; | ||
import net.minecraft.resource.NamespaceResourceManager; | ||
import net.minecraft.resource.ResourcePack; | ||
import net.minecraft.util.Identifier; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Mutable; | ||
import org.spongepowered.asm.mixin.Unique; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import java.io.InputStream; | ||
import java.util.Map; | ||
|
||
@Mixin(NamespaceResourceManager.EntryList.class) | ||
public class EntryListMixin implements EntryListDuckInterface { | ||
|
||
@Unique | ||
@Final | ||
@Mutable | ||
private Identifier envJsonIdentifier; | ||
|
||
@Unique | ||
@Final | ||
@Mutable | ||
private Map<ResourcePack, InputSupplier<InputStream>> envJsonSources; | ||
|
||
@Inject(method = "<init>(Lnet/minecraft/util/Identifier;)V", at = @At("TAIL")) | ||
private void envJsonInit(Identifier id, CallbackInfo ci) { | ||
this.envJsonIdentifier = EnvJsonUtils.getEnvJsonPath(id); | ||
this.envJsonSources = new Object2ObjectArrayMap<>(); | ||
} | ||
|
||
@Override | ||
public Identifier env_json$getEnvJsonIdentifier() { | ||
return this.envJsonIdentifier; | ||
} | ||
|
||
@Override | ||
public Map<ResourcePack, InputSupplier<InputStream>> env_json$getEnvJsonResources() { | ||
return this.envJsonSources; | ||
} | ||
|
||
@Override | ||
public void env_json$putEnvJsonSource(ResourcePack resourcePack, InputSupplier<InputStream> inputSupplier) { | ||
this.envJsonSources.put(resourcePack, inputSupplier); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
src/main/java/fr/firstmegagame4/env/json/mixin/GroupResourcePackMixin.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,46 @@ | ||
package fr.firstmegagame4.env.json.mixin; | ||
|
||
import com.llamalad7.mixinextras.injector.wrapoperation.Operation; | ||
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; | ||
import com.llamalad7.mixinextras.sugar.Share; | ||
import com.llamalad7.mixinextras.sugar.ref.LocalRef; | ||
import fr.firstmegagame4.env.json.api.EnvJson; | ||
import fr.firstmegagame4.env.json.impl.EnvJsonUtils; | ||
import fr.firstmegagame4.env.json.impl.resource.ResourceDuckInterface; | ||
import net.fabricmc.fabric.impl.resource.loader.GroupResourcePack; | ||
import net.minecraft.resource.InputSupplier; | ||
import net.minecraft.resource.ResourcePack; | ||
import net.minecraft.resource.ResourceType; | ||
import net.minecraft.util.Identifier; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.ModifyArg; | ||
|
||
import java.io.InputStream; | ||
|
||
// I know I shouldn't use an impl class, but I have no choice | ||
// Should try to load it with QSL when this one will be available for 1.20.4 | ||
@SuppressWarnings("UnstableApiUsage") | ||
@Mixin(value = GroupResourcePack.class, remap = false) | ||
public class GroupResourcePackMixin { | ||
|
||
@WrapOperation(method = "appendResources", at = @At(value = "INVOKE", target = "Lnet/minecraft/resource/ResourcePack;open(Lnet/minecraft/resource/ResourceType;Lnet/minecraft/util/Identifier;)Lnet/minecraft/resource/InputSupplier;")) | ||
private InputSupplier<InputStream> onResourceAdd(ResourcePack instance, ResourceType resourceType, Identifier identifier, Operation<InputSupplier<InputStream>> original, @Share("envJsonInputSupplier") LocalRef<InputSupplier<EnvJson>> ref) { | ||
InputSupplier<InputStream> inputSupplier = original.call(instance, resourceType, identifier); | ||
Identifier envJsonPath = EnvJsonUtils.getEnvJsonPath(identifier); | ||
if (inputSupplier != null) { | ||
InputSupplier<EnvJson> envJsonInputSupplier = () -> { | ||
InputSupplier<InputStream> supplier = instance.open(resourceType, envJsonPath); | ||
return supplier != null ? EnvJsonUtils.loadEnvJson(supplier) : EnvJsonUtils.ENV_JSON_NONE; | ||
}; | ||
ref.set(envJsonInputSupplier); | ||
} | ||
return inputSupplier; | ||
} | ||
|
||
@ModifyArg(method = "appendResources", at = @At(value = "INVOKE", target = "Ljava/util/List;add(Ljava/lang/Object;)Z")) | ||
private <E> E onResourceCreated(E e, @Share("envJsonInputSupplier") LocalRef<InputSupplier<EnvJson>> ref) { | ||
((ResourceDuckInterface) e).env_json$initEnvJsonSupplier(ref.get()); | ||
return e; | ||
} | ||
} |
Oops, something went wrong.