Compiling version (some features are currently disabled and need a rewrite)
This commit is contained in:
parent
b1f4173ce4
commit
f8bcba4d3a
48 changed files with 488 additions and 506 deletions
|
@ -1,7 +1,6 @@
|
|||
package org.betterx.bclib.mixin.client;
|
||||
|
||||
import org.betterx.bclib.api.v2.ModIntegrationAPI;
|
||||
import org.betterx.bclib.client.models.CustomModelBakery;
|
||||
|
||||
import net.minecraft.client.color.block.BlockColors;
|
||||
import net.minecraft.client.resources.model.ModelBakery;
|
||||
|
@ -35,7 +34,8 @@ public abstract class ModelBakeryMixin {
|
|||
) {
|
||||
//CustomModelBakery.setModelsLoaded(false);
|
||||
if (ModIntegrationAPI.hasCanvas()) {
|
||||
CustomModelBakery.loadEmissiveModels(unbakedCache);
|
||||
//TODO:1.19.3 this needs to change
|
||||
//CustomModelBakery.loadEmissiveModels(unbakedCache);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,114 +1,97 @@
|
|||
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.TextureAtlas;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.Resource;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
|
||||
import net.fabricmc.fabric.impl.client.texture.FabricSprite;
|
||||
import net.fabricmc.loader.api.FabricLoader;
|
||||
|
||||
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.CallbackInfo;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Optional;
|
||||
|
||||
@Mixin(TextureAtlas.class)
|
||||
public class TextureAtlasMixin {
|
||||
private static final int EMISSIVE_ALPHA = 254 << 24;
|
||||
private boolean bclib_modifyAtlas;
|
||||
|
||||
@Inject(method = "<init>*", at = @At("TAIL"))
|
||||
private void bclib_onAtlasInit(ResourceLocation resourceLocation, CallbackInfo info) {
|
||||
boolean hasOptifine = FabricLoader.getInstance().isModLoaded("optifabric");
|
||||
bclib_modifyAtlas = !hasOptifine && resourceLocation.toString().equals("minecraft:textures/atlas/blocks.png");
|
||||
if (bclib_modifyAtlas) {
|
||||
EmissiveTextureInfo.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@Inject(method = "load(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite$Info;IIIII)Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;", at = @At("HEAD"), cancellable = true)
|
||||
private void bclib_loadSprite(
|
||||
ResourceManager resourceManager,
|
||||
TextureAtlasSprite.Info spriteInfo,
|
||||
int atlasWidth,
|
||||
int atlasHeight,
|
||||
int maxLevel,
|
||||
int posX,
|
||||
int posY,
|
||||
CallbackInfoReturnable<TextureAtlasSprite> info
|
||||
) {
|
||||
if (!bclib_modifyAtlas) {
|
||||
return;
|
||||
}
|
||||
|
||||
ResourceLocation location = spriteInfo.name();
|
||||
if (!location.getPath().startsWith("block")) {
|
||||
return;
|
||||
}
|
||||
|
||||
ResourceLocation emissiveLocation = new ResourceLocation(
|
||||
location.getNamespace(),
|
||||
"textures/" + location.getPath() + "_e.png"
|
||||
);
|
||||
Optional<Resource> emissiveRes = 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
TextureAtlas self = (TextureAtlas) (Object) this;
|
||||
FabricSprite result = new FabricSprite(
|
||||
self,
|
||||
spriteInfo,
|
||||
maxLevel,
|
||||
atlasWidth,
|
||||
atlasHeight,
|
||||
posX,
|
||||
posY,
|
||||
sprite
|
||||
);
|
||||
EmissiveTextureInfo.addTexture(location);
|
||||
info.setReturnValue(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
//TODO: 1.19.3 How were FabricSprites replaced?
|
||||
// @Inject(method = "<init>*", at = @At("TAIL"))
|
||||
// private void bclib_onAtlasInit(ResourceLocation resourceLocation, CallbackInfo info) {
|
||||
// boolean hasOptifine = FabricLoader.getInstance().isModLoaded("optifabric");
|
||||
// bclib_modifyAtlas = !hasOptifine && resourceLocation.toString().equals("minecraft:textures/atlas/blocks.png");
|
||||
// if (bclib_modifyAtlas) {
|
||||
// EmissiveTextureInfo.clear();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Inject(method = "load(Lnet/minecraft/server/packs/resources/ResourceManager;Lnet/minecraft/client/renderer/texture/TextureAtlasSprite$Info;IIIII)Lnet/minecraft/client/renderer/texture/TextureAtlasSprite;", at = @At("HEAD"), cancellable = true)
|
||||
// private void bclib_loadSprite(
|
||||
// ResourceManager resourceManager,
|
||||
// TextureAtlasSprite.Info spriteInfo,
|
||||
// int atlasWidth,
|
||||
// int atlasHeight,
|
||||
// int maxLevel,
|
||||
// int posX,
|
||||
// int posY,
|
||||
// CallbackInfoReturnable<TextureAtlasSprite> info
|
||||
// ) {
|
||||
// if (!bclib_modifyAtlas) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// ResourceLocation location = spriteInfo.name();
|
||||
// if (!location.getPath().startsWith("block")) {
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// ResourceLocation emissiveLocation = new ResourceLocation(
|
||||
// location.getNamespace(),
|
||||
// "textures/" + location.getPath() + "_e.png"
|
||||
// );
|
||||
// Optional<Resource> emissiveRes = 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);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// TextureAtlas self = (TextureAtlas) (Object) this;
|
||||
// FabricSprite result = new FabricSprite(
|
||||
// self,
|
||||
// spriteInfo,
|
||||
// maxLevel,
|
||||
// atlasWidth,
|
||||
// atlasHeight,
|
||||
// posX,
|
||||
// posY,
|
||||
// sprite
|
||||
// );
|
||||
// EmissiveTextureInfo.addTexture(location);
|
||||
// info.setReturnValue(result);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
@ -1,48 +1,35 @@
|
|||
package org.betterx.bclib.mixin.common;
|
||||
|
||||
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeRegistry;
|
||||
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeData;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.RegistryAccess;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
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.ModifyArg;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
@Mixin(RegistryAccess.class)
|
||||
public interface RegistryAccessMixin {
|
||||
|
||||
@ModifyArg(method = "<clinit>", at = @At(value = "INVOKE", target = "Lnet/minecraft/Util;make(Ljava/util/function/Supplier;)Ljava/lang/Object;"))
|
||||
private static Supplier<ImmutableMap<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>>> together_addRegistry(
|
||||
Supplier<ImmutableMap<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>>> supplier
|
||||
) {
|
||||
return () -> {
|
||||
ImmutableMap.Builder<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>> builder = ImmutableMap.builder();
|
||||
//Make sure this gets added before WORLD_PRESETS
|
||||
put(builder, BCLBiomeRegistry.BCL_BIOMES_REGISTRY, BiomeData.CODEC);
|
||||
|
||||
Map<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>> res = supplier.get();
|
||||
builder.putAll(res);
|
||||
|
||||
return builder.build();
|
||||
};
|
||||
}
|
||||
|
||||
@Shadow
|
||||
static <E> void put(
|
||||
ImmutableMap.Builder<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>> builder,
|
||||
ResourceKey<? extends Registry<E>> resourceKey,
|
||||
Codec<E> codec
|
||||
) {
|
||||
throw new RuntimeException("Shadowed Call");
|
||||
}
|
||||
//TODO: 1.19.3 Will probably be a new custom data provider now
|
||||
// @ModifyArg(method = "<clinit>", at = @At(value = "INVOKE", target = "Lnet/minecraft/Util;make(Ljava/util/function/Supplier;)Ljava/lang/Object;"))
|
||||
// private static Supplier<ImmutableMap<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>>> together_addRegistry(
|
||||
// Supplier<ImmutableMap<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>>> supplier
|
||||
// ) {
|
||||
// return () -> {
|
||||
// ImmutableMap.Builder<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>> builder = ImmutableMap.builder();
|
||||
// //Make sure this gets added before WORLD_PRESETS
|
||||
// put(builder, BCLBiomeRegistry.BCL_BIOMES_REGISTRY, BiomeData.CODEC);
|
||||
//
|
||||
// Map<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>> res = supplier.get();
|
||||
// builder.putAll(res);
|
||||
//
|
||||
// return builder.build();
|
||||
// };
|
||||
// }
|
||||
//
|
||||
// @Shadow
|
||||
// static <E> void put(
|
||||
// ImmutableMap.Builder<ResourceKey<Registry<?>>, RegistryAccess.RegistryData<?>> builder,
|
||||
// ResourceKey<? extends Registry<E>> resourceKey,
|
||||
// Codec<E> codec
|
||||
// ) {
|
||||
// throw new RuntimeException("Shadowed Call");
|
||||
// }
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue