[Change] Removed Canvas Support

This commit is contained in:
Frank 2022-10-28 09:21:44 +02:00
parent e826dbc623
commit d9a586741e
11 changed files with 0 additions and 552 deletions

View file

@ -106,44 +106,4 @@ public class CustomModelBakery {
BlockModel model = provider.getItemModel(modelLocation);
models.put(modelLocation, model);
}
//TODO: 1.19.3 Handled differently now
// public static void loadEmissiveModels(Map<ResourceLocation, UnbakedModel> unbakedCache) {
// if (!ModIntegrationAPI.hasCanvas()) {
// return;
// }
//
// Map<ResourceLocation, UnbakedModel> cacheCopy = new HashMap<>(unbakedCache);
// Set<Pair<String, String>> strings = Sets.newConcurrentHashSet();
// Registry.BLOCK.keySet().forEach(blockID -> {
// Block block = Registry.BLOCK.get(blockID);
// ImmutableList<BlockState> states = block.getStateDefinition().getPossibleStates();
// boolean addBlock = false;
//
// for (BlockState state : states) {
// ResourceLocation stateID = BlockModelShaper.stateToModelLocation(blockID, state);
// UnbakedModel model = cacheCopy.get(stateID);
// if (model == null) {
// continue;
// }
// Collection<Material> materials = model.getMaterials(cacheCopy::get, strings);
// if (materials == null) {
// continue;
// }
// for (Material material : materials) {
// if (EmissiveTextureInfo.isEmissiveTexture(material.texture())) {
// addBlock = true;
// break;
// }
// }
// if (addBlock) {
// break;
// }
// }
//
// if (addBlock) {
// EmissiveTextureInfo.addBlock(blockID);
// }
// });
// }
}

View file

@ -1,33 +0,0 @@
package org.betterx.bclib.client.render;
import net.minecraft.resources.ResourceLocation;
import com.google.common.collect.Sets;
import java.util.Set;
public class EmissiveTextureInfo {
private static final Set<ResourceLocation> EMISSIVE_TEXTURES = Sets.newHashSet();
private static final Set<ResourceLocation> EMISSIVE_BLOCKS = Sets.newHashSet();
public static void clear() {
EMISSIVE_TEXTURES.clear();
EMISSIVE_BLOCKS.clear();
}
public static void addTexture(ResourceLocation texture) {
EMISSIVE_TEXTURES.add(texture);
}
public static void addBlock(ResourceLocation blockID) {
EMISSIVE_BLOCKS.add(blockID);
}
public static boolean isEmissiveTexture(ResourceLocation texture) {
return EMISSIVE_TEXTURES.contains(texture);
}
public static boolean isEmissiveBlock(ResourceLocation blockID) {
return EMISSIVE_BLOCKS.contains(blockID);
}
}

View file

@ -1,36 +0,0 @@
package org.betterx.bclib.mixin.client;
import org.betterx.bclib.api.v2.ModIntegrationAPI;
import net.minecraft.client.color.block.BlockColors;
import net.minecraft.client.resources.model.ModelBakery;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.profiling.ProfilerFiller;
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.CallbackInfo;
import java.util.Map;
@Mixin(ModelBakery.class)
public abstract class ModelBakeryMixin {
@Final
@Shadow
private Map<ResourceLocation, UnbakedModel> unbakedCache;
@Inject(method = "<init>*", at = @At("TAIL"))
private void bclib_findEmissiveModels(
BlockColors blockColors, ProfilerFiller profilerFiller, Map map, Map map2, CallbackInfo ci
) {
//CustomModelBakery.setModelsLoaded(false);
if (ModIntegrationAPI.hasCanvas()) {
//TODO:1.19.3 this needs to change
//CustomModelBakery.loadEmissiveModels(unbakedCache);
}
}
}

View file

@ -1,58 +0,0 @@
package org.betterx.bclib.mixin.client;
import org.betterx.bclib.BCLib;
import org.betterx.bclib.api.v2.ModIntegrationAPI;
import org.betterx.bclib.client.render.EmissiveTextureInfo;
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 java.io.IOException;
import java.util.Map;
@Mixin(MultiPackResourceManager.class)
public class MultiPackResourceManagerMixin {
@Final
@Shadow
private Map<String, FallbackResourceManager> namespacedManagers;
private final 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.getResource(resourceLocation).isEmpty()) {
info.setReturnValue(resourceManager.getResource(bclib_alphaEmissionMaterial).get());
}
}
}

View file

