diff --git a/chunky/src/java/se/llbit/chunky/renderer/scene/Scene.java b/chunky/src/java/se/llbit/chunky/renderer/scene/Scene.java index 54a69d051..9b01b75a9 100644 --- a/chunky/src/java/se/llbit/chunky/renderer/scene/Scene.java +++ b/chunky/src/java/se/llbit/chunky/renderer/scene/Scene.java @@ -3073,17 +3073,15 @@ public Collection getChunks() { } /** - * Clears the reset reason and returns the previous reason. + * Get the reset reason. * @return the current reset reason */ - public synchronized ResetReason getResetReason() { + public ResetReason getResetReason() { return resetReason; } public void setResetReason(ResetReason resetReason) { - if (this.resetReason != ResetReason.SCENE_LOADED) { - this.resetReason = resetReason; - } + this.resetReason = resetReason; } public void importMaterials() { diff --git a/chunky/src/java/se/llbit/chunky/renderer/scene/SynchronousSceneManager.java b/chunky/src/java/se/llbit/chunky/renderer/scene/SynchronousSceneManager.java index 1432dd958..2ca51a41b 100644 --- a/chunky/src/java/se/llbit/chunky/renderer/scene/SynchronousSceneManager.java +++ b/chunky/src/java/se/llbit/chunky/renderer/scene/SynchronousSceneManager.java @@ -235,10 +235,14 @@ public void saveScene(SceneIOProvider ioContext, Scene scene) throws Interrupted @Override public void loadFreshChunks(World world, Collection chunksToLoad) { synchronized (scene) { + int yClipMin = scene.getYClipMin(); + int yClipMax = scene.getYClipMax(); scene.clear(); - scene.loadChunks(taskTracker, world, chunksToLoad); scene.resetScene(null, context.getChunky().getSceneFactory()); + scene.setYClipMin(yClipMin); + scene.setYClipMax(yClipMax); context.setSceneDirectory(new File(context.getChunky().options.sceneDir, scene.name)); + scene.loadChunks(taskTracker, world, chunksToLoad); scene.refresh(); scene.setResetReason(ResetReason.SCENE_LOADED); scene.setRenderMode(RenderMode.PREVIEW); @@ -253,9 +257,9 @@ public void saveScene(SceneIOProvider ioContext, Scene scene) throws Interrupted if (prevChunkCount == 0) { scene.moveCameraToCenter(); } - scene.refresh(); scene.setResetReason(ResetReason.SCENE_LOADED); scene.setRenderMode(RenderMode.PREVIEW); + scene.refresh(); } onChunksLoaded.run(); } @@ -263,9 +267,9 @@ public void saveScene(SceneIOProvider ioContext, Scene scene) throws Interrupted @Override public void reloadChunks() { synchronized (scene) { scene.reloadChunks(taskTracker); - scene.refresh(); scene.setResetReason(ResetReason.SCENE_LOADED); scene.setRenderMode(RenderMode.PREVIEW); + scene.refresh(); } onChunksLoaded.run(); } diff --git a/chunky/src/java/se/llbit/chunky/ui/ChunkMap.java b/chunky/src/java/se/llbit/chunky/ui/ChunkMap.java index 76b1f9d51..411e8740b 100644 --- a/chunky/src/java/se/llbit/chunky/ui/ChunkMap.java +++ b/chunky/src/java/se/llbit/chunky/ui/ChunkMap.java @@ -159,16 +159,22 @@ public ChunkMap(WorldMapLoader loader, ChunkyFxController controller, newScene.setGraphic(new ImageView(Icon.sky.fxImage())); newScene.setOnAction(event -> { SceneManager sceneManager = controller.getRenderController().getSceneManager(); - sceneManager - .loadFreshChunks(mapLoader.getWorld(), controller.getChunkSelection().getSelection()); + sceneManager.getSceneProvider().withEditSceneProtected(scene -> { + scene.setYClipMin(mapView.getYMin()); + scene.setYClipMax(mapView.getYMax()); + }); + sceneManager.loadFreshChunks(mapLoader.getWorld(), controller.getChunkSelection().getSelection()); }); newScene.setDisable(chunkSelection.isEmpty()); MenuItem loadSelection = new MenuItem("Load selected chunks"); loadSelection.setOnAction(event -> { SceneManager sceneManager = controller.getRenderController().getSceneManager(); - sceneManager - .loadChunks(mapLoader.getWorld(), controller.getChunkSelection().getSelection()); + sceneManager.getSceneProvider().withEditSceneProtected(scene -> { + scene.setYClipMin(mapView.getYMin()); + scene.setYClipMax(mapView.getYMax()); + }); + sceneManager.loadChunks(mapLoader.getWorld(), controller.getChunkSelection().getSelection()); }); loadSelection.setDisable(chunkSelection.isEmpty()); diff --git a/chunky/src/java/se/llbit/chunky/ui/render/tabs/GeneralTab.java b/chunky/src/java/se/llbit/chunky/ui/render/tabs/GeneralTab.java index b46ac8e1e..31dce0c75 100644 --- a/chunky/src/java/se/llbit/chunky/ui/render/tabs/GeneralTab.java +++ b/chunky/src/java/se/llbit/chunky/ui/render/tabs/GeneralTab.java @@ -187,6 +187,12 @@ public GeneralTab() throws IOException { canvasSizeInput.setSize(scene.canvasConfig.getCropWidth(), scene.canvasConfig.getCropHeight()); } + @Override + public void onChunksLoaded() { + yMin.set(scene.getYClipMin()); + yMax.set(scene.getYClipMax()); + } + @Override public String getTabTitle() { return "Scene"; } @@ -508,14 +514,10 @@ 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); } } }