Skip to content

Commit 8ccba79

Browse files
Some fixes
1 parent f154ead commit 8ccba79

File tree

11 files changed

+43
-19
lines changed

11 files changed

+43
-19
lines changed

client/src/main/java/org/geysermc/rainbow/client/MinecraftAssetResolver.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.geysermc.rainbow.client;
22

3+
import com.mojang.blaze3d.platform.NativeImage;
34
import net.minecraft.client.Minecraft;
45
import net.minecraft.client.renderer.item.ClientItem;
56
import net.minecraft.client.renderer.texture.SpriteContents;
@@ -8,26 +9,31 @@
89
import net.minecraft.client.resources.model.EquipmentClientInfo;
910
import net.minecraft.client.resources.model.ModelManager;
1011
import net.minecraft.client.resources.model.ResolvedModel;
11-
import net.minecraft.data.AtlasIds;
1212
import net.minecraft.resources.ResourceKey;
1313
import net.minecraft.resources.ResourceLocation;
14+
import net.minecraft.server.packs.resources.ResourceManager;
1415
import net.minecraft.world.item.equipment.EquipmentAsset;
16+
import org.geysermc.rainbow.Rainbow;
17+
import org.geysermc.rainbow.RainbowIO;
1518
import org.geysermc.rainbow.client.accessor.ResolvedModelAccessor;
1619
import org.geysermc.rainbow.client.mixin.EntityRenderDispatcherAccessor;
1720
import org.geysermc.rainbow.mapping.AssetResolver;
1821
import org.geysermc.rainbow.mapping.texture.TextureResource;
1922
import org.geysermc.rainbow.mixin.SpriteContentsAccessor;
2023

24+
import java.io.InputStream;
2125
import java.util.Optional;
2226

