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

Some fixes

This commit is contained in:
Eclipse
2025-10-19 11:43:02 +00:00
parent f154eadc43
commit 8ccba795e7
11 changed files with 43 additions and 19 deletions

View File

@@ -18,5 +18,5 @@ public interface AssetResolver {
Optional<EquipmentClientInfo> getEquipmentInfo(ResourceKey<EquipmentAsset> key);
Optional<TextureResource> getBlockTexture(ResourceLocation location);
Optional<TextureResource> getTexture(ResourceLocation atlas, ResourceLocation location);
}

View File

@@ -10,7 +10,6 @@ import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.equipment.Equippable;
import org.geysermc.rainbow.mapping.AssetResolver;
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.pack.attachable.BedrockAttachable;
@@ -34,7 +33,7 @@ public class AttachableMapper {
.filter(assetInfo -> !assetInfo.getSecond().isEmpty())
.map(assetInfo -> {
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());
}))
.map(attachable -> {

View File

@@ -3,6 +3,7 @@ package org.geysermc.rainbow.mapping.geometry;
import net.minecraft.client.renderer.block.model.TextureSlots;
import net.minecraft.client.resources.model.Material;
import net.minecraft.client.resources.model.ResolvedModel;
import net.minecraft.data.AtlasIds;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import org.geysermc.rainbow.Rainbow;
@@ -36,7 +37,7 @@ public record BedrockGeometryContext(Optional<MappedGeometry> geometry,
if (layer0Texture != null) {
geometry = Optional.empty();
animation = Optional.empty();
icon = TextureHolder.createBuiltIn(layer0Texture.texture());
icon = TextureHolder.createBuiltIn(AtlasIds.BLOCKS, layer0Texture.texture());
} else {
// 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)

View File

@@ -11,17 +11,19 @@ import java.util.Objects;
import java.util.Optional;
public class BuiltInTextureHolder extends TextureHolder {
private final ResourceLocation atlas;
private final ResourceLocation source;
public BuiltInTextureHolder(ResourceLocation location, ResourceLocation source) {
public BuiltInTextureHolder(ResourceLocation location, ResourceLocation atlas, ResourceLocation source) {
super(location);
this.atlas = atlas;
this.source = source;
}
@Override
public Optional<byte[]> load(AssetResolver assetResolver, ProblemReporter reporter) {
return RainbowIO.safeIO(() -> {
try (TextureResource texture = assetResolver.getBlockTexture(source).orElse(null)) {
try (TextureResource texture = assetResolver.getTexture(atlas, source).orElse(null)) {
Objects.requireNonNull(texture);
try (NativeImage firstFrame = texture.getFirstFrame(false)) {
return NativeImageUtil.writeToByteArray(firstFrame);

View File

@@ -55,7 +55,7 @@ public record StitchedTextures(Map<String, TextureAtlasSprite> sprites, Supplier
private static Optional<SpriteContents> readSpriteContents(ResourceLocation location, PackContext context) {
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) {
return new SpriteContents(location, texture.sizeOfFrame(), texture.getFirstFrame(true));
}

View File

@@ -30,12 +30,12 @@ public abstract class TextureHolder {
return new CustomTextureHolder(location, supplier);
}
public static TextureHolder createBuiltIn(ResourceLocation location, ResourceLocation source) {
return new BuiltInTextureHolder(location, source);
public static TextureHolder createBuiltIn(ResourceLocation location, ResourceLocation atlas, ResourceLocation source) {
return new BuiltInTextureHolder(location, atlas, source);
}
public static TextureHolder createBuiltIn(ResourceLocation location) {
return createBuiltIn(location, location);
public static TextureHolder createBuiltIn(ResourceLocation atlas, ResourceLocation location) {
return createBuiltIn(location, atlas, location);
}
public static TextureHolder createNonExistent(ResourceLocation location) {

View File

@@ -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());
}
public TextureResource(NativeImage texture) {
this(texture, Optional.empty());
}
public NativeImage getFirstFrame(boolean copy) {
if (frameSize.isEmpty() && !copy) {
return texture;
}
FrameSize size = sizeOfFrame();
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;
}