Skip to content

Commit

Permalink
feat: update to minestom main repo
Browse files Browse the repository at this point in the history
  • Loading branch information
mworzala committed Feb 12, 2024
1 parent 7299025 commit 4ad3d97
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repositories {
}

dependencies {
val minestom = libs.minestomSnapshot
val minestom = libs.minestom

compileOnly(minestom)
implementation(libs.zstd)
Expand Down
6 changes: 2 additions & 4 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
metadata.format.version = "1.1"

[versions]
minestom = "9f3ee89506"
minestomSnapshot = "1_20_4-615248dc5b"
minestom = "7320437640"
zstd = "1.5.5-3"
fastutil = "8.5.12"

nexuspublish = "1.3.0"

[libraries]
minestom = { group = "dev.hollowcube", name = "minestom-ce", version.ref = "minestom" }
minestomSnapshot = { group = "dev.hollowcube", name = "minestom-ce-snapshots", version.ref = "minestomSnapshot" }
minestom = { group = "net.minestom", name = "minestom-snapshots", version.ref = "minestom" }
zstd = { group = "com.github.luben", name = "zstd-jni", version.ref = "zstd" }
fastutil = { group = "it.unimi.dsi", name = "fastutil", version.ref = "fastutil" }

Expand Down
24 changes: 18 additions & 6 deletions src/main/java/net/hollowcube/polar/PolarLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import net.minestom.server.instance.block.BlockManager;
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.world.biomes.Biome;
import net.minestom.server.world.biomes.BiomeManager;
import net.minestom.server.world.biomes.VanillaBiome;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -33,13 +35,16 @@
@SuppressWarnings("UnstableApiUsage")
public class PolarLoader implements IChunkLoader {
private static final BlockManager BLOCK_MANAGER = MinecraftServer.getBlockManager();
private static final BiomeManager BIOME_MANAGER = MinecraftServer.getBiomeManager();
private static final ExceptionManager EXCEPTION_HANDLER = MinecraftServer.getExceptionManager();
static final Logger logger = LoggerFactory.getLogger(PolarLoader.class);

// Account for changes between main Minestom and minestom-ce.
private static final ChunkSupplierShim CHUNK_SUPPLIER = ChunkSupplierShim.select();

private final Map<String, Biome> biomeReadCache = new ConcurrentHashMap<>();
private static final int PLAINS_BIOME_ID = BIOME_MANAGER.getId(VanillaBiome.PLAINS);

private final Map<String, Integer> biomeReadCache = new ConcurrentHashMap<>();
private final Map<Integer, String> biomeWriteCache = new ConcurrentHashMap<>();

private final Path savePath;
Expand Down Expand Up @@ -189,12 +194,19 @@ private void loadSection(@NotNull PolarSection sectionData, @NotNull Section sec

// Biomes
var rawBiomePalette = sectionData.biomePalette();
var biomePalette = new Biome[rawBiomePalette.length];
var biomePalette = new int[rawBiomePalette.length];
for (int i = 0; i < rawBiomePalette.length; i++) {
biomePalette[i] = biomeReadCache.computeIfAbsent(rawBiomePalette[i], worldAccess::getBiome);
biomePalette[i] = biomeReadCache.computeIfAbsent(rawBiomePalette[i], name -> {
var biomeId = BIOME_MANAGER.getId(worldAccess.getBiome(name));
if (biomeId == -1) {
logger.error("Failed to find biome: {}", name);
biomeId = PLAINS_BIOME_ID;
}
return biomeId;
});
}
if (biomePalette.length == 1) {
section.biomePalette().fill(biomePalette[0].id());
section.biomePalette().fill(biomePalette[0]);
} else {
final var paletteData = sectionData.biomeData();
section.biomePalette().setAll((x, y, z) -> {
Expand All @@ -204,10 +216,10 @@ private void loadSection(@NotNull PolarSection sectionData, @NotNull Section sec
if (paletteIndex >= biomePalette.length) {
logger.error("Invalid biome palette index. This is probably a corrupted world, " +
"but it has been loaded with plains instead. No data has been written.");
return Biome.PLAINS.id();
return PLAINS_BIOME_ID;
}

return biomePalette[paletteIndex].id();
return biomePalette[paletteIndex];
});
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/net/hollowcube/polar/PolarReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@

@SuppressWarnings("UnstableApiUsage")
public class PolarReader {
private static final boolean FORCE_LEGACY_NBT = Boolean.getBoolean("polar.debug.force-legacy-nbt");

private PolarReader() {}

public static @NotNull PolarWorld read(byte @NotNull [] data) {
Expand Down Expand Up @@ -136,7 +138,7 @@ private PolarReader() {}

NBTCompound nbt = null;
if (version <= PolarWorld.VERSION_USERDATA_OPT_BLOCK_ENT_NBT || buffer.read(BOOLEAN)) {
if (version <= PolarWorld.VERSION_MINESTOM_NBT_READ_BREAK) {
if (version <= PolarWorld.VERSION_MINESTOM_NBT_READ_BREAK || FORCE_LEGACY_NBT) {
nbt = (NBTCompound) legacyReadNBT(buffer);
} else {
nbt = (NBTCompound) buffer.read(NBT);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/hollowcube/polar/PolarWorldAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import net.minestom.server.network.NetworkBuffer;
import net.minestom.server.utils.NamespaceID;
import net.minestom.server.world.biomes.Biome;
import net.minestom.server.world.biomes.BiomeManager;
import net.minestom.server.world.biomes.VanillaBiome;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand Down Expand Up @@ -75,7 +75,7 @@ default void saveChunkData(@NotNull Chunk chunk, @NotNull NetworkBuffer userData
var biome = MinecraftServer.getBiomeManager().getByName(NamespaceID.from(name));
if (biome == null) {
PolarLoader.logger.error("Failed to find biome: {}", name);
biome = Biome.PLAINS;
biome = VanillaBiome.PLAINS;
}
return biome;
}
Expand All @@ -84,9 +84,9 @@ default void saveChunkData(@NotNull Chunk chunk, @NotNull NetworkBuffer userData
var biome = MinecraftServer.getBiomeManager().getById(id);
if (biome == null) {
PolarLoader.logger.error("Failed to find biome: {}", id);
biome = Biome.PLAINS;
biome = VanillaBiome.PLAINS;
}
return biome.name().asString();
return biome.name();
}

}

0 comments on commit 4ad3d97

Please sign in to comment.