2327
public class MinecraftAssetResolver implements AssetResolver {
2428
private final ModelManager modelManager;
2529
private final EquipmentAssetManager equipmentAssetManager;
30+
private final ResourceManager resourceManager;
2631
private final AtlasManager atlasManager;
2732

2833
public MinecraftAssetResolver(Minecraft minecraft) {
2934
modelManager = minecraft.getModelManager();
3035
equipmentAssetManager = ((EntityRenderDispatcherAccessor) minecraft.getEntityRenderDispatcher()).getEquipmentAssets();
36+
resourceManager = minecraft.getResourceManager();
3137
atlasManager = minecraft.getAtlasManager();
3238
}
3339

@@ -47,8 +53,19 @@ public Optional<EquipmentClientInfo> getEquipmentInfo(ResourceKey<EquipmentAsset
4753
}
4854

4955
@Override
50-
public Optional<TextureResource> getBlockTexture(ResourceLocation location) {
51-
SpriteContents contents = atlasManager.getAtlasOrThrow(AtlasIds.BLOCKS).getSprite(location).contents();
52-
return Optional.of(new TextureResource(((SpriteContentsAccessor) contents).getOriginalImage(), contents.width(), contents.height()));
56+
public Optional<TextureResource> getTexture(ResourceLocation atlas, ResourceLocation location) {
57+
if (atlas == null) {
58+
// Not in an atlas - so not animated, probably?
59+
return RainbowIO.safeIO(() -> {
60+
try (InputStream textureStream = resourceManager.open(Rainbow.decorateTextureLocation(location))) {
61+
return new TextureResource(NativeImage.read(textureStream));
62+
}
63+
});
64+
}
65+
SpriteContents contents = atlasManager.getAtlasOrThrow(atlas).getSprite(location).contents();
66+
NativeImage original = ((SpriteContentsAccessor) contents).getOriginalImage();
67+
NativeImage textureCopy = new NativeImage(original.getWidth(), original.getHeight(), false);
68+
textureCopy.copyFrom(original);
69+
return Optional.of(new TextureResource(textureCopy, contents.width(), contents.height()));
5370
}
5471
}

client/src/main/java/org/geysermc/rainbow/client/MinecraftPackSerializer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public MinecraftPackSerializer(Minecraft minecraft) {
2828
@Override
2929
public <T> CompletableFuture<?> saveJson(Codec<T> codec, T object, Path path) {
3030
DynamicOps<JsonElement> ops = RegistryOps.create(JsonOps.INSTANCE, registries);
31-
return CompletableFuture.runAsync(() -> RainbowIO.safeIO(() -> CodecUtil.trySaveJson(codec, object, path.resolveSibling(path.getFileName() + ".json"), ops)),
31+
return CompletableFuture.runAsync(() -> RainbowIO.safeIO(() -> CodecUtil.trySaveJson(codec, object, path, ops)),
3232
Util.backgroundExecutor().forName("PackSerializer-saveJson"));
3333
}
3434

client/src/main/java/org/geysermc/rainbow/client/PackManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public final class PackManager {
3535

3636
private static final Path EXPORT_DIRECTORY = FabricLoader.getInstance().getGameDir().resolve(Rainbow.MOD_ID);
3737
private static final Path PACK_DIRECTORY = Path.of("pack");
38-
private static final Path MAPPINGS_FILE = Path.of("geyser_mappings");
38+
private static final Path MAPPINGS_FILE = Path.of("geyser_mappings.json");
3939
private static final Path PACK_ZIP_FILE = Path.of("pack.zip");
4040
private static final Path REPORT_FILE = Path.of("report.txt");
4141

datagen/src/main/java/org/geysermc/rainbow/datagen/RainbowModelProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,8 @@ public Optional<EquipmentClientInfo> getEquipmentInfo(ResourceKey<EquipmentAsset
216216
}
217217

218218
@Override
219-
public Optional<TextureResource> getBlockTexture(ResourceLocation location) {
219+
public Optional<TextureResource> getTexture(ResourceLocation atlas, ResourceLocation location) {
220+
// We don't care about atlas since there are none loaded at datagen
220221
return resourceManager.getResource(Rainbow.decorateTextureLocation(location))
221222
.flatMap(resource -> RainbowIO.safeIO(() -> {
222223
Optional<AnimationMetadataSection> animationMetadata = resource.metadata().getSection(AnimationMetadataSection.TYPE);

rainbow/src/main/java/org/geysermc/rainbow/mapping/AssetResolver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ public interface AssetResolver {
1818

1919
Optional<EquipmentClientInfo> getEquipmentInfo(ResourceKey<EquipmentAsset> key);
2020

21-
Optional<TextureResource> getBlockTexture(ResourceLocation location);
21+
Optional<TextureResource> getTexture(ResourceLocation atlas, ResourceLocation location);
2222
}

rainbow/src/main/java/org/geysermc/rainbow/mapping/attachable/AttachableMapper.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
import net.minecraft.world.item.equipment.Equippable;
1111
import org.geysermc.rainbow.mapping.AssetResolver;
1212
import org.geysermc.rainbow.mapping.geometry.BedrockGeometryContext;
13-
import org.geysermc.rainbow.mapping.geometry.MappedGeometry;
1413
import org.geysermc.rainbow.mapping.texture.TextureHolder;
1514
import org.geysermc.rainbow.pack.attachable.BedrockAttachable;
1615

@@ -34,7 +33,7 @@ public static AttachableCreator mapItem(AssetResolver assetResolver, BedrockGeom
3433
.filter(assetInfo -> !assetInfo.getSecond().isEmpty())
3534
.map(assetInfo -> {
3635
ResourceLocation equipmentTexture = getTexture(assetInfo.getSecond(), getLayer(assetInfo.getFirst()));
37-
textureConsumer.accept(TextureHolder.createBuiltIn(equipmentTexture));
36+
textureConsumer.accept(TextureHolder.createBuiltIn(null, equipmentTexture));
3837
return BedrockAttachable.equipment(bedrockIdentifier, assetInfo.getFirst(), equipmentTexture.getPath());
3938
}))
4039
.map(attachable -> {

rainbow/src/main/java/org/geysermc/rainbow/mapping/geometry/BedrockGeometryContext.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import net.minecraft.client.renderer.block.model.TextureSlots;
44
import net.minecraft.client.resources.model.Material;
55
import net.minecraft.client.resources.model.ResolvedModel;
6+
import net.minecraft.data.AtlasIds;
67
import net.minecraft.resources.ResourceLocation;
78
import net.minecraft.world.item.ItemStack;
89
import org.geysermc.rainbow.Rainbow;
@@ -36,7 +37,7 @@ public static BedrockGeometryContext create(ResourceLocation bedrockIdentifier,
3637
if (layer0Texture != null) {
3738
geometry = Optional.empty();
3839
animation = Optional.empty();
39-
icon = TextureHolder.createBuiltIn(layer0Texture.texture());
40+
icon = TextureHolder.createBuiltIn(AtlasIds.BLOCKS, layer0Texture.texture());
4041
} else {
4142
// Unknown model (doesn't use layer0), so we immediately assume the geometry is custom
4243
// This check should probably be done differently (actually check if the model is 2D or 3D)

rainbow/src/main/java/org/geysermc/rainbow/mapping/texture/BuiltInTextureHolder.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,19 @@
1111
import java.util.Optional;
1212

1313
public class BuiltInTextureHolder extends TextureHolder {
14+
private final ResourceLocation atlas;
1415
private final ResourceLocation source;
1516

16-
public BuiltInTextureHolder(ResourceLocation location, ResourceLocation source) {
17+
public BuiltInTextureHolder(ResourceLocation location, ResourceLocation atlas, ResourceLocation source) {
1718
super(location);
19+
this.atlas = atlas;
1820
this.source = source;
1921
}
2022

2123
@Override
2224
public Optional<byte[]> load(AssetResolver assetResolver, ProblemReporter reporter) {
2325
return RainbowIO.safeIO(() -> {
24-
try (TextureResource texture = assetResolver.getBlockTexture(source).orElse(null)) {
26+
try (TextureResource texture = assetResolver.getTexture(atlas, source).orElse(null)) {
2527
Objects.requireNonNull(texture);
2628
try (NativeImage firstFrame = texture.getFirstFrame(false)) {
2729
return NativeImageUtil.writeToByteArray(firstFrame);

rainbow/src/main/java/org/geysermc/rainbow/mapping/texture/StitchedTextures.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ private static SpriteLoader.Preparations prepareStitching(Stream<ResourceLocatio
5555

5656
private static Optional<SpriteContents> readSpriteContents(ResourceLocation location, PackContext context) {
5757
return RainbowIO.safeIO(() -> {
58-
try (TextureResource texture = context.assetResolver().getBlockTexture(location).orElse(null)) {
58+
try (TextureResource texture = context.assetResolver().getTexture(AtlasIds.BLOCKS, location).orElse(null)) {
5959
if (texture != null) {
6060
return new SpriteContents(location, texture.sizeOfFrame(), texture.getFirstFrame(true));
6161
}

rainbow/src/main/java/org/geysermc/rainbow/mapping/texture/TextureHolder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ public static TextureHolder createCustom(ResourceLocation location, Supplier<Nat
3030
return new CustomTextureHolder(location, supplier);
3131
}
3232

33-
public static TextureHolder createBuiltIn(ResourceLocation location, ResourceLocation source) {
34-
return new BuiltInTextureHolder(location, source);
33+
public static TextureHolder createBuiltIn(ResourceLocation location, ResourceLocation atlas, ResourceLocation source) {
34+
return new BuiltInTextureHolder(location, atlas, source);
3535
}
3636

37-
public static TextureHolder createBuiltIn(ResourceLocation location) {
38-
return createBuiltIn(location, location);
37+
public static TextureHolder createBuiltIn(ResourceLocation atlas, ResourceLocation location) {
38+
return createBuiltIn(location, atlas, location);
3939
}
4040

4141
public static TextureHolder createNonExistent(ResourceLocation location) {

0 commit comments

Comments
 (0)