@ -1,157 +0,0 @@
package org.betterx.bclib.mixin.client;
import org.betterx.bclib.BCLib;
import org.betterx.bclib.client.render.EmissiveTextureInfo;
import com.mojang.blaze3d.platform.NativeImage;
import net.minecraft.client.renderer.texture.SpriteContents;
import net.minecraft.client.renderer.texture.SpriteLoader;
import net.minecraft.client.resources.metadata.animation.AnimationMetadataSection;
import net.minecraft.client.resources.metadata.animation.FrameSize;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.Resource;
import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.util.Mth;
import net.fabricmc.loader.api.FabricLoader;
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.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.io.IOException;
import java.util.Optional;
import java.util.function.BiConsumer;
@Mixin(SpriteLoader.class)
public class TextureAtlasMixin {
@Shadow
@Final
private ResourceLocation location;
private static final int EMISSIVE_ALPHA = 254 << 24;
private boolean bclib_modifyAtlas;
private static ResourceManager bclib_resourceManager;
@Inject(method = "<init>*", at = @At("TAIL"))
private void bclib_onAtlasInit(
ResourceLocation textureAtlasLocation,
int maxSupportedTextureSize,
CallbackInfo ci
) {
boolean hasOptifine = FabricLoader.getInstance().isModLoaded("optifabric");
bclib_modifyAtlas = !hasOptifine && textureAtlasLocation.toString()
.equals("minecraft:textures/atlas/blocks.png");
if (bclib_modifyAtlas) {
EmissiveTextureInfo.clear();
}
}
@Inject(method = "listSprites(Lnet/minecraft/server/packs/resources/ResourceManager;Ljava/lang/String;Ljava/lang/String;Ljava/util/function/BiConsumer;)V", at = @At("HEAD"), cancellable = true)
private static void bclib_listSprites(
ResourceManager resourceManager,
String string,
String string2,
BiConsumer<ResourceLocation, Resource> biConsumer,
CallbackInfo ci
) {
bclib_resourceManager = resourceManager;
}
@Inject(method = "loadSprite", at = @At("HEAD"), cancellable = true)
private void bclib_loadSprite(
ResourceLocation location, Resource resource, CallbackInfoReturnable<SpriteContents> cir
) {
if (!bclib_modifyAtlas || bclib_resourceManager == null) {
return;
}
if (!location.getPath().startsWith("block")) {
return;
}
AnimationMetadataSection animationMetadataSection;
try {
animationMetadataSection = resource.metadata()
.getSection(AnimationMetadataSection.SERIALIZER)
.orElse(AnimationMetadataSection.EMPTY);
} catch (Exception exception) {
BCLib.LOGGER.error("Unable to parse metadata from {} : {}", (Object) this.location, (Object) exception);
cir.setReturnValue(null);
cir.cancel();
return;
}
ResourceLocation emissiveLocation = new ResourceLocation(
location.getNamespace(),
"textures/" + location.getPath() + "_e.png"
);
Optional<Resource> emissiveRes = bclib_resourceManager.getResource(emissiveLocation);
if (emissiveRes.isPresent()) {
NativeImage sprite = null;
NativeImage emission = null;
try {
// ResourceLocation spriteLocation = new ResourceLocation(
// location.getNamespace(),
// "textures/" + location.getPath() + ".png"
// );
//Resource resource = resourceManager.getResource(spriteLocation).orElse(null);
sprite = NativeImage.read(resource.open());
resource = emissiveRes.get();
emission = NativeImage.read(resource.open());
} catch (IOException e) {
BCLib.LOGGER.warning(e.getMessage());
}
if (sprite != null && emission != null) {
int width = Math.min(sprite.getWidth(), emission.getWidth());
int height = Math.min(sprite.getHeight(), emission.getHeight());
for (int x = 0; x < width; x++) {
for (int y = 0; y < height; y++) {
int argb = emission.getPixelRGBA(x, y);
int alpha = (argb >> 24) & 255;
if (alpha > 127) {
int r = (argb >> 16) & 255;
int g = (argb >> 8) & 255;
int b = argb & 255;
if (r > 0 || g > 0 || b > 0) {
argb = (argb & 0x00FFFFFF) | EMISSIVE_ALPHA;
sprite.setPixelRGBA(x, y, argb);
}
}
}
}
FrameSize frameSize = animationMetadataSection.calculateFrameSize(
sprite.getWidth(),
sprite.getHeight()
);
if (!Mth.isDivisionInteger(
sprite.getWidth(),
frameSize.width()
) || !Mth.isDivisionInteger(sprite.getHeight(), frameSize.height())) {
BCLib.LOGGER.error(
"Image {} size {},{} is not multiple of frame size {},{}",
this.location,
sprite.getWidth(),
sprite.getHeight(),
frameSize.width(),
frameSize.height()
);
sprite.close();
cir.setReturnValue(null);
cir.cancel();
}
SpriteContents result = new SpriteContents(location, frameSize, sprite, animationMetadataSection);
EmissiveTextureInfo.addTexture(location);
cir.setReturnValue(result);
}
}
}
}