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:
@@ -3,7 +3,6 @@ package org.geysermc.rainbow.client;
|
||||
import com.mojang.blaze3d.platform.NativeImage;
|
||||
import net.minecraft.client.Minecraft;
|
||||
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.TextureAtlasSprite;
|
||||
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.ModelManager;
|
||||
import net.minecraft.client.resources.model.ResolvedModel;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.packs.resources.ResourceManager;
|
||||
import net.minecraft.world.item.equipment.EquipmentAsset;
|
||||
import org.geysermc.rainbow.Rainbow;
|
||||
@@ -40,13 +39,13 @@ public class MinecraftAssetResolver implements AssetResolver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ResolvedModel> getResolvedModel(ResourceLocation location) {
|
||||
return ((ResolvedModelAccessor) modelManager).rainbow$getResolvedModel(location);
|
||||
public Optional<ResolvedModel> getResolvedModel(Identifier identifier) {
|
||||
return ((ResolvedModelAccessor) modelManager).rainbow$getResolvedModel(identifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ClientItem> getClientItem(ResourceLocation location) {
|
||||
return ((ResolvedModelAccessor) modelManager).rainbow$getClientItem(location);
|
||||
public Optional<ClientItem> getClientItem(Identifier identifier) {
|
||||
return ((ResolvedModelAccessor) modelManager).rainbow$getClientItem(identifier);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -55,17 +54,17 @@ public class MinecraftAssetResolver implements AssetResolver {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<TextureResource> getTexture(ResourceLocation atlasId, ResourceLocation location) {
|
||||
public Optional<TextureResource> getTexture(Identifier atlasId, Identifier identifier) {
|
||||
if (atlasId == null) {
|
||||
// Not in an atlas - so not animated, probably?
|
||||
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));
|
||||
}
|
||||
});
|
||||
}
|
||||
TextureAtlas atlas = atlasManager.getAtlasOrThrow(atlasId);
|
||||
TextureAtlasSprite sprite = atlas.getSprite(location);
|
||||
TextureAtlasSprite sprite = atlas.getSprite(identifier);
|
||||
if (sprite == atlas.missingSprite()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ import com.google.gson.JsonElement;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.DynamicOps;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.util.Util;
|
||||
import org.geysermc.rainbow.CodecUtil;
|
||||
import org.geysermc.rainbow.RainbowIO;
|
||||
import org.geysermc.rainbow.mapping.PackSerializer;
|
||||
|
||||
@@ -2,7 +2,7 @@ package org.geysermc.rainbow.client.accessor;
|
||||
|
||||
import net.minecraft.client.renderer.item.ClientItem;
|
||||
import net.minecraft.client.resources.model.ResolvedModel;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.resources.Identifier;
|
||||
|
||||
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
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import net.minecraft.client.renderer.item.ClientItem;
|
||||
import net.minecraft.client.resources.model.ClientItemInfoLoader;
|
||||
import net.minecraft.client.resources.model.ModelManager;
|
||||
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 org.geysermc.rainbow.client.accessor.ResolvedModelAccessor;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
@@ -22,9 +22,9 @@ import java.util.concurrent.CompletableFuture;
|
||||
@Mixin(ModelManager.class)
|
||||
public abstract class ModelManagerMixin implements PreparableReloadListener, AutoCloseable, ResolvedModelAccessor {
|
||||
@Unique
|
||||
private Map<ResourceLocation, ResolvedModel> unbakedResolvedModels;
|
||||
private Map<Identifier, ResolvedModel> unbakedResolvedModels;
|
||||
@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))
|
||||
private static Object setResolvedModels(CompletableFuture<?> instance, Operation<Object> original) {
|
||||
@@ -32,7 +32,7 @@ public abstract class ModelManagerMixin implements PreparableReloadListener, Aut
|
||||
try {
|
||||
// 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
|
||||
((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) {
|
||||
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;"))
|
||||
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"
|
||||
ModelManagerMixin thiz = ((ModelManagerMixin) (Object) Minecraft.getInstance().getModelManager());
|
||||
thiz.clientItems = original.call(instance);
|
||||
@@ -48,12 +48,12 @@ public abstract class ModelManagerMixin implements PreparableReloadListener, Aut
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ResolvedModel> rainbow$getResolvedModel(ResourceLocation location) {
|
||||
return unbakedResolvedModels == null ? Optional.empty() : Optional.ofNullable(unbakedResolvedModels.get(location));
|
||||
public Optional<ResolvedModel> rainbow$getResolvedModel(Identifier identifier) {
|
||||
return unbakedResolvedModels == null ? Optional.empty() : Optional.ofNullable(unbakedResolvedModels.get(identifier));
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<ClientItem> rainbow$getClientItem(ResourceLocation location) {
|
||||
return clientItems == null ? Optional.empty() : Optional.ofNullable(clientItems.get(location));
|
||||
public Optional<ClientItem> rainbow$getClientItem(Identifier identifier) {
|
||||
return clientItems == null ? Optional.empty() : Optional.ofNullable(clientItems.get(identifier));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package org.geysermc.rainbow.client.render;
|
||||
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.resources.Identifier;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import org.geysermc.rainbow.mapping.geometry.GeometryRenderer;
|
||||
import org.geysermc.rainbow.mapping.texture.TextureHolder;
|
||||
@@ -11,7 +11,7 @@ public class MinecraftGeometryRenderer implements GeometryRenderer {
|
||||
public static final MinecraftGeometryRenderer INSTANCE = new MinecraftGeometryRenderer();
|
||||
|
||||
@Override
|
||||
public TextureHolder render(ResourceLocation location, ItemStack stack) {
|
||||
return new RenderedTextureHolder(location, stack);
|
||||
public TextureHolder render(Identifier identifier, ItemStack stack) {
|
||||
return new RenderedTextureHolder(identifier, stack);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.pip.OversizedItemRenderState;
|
||||
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.world.item.ItemDisplayContext;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
@@ -35,8 +35,8 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
public class RenderedTextureHolder extends TextureHolder {
|
||||
private final ItemStack stackToRender;
|
||||
|
||||
public RenderedTextureHolder(ResourceLocation location, ItemStack stackToRender) {
|
||||
super(location);
|
||||
public RenderedTextureHolder(Identifier identifier, ItemStack stackToRender) {
|
||||
super(identifier);
|
||||
this.stackToRender = stackToRender;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user