From a12c1a1355ec118cfeb27fbe1948f617d811e41f Mon Sep 17 00:00:00 2001 From: Lukas Rieger Date: Fri, 28 Nov 2025 20:56:09 +0100 Subject: [PATCH 1/2] Rework resource-pool and reduce overuse of ResourcePath --- .../bluemap/core/map/TextureGallery.java | 32 ++++----- .../map/hires/block/LiquidModelRenderer.java | 5 +- .../hires/block/ResourceModelRenderer.java | 5 +- .../hires/entity/ResourceModelRenderer.java | 3 +- .../bluemap/core/resources/ResourcePath.java | 6 +- .../core/resources/pack/ResourcePool.java | 69 +++++++------------ .../resourcepack/atlas/DirectorySource.java | 3 +- .../atlas/PalettedPermutationsSource.java | 17 +++-- .../pack/resourcepack/atlas/SingleSource.java | 12 ++-- .../pack/resourcepack/atlas/Source.java | 4 +- .../resourcepack/atlas/UnstitchSource.java | 7 +- .../resourcepack/model/TextureVariable.java | 2 +- .../pack/resourcepack/texture/Texture.java | 32 +++++---- 13 files changed, 90 insertions(+), 107 deletions(-) diff --git a/core/src/main/java/de/bluecolored/bluemap/core/map/TextureGallery.java b/core/src/main/java/de/bluecolored/bluemap/core/map/TextureGallery.java index c05637d1f..6197684b9 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/map/TextureGallery.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/map/TextureGallery.java @@ -25,7 +25,6 @@ package de.bluecolored.bluemap.core.map; import com.google.gson.*; -import de.bluecolored.bluemap.core.resources.ResourcePath; import de.bluecolored.bluemap.core.resources.adapter.ResourcesGson; import de.bluecolored.bluemap.core.resources.pack.ResourcePool; import de.bluecolored.bluemap.core.resources.pack.resourcepack.ResourcePack; @@ -46,7 +45,7 @@ public class TextureGallery { .setFieldNamingPolicy(FieldNamingPolicy.IDENTITY) .create(); - private final Map, TextureMapping> textureMappings; + private final Map textureMappings; private int nextId; public TextureGallery() { @@ -59,34 +58,33 @@ public void clear() { this.nextId = 0; } - public int get(@Nullable ResourcePath textureResourcePath) { + public int get(@Nullable Key textureResourcePath) { if (textureResourcePath == null) textureResourcePath = ResourcePack.MISSING_TEXTURE; TextureMapping mapping = textureMappings.get(textureResourcePath); return mapping != null ? mapping.getId() : 0; } - public synchronized void put(ResourcePath textureResourcePath) { - textureMappings.compute(textureResourcePath, (r, mapping) -> { + public synchronized void put(Key key, Texture texture) { + textureMappings.compute(key, (r, mapping) -> { if (mapping == null) - return new TextureMapping(nextId++, textureResourcePath.getResource()); - - Texture texture = textureResourcePath.getResource(); - if (texture != null) mapping.setTexture(texture); + return new TextureMapping(nextId++, texture); + else if (texture != null) mapping.setTexture(texture); return mapping; }); } public synchronized void put(ResourcePool texturePool) { - this.put(ResourcePack.MISSING_TEXTURE); // put this first - texturePool.paths() + this.put(ResourcePack.MISSING_TEXTURE, ResourcePack.MISSING_TEXTURE.getResource()); // put this first + texturePool.entrySet() .stream() .sorted(Comparator - .comparing((ResourcePath r) -> { - Texture texture = r.getResource(texturePool::get); + .comparing((Map.Entry entry) -> { + Texture texture = entry.getValue(); return texture != null && texture.getColorPremultiplied().a < 1f; }) - .thenComparing(Key::getFormatted)) - .forEach(this::put); + .thenComparing(entry -> entry.getKey().getFormatted()) + ) + .forEach(entry -> put(entry.getKey(), entry.getValue())); } public void writeTexturesFile(OutputStream out) throws IOException { @@ -115,8 +113,8 @@ public static TextureGallery readTexturesFile(InputStream in) throws IOException gallery.nextId = textures.length; for (int ordinal = 0; ordinal < textures.length; ordinal++) { Texture texture = textures[ordinal]; - if (texture != null) { - gallery.textureMappings.put(texture.getKey(), new TextureMapping(ordinal, texture)); + if (texture != null && texture.getKey() != null) { + gallery.textureMappings.putIfAbsent(texture.getKey(), new TextureMapping(ordinal, texture)); } } } catch (JsonParseException ex) { diff --git a/core/src/main/java/de/bluecolored/bluemap/core/map/hires/block/LiquidModelRenderer.java b/core/src/main/java/de/bluecolored/bluemap/core/map/hires/block/LiquidModelRenderer.java index e9cdafbe2..4d8cf9e54 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/map/hires/block/LiquidModelRenderer.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/map/hires/block/LiquidModelRenderer.java @@ -38,6 +38,7 @@ import de.bluecolored.bluemap.core.resources.pack.resourcepack.model.TextureVariable; import de.bluecolored.bluemap.core.resources.pack.resourcepack.texture.Texture; import de.bluecolored.bluemap.core.util.Direction; +import de.bluecolored.bluemap.core.util.Key; import de.bluecolored.bluemap.core.util.math.Color; import de.bluecolored.bluemap.core.util.math.MatrixM3f; import de.bluecolored.bluemap.core.util.math.VectorM2f; @@ -61,8 +62,8 @@ public class LiquidModelRenderer implements BlockRenderer { .scale(0.5f, 0.5f, 1) .translate(0.5f, 0.5f); - @Getter private final Function, Model> modelProvider; - @Getter private final Function, Texture> textureProvider; + @Getter private final Function modelProvider; + @Getter private final Function textureProvider; @Getter private final TextureGallery textureGallery; @Getter private final RenderSettings renderSettings; @Getter private final BlockColorCalculatorFactory.BlockColorCalculator blockColorCalculator; diff --git a/core/src/main/java/de/bluecolored/bluemap/core/map/hires/block/ResourceModelRenderer.java b/core/src/main/java/de/bluecolored/bluemap/core/map/hires/block/ResourceModelRenderer.java index 03aa280c2..65f92d957 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/map/hires/block/ResourceModelRenderer.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/map/hires/block/ResourceModelRenderer.java @@ -41,6 +41,7 @@ import de.bluecolored.bluemap.core.resources.pack.resourcepack.model.Model; import de.bluecolored.bluemap.core.resources.pack.resourcepack.texture.Texture; import de.bluecolored.bluemap.core.util.Direction; +import de.bluecolored.bluemap.core.util.Key; import de.bluecolored.bluemap.core.util.math.Color; import de.bluecolored.bluemap.core.util.math.MatrixM4f; import de.bluecolored.bluemap.core.util.math.VectorM2f; @@ -60,8 +61,8 @@ public class ResourceModelRenderer implements BlockRenderer { private static final float BLOCK_SCALE = 1f / 16f; - @Getter private final Function, Model> modelProvider; - @Getter private final Function, Texture> textureProvider; + @Getter private final Function modelProvider; + @Getter private final Function textureProvider; @Getter private final TextureGallery textureGallery; @Getter private final RenderSettings renderSettings; @Getter private final BlockColorCalculatorFactory.BlockColorCalculator blockColorCalculator; diff --git a/core/src/main/java/de/bluecolored/bluemap/core/map/hires/entity/ResourceModelRenderer.java b/core/src/main/java/de/bluecolored/bluemap/core/map/hires/entity/ResourceModelRenderer.java index b2bf905aa..8d51366e9 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/map/hires/entity/ResourceModelRenderer.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/map/hires/entity/ResourceModelRenderer.java @@ -38,6 +38,7 @@ import de.bluecolored.bluemap.core.resources.pack.resourcepack.model.Model; import de.bluecolored.bluemap.core.resources.pack.resourcepack.texture.Texture; import de.bluecolored.bluemap.core.util.Direction; +import de.bluecolored.bluemap.core.util.Key; import de.bluecolored.bluemap.core.util.math.Color; import de.bluecolored.bluemap.core.util.math.MatrixM4f; import de.bluecolored.bluemap.core.util.math.VectorM2f; @@ -56,7 +57,7 @@ public class ResourceModelRenderer implements EntityRenderer { private static final float SCALE = 1f / 16f; - @Getter private final Function, Model> modelProvider; + @Getter private final Function modelProvider; @Getter private final TextureGallery textureGallery; @Getter private final RenderSettings renderSettings; diff --git a/core/src/main/java/de/bluecolored/bluemap/core/resources/ResourcePath.java b/core/src/main/java/de/bluecolored/bluemap/core/resources/ResourcePath.java index c526c653b..e83ff0c90 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/resources/ResourcePath.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/resources/ResourcePath.java @@ -49,7 +49,7 @@ public ResourcePath(String formatted) { } public ResourcePath(String namespace, String value) { - super(namespace.toLowerCase(Locale.ROOT), value.toLowerCase(Locale.ROOT)); + super(namespace, value); } public ResourcePath(Key key) { @@ -57,7 +57,7 @@ public ResourcePath(Key key) { } public ResourcePath(Path filePath, int namespacePos, int valuePos) { - super(parsePath(filePath, namespacePos, valuePos).toLowerCase(Locale.ROOT)); + super(parsePath(filePath, namespacePos, valuePos)); } @Nullable @@ -66,7 +66,7 @@ public T getResource() { } @Nullable - public T getResource(Function, T> supplier) { + public T getResource(Function supplier) { if (resource == null) resource = supplier.apply(this); return resource; } diff --git a/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/ResourcePool.java b/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/ResourcePool.java index dce39e966..a4fcb5cfe 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/ResourcePool.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/ResourcePool.java @@ -25,75 +25,54 @@ package de.bluecolored.bluemap.core.resources.pack; import de.bluecolored.bluemap.core.logger.Logger; -import de.bluecolored.bluemap.core.resources.ResourcePath; import de.bluecolored.bluemap.core.util.Key; -import org.jetbrains.annotations.Nullable; import java.io.IOException; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; +import java.util.*; import java.util.function.BinaryOperator; +import java.util.function.Function; public class ResourcePool { - private final Map pool = new HashMap<>(); - private final Map> paths = new HashMap<>(); + private final Map resources = new HashMap<>(); - public void put(Key path, T value) { - put(new ResourcePath<>(path), value); + public T get(Key key) { + return resources.get(key); } - public synchronized void put(ResourcePath path, T value) { - pool.put(path, value); - paths.put(path, path); - path.setResource(value); + public void put(Key key, T value) { + Objects.requireNonNull(key, "key is null"); + resources.put(key, value); } - public void putIfAbsent(Key path, T value) { - putIfAbsent(new ResourcePath<>(path), value); + public void putIfAbsent(Key key, T value) { + Objects.requireNonNull(key, "key is null"); + resources.putIfAbsent(key, value); } - public synchronized void putIfAbsent(ResourcePath path, T value) { - if (pool.putIfAbsent(path, value) == null) { - paths.put(path, path); - path.setResource(value); - } + public boolean containsKey(Key key) { + return resources.containsKey(key); } - public Collection> paths() { - return paths.values(); + public void remove(Key key) { + resources.remove(key); } public Collection values() { - return pool.values(); - } - - public boolean contains(Key path) { - return paths.containsKey(path); - } - - public @Nullable T get(ResourcePath path) { - return pool.get(path); - } - - public @Nullable T get(Key path) { - ResourcePath rp = paths.get(path); - return rp == null ? null : rp.getResource(this::get); + return resources.values(); } - public synchronized void remove(Key path) { - ResourcePath removed = paths.remove(path); - if (removed != null) pool.remove(removed); + public Set> entrySet() { + return resources.entrySet(); } - public @Nullable ResourcePath getPath(Key path) { - return paths.get(path); + public Set keySet() { + return resources.keySet(); } - public void load(ResourcePath path, Loader loader) { + public void load(Key path, Loader loader) { try { - if (contains(path)) return; // don't load already present resources + if (this.containsKey(path)) return; // don't load already present resources T resource = loader.load(path); if (resource == null) return; // don't load missing resources @@ -104,7 +83,7 @@ public void load(ResourcePath path, Loader loader) { } } - public void load(ResourcePath path, Loader loader, BinaryOperator mergeFunction) { + public void load(Key path, Loader loader, BinaryOperator mergeFunction) { try { T resource = loader.load(path); if (resource == null) return; // don't load missing resources @@ -120,7 +99,7 @@ public void load(ResourcePath path, Loader loader, BinaryOperator merge } public interface Loader { - T load(ResourcePath resourcePath) throws IOException; + T load(Key resourcePath) throws IOException; } } diff --git a/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/atlas/DirectorySource.java b/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/atlas/DirectorySource.java index 1d238d0b1..9d049aeec 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/atlas/DirectorySource.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/atlas/DirectorySource.java @@ -24,7 +24,6 @@ */ package de.bluecolored.bluemap.core.resources.pack.resourcepack.atlas; -import de.bluecolored.bluemap.core.logger.Logger; import de.bluecolored.bluemap.core.resources.ResourcePath; import de.bluecolored.bluemap.core.resources.pack.ResourcePool; import de.bluecolored.bluemap.core.resources.pack.resourcepack.texture.Texture; @@ -83,7 +82,7 @@ public void load(Path root, ResourcePool textures, Predicate textu @Override @SneakyThrows - protected @Nullable Texture loadTexture(ResourcePath key, Path file) { + protected @Nullable Texture loadTexture(Key key, Path file) { return super.loadTexture(key, file); } diff --git a/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/atlas/PalettedPermutationsSource.java b/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/atlas/PalettedPermutationsSource.java index cc7efd833..072171358 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/atlas/PalettedPermutationsSource.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/atlas/PalettedPermutationsSource.java @@ -26,7 +26,6 @@ import com.google.gson.annotations.SerializedName; import de.bluecolored.bluemap.core.logger.Logger; -import de.bluecolored.bluemap.core.resources.ResourcePath; import de.bluecolored.bluemap.core.resources.pack.ResourcePool; import de.bluecolored.bluemap.core.resources.pack.resourcepack.texture.Texture; import de.bluecolored.bluemap.core.util.BufferedImageUtil; @@ -53,11 +52,11 @@ @SuppressWarnings({"unused", "FieldMayBeFinal"}) public class PalettedPermutationsSource extends Source { - private Set> textures; + private Set textures; private String separator = "_"; @SerializedName("palette_key") - private ResourcePath paletteKey; - private Map> permutations; + private Key paletteKey; + private Map permutations; @Override public void load(Path root, ResourcePool texturePool, Predicate textureFilter) throws IOException { @@ -66,7 +65,7 @@ public void load(Path root, ResourcePool texturePool, Predicate te if (permutations == null || permutations.isEmpty()) return; // textures - for (ResourcePath resource : textures) { + for (Key resource : textures) { texturePool.load(resource, rp -> { Path file = getFile(root, resource); return loadTexture(resource, file); @@ -80,7 +79,7 @@ public void load(Path root, ResourcePool texturePool, Predicate te }); // permutations - for (ResourcePath resource : permutations.values()) { + for (Key resource : permutations.values()) { texturePool.load(resource, rp -> { Path file = getFile(root, resource); return loadTexture(resource, file); @@ -118,7 +117,7 @@ public void bake(ResourcePool texturePool, Predicate textureFilter // generate textures Color tempColor = new Color(); - for (ResourcePath resource : textures) { + for (Key resource : textures) { Texture texture = texturePool.get(resource); if (texture == null) continue; BufferedImage image = texture.getTextureImage(); @@ -127,11 +126,11 @@ public void bake(ResourcePool texturePool, Predicate textureFilter String suffix = paletteEntry.getKey(); PaletteMap palette = paletteEntry.getValue(); - ResourcePath sprite = new ResourcePath<>( + Key sprite = new Key( resource.getNamespace(), resource.getValue() + separator + suffix ); - if (texturePool.contains(sprite)) continue; + if (texturePool.containsKey(sprite)) continue; if (!textureFilter.test(sprite)) continue; BufferedImage resultImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_ARGB); diff --git a/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/atlas/SingleSource.java b/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/atlas/SingleSource.java index d593d7ca1..465be94b5 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/atlas/SingleSource.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/atlas/SingleSource.java @@ -46,10 +46,10 @@ @SuppressWarnings("unused") public class SingleSource extends Source { - private ResourcePath resource; - private @Nullable ResourcePath sprite; + private Key resource; + private @Nullable Key sprite; - public SingleSource(ResourcePath resource) { + public SingleSource(Key resource) { this.resource = resource; } @@ -57,8 +57,8 @@ public SingleSource(ResourcePath resource) { public void load(Path root, ResourcePool textures, Predicate textureFilter) throws IOException { if (resource == null) return; - ResourcePath sprite = getSprite(); - if (textures.contains(sprite)) return; + Key sprite = getSprite(); + if (textures.containsKey(sprite)) return; if (!textureFilter.test(sprite)) return; Path file = getFile(root, resource); @@ -68,7 +68,7 @@ public void load(Path root, ResourcePool textures, Predicate textu if (texture != null) textures.put(sprite, texture); } - public ResourcePath getSprite() { + public Key getSprite() { return sprite == null ? resource : sprite; } diff --git a/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/atlas/Source.java b/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/atlas/Source.java index 35c976865..209fed8d5 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/atlas/Source.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/atlas/Source.java @@ -60,7 +60,7 @@ public void load(Path root, ResourcePool textures, Predicate textu public void bake(ResourcePool textures, Predicate textureFilter) throws IOException {} - protected @Nullable Texture loadTexture(ResourcePath key, Path file) throws IOException { + protected @Nullable Texture loadTexture(Key key, Path file) throws IOException { BufferedImage image = loadImage(file); if (image == null) return null; AnimationMeta animation = loadAnimation(file); @@ -82,7 +82,7 @@ public void bake(ResourcePool textures, Predicate textureFilter) t } } - protected Path getFile(Path root, ResourcePath key) { + protected Path getFile(Path root, Key key) { return root .resolve("assets") .resolve(key.getNamespace()) diff --git a/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/atlas/UnstitchSource.java b/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/atlas/UnstitchSource.java index 97d813267..34f98e439 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/atlas/UnstitchSource.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/atlas/UnstitchSource.java @@ -26,7 +26,6 @@ import com.google.gson.annotations.SerializedName; import de.bluecolored.bluemap.core.logger.Logger; -import de.bluecolored.bluemap.core.resources.ResourcePath; import de.bluecolored.bluemap.core.resources.pack.ResourcePool; import de.bluecolored.bluemap.core.resources.pack.resourcepack.texture.Texture; import de.bluecolored.bluemap.core.util.Key; @@ -49,7 +48,7 @@ @SuppressWarnings("unused") public class UnstitchSource extends Source { - private ResourcePath resource; + private Key resource; @SerializedName("divisor_x") private double divisorX; @SerializedName("divisor_y") private double divisorY; private Set regions; @@ -81,7 +80,7 @@ public void bake(ResourcePool textures, Predicate textureFilter) t for (Region region : regions) { if (region == null) continue; - if (textures.contains(region.sprite)) continue; + if (textures.containsKey(region.sprite)) continue; if (!textureFilter.test(region.sprite)) continue; try { @@ -124,7 +123,7 @@ public int hashCode() { @NoArgsConstructor(access = AccessLevel.PRIVATE) @AllArgsConstructor public static class Region { - private ResourcePath sprite; + private Key sprite; private double x; private double y; private double width; diff --git a/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/model/TextureVariable.java b/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/model/TextureVariable.java index 54d0ef8a2..78a438460 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/model/TextureVariable.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/model/TextureVariable.java @@ -110,7 +110,7 @@ public TextureVariable copy() { public void optimize(ResourcePool texturePool) { synchronized (TextureVariable.class) { if (texturePath != null) { - texturePath = texturePool.getPath(texturePath); + texturePath.getResource(texturePool::get); } } } diff --git a/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/texture/Texture.java b/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/texture/Texture.java index 9b6497470..22ead8e51 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/texture/Texture.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/texture/Texture.java @@ -26,6 +26,7 @@ import de.bluecolored.bluemap.core.resources.ResourcePath; import de.bluecolored.bluemap.core.util.BufferedImageUtil; +import de.bluecolored.bluemap.core.util.Key; import de.bluecolored.bluemap.core.util.Keyed; import de.bluecolored.bluemap.core.util.math.Color; import org.jetbrains.annotations.Nullable; @@ -38,11 +39,12 @@ import java.lang.ref.SoftReference; import java.util.Base64; +@SuppressWarnings("FieldMayBeFinal") public class Texture implements Keyed { private static final String TEXTURE_STRING_PREFIX = "data:image/png;base64,"; public static final Texture MISSING = new Texture( - new ResourcePath<>("bluemap", "missing"), + new Key("bluemap", "missing"), new Color().set(0.5f, 0f, 0.5f, 1.0f, false), false, "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAPklEQVR4Xu3MsQkAMAwDQe2/tFPnBB4gpLhG8MpkZpNkZ6AKZKAKZKAKZKAKZKAKZKAKZKAKWg0XD/UPnjg4MbX+EDdeTUwAAAAASUVORK5CYII=", @@ -50,7 +52,7 @@ public class Texture implements Keyed { null ); - private ResourcePath resourcePath; + private Key key; private Color color; private boolean halfTransparent; private String texture; @@ -59,14 +61,18 @@ public class Texture implements Keyed { private transient @Nullable Color colorPremultiplied; private transient SoftReference textureImage = new SoftReference<>(null); - @SuppressWarnings("unused") - private Texture() {} + private Texture() { + this.key = MISSING.key; + this.color = MISSING.color; + this.halfTransparent = false; + this.texture = MISSING.texture; + } private Texture( - ResourcePath resourcePath, Color color, boolean halfTransparent, + Key key, Color color, boolean halfTransparent, String texture, @Nullable AnimationMeta animation, @Nullable BufferedImage textureImage ) { - this.resourcePath = resourcePath; + this.key = new ResourcePath<>(key); this.color = color.straight(); this.halfTransparent = halfTransparent; this.texture = texture; @@ -74,8 +80,8 @@ private Texture( this.textureImage = new SoftReference<>(textureImage); } - private Texture(ResourcePath resourcePath) { - this.resourcePath = resourcePath; + private Texture(Key key) { + this.key = new ResourcePath<>(key); this.color = MISSING.color; this.halfTransparent = MISSING.halfTransparent; this.texture = MISSING.texture; @@ -83,8 +89,8 @@ private Texture(ResourcePath resourcePath) { } @Override - public ResourcePath getKey() { - return resourcePath; + public Key getKey() { + return key; } public Color getColorStraight() { @@ -126,11 +132,11 @@ public BufferedImage getTextureImage() throws IOException { return animation; } - public static Texture from(ResourcePath resourcePath, BufferedImage image) throws IOException { + public static Texture from(Key resourcePath, BufferedImage image) throws IOException { return from(resourcePath, image, null); } - public static Texture from(ResourcePath resourcePath, BufferedImage image, @Nullable AnimationMeta animation) throws IOException { + public static Texture from(Key resourcePath, BufferedImage image, @Nullable AnimationMeta animation) throws IOException { //check halfTransparency boolean halfTransparent = BufferedImageUtil.halfTransparent(image); @@ -146,7 +152,7 @@ public static Texture from(ResourcePath resourcePath, BufferedImage ima return new Texture(resourcePath, color, halfTransparent, base64, animation, image); } - public static Texture missing(ResourcePath resourcePath) { + public static Texture missing(Key resourcePath) { return new Texture(resourcePath); } From e26d1d3d1e3627af166715bfb0a7be92166d599c Mon Sep 17 00:00:00 2001 From: Lukas Rieger Date: Sun, 7 Dec 2025 23:59:40 +0100 Subject: [PATCH 2/2] Improve wording --- .../bluecolored/bluemap/core/resources/pack/ResourcePool.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/ResourcePool.java b/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/ResourcePool.java index a4fcb5cfe..e80593721 100644 --- a/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/ResourcePool.java +++ b/core/src/main/java/de/bluecolored/bluemap/core/resources/pack/ResourcePool.java @@ -41,12 +41,12 @@ public T get(Key key) { } public void put(Key key, T value) { - Objects.requireNonNull(key, "key is null"); + Objects.requireNonNull(key, "key can not be null"); resources.put(key, value); } public void putIfAbsent(Key key, T value) { - Objects.requireNonNull(key, "key is null"); + Objects.requireNonNull(key, "key can not be null"); resources.putIfAbsent(key, value); }