mirror of
https://github.com/GeyserMC/Rainbow.git
synced 2025-12-19 14:59:16 +00:00
Some fixes
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package org.geysermc.rainbow.client;
|
package org.geysermc.rainbow.client;
|
||||||
|
|
||||||
|
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.SpriteContents;
|
||||||
@@ -8,26 +9,31 @@ 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.data.AtlasIds;
|
|
||||||
import net.minecraft.resources.ResourceKey;
|
import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
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.RainbowIO;
|
||||||
import org.geysermc.rainbow.client.accessor.ResolvedModelAccessor;
|
import org.geysermc.rainbow.client.accessor.ResolvedModelAccessor;
|
||||||
import org.geysermc.rainbow.client.mixin.EntityRenderDispatcherAccessor;
|
import org.geysermc.rainbow.client.mixin.EntityRenderDispatcherAccessor;
|
||||||
import org.geysermc.rainbow.mapping.AssetResolver;
|
import org.geysermc.rainbow.mapping.AssetResolver;
|
||||||
import org.geysermc.rainbow.mapping.texture.TextureResource;
|
import org.geysermc.rainbow.mapping.texture.TextureResource;
|
||||||
import org.geysermc.rainbow.mixin.SpriteContentsAccessor;
|
import org.geysermc.rainbow.mixin.SpriteContentsAccessor;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class MinecraftAssetResolver implements AssetResolver {
|
public class MinecraftAssetResolver implements AssetResolver {
|
||||||
private final ModelManager modelManager;
|
private final ModelManager modelManager;
|
||||||
private final EquipmentAssetManager equipmentAssetManager;
|
private final EquipmentAssetManager equipmentAssetManager;
|
||||||
|
private final ResourceManager resourceManager;
|
||||||
private final AtlasManager atlasManager;
|
private final AtlasManager atlasManager;
|
||||||
|
|
||||||
public MinecraftAssetResolver(Minecraft minecraft) {
|
public MinecraftAssetResolver(Minecraft minecraft) {
|
||||||
modelManager = minecraft.getModelManager();
|
modelManager = minecraft.getModelManager();
|
||||||
equipmentAssetManager = ((EntityRenderDispatcherAccessor) minecraft.getEntityRenderDispatcher()).getEquipmentAssets();
|
equipmentAssetManager = ((EntityRenderDispatcherAccessor) minecraft.getEntityRenderDispatcher()).getEquipmentAssets();
|
||||||
|
resourceManager = minecraft.getResourceManager();
|
||||||
atlasManager = minecraft.getAtlasManager();
|
atlasManager = minecraft.getAtlasManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -47,8 +53,19 @@ public class MinecraftAssetResolver implements AssetResolver {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<TextureResource> getBlockTexture(ResourceLocation location) {
|
public Optional<TextureResource> getTexture(ResourceLocation atlas, ResourceLocation location) {
|
||||||
SpriteContents contents = atlasManager.getAtlasOrThrow(AtlasIds.BLOCKS).getSprite(location).contents();
|
if (atlas == null) {
|
||||||
return Optional.of(new TextureResource(((SpriteContentsAccessor) contents).getOriginalImage(), contents.width(), contents.height()));
|
// Not in an atlas - so not animated, probably?
|
||||||
|
return RainbowIO.safeIO(() -> {
|
||||||
|
try (InputStream textureStream = resourceManager.open(Rainbow.decorateTextureLocation(location))) {
|
||||||
|
return new TextureResource(NativeImage.read(textureStream));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
SpriteContents contents = atlasManager.getAtlasOrThrow(atlas).getSprite(location).contents();
|
||||||
|
NativeImage original = ((SpriteContentsAccessor) contents).getOriginalImage();
|
||||||
|
NativeImage textureCopy = new NativeImage(original.getWidth(), original.getHeight(), false);
|
||||||
|
textureCopy.copyFrom(original);
|
||||||
|
return Optional.of(new TextureResource(textureCopy, contents.width(), contents.height()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class MinecraftPackSerializer implements PackSerializer {
|
|||||||
@Override
|
@Override
|
||||||
public <T> CompletableFuture<?> saveJson(Codec<T> codec, T object, Path path) {
|
public <T> CompletableFuture<?> saveJson(Codec<T> codec, T object, Path path) {
|
||||||
DynamicOps<JsonElement> ops = RegistryOps.create(JsonOps.INSTANCE, registries);
|
DynamicOps<JsonElement> ops = RegistryOps.create(JsonOps.INSTANCE, registries);
|
||||||
return CompletableFuture.runAsync(() -> RainbowIO.safeIO(() -> CodecUtil.trySaveJson(codec, object, path.resolveSibling(path.getFileName() + ".json"), ops)),
|
return CompletableFuture.runAsync(() -> RainbowIO.safeIO(() -> CodecUtil.trySaveJson(codec, object, path, ops)),
|
||||||
Util.backgroundExecutor().forName("PackSerializer-saveJson"));
|
Util.backgroundExecutor().forName("PackSerializer-saveJson"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ public final class PackManager {
|
|||||||
|
|
||||||
private static final Path EXPORT_DIRECTORY = FabricLoader.getInstance().getGameDir().resolve(Rainbow.MOD_ID);
|
private static final Path EXPORT_DIRECTORY = FabricLoader.getInstance().getGameDir().resolve(Rainbow.MOD_ID);
|
||||||
private static final Path PACK_DIRECTORY = Path.of("pack");
|
private static final Path PACK_DIRECTORY = Path.of("pack");
|
||||||
private static final Path MAPPINGS_FILE = Path.of("geyser_mappings");
|
private static final Path MAPPINGS_FILE = Path.of("geyser_mappings.json");
|
||||||
private static final Path PACK_ZIP_FILE = Path.of("pack.zip");
|
private static final Path PACK_ZIP_FILE = Path.of("pack.zip");
|
||||||
private static final Path REPORT_FILE = Path.of("report.txt");
|
private static final Path REPORT_FILE = Path.of("report.txt");
|
||||||
|
|
||||||
|
|||||||
@@ -216,7 +216,8 @@ public abstract class RainbowModelProvider extends FabricModelProvider {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<TextureResource> getBlockTexture(ResourceLocation location) {
|
public Optional<TextureResource> getTexture(ResourceLocation atlas, ResourceLocation location) {
|
||||||
|
// We don't care about atlas since there are none loaded at datagen
|
||||||
return resourceManager.getResource(Rainbow.decorateTextureLocation(location))
|
return resourceManager.getResource(Rainbow.decorateTextureLocation(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);
|
||||||
|
|||||||
@@ -18,5 +18,5 @@ public interface AssetResolver {
|
|||||||
|
|
||||||
Optional<EquipmentClientInfo> getEquipmentInfo(ResourceKey<EquipmentAsset> key);
|
Optional<EquipmentClientInfo> getEquipmentInfo(ResourceKey<EquipmentAsset> key);
|
||||||
|
|
||||||
Optional<TextureResource> getBlockTexture(ResourceLocation location);
|
Optional<TextureResource> getTexture(ResourceLocation atlas, ResourceLocation location);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import net.minecraft.world.entity.EquipmentSlot;
|
|||||||
import net.minecraft.world.item.equipment.Equippable;
|
import net.minecraft.world.item.equipment.Equippable;
|
||||||
import org.geysermc.rainbow.mapping.AssetResolver;
|
import org.geysermc.rainbow.mapping.AssetResolver;
|
||||||
import org.geysermc.rainbow.mapping.geometry.BedrockGeometryContext;
|
import org.geysermc.rainbow.mapping.geometry.BedrockGeometryContext;
|
||||||
import org.geysermc.rainbow.mapping.geometry.MappedGeometry;
|
|
||||||
import org.geysermc.rainbow.mapping.texture.TextureHolder;
|
import org.geysermc.rainbow.mapping.texture.TextureHolder;
|
||||||
import org.geysermc.rainbow.pack.attachable.BedrockAttachable;
|
import org.geysermc.rainbow.pack.attachable.BedrockAttachable;
|
||||||
|
|
||||||
@@ -34,7 +33,7 @@ public class AttachableMapper {
|
|||||||
.filter(assetInfo -> !assetInfo.getSecond().isEmpty())
|
.filter(assetInfo -> !assetInfo.getSecond().isEmpty())
|
||||||
.map(assetInfo -> {
|
.map(assetInfo -> {
|
||||||
ResourceLocation equipmentTexture = getTexture(assetInfo.getSecond(), getLayer(assetInfo.getFirst()));
|
ResourceLocation equipmentTexture = getTexture(assetInfo.getSecond(), getLayer(assetInfo.getFirst()));
|
||||||
textureConsumer.accept(TextureHolder.createBuiltIn(equipmentTexture));
|
textureConsumer.accept(TextureHolder.createBuiltIn(null, equipmentTexture));
|
||||||
return BedrockAttachable.equipment(bedrockIdentifier, assetInfo.getFirst(), equipmentTexture.getPath());
|
return BedrockAttachable.equipment(bedrockIdentifier, assetInfo.getFirst(), equipmentTexture.getPath());
|
||||||
}))
|
}))
|
||||||
.map(attachable -> {
|
.map(attachable -> {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package org.geysermc.rainbow.mapping.geometry;
|
|||||||
import net.minecraft.client.renderer.block.model.TextureSlots;
|
import net.minecraft.client.renderer.block.model.TextureSlots;
|
||||||
import net.minecraft.client.resources.model.Material;
|
import net.minecraft.client.resources.model.Material;
|
||||||
import net.minecraft.client.resources.model.ResolvedModel;
|
import net.minecraft.client.resources.model.ResolvedModel;
|
||||||
|
import net.minecraft.data.AtlasIds;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
import org.geysermc.rainbow.Rainbow;
|
import org.geysermc.rainbow.Rainbow;
|
||||||
@@ -36,7 +37,7 @@ public record BedrockGeometryContext(Optional<MappedGeometry> geometry,
|
|||||||
if (layer0Texture != null) {
|
if (layer0Texture != null) {
|
||||||
geometry = Optional.empty();
|
geometry = Optional.empty();
|
||||||
animation = Optional.empty();
|
animation = Optional.empty();
|
||||||
icon = TextureHolder.createBuiltIn(layer0Texture.texture());
|
icon = TextureHolder.createBuiltIn(AtlasIds.BLOCKS, layer0Texture.texture());
|
||||||
} else {
|
} else {
|
||||||
// Unknown model (doesn't use layer0), so we immediately assume the geometry is custom
|
// Unknown model (doesn't use layer0), so we immediately assume the geometry is custom
|
||||||
// This check should probably be done differently (actually check if the model is 2D or 3D)
|
// This check should probably be done differently (actually check if the model is 2D or 3D)
|
||||||
|
|||||||
@@ -11,17 +11,19 @@ import java.util.Objects;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public class BuiltInTextureHolder extends TextureHolder {
|
public class BuiltInTextureHolder extends TextureHolder {
|
||||||
|
private final ResourceLocation atlas;
|
||||||
private final ResourceLocation source;
|
private final ResourceLocation source;
|
||||||
|
|
||||||
public BuiltInTextureHolder(ResourceLocation location, ResourceLocation source) {
|
public BuiltInTextureHolder(ResourceLocation location, ResourceLocation atlas, ResourceLocation source) {
|
||||||
super(location);
|
super(location);
|
||||||
|
this.atlas = atlas;
|
||||||
this.source = source;
|
this.source = source;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Optional<byte[]> load(AssetResolver assetResolver, ProblemReporter reporter) {
|
public Optional<byte[]> load(AssetResolver assetResolver, ProblemReporter reporter) {
|
||||||
return RainbowIO.safeIO(() -> {
|
return RainbowIO.safeIO(() -> {
|
||||||
try (TextureResource texture = assetResolver.getBlockTexture(source).orElse(null)) {
|
try (TextureResource texture = assetResolver.getTexture(atlas, source).orElse(null)) {
|
||||||
Objects.requireNonNull(texture);
|
Objects.requireNonNull(texture);
|
||||||
try (NativeImage firstFrame = texture.getFirstFrame(false)) {
|
try (NativeImage firstFrame = texture.getFirstFrame(false)) {
|
||||||
return NativeImageUtil.writeToByteArray(firstFrame);
|
return NativeImageUtil.writeToByteArray(firstFrame);
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ public record StitchedTextures(Map<String, TextureAtlasSprite> sprites, Supplier
|
|||||||
|
|
||||||
private static Optional<SpriteContents> readSpriteContents(ResourceLocation location, PackContext context) {
|
private static Optional<SpriteContents> readSpriteContents(ResourceLocation location, PackContext context) {
|
||||||
return RainbowIO.safeIO(() -> {
|
return RainbowIO.safeIO(() -> {
|
||||||
try (TextureResource texture = context.assetResolver().getBlockTexture(location).orElse(null)) {
|
try (TextureResource texture = context.assetResolver().getTexture(AtlasIds.BLOCKS, location).orElse(null)) {
|
||||||
if (texture != null) {
|
if (texture != null) {
|
||||||
return new SpriteContents(location, texture.sizeOfFrame(), texture.getFirstFrame(true));
|
return new SpriteContents(location, texture.sizeOfFrame(), texture.getFirstFrame(true));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,12 +30,12 @@ public abstract class TextureHolder {
|
|||||||
return new CustomTextureHolder(location, supplier);
|
return new CustomTextureHolder(location, supplier);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TextureHolder createBuiltIn(ResourceLocation location, ResourceLocation source) {
|
public static TextureHolder createBuiltIn(ResourceLocation location, ResourceLocation atlas, ResourceLocation source) {
|
||||||
return new BuiltInTextureHolder(location, source);
|
return new BuiltInTextureHolder(location, atlas, source);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TextureHolder createBuiltIn(ResourceLocation location) {
|
public static TextureHolder createBuiltIn(ResourceLocation atlas, ResourceLocation location) {
|
||||||
return createBuiltIn(location, location);
|
return createBuiltIn(location, atlas, location);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TextureHolder createNonExistent(ResourceLocation location) {
|
public static TextureHolder createNonExistent(ResourceLocation location) {
|
||||||
|
|||||||
@@ -11,13 +11,17 @@ public record TextureResource(NativeImage texture, Optional<FrameSize> frameSize
|
|||||||
this(texture, texture.getWidth() != width || texture.getHeight() != height ? Optional.of(new FrameSize(width, height)) : Optional.empty());
|
this(texture, texture.getWidth() != width || texture.getHeight() != height ? Optional.of(new FrameSize(width, height)) : Optional.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public TextureResource(NativeImage texture) {
|
||||||
|
this(texture, Optional.empty());
|
||||||
|
}
|
||||||
|
|
||||||
public NativeImage getFirstFrame(boolean copy) {
|
public NativeImage getFirstFrame(boolean copy) {
|
||||||
if (frameSize.isEmpty() && !copy) {
|
if (frameSize.isEmpty() && !copy) {
|
||||||
return texture;
|
return texture;
|
||||||
}
|
}
|
||||||
FrameSize size = sizeOfFrame();
|
FrameSize size = sizeOfFrame();
|
||||||
NativeImage firstFrame = new NativeImage(size.width(), size.height(), false);
|
NativeImage firstFrame = new NativeImage(size.width(), size.height(), false);
|
||||||
texture.copyRect(firstFrame, 0, 0, 0, 0, size.width(), size.height(), false, false);
|
firstFrame.copyFrom(texture);
|
||||||
return firstFrame;
|
return firstFrame;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user