Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Registerable WorldFormat api #1795

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions chunky/src/java/se/llbit/chunky/chunk/biome/BiomeData2d.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package se.llbit.chunky.chunk.biome;

import se.llbit.chunky.world.JavaChunk;
import se.llbit.chunky.world.biome.BiomePalette;
import se.llbit.chunky.world.biome.Biomes;
import se.llbit.nbt.Tag;
Expand Down Expand Up @@ -34,7 +35,7 @@ public void clear() {
}

public static void loadBiomeDataByteArray(Tag chunkData, BiomeData2d biomeData, BiomePalette biomePalette) {
byte[] data = chunkData.get(LEVEL_BIOMES).byteArray();
byte[] data = chunkData.get(JavaChunk.LEVEL_BIOMES).byteArray();
int i = 0;
for(int z = 0; z < Z_MAX; z++) {
for(int x = 0; x < X_MAX; x++) {
Expand All @@ -46,7 +47,7 @@ public static void loadBiomeDataByteArray(Tag chunkData, BiomeData2d biomeData,

public static void loadBiomeDataIntArray(Tag chunkData, BiomeData2d biomeData, BiomePalette biomePalette) {
// Since Minecraft 1.13, biome IDs are stored in an int vector with 256 entries (one for each XZ position).
int[] data = chunkData.get(LEVEL_BIOMES).intArray();
int[] data = chunkData.get(JavaChunk.LEVEL_BIOMES).intArray();
int i = 0;
for(int z = 0; z < Z_MAX; z++) {
for(int x = 0; x < X_MAX; x++) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package se.llbit.chunky.chunk.biome;

import se.llbit.chunky.chunk.ChunkData;
import se.llbit.chunky.world.JavaChunk;
import se.llbit.chunky.world.biome.Biome;
import se.llbit.chunky.world.biome.BiomePalette;
import se.llbit.chunky.world.biome.Biomes;
Expand All @@ -19,7 +20,7 @@ public class BiomeDataFactory {
//TODO: Ideally we would have registered factory impls with an isValidFor(Tag chunkTag), but this messy if chain works for now
public static void loadBiomeData(ChunkData chunkData, Tag chunkTag, BiomePalette biomePalette, int yMin, int yMax) {
BiomeData biomeData = chunkData.getBiomeData();
Tag biomeTagsPre21w39a = chunkTag.get(LEVEL_BIOMES);
Tag biomeTagsPre21w39a = chunkTag.get(JavaChunk.LEVEL_BIOMES);
if (!biomeTagsPre21w39a.isError()) { // pre21w39a tag exists
if (biomeTagsPre21w39a.isByteArray(X_MAX * Z_MAX)) {
if (!(biomeData instanceof BiomeData2d)) {
Expand All @@ -43,7 +44,7 @@ public static void loadBiomeData(ChunkData chunkData, Tag chunkTag, BiomePalette
chunkData.setBiomeData(biomeData);
return;
}
} else if (!chunkTag.get(SECTIONS_POST_21W39A).isError()) { // in 21w39a biome tags moved into the sections array
} else if (!chunkTag.get(JavaChunk.SECTIONS_POST_21W39A).isError()) { // in 21w39a biome tags moved into the sections array
if(!(biomeData instanceof GenericQuartBiomeData3d)) {
biomeData = new GenericQuartBiomeData3d();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package se.llbit.chunky.chunk.biome;

import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import se.llbit.chunky.world.JavaChunk;
import se.llbit.chunky.world.biome.Biome;
import se.llbit.chunky.world.biome.BiomePalette;
import se.llbit.chunky.world.biome.Biomes;
Expand Down Expand Up @@ -60,7 +61,7 @@ public void clear() {
}

public static void loadBiomeDataPost21w39a(Tag chunkData, GenericQuartBiomeData3d biomeData, BiomePalette biomePalette, int yMin, int yMax) {
Tag sections = chunkData.get(SECTIONS_POST_21W39A);
Tag sections = chunkData.get(JavaChunk.SECTIONS_POST_21W39A);
if (sections.isList()) {
for (SpecificTag section : sections.asList()) {
Tag yTag = section.get("Y");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import java.util.Arrays;

import static se.llbit.chunky.world.Chunk.LEVEL_BIOMES;
import static se.llbit.chunky.world.JavaChunk.LEVEL_BIOMES;

/**
* Implementation of a 3D biome grid where the smallest size of a biome is 4x4x4 blocks
Expand Down
9 changes: 4 additions & 5 deletions chunky/src/java/se/llbit/chunky/map/MapTile.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import se.llbit.chunky.resources.BitmapImage;
import se.llbit.chunky.world.*;
import se.llbit.chunky.world.region.Region;

/**
* A tile in the 2D world map or minimap. The tile contains either a chunk or a region.
Expand Down Expand Up @@ -71,14 +70,14 @@ public void draw(MapBuffer buffer, WorldMapLoader mapLoader, ChunkView view,
}
} else {
RegionPosition regionPos = new RegionPosition(pos.x, pos.z); // intentionally don't convert, this position represented a region already.

boolean isValid = mapLoader.getWorld().currentDimension().regionExistsWithinRange(regionPos, view.yMin, view.yMax);
Region region = mapLoader.getWorld().currentDimension().getRegionWithinRange(regionPos, view.yMin, view.yMax);

int pixelOffset = 0;
for (int z = 0; z < 32; ++z) {
for (int x = 0; x < 32; ++x) {
Chunk chunk = region.getChunk(x, z);
//Calculate the chunk position as empty chunks are (0, 0)
ChunkPosition pos = region.getPosition().asChunkPosition(x, z);
ChunkPosition pos = regionPos.asChunkPosition(x, z);
Chunk chunk = mapLoader.getWorld().currentDimension().getChunk(pos);

pixels[pixelOffset] = chunk.biomeColor();
if (isValid && !(chunk instanceof EmptyRegionChunk) && selection.isSelected(pos)) {
Expand Down
2 changes: 1 addition & 1 deletion chunky/src/java/se/llbit/chunky/map/WorldMapLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public WorldMapLoader(ChunkyFxController controller, MapView mapView) {
* This is called when a new world is loaded
*/
public void loadWorld(File worldDir) {
if (World.isWorldDir(worldDir)) {
if (JavaWorld.isWorldDir(worldDir)) {
if (world != null) {
world.currentDimension().removeChunkTopographyListener(this);
}
Expand Down
7 changes: 4 additions & 3 deletions chunky/src/java/se/llbit/chunky/renderer/scene/Scene.java
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ public synchronized void loadScene(RenderContext context, String sceneName, Task
loadedWorld = EmptyWorld.INSTANCE;
if (!worldPath.isEmpty()) {
File worldDirectory = new File(worldPath);
if (World.isWorldDir(worldDirectory)) {
if (JavaWorld.isWorldDir(worldDirectory)) {
loadedWorld = World.loadWorld(worldDirectory, worldDimension, World.LoggedWarnings.NORMAL);
} else {
Log.info("Could not load world: " + worldPath);
Expand Down Expand Up @@ -821,7 +821,7 @@ public synchronized void loadChunks(TaskTracker taskTracker, World world, Collec
}

for (RegionPosition region : regions) {
dimension.getRegion(region).parse(yMin, yMax);
((JavaDimension) dimension).getRegion(region).parse(yMin, yMax);
}
}

Expand Down Expand Up @@ -1192,7 +1192,8 @@ public synchronized void loadChunks(TaskTracker taskTracker, World world, Collec

if (!chunkData.isEmpty()){
nonEmptyChunks.add(cp);
if (dimension.getChunk(cp).getVersion() == ChunkVersion.PRE_FLATTENING) {
Chunk chunk = dimension.getChunk(cp);
if (chunk instanceof JavaChunk javaChunk && javaChunk.getVersion() == ChunkVersion.PRE_FLATTENING) {
legacyChunks.add(cp);
}
}
Expand Down
8 changes: 0 additions & 8 deletions chunky/src/java/se/llbit/chunky/ui/ChunkMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,16 @@

import javafx.application.Platform;
import javafx.geometry.Point2D;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.canvas.Canvas;
import javafx.scene.canvas.GraphicsContext;
import javafx.scene.control.*;
import javafx.scene.control.Button;
import javafx.scene.control.Dialog;
import javafx.scene.control.MenuItem;
import javafx.scene.image.Image;
import javafx.scene.image.ImageView;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseButton;
import javafx.scene.input.MouseEvent;
import javafx.scene.input.ScrollEvent;
import javafx.scene.layout.Border;
import javafx.scene.layout.GridPane;
import javafx.stage.PopupWindow;
import se.llbit.chunky.map.MapBuffer;
import se.llbit.chunky.map.MapView;
Expand All @@ -45,7 +39,6 @@
import se.llbit.chunky.renderer.scene.SceneManager;
import se.llbit.chunky.ui.controller.ChunkyFxController;
import se.llbit.chunky.ui.dialogs.SelectChunksInRadiusDialog;
import se.llbit.chunky.ui.elements.TextFieldLabelWrapper;
import se.llbit.chunky.world.*;
import se.llbit.chunky.world.Dimension;
import se.llbit.chunky.world.listeners.ChunkUpdateListener;
Expand All @@ -57,7 +50,6 @@
import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.Optional;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicBoolean;

import it.unimi.dsi.fastutil.ints.IntIntPair;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.property.BooleanProperty;
Expand Down Expand Up @@ -482,19 +483,15 @@ public File getSceneFile(String fileName) {
}
if (!reloaded) {
ignoreYUpdate.set(true);
if (mapLoader.getWorld().getVersionId() >= World.VERSION_21W06A) {
yMin.setRange(-64, 320);
yMin.set(-64);
yMax.setRange(-64, 320);
yMax.set(320);
mapView.setYMinMax(-64, 320);
} else {
yMin.setRange(0, 256);
yMin.set(0);
yMax.setRange(0, 256);
yMax.set(256);
mapView.setYMinMax(0, 256);
}
IntIntPair heightRange = mapLoader.getWorld().currentDimension().heightRange();
int min = heightRange.firstInt();
int max = heightRange.secondInt();
yMin.setRange(min, max);
yMin.set(min);
yMax.setRange(min, max);
yMax.set(max);
mapView.setYMinMax(min, max);

yMin.getStyleClass().removeAll("invalid");
yMax.getStyleClass().removeAll("invalid");
ignoreYUpdate.set(false);
Expand Down Expand Up @@ -680,13 +677,9 @@ public File getSceneFile(String fileName) {
mapOverlay.setOnKeyReleased(map::onKeyReleased);

mapLoader.loadWorld(PersistentSettings.getLastWorld());
if (mapLoader.getWorld().getVersionId() >= World.VERSION_21W06A) {
mapView.setYMin(-64);
mapView.setYMax(320);
} else {
mapView.setYMin(0);
mapView.setYMax(256);
}
IntIntPair heightRange = mapLoader.getWorld().currentDimension().heightRange();
mapView.setYMin(heightRange.firstInt());
mapView.setYMax(heightRange.secondInt());

canvas = new RenderCanvasFx(this, chunky.getSceneManager().getScene(),
chunky.getRenderController().getRenderManager());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@
import se.llbit.chunky.map.WorldMapLoader;
import se.llbit.chunky.resources.MinecraftFinder;
import se.llbit.chunky.resources.ResourcePackLoader;
import se.llbit.chunky.resources.TexturePackLoader;
import se.llbit.chunky.ui.TableSortConfigSerializer;
import se.llbit.chunky.world.EmptyWorld;
import se.llbit.chunky.world.World;
import se.llbit.chunky.world.worldformat.WorldFormat;
import se.llbit.fxutil.Dialogs;
import se.llbit.json.JsonArray;
import se.llbit.log.Log;

import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.text.DateFormat;
import java.util.*;
Expand Down Expand Up @@ -186,17 +188,25 @@ private void fillWorldList(final File worldSavesDir) {
statusLabel.setText("Loading worlds list...");
disableControls(true);

Task<List<World>> loadWorldsTask = new Task<List<World>>() {
Task<List<World>> loadWorldsTask = new Task<>() {
@Override
protected List<World> call() {
List<World> worlds = new ArrayList<>();
if (worldSavesDir != null) {
File[] worldDirs = worldSavesDir.listFiles();
if (worldDirs != null) {
for (File dir : worldDirs) {
if (World.isWorldDir(dir)) {
worlds.add(World.loadWorld(dir, World.OVERWORLD_DIMENSION,
World.LoggedWarnings.SILENT));
for (WorldFormat worldFormat : WorldFormat.worldFormats) {
if (worldFormat.isValid(dir.toPath())) {
try {
World world = worldFormat.loadWorld(dir.toPath(), String.valueOf(World.OVERWORLD_DIMENSION));
if (world != EmptyWorld.INSTANCE) {
worlds.add(world);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
}
}
Expand Down
19 changes: 9 additions & 10 deletions chunky/src/java/se/llbit/chunky/ui/render/tabs/GeneralTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package se.llbit.chunky.ui.render.tabs;

import it.unimi.dsi.fastutil.ints.IntIntPair;
import javafx.beans.binding.Bindings;
import javafx.beans.value.ChangeListener;
import javafx.fxml.FXML;
Expand Down Expand Up @@ -506,16 +507,14 @@ private void updateCanvasCrop() {
}

private void updateYClipSlidersRanges(World world) {
if (world != null && world.getVersionId() >= World.VERSION_21W06A) {
yMin.setRange(-64, 320);
yMin.set(-64);
yMax.setRange(-64, 320);
yMax.set(320);
} else {
yMin.setRange(0, 256);
yMin.set(0);
yMax.setRange(0, 256);
yMax.set(256);
if (world != null) {
IntIntPair heightRange = world.currentDimension().heightRange();
int min = heightRange.firstInt();
int max = heightRange.secondInt();
yMin.setRange(min, max);
yMin.set(min);
yMax.setRange(min, max);
yMax.set(max);
}
}
}
Loading
Loading