diff --git a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/FullDataPointIdMap.java b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/FullDataPointIdMap.java index 74d1e1645..589d327f1 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/FullDataPointIdMap.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/FullDataPointIdMap.java @@ -7,6 +7,7 @@ import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrappe import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper; import com.seibel.distanthorizons.core.util.objects.dataStreams.*; import com.seibel.distanthorizons.core.wrapperInterfaces.IWrapperFactory; +import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper; import java.io.*; import java.util.ArrayList; @@ -86,25 +87,25 @@ public class FullDataPointIdMap } /** Serializes all contained entries into the given stream, formatted in UTF */ - public void serialize(DhDataOutputStream outputStream) throws IOException + public void serialize(DhDataOutputStream outputStream, ILevelWrapper levelWrapper) throws IOException { lock.readLock().lock(); outputStream.writeInt(this.entries.size()); for (Entry entry : this.entries) { - outputStream.writeUTF(entry.serialize()); + outputStream.writeUTF(entry.serialize(levelWrapper)); } lock.readLock().unlock(); } /** Creates a new IdBiomeBlockStateMap from the given UTF formatted stream */ - public static FullDataPointIdMap deserialize(DhDataInputStream inputStream) throws IOException, InterruptedException + public static FullDataPointIdMap deserialize(DhDataInputStream inputStream, ILevelWrapper levelWrapper) throws IOException, InterruptedException { int entityCount = inputStream.readInt(); FullDataPointIdMap newMap = new FullDataPointIdMap(); for (int i = 0; i < entityCount; i++) { - newMap.entries.add(Entry.deserialize(inputStream.readUTF())); + newMap.entries.add(Entry.deserialize(inputStream.readUTF(), levelWrapper)); } return newMap; } @@ -160,9 +161,9 @@ public class FullDataPointIdMap } - public String serialize() { return this.biome.serialize() + SEPARATOR_STRING + this.blockState.serialize(); } + public String serialize(ILevelWrapper levelWrapper) { return this.biome.serialize(levelWrapper) + SEPARATOR_STRING + this.blockState.serialize(); } - public static Entry deserialize(String str) throws IOException, InterruptedException + public static Entry deserialize(String str, ILevelWrapper levelWrapper) throws IOException, InterruptedException { String[] stringArray = str.split(SEPARATOR_STRING); if (stringArray.length != 2) @@ -176,7 +177,7 @@ public class FullDataPointIdMap throw new InterruptedException(FullDataPointIdMap.class.getSimpleName()+" task interrupted."); } - IBiomeWrapper biome = WRAPPER_FACTORY.deserializeBiomeWrapper(stringArray[0]); + IBiomeWrapper biome = WRAPPER_FACTORY.deserializeBiomeWrapper(stringArray[0], levelWrapper); IBlockStateWrapper blockState = WRAPPER_FACTORY.deserializeBlockStateWrapper(stringArray[1]); return new Entry(biome, blockState); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/CompleteFullDataSource.java b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/CompleteFullDataSource.java index 98b7bf8bf..4f34884df 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/CompleteFullDataSource.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/CompleteFullDataSource.java @@ -17,6 +17,7 @@ import com.seibel.distanthorizons.core.util.LodUtil; import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataInputStream; import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataOutputStream; import com.seibel.distanthorizons.core.dataObjects.fullData.FullDataPointIdMap; +import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper; import com.seibel.distanthorizons.coreapi.util.BitShiftUtil; import org.apache.logging.log4j.Logger; @@ -226,14 +227,14 @@ public class CompleteFullDataSource extends FullDataArrayAccessor implements IFu @Override - public void writeIdMappings(DhDataOutputStream outputStream) throws IOException + public void writeIdMappings(DhDataOutputStream outputStream, ILevelWrapper levelWrapper) throws IOException { outputStream.writeInt(IFullDataSource.DATA_GUARD_BYTE); - this.mapping.serialize(outputStream); + this.mapping.serialize(outputStream, levelWrapper); } @Override - public FullDataPointIdMap readIdMappings(long[][] dataPoints, DhDataInputStream inputStream) throws IOException, InterruptedException + public FullDataPointIdMap readIdMappings(long[][] dataPoints, DhDataInputStream inputStream, ILevelWrapper levelWrapper) throws IOException, InterruptedException { int guardByte = inputStream.readInt(); if (guardByte != IFullDataSource.DATA_GUARD_BYTE) @@ -241,7 +242,7 @@ public class CompleteFullDataSource extends FullDataArrayAccessor implements IFu throw new IOException("Invalid data content end guard for ID mapping"); } - return FullDataPointIdMap.deserialize(inputStream); + return FullDataPointIdMap.deserialize(inputStream, levelWrapper); } @Override public void setIdMapping(FullDataPointIdMap mappings) { this.mapping.mergeAndReturnRemappedEntityIds(mappings); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/HighDetailIncompleteFullDataSource.java b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/HighDetailIncompleteFullDataSource.java index 6b67c65ad..a6fbe00f2 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/HighDetailIncompleteFullDataSource.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/HighDetailIncompleteFullDataSource.java @@ -17,6 +17,7 @@ import com.seibel.distanthorizons.core.util.LodUtil; import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataInputStream; import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataOutputStream; import com.seibel.distanthorizons.core.dataObjects.fullData.FullDataPointIdMap; +import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper; import com.seibel.distanthorizons.coreapi.util.BitShiftUtil; import org.apache.logging.log4j.Logger; @@ -350,14 +351,14 @@ public class HighDetailIncompleteFullDataSource implements IIncompleteFullDataSo @Override - public void writeIdMappings(DhDataOutputStream dataOutputStream) throws IOException + public void writeIdMappings(DhDataOutputStream dataOutputStream, ILevelWrapper levelWrapper) throws IOException { dataOutputStream.writeInt(IFullDataSource.DATA_GUARD_BYTE); - this.mapping.serialize(dataOutputStream); + this.mapping.serialize(dataOutputStream, levelWrapper); } @Override - public FullDataPointIdMap readIdMappings(long[][][] dataPoints, DhDataInputStream inputStream) throws IOException, InterruptedException + public FullDataPointIdMap readIdMappings(long[][][] dataPoints, DhDataInputStream inputStream, ILevelWrapper levelWrapper) throws IOException, InterruptedException { // mark the start of the ID data int idMappingStartByte = inputStream.readInt(); @@ -368,7 +369,7 @@ public class HighDetailIncompleteFullDataSource implements IIncompleteFullDataSo } // deserialize the ID data - return FullDataPointIdMap.deserialize(inputStream); + return FullDataPointIdMap.deserialize(inputStream, levelWrapper); } @Override public void setIdMapping(FullDataPointIdMap mappings) { this.mapping.mergeAndReturnRemappedEntityIds(mappings); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/LowDetailIncompleteFullDataSource.java b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/LowDetailIncompleteFullDataSource.java index 25de2c369..74ea29198 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/LowDetailIncompleteFullDataSource.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/LowDetailIncompleteFullDataSource.java @@ -17,6 +17,7 @@ import com.seibel.distanthorizons.core.util.LodUtil; import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataInputStream; import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataOutputStream; import com.seibel.distanthorizons.core.dataObjects.fullData.FullDataPointIdMap; +import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper; import com.seibel.distanthorizons.coreapi.util.BitShiftUtil; import org.apache.logging.log4j.Logger; @@ -237,14 +238,14 @@ public class LowDetailIncompleteFullDataSource extends FullDataArrayAccessor imp @Override - public void writeIdMappings(DhDataOutputStream outputStream) throws IOException + public void writeIdMappings(DhDataOutputStream outputStream, ILevelWrapper levelWrapper) throws IOException { outputStream.writeInt(IFullDataSource.DATA_GUARD_BYTE); - this.mapping.serialize(outputStream); + this.mapping.serialize(outputStream, levelWrapper); } @Override - public FullDataPointIdMap readIdMappings(StreamDataPointContainer streamDataPointContainer, DhDataInputStream inputStream) throws IOException, InterruptedException + public FullDataPointIdMap readIdMappings(StreamDataPointContainer streamDataPointContainer, DhDataInputStream inputStream, ILevelWrapper levelWrapper) throws IOException, InterruptedException { // Id mapping int dataPresentFlag = inputStream.readInt(); @@ -252,7 +253,7 @@ public class LowDetailIncompleteFullDataSource extends FullDataArrayAccessor imp { throw new IOException("invalid ID mapping end guard"); } - return FullDataPointIdMap.deserialize(inputStream); + return FullDataPointIdMap.deserialize(inputStream, levelWrapper); } @Override public void setIdMapping(FullDataPointIdMap mappings) { this.mapping.mergeAndReturnRemappedEntityIds(mappings); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/interfaces/IStreamableFullDataSource.java b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/interfaces/IStreamableFullDataSource.java index 92d9fc146..11c37fae8 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/interfaces/IStreamableFullDataSource.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/dataObjects/fullData/sources/interfaces/IStreamableFullDataSource.java @@ -8,6 +8,7 @@ import com.seibel.distanthorizons.core.file.fullDatafile.FullDataMetaFile; import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataInputStream; import com.seibel.distanthorizons.core.util.objects.dataStreams.DhDataOutputStream; import com.seibel.distanthorizons.core.util.objects.dataStreams.*; +import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper; import java.io.IOException; @@ -55,7 +56,7 @@ public interface IStreamableFullDataSource read(DhSectionPos pos) { // TODO: LOD data file updating is probably incomplete return super.read(pos).thenCompose((fullDataSource) -> { - CompletableFuture responseFuture = networkClient.sendRequest(new ChunkRequestMessage(pos)) + CompletableFuture responseFuture = networkClient.sendRequest(new FullDataSourceRequestMessage(pos)) .exceptionally(throwable -> { LOGGER.error(throwable); return null; diff --git a/core/src/main/java/com/seibel/distanthorizons/core/network/messages/ChunkResponseMessage.java b/core/src/main/java/com/seibel/distanthorizons/core/network/messages/ChunkResponseMessage.java deleted file mode 100644 index 14119a582..000000000 --- a/core/src/main/java/com/seibel/distanthorizons/core/network/messages/ChunkResponseMessage.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.seibel.distanthorizons.core.network.messages; - -import com.seibel.distanthorizons.core.network.protocol.FutureTrackableNetworkMessage; -import com.seibel.distanthorizons.core.network.protocol.INetworkObject; -import com.seibel.distanthorizons.core.pos.DhSectionPos; -import io.netty.buffer.ByteBuf; - -public class ChunkResponseMessage extends FutureTrackableNetworkMessage -{ - public ChunkResponseMessage() {} - - @Override - public void encode0(ByteBuf out) - { - } - - @Override - public void decode0(ByteBuf in) - { - } -} diff --git a/core/src/main/java/com/seibel/distanthorizons/core/network/messages/ChunkRequestMessage.java b/core/src/main/java/com/seibel/distanthorizons/core/network/messages/FullDataSourceRequestMessage.java similarity index 76% rename from core/src/main/java/com/seibel/distanthorizons/core/network/messages/ChunkRequestMessage.java rename to core/src/main/java/com/seibel/distanthorizons/core/network/messages/FullDataSourceRequestMessage.java index 0d9d96898..3bef7e812 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/network/messages/ChunkRequestMessage.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/network/messages/FullDataSourceRequestMessage.java @@ -5,13 +5,13 @@ import com.seibel.distanthorizons.core.network.protocol.INetworkObject; import com.seibel.distanthorizons.core.pos.DhSectionPos; import io.netty.buffer.ByteBuf; -public class ChunkRequestMessage extends FutureTrackableNetworkMessage +public class FullDataSourceRequestMessage extends FutureTrackableNetworkMessage { public DhSectionPos dhSectionPos; - public ChunkRequestMessage() {} + public FullDataSourceRequestMessage() {} - public ChunkRequestMessage(DhSectionPos dhSectionPos) { + public FullDataSourceRequestMessage(DhSectionPos dhSectionPos) { this.dhSectionPos = dhSectionPos; } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/network/messages/FullDataSourceResponseMessage.java b/core/src/main/java/com/seibel/distanthorizons/core/network/messages/FullDataSourceResponseMessage.java new file mode 100644 index 000000000..a35c09f5d --- /dev/null +++ b/core/src/main/java/com/seibel/distanthorizons/core/network/messages/FullDataSourceResponseMessage.java @@ -0,0 +1,34 @@ +package com.seibel.distanthorizons.core.network.messages; + +import com.seibel.distanthorizons.core.dataObjects.fullData.sources.interfaces.IFullDataSource; +import com.seibel.distanthorizons.core.level.DhServerLevel; +import com.seibel.distanthorizons.core.network.protocol.FutureTrackableNetworkMessage; +import io.netty.buffer.ByteBuf; + +import java.io.IOException; + +public class FullDataSourceResponseMessage extends FutureTrackableNetworkMessage +{ + public IFullDataSource fullDataSource; + public DhServerLevel level; + + public FullDataSourceResponseMessage() {} + public FullDataSourceResponseMessage(IFullDataSource fullDataSource, DhServerLevel level) + { + this.fullDataSource = fullDataSource; + this.level = level; + } + + @Override + public void encode0(ByteBuf out) throws IOException + { + //fullDataSource.writeToStream(new DhDataOutputStream(new ByteBufOutputStream(out)), level); + } + + @Override + public void decode0(ByteBuf in) + { + //DhSectionPos sectionPos = INetworkObject.decode(new DhSectionPos((byte) 0, (byte) 0, (byte) 0), in); + //fullDataSource = HighDetailIncompleteFullDataSource.createEmpty(sectionPos); + } +} diff --git a/core/src/main/java/com/seibel/distanthorizons/core/network/protocol/FutureTrackableNetworkMessage.java b/core/src/main/java/com/seibel/distanthorizons/core/network/protocol/FutureTrackableNetworkMessage.java index 96e5e326d..dc6596950 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/network/protocol/FutureTrackableNetworkMessage.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/network/protocol/FutureTrackableNetworkMessage.java @@ -15,16 +15,30 @@ public abstract class FutureTrackableNetworkMessage implements INetworkMessage @Override public final void encode(ByteBuf out) { - out.writeInt(futureId); - this.encode0(out); + try + { + out.writeInt(futureId); + this.encode0(out); + } + catch (Exception e) + { + throw new RuntimeException(e); + } } @Override public final void decode(ByteBuf in) { - futureId = in.readInt(); - this.decode0(in); + try + { + futureId = in.readInt(); + this.decode0(in); + } + catch (Exception e) + { + throw new RuntimeException(e); + } } - protected abstract void encode0(ByteBuf out); - protected abstract void decode0(ByteBuf in); + protected abstract void encode0(ByteBuf out) throws Exception; + protected abstract void decode0(ByteBuf in) throws Exception; } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/network/protocol/MessageRegistry.java b/core/src/main/java/com/seibel/distanthorizons/core/network/protocol/MessageRegistry.java index 63224344b..0d7d1d2a7 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/network/protocol/MessageRegistry.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/network/protocol/MessageRegistry.java @@ -29,8 +29,8 @@ public class MessageRegistry this.registerMessage(AckMessage.class, AckMessage::new); this.registerMessage(PlayerUUIDMessage.class, PlayerUUIDMessage::new); this.registerMessage(RemotePlayerConfigMessage.class, RemotePlayerConfigMessage::new); - this.registerMessage(ChunkRequestMessage.class, ChunkRequestMessage::new); - this.registerMessage(ChunkResponseMessage.class, ChunkResponseMessage::new); + this.registerMessage(FullDataSourceRequestMessage.class, FullDataSourceRequestMessage::new); + this.registerMessage(FullDataSourceResponseMessage.class, FullDataSourceResponseMessage::new); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/world/DhServerWorld.java b/core/src/main/java/com/seibel/distanthorizons/core/world/DhServerWorld.java index 088a814e7..f8e1407ad 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/world/DhServerWorld.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/world/DhServerWorld.java @@ -2,25 +2,21 @@ package com.seibel.distanthorizons.core.world; import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; -import com.seibel.distanthorizons.core.file.fullDatafile.FullDataMetaFile; -import com.seibel.distanthorizons.core.file.fullDatafile.IFullDataSourceProvider; import com.seibel.distanthorizons.core.file.structure.LocalSaveStructure; import com.seibel.distanthorizons.core.level.DhServerLevel; import com.seibel.distanthorizons.core.level.IDhLevel; import com.seibel.distanthorizons.core.network.NetworkServer; import com.seibel.distanthorizons.core.network.messages.*; -import com.seibel.distanthorizons.core.network.messages.ChunkRequestMessage; import com.seibel.distanthorizons.core.network.objects.RemotePlayer; import com.seibel.distanthorizons.core.network.protocol.FutureTrackableNetworkMessage; import com.seibel.distanthorizons.core.pos.DhBlockPos2D; import com.seibel.distanthorizons.core.util.LodUtil; import com.seibel.distanthorizons.core.wrapperInterfaces.misc.IServerPlayerWrapper; -import com.seibel.distanthorizons.core.wrapperInterfaces.world.IServerLevelWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper; +import com.seibel.distanthorizons.core.wrapperInterfaces.world.IServerLevelWrapper; import io.netty.channel.ChannelHandlerContext; import java.io.File; -import java.nio.file.FileAlreadyExistsException; import java.util.HashMap; import java.util.UUID; import java.util.concurrent.CompletableFuture; @@ -91,7 +87,7 @@ public class DhServerWorld extends AbstractDhWorld implements IDhServerWorld channelContext.writeAndFlush(new AckMessage(RemotePlayerConfigMessage.class)); }); - this.networkServer.registerHandler(ChunkRequestMessage.class, (msg, ctx) -> + this.networkServer.registerHandler(FullDataSourceRequestMessage.class, (msg, ctx) -> { if (msg.dhSectionPos == null) { LOGGER.warn("RequestChunksMessage received with null msg.dhSectionPos"); @@ -107,9 +103,11 @@ public class DhServerWorld extends AbstractDhWorld implements IDhServerWorld // TODO: Add level to packet level.serverside.worldGenTick(new DhBlockPos2D(msg.dhSectionPos.sectionX, msg.dhSectionPos.sectionZ)); - - // Send chunk response message back - ctx.writeAndFlush(FutureTrackableNetworkMessage.makeResponse(msg, new ChunkResponseMessage())); + + level.serverside.dataFileHandler.read(msg.dhSectionPos).thenAccept(fullDataSource -> { + // Send chunk response message back + ctx.writeAndFlush(FutureTrackableNetworkMessage.makeResponse(msg, new FullDataSourceResponseMessage(fullDataSource, level))); + }); }); } diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/IWrapperFactory.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/IWrapperFactory.java index ef271da61..0eeaf4efd 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/IWrapperFactory.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/IWrapperFactory.java @@ -23,6 +23,7 @@ import com.seibel.distanthorizons.core.level.IDhLevel; import com.seibel.distanthorizons.core.wrapperInterfaces.block.IBlockStateWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.chunk.IChunkWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.world.IBiomeWrapper; +import com.seibel.distanthorizons.core.wrapperInterfaces.world.ILevelWrapper; import com.seibel.distanthorizons.core.wrapperInterfaces.worldGeneration.AbstractBatchGenerationEnvironmentWrapper; import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindable; @@ -37,7 +38,7 @@ import java.io.IOException; public interface IWrapperFactory extends IBindable { AbstractBatchGenerationEnvironmentWrapper createBatchGenerator(IDhLevel targetLevel); - IBiomeWrapper deserializeBiomeWrapper(String str) throws IOException; + IBiomeWrapper deserializeBiomeWrapper(String str, ILevelWrapper levelWrapper) throws IOException; IBlockStateWrapper deserializeBlockStateWrapper(String str) throws IOException; IBlockStateWrapper getAirBlockStateWrapper(); diff --git a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/world/IBiomeWrapper.java b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/world/IBiomeWrapper.java index 69fabc533..e959de2e5 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/world/IBiomeWrapper.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/wrapperInterfaces/world/IBiomeWrapper.java @@ -29,5 +29,5 @@ import com.seibel.distanthorizons.coreapi.interfaces.dependencyInjection.IBindab public interface IBiomeWrapper extends IDhApiBiomeWrapper, IBindable { String getName(); - String serialize(); + String serialize(ILevelWrapper levelWrapper); }