From 573a284580acacbf12c347d3fc716537cc67182f Mon Sep 17 00:00:00 2001 From: s809 <43530948+s809@users.noreply.github.com> Date: Sat, 13 Jan 2024 19:44:48 +0500 Subject: [PATCH] Fix generation --- .../core/level/DhClientLevel.java | 4 +++ .../core/level/DhServerLevel.java | 29 ++++++++++--------- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/core/src/main/java/com/seibel/distanthorizons/core/level/DhClientLevel.java b/core/src/main/java/com/seibel/distanthorizons/core/level/DhClientLevel.java index 0150fb821..3ec690fba 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/level/DhClientLevel.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/level/DhClientLevel.java @@ -85,6 +85,10 @@ public class DhClientLevel extends DhLevel implements IDhClientLevel public DhClientLevel(AbstractSaveStructure saveStructure, IClientLevelWrapper clientLevelWrapper, @Nullable ClientNetworkState networkState) { this(saveStructure, clientLevelWrapper, null, true, networkState); } public DhClientLevel(AbstractSaveStructure saveStructure, IClientLevelWrapper clientLevelWrapper, @Nullable File fullDataSaveDirOverride, boolean enableRendering, @Nullable ClientNetworkState networkState) { + if (saveStructure.getFullDataFolder(clientLevelWrapper).mkdirs()) + { + LOGGER.warn("unable to create data folder."); + } this.levelWrapper = clientLevelWrapper; this.saveStructure = saveStructure; this.dataFileHandler = new RemoteFullDataFileHandler(this, saveStructure, fullDataSaveDirOverride); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/level/DhServerLevel.java b/core/src/main/java/com/seibel/distanthorizons/core/level/DhServerLevel.java index 2a01dbcc6..0ecb29c05 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/level/DhServerLevel.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/level/DhServerLevel.java @@ -104,9 +104,7 @@ public class DhServerLevel extends DhLevel implements IDhServerLevel { IncompleteDataSourceEntry entry = incompleteDataSources.computeIfAbsent(msg.dhSectionPos, pos -> { IncompleteDataSourceEntry newEntry = new IncompleteDataSourceEntry(); - serverside.dataFileHandler.getAsync(msg.dhSectionPos).thenAccept(fullDataSource -> { - newEntry.fullDataSource = fullDataSource; - }); + this.trySetGeneratedDataSourceToEntry(newEntry, pos); return newEntry; }); // If this fails, current entry is being drained and need to create another one @@ -169,17 +167,9 @@ public class DhServerLevel extends DhLevel implements IDhServerLevel { IncompleteDataSourceEntry entry = mapEntry.getValue(); - if (entry.fullDataSource == null) + if (entry.fullDataSource == null || entry.fullDataSource instanceof IIncompleteFullDataSource) continue; - if (entry.fullDataSource instanceof IIncompleteFullDataSource) - { - IIncompleteFullDataSource incompleteSource = (IIncompleteFullDataSource) entry.fullDataSource; - if (!incompleteSource.hasBeenPromoted()) - continue; - entry.fullDataSource = incompleteSource.tryPromotingToCompleteDataSource(); - } - LodUtil.assertTrue(entry.fullDataSource instanceof CompleteFullDataSource, "Invalid full data source"); incompleteDataSources.remove(mapEntry.getKey()); @@ -310,10 +300,23 @@ public class DhServerLevel extends DhLevel implements IDhServerLevel @Override public boolean hasSkyLight() { return this.serverLevelWrapper.hasSkyLight(); } + private void trySetGeneratedDataSourceToEntry(IncompleteDataSourceEntry entry, DhSectionPos pos) + { + this.serverside.dataFileHandler.getAsync(pos).thenAccept(fullDataSource -> { + if (fullDataSource instanceof IIncompleteFullDataSource) + fullDataSource = ((IIncompleteFullDataSource) fullDataSource).tryPromotingToCompleteDataSource(); + if (fullDataSource instanceof CompleteFullDataSource) + entry.fullDataSource = fullDataSource; + }); + } + @Override public void onWorldGenTaskComplete(DhSectionPos pos) { - //TODO: Send packet to client + IncompleteDataSourceEntry entry = this.incompleteDataSources.get(pos); + if (entry == null) return; + + this.trySetGeneratedDataSourceToEntry(entry, pos); } private static class IncompleteDataSourceEntry