1
0
mirror of https://github.com/GeyserMC/Rainbow.git synced 2025-12-19 14:59:16 +00:00

Client module fixes

This commit is contained in:
Eclipse
2025-11-12 14:06:56 +00:00
parent fc58393acc
commit ebb7d15479
9 changed files with 32 additions and 33 deletions

View File

@@ -3,7 +3,6 @@ package org.geysermc.rainbow.client;
import com.mojang.blaze3d.platform.NativeImage; import com.mojang.blaze3d.platform.NativeImage;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.item.ClientItem; import net.minecraft.client.renderer.item.ClientItem;
import net.minecraft.client.renderer.texture.SpriteContents;
import net.minecraft.client.renderer.texture.TextureAtlas; import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.resources.model.AtlasManager; import net.minecraft.client.resources.model.AtlasManager;
@@ -11,8 +10,8 @@ import net.minecraft.client.resources.model.EquipmentAssetManager;
import net.minecraft.client.resources.model.EquipmentClientInfo; import net.minecraft.client.resources.model.EquipmentClientInfo;
import net.minecraft.client.resources.model.ModelManager; import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.client.resources.model.ResolvedModel; import net.minecraft.client.resources.model.ResolvedModel;
import net.minecraft.resources.Identifier;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.packs.resources.ResourceManager; import net.minecraft.server.packs.resources.ResourceManager;
import net.minecraft.world.item.equipment.EquipmentAsset; import net.minecraft.world.item.equipment.EquipmentAsset;
import org.geysermc.rainbow.Rainbow; import org.geysermc.rainbow.Rainbow;
@@ -40,13 +39,13 @@ public class MinecraftAssetResolver implements AssetResolver {
} }
@Override @Override
public Optional<ResolvedModel> getResolvedModel(ResourceLocation location) { public Optional<ResolvedModel> getResolvedModel(Identifier identifier) {
return ((ResolvedModelAccessor) modelManager).rainbow$getResolvedModel(location); return ((ResolvedModelAccessor) modelManager).rainbow$getResolvedModel(identifier);
} }
@Override @Override
public Optional<ClientItem> getClientItem(ResourceLocation location) { public Optional<ClientItem> getClientItem(Identifier identifier) {
return ((ResolvedModelAccessor) modelManager).rainbow$getClientItem(location); return ((ResolvedModelAccessor) modelManager).rainbow$getClientItem(identifier);
} }
@Override @Override
@@ -55,17 +54,17 @@ public class MinecraftAssetResolver implements AssetResolver {
} }
@Override @Override
public Optional<TextureResource> getTexture(ResourceLocation atlasId, ResourceLocation location) { public Optional<TextureResource> getTexture(Identifier atlasId, Identifier identifier) {
if (atlasId == null) { if (atlasId == null) {
// Not in an atlas - so not animated, probably? // Not in an atlas - so not animated, probably?
return RainbowIO.safeIO(() -> { return RainbowIO.safeIO(() -> {
try (InputStream textureStream = resourceManager.open(Rainbow.decorateTextureLocation(location))) { try (InputStream textureStream = resourceManager.open(Rainbow.decorateTextureIdentifier(identifier))) {
return new TextureResource(NativeImage.read(textureStream)); return new TextureResource(NativeImage.read(textureStream));
} }
}); });
} }
TextureAtlas atlas = atlasManager.getAtlasOrThrow(atlasId); TextureAtlas atlas = atlasManager.getAtlasOrThrow(atlasId);
TextureAtlasSprite sprite = atlas.getSprite(location); TextureAtlasSprite sprite = atlas.getSprite(identifier);
if (sprite == atlas.missingSprite()) { if (sprite == atlas.missingSprite()) {
return Optional.empty(); return Optional.empty();
} }

View File

@@ -4,10 +4,10 @@ import com.google.gson.JsonElement;
import com.mojang.serialization.Codec; import com.mojang.serialization.Codec;
import com.mojang.serialization.DynamicOps; import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.JsonOps; import com.mojang.serialization.JsonOps;
import net.minecraft.Util;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.core.HolderLookup; import net.minecraft.core.HolderLookup;
import net.minecraft.resources.RegistryOps; import net.minecraft.resources.RegistryOps;
import net.minecraft.util.Util;
import org.geysermc.rainbow.CodecUtil; import org.geysermc.rainbow.CodecUtil;
import org.geysermc.rainbow.RainbowIO; import org.geysermc.rainbow.RainbowIO;
import org.geysermc.rainbow.mapping.PackSerializer; import org.geysermc.rainbow.mapping.PackSerializer;

View File

@@ -2,7 +2,7 @@ package org.geysermc.rainbow.client.accessor;
import net.minecraft.client.renderer.item.ClientItem; import net.minecraft.client.renderer.item.ClientItem;
import net.minecraft.client.resources.model.ResolvedModel; import net.minecraft.client.resources.model.ResolvedModel;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.Identifier;
import java.util.Optional; import java.util.Optional;
@@ -10,7 +10,7 @@ import java.util.Optional;
// This comes with some extra memory usage, but Rainbow should only be used to convert packs, so it should be fine // This comes with some extra memory usage, but Rainbow should only be used to convert packs, so it should be fine
public interface ResolvedModelAccessor { public interface ResolvedModelAccessor {
Optional<ResolvedModel> rainbow$getResolvedModel(ResourceLocation location); Optional<ResolvedModel> rainbow$getResolvedModel(Identifier identifier);
Optional<ClientItem> rainbow$getClientItem(ResourceLocation location); Optional<ClientItem> rainbow$getClientItem(Identifier identifier);
} }

View File

@@ -7,7 +7,7 @@ import net.minecraft.client.renderer.item.ClientItem;
import net.minecraft.client.resources.model.ClientItemInfoLoader; import net.minecraft.client.resources.model.ClientItemInfoLoader;
import net.minecraft.client.resources.model.ModelManager; import net.minecraft.client.resources.model.ModelManager;
import net.minecraft.client.resources.model.ResolvedModel; import net.minecraft.client.resources.model.ResolvedModel;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.Identifier;
import net.minecraft.server.packs.resources.PreparableReloadListener; import net.minecraft.server.packs.resources.PreparableReloadListener;
import org.geysermc.rainbow.client.accessor.ResolvedModelAccessor; import org.geysermc.rainbow.client.accessor.ResolvedModelAccessor;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
@@ -22,9 +22,9 @@ import java.util.concurrent.CompletableFuture;
@Mixin(ModelManager.class) @Mixin(ModelManager.class)
public abstract class ModelManagerMixin implements PreparableReloadListener, AutoCloseable, ResolvedModelAccessor { public abstract class ModelManagerMixin implements PreparableReloadListener, AutoCloseable, ResolvedModelAccessor {
@Unique @Unique
private Map<ResourceLocation, ResolvedModel> unbakedResolvedModels; private Map<Identifier, ResolvedModel> unbakedResolvedModels;
@Unique @Unique
private Map<ResourceLocation, ClientItem> clientItems; private Map<Identifier, ClientItem> clientItems;
@WrapOperation(method = "method_65753", at = @At(value = "INVOKE", target = "Ljava/util/concurrent/CompletableFuture;join()Ljava/lang/Object;", ordinal = 1)) @WrapOperation(method = "method_65753", at = @At(value = "INVOKE", target = "Ljava/util/concurrent/CompletableFuture;join()Ljava/lang/Object;", ordinal = 1))
private static Object setResolvedModels(CompletableFuture<?> instance, Operation<Object> original) { private static Object setResolvedModels(CompletableFuture<?> instance, Operation<Object> original) {
@@ -32,7 +32,7 @@ public abstract class ModelManagerMixin implements PreparableReloadListener, Aut
try { try {
// Couldn't be bothered setting up access wideners, this resolves the second component of the ResolvedModels record, which is called "models" // Couldn't be bothered setting up access wideners, this resolves the second component of the ResolvedModels record, which is called "models"
// Ideally we'd somehow use the "this" instance, but that's not possible here since the lambda we inject into is a static one // Ideally we'd somehow use the "this" instance, but that's not possible here since the lambda we inject into is a static one
((ModelManagerMixin) (Object) Minecraft.getInstance().getModelManager()).unbakedResolvedModels = (Map<ResourceLocation, ResolvedModel>) resolved.getClass().getRecordComponents()[1].getAccessor().invoke(resolved); ((ModelManagerMixin) (Object) Minecraft.getInstance().getModelManager()).unbakedResolvedModels = (Map<Identifier, ResolvedModel>) resolved.getClass().getRecordComponents()[1].getAccessor().invoke(resolved);
} catch (IllegalAccessException | InvocationTargetException | ClassCastException exception) { } catch (IllegalAccessException | InvocationTargetException | ClassCastException exception) {
throw new RuntimeException(exception); throw new RuntimeException(exception);
} }
@@ -40,7 +40,7 @@ public abstract class ModelManagerMixin implements PreparableReloadListener, Aut
} }
@WrapOperation(method = "method_65753", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resources/model/ClientItemInfoLoader$LoadedClientInfos;contents()Ljava/util/Map;")) @WrapOperation(method = "method_65753", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/resources/model/ClientItemInfoLoader$LoadedClientInfos;contents()Ljava/util/Map;"))
private static Map<ResourceLocation, ClientItem> setClientItems(ClientItemInfoLoader.LoadedClientInfos instance, Operation<Map<ResourceLocation, ClientItem>> original) { private static Map<Identifier, ClientItem> setClientItems(ClientItemInfoLoader.LoadedClientInfos instance, Operation<Map<Identifier, ClientItem>> original) {
// Same note as above for not using "this" // Same note as above for not using "this"
ModelManagerMixin thiz = ((ModelManagerMixin) (Object) Minecraft.getInstance().getModelManager()); ModelManagerMixin thiz = ((ModelManagerMixin) (Object) Minecraft.getInstance().getModelManager());
thiz.clientItems = original.call(instance); thiz.clientItems = original.call(instance);
@@ -48,12 +48,12 @@ public abstract class ModelManagerMixin implements PreparableReloadListener, Aut
} }
@Override @Override
public Optional<ResolvedModel> rainbow$getResolvedModel(ResourceLocation location) { public Optional<ResolvedModel> rainbow$getResolvedModel(Identifier identifier) {
return unbakedResolvedModels == null ? Optional.empty() : Optional.ofNullable(unbakedResolvedModels.get(location)); return unbakedResolvedModels == null ? Optional.empty() : Optional.ofNullable(unbakedResolvedModels.get(identifier));
} }
@Override @Override
public Optional<ClientItem> rainbow$getClientItem(ResourceLocation location) { public Optional<ClientItem> rainbow$getClientItem(Identifier identifier) {
return clientItems == null ? Optional.empty() : Optional.ofNullable(clientItems.get(location)); return clientItems == null ? Optional.empty() : Optional.ofNullable(clientItems.get(identifier));
} }
} }

View File

@@ -1,6 +1,6 @@
package org.geysermc.rainbow.client.render; package org.geysermc.rainbow.client.render;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.Identifier;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import org.geysermc.rainbow.mapping.geometry.GeometryRenderer; import org.geysermc.rainbow.mapping.geometry.GeometryRenderer;
import org.geysermc.rainbow.mapping.texture.TextureHolder; import org.geysermc.rainbow.mapping.texture.TextureHolder;
@@ -11,7 +11,7 @@ public class MinecraftGeometryRenderer implements GeometryRenderer {
public static final MinecraftGeometryRenderer INSTANCE = new MinecraftGeometryRenderer(); public static final MinecraftGeometryRenderer INSTANCE = new MinecraftGeometryRenderer();
@Override @Override
public TextureHolder render(ResourceLocation location, ItemStack stack) { public TextureHolder render(Identifier identifier, ItemStack stack) {
return new RenderedTextureHolder(location, stack); return new RenderedTextureHolder(identifier, stack);
} }
} }

