47 lines
2.0 KiB
Java
47 lines
2.0 KiB
Java
|
package com.thebrokenrail.energonrelics.mixin;
|
||
|
|
||
|
import com.thebrokenrail.energonrelics.EnergonRelics;
|
||
|
import com.thebrokenrail.energonrelics.client.config.UserConfig;
|
||
|
import me.sargunvohra.mcmods.autoconfig1u.AutoConfig;
|
||
|
import net.fabricmc.api.EnvType;
|
||
|
import net.fabricmc.api.Environment;
|
||
|
import net.minecraft.resource.AbstractFileResourcePack;
|
||
|
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.Inject;
|
||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||
|
|
||
|
import java.io.IOException;
|
||
|
import java.io.InputStream;
|
||
|
|
||
|
@Environment(EnvType.CLIENT)
|
||
|
@Mixin(AbstractFileResourcePack.class)
|
||
|
public class MixinAbstractFileResourcePack {
|
||
|
@Inject(at = @At("HEAD"), method = "open", cancellable = true)
|
||
|
public void injectOpen(ResourceType type, Identifier id, CallbackInfoReturnable<InputStream> info) {
|
||
|
if (id.getNamespace().equals(EnergonRelics.NAMESPACE)) {
|
||
|
try {
|
||
|
Identifier newID = new Identifier(AutoConfig.getConfigHolder(UserConfig.class).getConfig().textureSet.namespace(), id.getPath());
|
||
|
InputStream in = ((AbstractFileResourcePack) (Object) this).open(type, newID);
|
||
|
if (in != null) {
|
||
|
info.setReturnValue(in);
|
||
|
}
|
||
|
} catch (IOException ignored) {
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@Inject(at = @At("HEAD"), method = "contains", cancellable = true)
|
||
|
public void injectContains(ResourceType type, Identifier id, CallbackInfoReturnable<Boolean> info) {
|
||
|
if (id.getNamespace().equals(EnergonRelics.NAMESPACE)) {
|
||
|
Identifier newID = new Identifier(AutoConfig.getConfigHolder(UserConfig.class).getConfig().textureSet.namespace(), id.getPath());
|
||
|
boolean out = ((AbstractFileResourcePack) (Object) this).contains(type, newID);
|
||
|
if (out) {
|
||
|
info.setReturnValue(true);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|