Skip to content

Commit 47021e3

Browse files
committed
Add initial support for 26.1 world and resource changes
1 parent c232a79 commit 47021e3

16 files changed

Lines changed: 254 additions & 101 deletions

File tree

common/src/main/java/de/bluecolored/bluemap/common/BlueMapService.java

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
import de.bluecolored.bluemap.core.util.FileHelper;
4040
import de.bluecolored.bluemap.core.util.Key;
4141
import de.bluecolored.bluemap.core.world.World;
42+
import de.bluecolored.bluemap.core.world.WorldLoader;
43+
import de.bluecolored.bluemap.core.world.WorldLoaderType;
4244
import de.bluecolored.bluemap.core.world.mca.MCAWorld;
4345
import org.jetbrains.annotations.Nullable;
4446

@@ -206,15 +208,16 @@ private synchronized void loadMap(String id, MapConfig mapConfig) throws Configu
206208
String worldId = World.id(worldFolder, dimension);
207209
World world = worlds.get(worldId);
208210
if (world == null) {
211+
WorldLoader worldLoader = mapConfig.getLoader();
212+
209213
try {
210214
Logger.global.logDebug("Loading world " + worldId + " ...");
211-
world = MCAWorld.load(worldFolder, dimension, loadDataPack(worldFolder));
215+
List<Path> worldPacks = worldLoader.worldDataPacks(worldFolder, dimension);
216+
DataPack dataPack = loadDataPack(worldPacks);
217+
world = MCAWorld.load(worldFolder, dimension, dataPack);
212218
worlds.put(worldId, world);
213219
} catch (IOException ex) {
214-
throw new ConfigurationException(
215-
"Failed to load world " + worldId + "!\n" +
216-
"Is the level.dat of that world present and not corrupted?",
217-
ex);
220+
throw new ConfigurationException("Failed to load world " + worldId + "!", ex);
218221
}
219222
}
220223

@@ -310,23 +313,12 @@ public synchronized ResourcePack getOrLoadResourcePack() throws ConfigurationExc
310313
return this.resourcePack;
311314
}
312315

