Fixed MultiPackResourceManagerMixin
This commit is contained in:
parent
12a8b0c23a
commit
c783d007b1
4 changed files with 83 additions and 92 deletions
|
@ -0,0 +1,53 @@
|
||||||
|
package ru.bclib.mixin.client;
|
||||||
|
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.packs.resources.FallbackResourceManager;
|
||||||
|
import net.minecraft.server.packs.resources.MultiPackResourceManager;
|
||||||
|
import net.minecraft.server.packs.resources.Resource;
|
||||||
|
import net.minecraft.server.packs.resources.ResourceManager;
|
||||||
|
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.Inject;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
import ru.bclib.BCLib;
|
||||||
|
import ru.bclib.api.ModIntegrationAPI;
|
||||||
|
import ru.bclib.client.render.EmissiveTextureInfo;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@Mixin(MultiPackResourceManager.class)
|
||||||
|
public class MultiPackResourceManagerMixin {
|
||||||
|
@Final
|
||||||
|
@Shadow
|
||||||
|
private Map<String, FallbackResourceManager> namespacedManagers;
|
||||||
|
|
||||||
|
private ResourceLocation bclib_alphaEmissionMaterial = BCLib.makeID("materialmaps/block/alpha_emission.json");
|
||||||
|
|
||||||
|
@Inject(method = "getResource", at = @At("HEAD"), cancellable = true)
|
||||||
|
private void bclib_getResource(ResourceLocation resourceLocation, CallbackInfoReturnable<Resource> info) throws IOException {
|
||||||
|
if (!ModIntegrationAPI.hasCanvas()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!resourceLocation.getPath().startsWith("materialmaps")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!resourceLocation.getPath().contains("/block/")) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String name = resourceLocation.getPath().replace("materialmaps/block/", "").replace(".json", "");
|
||||||
|
ResourceLocation blockID = new ResourceLocation(resourceLocation.getNamespace(), name);
|
||||||
|
|
||||||
|
if (!EmissiveTextureInfo.isEmissiveBlock(blockID)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
ResourceManager resourceManager = this.namespacedManagers.get(resourceLocation.getNamespace());
|
||||||
|
if (resourceManager != null && !resourceManager.hasResource(resourceLocation)) {
|
||||||
|
info.setReturnValue(resourceManager.getResource(bclib_alphaEmissionMaterial));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,53 +0,0 @@
|
||||||
package ru.bclib.mixin.client;
|
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.server.packs.resources.FallbackResourceManager;
|
|
||||||
import net.minecraft.server.packs.resources.Resource;
|
|
||||||
import net.minecraft.server.packs.resources.ResourceManager;
|
|
||||||
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.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
||||||
import ru.bclib.BCLib;
|
|
||||||
import ru.bclib.api.ModIntegrationAPI;
|
|
||||||
import ru.bclib.client.render.EmissiveTextureInfo;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
//TODO: 1.18.2 Disabled to have a compilable Version
|
|
||||||
//@Mixin(SimpleReloadableResourceManager.class)
|
|
||||||
//public class SimpleReloadableResourceManagerMixin {
|
|
||||||
// @Final
|
|
||||||
// @Shadow
|
|
||||||
// private Map<String, FallbackResourceManager> namespacedPacks;
|
|
||||||
//
|
|
||||||
// private ResourceLocation bclib_alphaEmissionMaterial = BCLib.makeID("materialmaps/block/alpha_emission.json");
|
|
||||||
//
|
|
||||||
// @Inject(method = "getResource", at = @At("HEAD"), cancellable = true)
|
|
||||||
// private void bclib_getResource(ResourceLocation resourceLocation, CallbackInfoReturnable<Resource> info) throws IOException {
|
|
||||||
// if (!ModIntegrationAPI.hasCanvas()) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// if (!resourceLocation.getPath().startsWith("materialmaps")) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// if (!resourceLocation.getPath().contains("/block/")) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// String name = resourceLocation.getPath().replace("materialmaps/block/", "").replace(".json", "");
|
|
||||||
// ResourceLocation blockID = new ResourceLocation(resourceLocation.getNamespace(), name);
|
|
||||||
//
|
|
||||||
// if (!EmissiveTextureInfo.isEmissiveBlock(blockID)) {
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// ResourceManager resourceManager = this.namespacedPacks.get(resourceLocation.getNamespace());
|
|
||||||
// if (resourceManager != null && !resourceManager.hasResource(resourceLocation)) {
|
|
||||||
// info.setReturnValue(resourceManager.getResource(bclib_alphaEmissionMaterial));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
package ru.bclib.mixin.common;
|
||||||
|
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.packs.resources.MultiPackResourceManager;
|
||||||
|
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;
|
||||||
|
|
||||||
|
@Mixin(MultiPackResourceManager.class)
|
||||||
|
public class MultiPackResourceManagerMixin {
|
||||||
|
private static final String[] BCLIB_MISSING_RESOURCES = new String[] {
|
||||||
|
"dimension/the_end.json",
|
||||||
|
"dimension/the_nether.json",
|
||||||
|
"dimension_type/the_end.json",
|
||||||
|
"dimension_type/the_nether.json"
|
||||||
|
};
|
||||||
|
|
||||||
|
@Inject(method = "hasResource", at = @At("HEAD"), cancellable = true)
|
||||||
|
private void bclib_hasResource(ResourceLocation resourceLocation, CallbackInfoReturnable<Boolean> info) {
|
||||||
|
if (resourceLocation.getNamespace().equals("minecraft")) {
|
||||||
|
for (String key: BCLIB_MISSING_RESOURCES) {
|
||||||
|
if (resourceLocation.getPath().equals(key)) {
|
||||||
|
info.setReturnValue(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,39 +0,0 @@
|
||||||
package ru.bclib.mixin.common;
|
|
||||||
|
|
||||||
import net.minecraft.resources.ResourceLocation;
|
|
||||||
import net.minecraft.server.packs.resources.FallbackResourceManager;
|
|
||||||
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.Inject;
|
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
|
||||||
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
//TODO: 1.18.2 Disabled to have a compilable Version
|
|
||||||
//@Mixin(SimpleReloadableResourceManager.class)
|
|
||||||
//public class SimpleReloadableResourceManagerMixin {
|
|
||||||
// @Final
|
|
||||||
// @Shadow
|
|
||||||
// private Map<String, FallbackResourceManager> namespacedPacks;
|
|
||||||
//
|
|
||||||
// private static final String[] BCLIB_MISSING_RESOURCES = new String[] {
|
|
||||||
// "dimension/the_end.json",
|
|
||||||
// "dimension/the_nether.json",
|
|
||||||
// "dimension_type/the_end.json",
|
|
||||||
// "dimension_type/the_nether.json"
|
|
||||||
// };
|
|
||||||
//
|
|
||||||
// @Inject(method = "hasResource", at = @At("HEAD"), cancellable = true)
|
|
||||||
// private void bclib_hasResource(ResourceLocation resourceLocation, CallbackInfoReturnable<Boolean> info) {
|
|
||||||
// if (resourceLocation.getNamespace().equals("minecraft")) {
|
|
||||||
// for (String key: BCLIB_MISSING_RESOURCES) {
|
|
||||||
// if (resourceLocation.getPath().equals(key)) {
|
|
||||||
// info.setReturnValue(false);
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
//}
|
|
Loading…
Add table
Add a link
Reference in a new issue