diff --git a/BlueMapCommon/BlueMapVue b/BlueMapCommon/BlueMapVue index 0776e69c..be1c4b49 160000 --- a/BlueMapCommon/BlueMapVue +++ b/BlueMapCommon/BlueMapVue @@ -1 +1 @@ -Subproject commit 0776e69c88ed24e2d2f0141e616d0512a5482ac9 +Subproject commit be1c4b4939d88d8a8da166219c1968ec290e40ac diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/BlueMapService.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/BlueMapService.java index 80298a93..fe0f8889 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/BlueMapService.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/BlueMapService.java @@ -327,9 +327,6 @@ public synchronized ResourcePack getResourcePack() throws ConfigurationException resourcePack.loadResources(defaultResourceFile); resourcePack.bake(); - - StateDumper.global().dump(Path.of("dump.json")); - } catch (IOException | RuntimeException e) { throw new ConfigurationException("Failed to parse resources!\n" + "Is one of your resource-packs corrupted?", e); diff --git a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/web/MapStorageRequestHandler.java b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/web/MapStorageRequestHandler.java index c30efa05..320e4ee0 100644 --- a/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/web/MapStorageRequestHandler.java +++ b/BlueMapCommon/src/main/java/de/bluecolored/bluemap/common/web/MapStorageRequestHandler.java @@ -117,8 +117,8 @@ public HttpResponse handle(HttpRequest request) { // provide meta-data Matcher metaMatcher = META_PATTERN.matcher(path); if (metaMatcher.matches()) { - String mapId = tileMatcher.group(1); - String metaFilePath = tileMatcher.group(2); + String mapId = metaMatcher.group(1); + String metaFilePath = metaMatcher.group(2); Storage storage = mapStorageProvider.apply(mapId); if (storage != null) { @@ -191,7 +191,6 @@ private static long stringToTimestamp(String timeString) throws IllegalArgumentE int month = Calendar.JANUARY; switch (timeString.substring(8, 11)){ - case "Jan" : month = Calendar.JANUARY; break; case "Feb" : month = Calendar.FEBRUARY; break; case "Mar" : month = Calendar.MARCH; break; case "Apr" : month = Calendar.APRIL; break; diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/TextureGallery.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/TextureGallery.java index 1487f5d7..61eb1f90 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/TextureGallery.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/map/TextureGallery.java @@ -6,6 +6,7 @@ import de.bluecolored.bluemap.core.resources.adapter.ResourcesGson; import de.bluecolored.bluemap.core.resources.resourcepack.ResourcePack; import de.bluecolored.bluemap.core.resources.resourcepack.texture.Texture; +import org.jetbrains.annotations.Nullable; import java.io.*; import java.util.HashMap; @@ -22,7 +23,8 @@ public TextureGallery() { this.nextId = 0; } - public int get(ResourcePath textureResourcePath) { + public int get(@Nullable ResourcePath textureResourcePath) { + if (textureResourcePath == null) textureResourcePath = ResourcePack.MISSING_TEXTURE; Integer ordinal = ordinalMap.get(textureResourcePath); return ordinal != null ? ordinal : 0; } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/resourcepack/ResourcePack.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/resourcepack/ResourcePack.java index 349aae8f..87d8d88e 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/resourcepack/ResourcePack.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/resourcepack/ResourcePack.java @@ -41,7 +41,9 @@ public class ResourcePack { private final Map> blockStatePaths; private final Map, BlockState> blockStates; + private final Map> blockModelPaths; private final Map, BlockModel> blockModels; + private final Map> texturePaths; private final Map, Texture> textures; private final Map, BufferedImage> colormaps; @@ -54,7 +56,9 @@ public class ResourcePack { public ResourcePack() { this.blockStatePaths = new HashMap<>(); this.blockStates = new HashMap<>(); + this.blockModelPaths = new HashMap<>(); this.blockModels = new HashMap<>(); + this.texturePaths = new HashMap<>(); this.textures = new HashMap<>(); this.colormaps = new HashMap<>(); @@ -68,6 +72,11 @@ public ResourcePack() { .build(this::loadBlockProperties); } + @Nullable + public ResourcePath getBlockStatePath(String formatted) { + return blockStatePaths.get(formatted); + } + @Nullable public BlockState getBlockState(de.bluecolored.bluemap.core.world.BlockState blockState) { ResourcePath path = blockStatePaths.get(blockState.getFormatted()); @@ -84,6 +93,11 @@ public Map, BlockState> getBlockStates() { return blockStates; } + @Nullable + public ResourcePath getBlockModelPath(String formatted) { + return blockModelPaths.get(formatted); + } + @Nullable public BlockModel getBlockModel(ResourcePath path) { BlockModel blockModel = blockModels.get(path); @@ -94,6 +108,11 @@ public Map, BlockModel> getBlockModels() { return blockModels; } + @Nullable + public ResourcePath getTexturePath(String formatted) { + return texturePaths.get(formatted); + } + @Nullable public Texture getTexture(ResourcePath path) { Texture texture = textures.get(path); @@ -279,12 +298,23 @@ public synchronized void loadResources(Path root) throws IOException { public synchronized void bake() throws IOException { Logger.global.logInfo("Baking resources..."); - for (ResourcePath path : blockStates.keySet()) { - blockStatePaths.put(path.getFormatted(), path); + // fill path maps + blockStates.keySet().forEach(path -> blockStatePaths.put(path.getFormatted(), path)); + blockModels.keySet().forEach(path -> blockModelPaths.put(path.getFormatted(), path)); + textures.keySet().forEach(path -> texturePaths.put(path.getFormatted(), path)); + + // optimize references + for (BlockModel model : blockModels.values()) { + model.optimize(this); } + // apply model parents for (BlockModel model : blockModels.values()) { model.applyParent(this); + } + + // calculate model properties + for (BlockModel model : blockModels.values()) { model.calculateProperties(this); } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/resourcepack/blockmodel/BlockModel.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/resourcepack/blockmodel/BlockModel.java index 710ba14c..63f96c19 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/resourcepack/blockmodel/BlockModel.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/resourcepack/blockmodel/BlockModel.java @@ -7,9 +7,7 @@ import de.bluecolored.bluemap.core.util.Direction; import org.jetbrains.annotations.Nullable; -import java.util.HashMap; -import java.util.List; -import java.util.Map; +import java.util.*; @SuppressWarnings({"FieldMayBeFinal", "FieldCanBeLocal"}) @DebugDump @@ -56,6 +54,18 @@ public boolean isOccluding() { return occluding; } + public synchronized void optimize(ResourcePack resourcePack) { + for (var variable : this.textures.values()) { + variable.optimize(resourcePack); + } + + if (this.elements != null) { + for (var element : elements) { + element.optimize(resourcePack); + } + } + } + public synchronized void applyParent(ResourcePack resourcePack) { if (this.parent == null) return; @@ -72,8 +82,17 @@ public synchronized void applyParent(ResourcePack resourcePack) { if (parent != null) { parent.applyParent(resourcePack); - parent.textures.forEach(this.textures::putIfAbsent); - if (this.elements == null) this.elements = parent.elements; + parent.textures.forEach(this::applyTextureVariable); + if (this.elements == null && parent.elements != null) { + this.elements = new ArrayList<>(); + parent.elements.forEach(element -> this.elements.add(element.copy())); + } + } + } + + private synchronized void applyTextureVariable(String key, TextureVariable value) { + if (!this.textures.containsKey(key)) { + this.textures.put(key, value.copy()); } } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/resourcepack/blockmodel/Element.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/resourcepack/blockmodel/Element.java index 31c2ed72..3aefd895 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/resourcepack/blockmodel/Element.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/resourcepack/blockmodel/Element.java @@ -8,6 +8,7 @@ import com.google.gson.stream.JsonReader; import de.bluecolored.bluemap.core.debug.DebugDump; import de.bluecolored.bluemap.core.resources.AbstractTypeAdapterFactory; +import de.bluecolored.bluemap.core.resources.resourcepack.ResourcePack; import de.bluecolored.bluemap.core.util.Direction; import java.io.IOException; @@ -25,7 +26,17 @@ public class Element { private boolean shade = true; private EnumMap faces = new EnumMap<>(Direction.class); - private Element(){} + @SuppressWarnings("unused") + private Element() {} + + private Element(Element copyFrom) { + this.from = copyFrom.from; + this.to = copyFrom.to; + this.rotation = copyFrom.rotation; + this.shade = copyFrom.shade; + + copyFrom.faces.forEach((direction, face) -> this.faces.put(direction, face.copy())); + } private void init() { faces.forEach((direction, face) -> face.init(direction, this::calculateDefaultUV)); @@ -84,6 +95,10 @@ public EnumMap getFaces() { return faces; } + public Element copy() { + return new Element(this); + } + boolean isFullCube() { if (!(FULL_BLOCK_MIN.equals(from) && FULL_BLOCK_MAX.equals(to))) return false; for (Direction dir : Direction.values()) { @@ -92,6 +107,12 @@ boolean isFullCube() { return true; } + public void optimize(ResourcePack resourcePack) { + for (var face : faces.values()) { + face.optimize(resourcePack); + } + } + static class Adapter extends AbstractTypeAdapterFactory { public Adapter() { diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/resourcepack/blockmodel/Face.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/resourcepack/blockmodel/Face.java index 19d92fab..bf5d3d02 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/resourcepack/blockmodel/Face.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/resourcepack/blockmodel/Face.java @@ -2,8 +2,7 @@ import com.flowpowered.math.vector.Vector4f; import de.bluecolored.bluemap.core.debug.DebugDump; -import de.bluecolored.bluemap.core.resources.ResourcePath; -import de.bluecolored.bluemap.core.resources.resourcepack.texture.Texture; +import de.bluecolored.bluemap.core.resources.resourcepack.ResourcePack; import de.bluecolored.bluemap.core.util.Direction; import java.util.function.Function; @@ -12,7 +11,7 @@ @DebugDump public class Face { - private static final TextureVariable DEFAULT_TEXTURE = new TextureVariable((ResourcePath) null); + private static final TextureVariable DEFAULT_TEXTURE = new TextureVariable(ResourcePack.MISSING_TEXTURE); private Vector4f uv; private TextureVariable texture = DEFAULT_TEXTURE; @@ -20,7 +19,16 @@ public class Face { private int rotation = 0; private int tintindex = -1; - private Face(){} + @SuppressWarnings("unused") + private Face() {} + + private Face(Face copyFrom) { + this.uv = copyFrom.uv; + this.texture = copyFrom.texture.copy(); + this.cullface = copyFrom.cullface; + this.rotation = copyFrom.rotation; + this.tintindex = copyFrom.tintindex; + } void init(Direction direction, Function defaultUvCalculator) { if (cullface == null) cullface = direction; @@ -47,4 +55,11 @@ public int getTintindex() { return tintindex; } + public Face copy() { + return new Face(this); + } + + public void optimize(ResourcePack resourcePack) { + this.texture.optimize(resourcePack); + } } diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/resourcepack/blockmodel/TextureVariable.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/resourcepack/blockmodel/TextureVariable.java index 11b92cbb..cc7efed1 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/resourcepack/blockmodel/TextureVariable.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/resources/resourcepack/blockmodel/TextureVariable.java @@ -6,10 +6,12 @@ import com.google.gson.stream.JsonWriter; import de.bluecolored.bluemap.core.debug.DebugDump; import de.bluecolored.bluemap.core.resources.ResourcePath; +import de.bluecolored.bluemap.core.resources.resourcepack.ResourcePack; import de.bluecolored.bluemap.core.resources.resourcepack.texture.Texture; import org.jetbrains.annotations.Nullable; import java.io.IOException; +import java.util.Objects; import java.util.function.Function; @DebugDump @@ -21,8 +23,15 @@ public class TextureVariable { private transient volatile boolean isReference, isResolving; + private TextureVariable(TextureVariable copyFrom) { + this.referenceName = copyFrom.referenceName; + this.texturePath = copyFrom.texturePath; + this.isReference = copyFrom.isReference; + this.isResolving = copyFrom.isResolving; + } + public TextureVariable(String referenceName) { - this.referenceName = referenceName; + this.referenceName = Objects.requireNonNull(referenceName); this.texturePath = null; this.isReference = true; this.isResolving = false; @@ -30,7 +39,7 @@ public TextureVariable(String referenceName) { public TextureVariable(ResourcePath texturePath) { this.referenceName = null; - this.texturePath = texturePath; + this.texturePath = Objects.requireNonNull(texturePath); this.isReference = false; this.isResolving = false; } @@ -68,6 +77,7 @@ private ResourcePath resolveTexturePath(Function { @Override diff --git a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/Key.java b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/Key.java index ace6f944..5581390f 100644 --- a/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/Key.java +++ b/BlueMapCore/src/main/java/de/bluecolored/bluemap/core/util/Key.java @@ -44,12 +44,13 @@ public String getFormatted() { return formatted; } + @SuppressWarnings("StringEquality") @Override public boolean equals(Object o) { if (this == o) return true; if (o == null || getClass() != o.getClass()) return false; ResourcePath that = (ResourcePath) o; - return getFormatted().equals(that.getFormatted()); + return getFormatted() == that.getFormatted(); } @Override