313-
public synchronized DataPack loadDataPack(Path worldFolder) throws ConfigurationException, InterruptedException {
316+
public synchronized DataPack loadDataPack(List<Path> worldPacks) throws ConfigurationException, InterruptedException {
314317
MinecraftVersion minecraftVersion = getOrLoadMinecraftVersion();
315318
Path vanillaDataPack = minecraftVersion.getDataPack();
316319

317320
if (Thread.interrupted()) throw new InterruptedException();
318321

319-
// also load world datapacks
320-
Iterable<Path> worldPacks = List.of();
321-
Path worldPacksFolder = worldFolder.resolve("datapacks");
322-
if (Files.isDirectory(worldPacksFolder)) {
323-
try (Stream<Path> worldPacksStream = Files.list(worldPacksFolder)) {
324-
worldPacks = worldPacksStream.toList();
325-
} catch (IOException e) {
326-
throw new ConfigurationException("Failed to access the worlds datapacks folder.", e);
327-
}
328-
}
329-
330322
Deque<Path> packRoots = getPackRoots(worldPacks);
331323
packRoots.addLast(vanillaDataPack);
332324

common/src/main/java/de/bluecolored/bluemap/common/commands/commands/DebugCommand.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,6 @@ public Component block(CommandSource source, World world, @Argument("x") int x,
134134
item("world", text(world.getId()).color(HIGHLIGHT_COLOR)
135135
.appendNewline()
136136
.append(details(BASE_COLOR,
137-
item("name", world.getName()),
138137
item("min-y", world.getDimensionType().getMinY()),
139138
item("height", world.getDimensionType().getHeight())
140139
))

common/src/main/java/de/bluecolored/bluemap/common/config/ConfigManager.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import de.bluecolored.bluemap.core.BlueMap;
3333
import de.bluecolored.bluemap.core.map.mask.CombinedMask;
3434
import de.bluecolored.bluemap.core.util.Key;
35+
import de.bluecolored.bluemap.core.world.WorldLoaderType;
3536
import de.bluecolored.bluenbt.TypeToken;
3637
import org.spongepowered.configurate.ConfigurateException;
3738
import org.spongepowered.configurate.ConfigurationNode;
@@ -165,6 +166,7 @@ private ConfigurationLoader<? extends ConfigurationNode> getLoader(Path path){
165166
b.register(Vector2d.class, new Vector2dTypeSerializer());
166167
b.register(Key.class, new KeyTypeSerializer());
167168
b.register(CombinedMask.class, new CombinedMaskSerializer());
169+
b.register(WorldLoaderType.class, new RegistryTypeSerializer<>(WorldLoaderType.REGISTRY, Key.BLUEMAP_NAMESPACE, WorldLoaderType.ANVIL));
168170

169171
// ignore missing @ConfigSerializable annotation for subtypes of the following types
170172
b.register(type -> TypeToken.of(type).is( StorageConfig.class ), new ObjectMapperSerializer());

common/src/main/java/de/bluecolored/bluemap/common/config/MapConfig.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import de.bluecolored.bluemap.core.map.MapSettings;
3636
import de.bluecolored.bluemap.core.map.mask.CombinedMask;
3737
import de.bluecolored.bluemap.core.util.Key;
38+
import de.bluecolored.bluemap.core.world.WorldLoaderType;
3839
import lombok.AccessLevel;
3940
import lombok.Getter;
4041
import org.jetbrains.annotations.Nullable;
@@ -53,6 +54,7 @@
5354
@Getter
5455
public class MapConfig implements MapSettings {
5556

57+
private WorldLoaderType loader = WorldLoaderType.ANVIL;
5658
@Nullable private Path world = null;
5759
@Nullable private Key dimension = null;
5860

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
/*
2+
* This file is part of BlueMap, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) Blue (Lukas Rieger) <https://bluecolored.de>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package de.bluecolored.bluemap.common.config.typeserializer;
26+
27+
import de.bluecolored.bluemap.core.util.Key;
28+
import de.bluecolored.bluemap.core.util.Keyed;
29+
import de.bluecolored.bluemap.core.util.Registry;
30+
import lombok.RequiredArgsConstructor;
31+
import org.jetbrains.annotations.Nullable;
32+
import org.spongepowered.configurate.ConfigurationNode;
33+
import org.spongepowered.configurate.serialize.SerializationException;
34+
import org.spongepowered.configurate.serialize.TypeSerializer;
35+
36+
import java.lang.reflect.Type;
37+
38+
@RequiredArgsConstructor
39+
public class RegistryTypeSerializer<T extends Keyed> implements TypeSerializer<T> {
40+
41+
private final Registry<T> registry;
42+
private final String defaultNamespace;
43+
private final T defaultValue;
44+
45+
@Override
46+
public T deserialize(Type type, ConfigurationNode node) throws SerializationException {
47+
String keyString = node.getString();
48+
if (keyString == null) return defaultValue;
49+
50+
Key key = Key.parse(keyString, defaultNamespace);
51+
T value = registry.get(key);
52+
if (value != null) return value;
53+
54+
throw new SerializationException("Unknown key '" + keyString + "' for type '" + type.getTypeName() + "'");
55+
}
56+
57+
@Override
58+
public void serialize(Type type, @Nullable T obj, ConfigurationNode node) throws SerializationException {
59+
if (obj == null) return;
60+
node.set(obj.getKey().getFormatted());
61+
}
62+
63+
}

core/src/main/java/de/bluecolored/bluemap/core/map/hires/RenderPassType.java

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,14 @@
2424
*/
2525
package de.bluecolored.bluemap.core.map.hires;
2626

27-
import de.bluecolored.bluemap.core.map.TextureGallery;
2827
import de.bluecolored.bluemap.core.map.hires.block.BlockRenderPass;
2928
import de.bluecolored.bluemap.core.map.hires.entity.EntityRenderPass;
30-
import de.bluecolored.bluemap.core.resources.pack.resourcepack.ResourcePack;
3129
import de.bluecolored.bluemap.core.util.Key;
3230
import de.bluecolored.bluemap.core.util.Keyed;
3331
import de.bluecolored.bluemap.core.util.Registry;
3432
import lombok.Getter;
3533
import lombok.RequiredArgsConstructor;
34+
import lombok.experimental.Delegate;
3635

3736
public interface RenderPassType extends Keyed, RenderPassFactory {
3837

@@ -47,14 +46,8 @@ public interface RenderPassType extends Keyed, RenderPassFactory {
4746
@RequiredArgsConstructor
4847
class Impl implements RenderPassType {
4948

50-
@Getter
51-
private final Key key;
52-
private final RenderPassFactory factory;
53-
54-
@Override
55-
public RenderPass create(ResourcePack resourcePack, TextureGallery textureGallery, RenderSettings renderSettings) {
56-
return factory.create(resourcePack, textureGallery, renderSettings);
57-
}
49+
@Getter private final Key key;
50+
@Delegate private final RenderPassFactory factory;
5851

5952
}
6053

core/src/main/java/de/bluecolored/bluemap/core/map/hires/block/BlockRendererType.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,13 @@
2424
*/
2525
package de.bluecolored.bluemap.core.map.hires.block;
2626

27-
import de.bluecolored.bluemap.core.map.TextureGallery;
28-
import de.bluecolored.bluemap.core.map.hires.RenderSettings;
29-
import de.bluecolored.bluemap.core.resources.pack.resourcepack.ResourcePack;
3027
import de.bluecolored.bluemap.core.util.Key;
3128
import de.bluecolored.bluemap.core.util.Keyed;
3229
import de.bluecolored.bluemap.core.util.Registry;
3330
import de.bluecolored.bluemap.core.world.BlockState;
3431
import lombok.Getter;
3532
import lombok.RequiredArgsConstructor;
33+
import lombok.experimental.Delegate;
3634

3735
public interface BlockRendererType extends Keyed, BlockRendererFactory {
3836

@@ -68,12 +66,7 @@ default boolean isFallbackFor(BlockState blockState) {
6866
class Impl implements BlockRendererType {
6967

7068
@Getter private final Key key;
71-
private final BlockRendererFactory rendererFactory;
72-
73-
@Override
74-
public BlockRenderer create(ResourcePack resourcePack, TextureGallery textureGallery, RenderSettings renderSettings) {
75-
return rendererFactory.create(resourcePack, textureGallery, renderSettings);
76-
}
69+
@Delegate private final BlockRendererFactory rendererFactory;
7770

7871
}
7972

core/src/main/java/de/bluecolored/bluemap/core/map/hires/entity/EntityRendererType.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,12 @@
2424
*/
2525
package de.bluecolored.bluemap.core.map.hires.entity;
2626

27-
import de.bluecolored.bluemap.core.map.TextureGallery;
28-
import de.bluecolored.bluemap.core.map.hires.RenderSettings;
29-
import de.bluecolored.bluemap.core.map.hires.block.LiquidModelRenderer;
30-
import de.bluecolored.bluemap.core.resources.pack.resourcepack.ResourcePack;
3127
import de.bluecolored.bluemap.core.util.Key;
3228
import de.bluecolored.bluemap.core.util.Keyed;
3329
import de.bluecolored.bluemap.core.util.Registry;
34-
import de.bluecolored.bluemap.core.world.BlockState;
3530
import lombok.Getter;
3631
import lombok.RequiredArgsConstructor;
32+
import lombok.experimental.Delegate;
3733

3834
public interface EntityRendererType extends Keyed, EntityRendererFactory {
3935

@@ -65,12 +61,7 @@ default boolean isFallbackFor(Key entityType) {
6561
class Impl implements EntityRendererType {
6662

6763
@Getter private final Key key;
68-
private final EntityRendererFactory rendererFactory;
69-
70-
@Override
71-
public EntityRenderer create(ResourcePack resourcePack, TextureGallery textureGallery, RenderSettings renderSettings) {
72-
return rendererFactory.create(resourcePack, textureGallery, renderSettings);
73-
}
64+
@Delegate private final EntityRendererFactory rendererFactory;
7465

7566
}
7667

core/src/main/java/de/bluecolored/bluemap/core/resources/pack/resourcepack/model/TextureVariable.java

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,12 @@
2727
import com.google.gson.TypeAdapter;
2828
import com.google.gson.annotations.JsonAdapter;
2929
import com.google.gson.stream.JsonReader;
30+
import com.google.gson.stream.JsonToken;
3031
import com.google.gson.stream.JsonWriter;
3132
import de.bluecolored.bluemap.core.resources.ResourcePath;
3233
import de.bluecolored.bluemap.core.resources.pack.ResourcePool;
33-
import de.bluecolored.bluemap.core.resources.pack.resourcepack.ResourcePack;
3434
import de.bluecolored.bluemap.core.resources.pack.resourcepack.texture.Texture;
3535
import lombok.Getter;
36-
import lombok.Setter;
3736
import org.jetbrains.annotations.Nullable;
3837

3938
import java.io.IOException;
@@ -124,7 +123,32 @@ public void write(JsonWriter out, TextureVariable value) throws IOException {
124123

125124
@Override
126125
public TextureVariable read(JsonReader in) throws IOException {
127-
String value = in.nextString();
126+
TextureVariable result = null;
127+
128+
JsonToken token = in.peek();
129+
switch (token) {
130+
case JsonToken.STRING -> {
131+
result = fromString(in.nextString());
132+
}
133+
case JsonToken.BEGIN_OBJECT -> {
134+
in.beginObject();
135+
while (in.peek() != JsonToken.END_OBJECT) {
136+
String key = in.nextName();
137+
switch (key) {
138+
case "sprite" -> result = fromString(in.nextString());
139+
default -> in.skipValue();
140+
}
141+
}
142+
in.endObject();
143+
}
144+
default -> throw new IOException("Failed ot parse TextureVariable: Expected STRING or OBJECT but got " + token);
145+
}
146+
147+
if (result == null) throw new IOException("Failed ot parse TextureVariable: No sprite provided");
148+
return result;
149+
}
150+
151+
private TextureVariable fromString(String value) throws IOException {
128152
if (value.isEmpty()) throw new IOException("Can't parse an empty String into a TextureVariable");
129153

130154
if (value.charAt(0) == '#') {

core/src/main/java/de/bluecolored/bluemap/core/world/World.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ public interface World {
4747

4848
String getId();
4949

50-
String getName();
51-
5250
DimensionType getDimensionType();
5351

5452
Grid getChunkGrid();
@@ -110,16 +108,16 @@ default void preloadRegionChunks(int x, int z) {
110108
void iterateEntities(int minX, int minZ, int maxX, int maxZ, Consumer<Entity> entityConsumer);
111109

112110
/**
113-
* Generates a unique world-id based on a world-folder and a dimension
111+
* Generates a unique world-id based on a path and a dimension
114112
*/
115-
static String id(Path worldFolder, Key dimension) {
116-
worldFolder = worldFolder.toAbsolutePath().normalize();
113+
static String id(Path path, Key dimension) {
114+
path = path.toAbsolutePath().normalize();
117115

118116
Path workingDir = Path.of("").toAbsolutePath().normalize();
119-
if (worldFolder.startsWith(workingDir))
120-
worldFolder = workingDir.relativize(worldFolder);
117+
if (path.startsWith(workingDir))
118+
path = workingDir.relativize(path);
121119

122-
return worldFolder + "#" + dimension.getFormatted();
120+
return path + "#" + dimension.getFormatted();
123121
}
124122

125123
}

0 commit comments

Comments
 (0)