View File

@@ -12,7 +12,7 @@ import net.minecraft.client.gui.render.state.GuiItemRenderState;
import net.minecraft.client.gui.render.state.GuiRenderState; import net.minecraft.client.gui.render.state.GuiRenderState;
import net.minecraft.client.gui.render.state.pip.OversizedItemRenderState; import net.minecraft.client.gui.render.state.pip.OversizedItemRenderState;
import net.minecraft.client.renderer.item.TrackingItemStackRenderState; import net.minecraft.client.renderer.item.TrackingItemStackRenderState;
import net.minecraft.resources.ResourceLocation; import net.minecraft.resources.Identifier;
import net.minecraft.util.ProblemReporter; import net.minecraft.util.ProblemReporter;
import net.minecraft.world.item.ItemDisplayContext; import net.minecraft.world.item.ItemDisplayContext;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
@@ -35,8 +35,8 @@ import java.util.concurrent.locks.ReentrantLock;
public class RenderedTextureHolder extends TextureHolder { public class RenderedTextureHolder extends TextureHolder {
private final ItemStack stackToRender; private final ItemStack stackToRender;
public RenderedTextureHolder(ResourceLocation location, ItemStack stackToRender) { public RenderedTextureHolder(Identifier identifier, ItemStack stackToRender) {
super(location); super(identifier);
this.stackToRender = stackToRender; this.stackToRender = stackToRender;
} }

View File

@@ -223,7 +223,7 @@ public abstract class RainbowModelProvider extends FabricModelProvider {
@Override @Override
public Optional<TextureResource> getTexture(ResourceLocation atlas, ResourceLocation location) { public Optional<TextureResource> getTexture(ResourceLocation atlas, ResourceLocation location) {
// We don't care about atlas since there are none loaded at datagen // We don't care about atlas since there are none loaded at datagen
return resourceManager.getResource(Rainbow.decorateTextureLocation(location)) return resourceManager.getResource(Rainbow.decorateTextureIdentifier(location))
.flatMap(resource -> RainbowIO.safeIO(() -> { .flatMap(resource -> RainbowIO.safeIO(() -> {
Optional<AnimationMetadataSection> animationMetadata = resource.metadata().getSection(AnimationMetadataSection.TYPE); Optional<AnimationMetadataSection> animationMetadata = resource.metadata().getSection(AnimationMetadataSection.TYPE);
try (InputStream textureStream = resource.open()) { try (InputStream textureStream = resource.open()) {

View File

@@ -18,11 +18,11 @@ public class Rainbow {
return identifier.toString().replace(':', '.').replace('/', '_'); return identifier.toString().replace(':', '.').replace('/', '_');
} }
public static Identifier decorateResourceLocation(Identifier identifier, String type, String extension) { public static Identifier decorateIdentifier(Identifier identifier, String type, String extension) {
return identifier.withPath(path -> type + "/" + path + "." + extension); return identifier.withPath(path -> type + "/" + path + "." + extension);
} }
public static Identifier decorateTextureLocation(Identifier identifier) { public static Identifier decorateTextureIdentifier(Identifier identifier) {
return decorateResourceLocation(identifier, "textures", "png"); return decorateIdentifier(identifier, "textures", "png");
} }
} }

View File

@@ -125,7 +125,7 @@ public class BedrockPack {
futures.add(serializer.saveJson(BedrockTextureAtlas.CODEC, BedrockTextureAtlas.itemAtlas(name, itemTextures), paths.itemAtlas())); futures.add(serializer.saveJson(BedrockTextureAtlas.CODEC, BedrockTextureAtlas.itemAtlas(name, itemTextures), paths.itemAtlas()));
Function<TextureHolder, CompletableFuture<?>> textureSaver = texture -> { Function<TextureHolder, CompletableFuture<?>> textureSaver = texture -> {
Identifier textureIdentifier = Rainbow.decorateTextureLocation(texture.location()); Identifier textureIdentifier = Rainbow.decorateTextureIdentifier(texture.location());
return texture.save(context.assetResolver(), serializer, paths.packRoot().resolve(textureIdentifier.getPath()), reporter); return texture.save(context.assetResolver(), serializer, paths.packRoot().resolve(textureIdentifier.getPath()), reporter);
}; };