Merge branch 'main' of https://gitlab.com/jeseibel/distant-horizons-core
This commit is contained in:
@@ -736,6 +736,17 @@ public class Config
|
||||
+ "")
|
||||
.build();
|
||||
|
||||
public static ConfigEntry<Boolean> enableMultiverseNetworking = new ConfigEntry.Builder<Boolean>()
|
||||
.set(true)
|
||||
.comment(""
|
||||
+ "If true Distant Horizons will attempt to communicate with the connected \n"
|
||||
+ "server in order to improve multiverse support. \n"
|
||||
+ "If you experience network issues when attempting to join a server, disable this option. \n"
|
||||
+ "\n"
|
||||
+ "Note: this requires setup on the server in order to function. \n"
|
||||
+ "")
|
||||
.build();
|
||||
|
||||
}
|
||||
|
||||
public static class MultiThreading
|
||||
|
||||
@@ -85,6 +85,8 @@ public class NetworkClient extends NetworkEventSource implements AutoCloseable
|
||||
LOGGER.info("Connecting to server: "+this.address);
|
||||
this.connectionState = EConnectionState.OPEN;
|
||||
|
||||
// FIXME sometimes this causes the MC connection to crash
|
||||
// this might happen if the URL can't be converted to a IP (IE UnknownHostException)
|
||||
ChannelFuture connectFuture = this.clientBootstrap.connect(this.address);
|
||||
connectFuture.addListener((ChannelFuture channelFuture) ->
|
||||
{
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package com.seibel.distanthorizons.core.world;
|
||||
|
||||
import com.seibel.distanthorizons.core.config.Config;
|
||||
import com.seibel.distanthorizons.core.dependencyInjection.SingletonInjector;
|
||||
import com.seibel.distanthorizons.core.file.structure.ClientOnlySaveStructure;
|
||||
import com.seibel.distanthorizons.core.level.IDhLevel;
|
||||
import com.seibel.distanthorizons.core.level.DhClientLevel;
|
||||
import com.seibel.distanthorizons.core.level.IDhLevel;
|
||||
import com.seibel.distanthorizons.core.network.NetworkClient;
|
||||
import com.seibel.distanthorizons.core.network.messages.*;
|
||||
import com.seibel.distanthorizons.core.network.messages.HelloMessage;
|
||||
import com.seibel.distanthorizons.core.network.messages.PlayerUUIDMessage;
|
||||
import com.seibel.distanthorizons.core.network.messages.RemotePlayerConfigMessage;
|
||||
import com.seibel.distanthorizons.core.network.objects.RemotePlayer;
|
||||
import com.seibel.distanthorizons.core.pos.DhBlockPos2D;
|
||||
import com.seibel.distanthorizons.core.pos.DhSectionPos;
|
||||
import com.seibel.distanthorizons.core.util.ThreadUtil;
|
||||
import com.seibel.distanthorizons.core.util.objects.EventLoop;
|
||||
import com.seibel.distanthorizons.core.wrapperInterfaces.minecraft.IMinecraftClientWrapper;
|
||||
@@ -34,9 +33,13 @@ public class DhClientWorld extends AbstractDhWorld implements IDhClientWorld
|
||||
// TODO why does this executor have 2 threads?
|
||||
public ExecutorService dhTickerThread = ThreadUtil.makeSingleThreadPool("DH Client World Ticker Thread", 2);
|
||||
public EventLoop eventLoop = new EventLoop(this.dhTickerThread, this::_clientTick);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//==============//
|
||||
// constructors //
|
||||
//==============//
|
||||
|
||||
public DhClientWorld()
|
||||
{
|
||||
super(EWorldEnvironment.Client_Only);
|
||||
@@ -44,32 +47,49 @@ public class DhClientWorld extends AbstractDhWorld implements IDhClientWorld
|
||||
this.saveStructure = new ClientOnlySaveStructure();
|
||||
this.levels = new ConcurrentHashMap<>();
|
||||
|
||||
// TODO server specific configs
|
||||
this.networkClient = new NetworkClient(MC_CLIENT.getCurrentServerIp(), 25049);
|
||||
registerNetworkHandlers();
|
||||
if (Config.Client.Advanced.Multiplayer.enableMultiverseNetworking.get())
|
||||
{
|
||||
// TODO server specific configs
|
||||
this.networkClient = new NetworkClient(MC_CLIENT.getCurrentServerIp(), 25049);
|
||||
this.registerNetworkHandlers();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.networkClient = null;
|
||||
}
|
||||
|
||||
LOGGER.info("Started DhWorld of type "+this.environment);
|
||||
}
|
||||
|
||||
private void registerNetworkHandlers() {
|
||||
networkClient.registerAckHandler(HelloMessage.class, ctx -> {
|
||||
this.networkClient.registerAckHandler(HelloMessage.class, (msg, ctx) ->
|
||||
{
|
||||
ctx.writeAndFlush(new PlayerUUIDMessage(MC_CLIENT.getPlayerUUID()));
|
||||
});
|
||||
|
||||
// TODO Proper payload handling
|
||||
networkClient.registerAckHandler(PlayerUUIDMessage.class, ctx -> {
|
||||
this.networkClient.registerAckHandler(PlayerUUIDMessage.class, ctx ->
|
||||
{
|
||||
ctx.writeAndFlush(new RemotePlayerConfigMessage(new RemotePlayer.Payload()));
|
||||
});
|
||||
networkClient.registerHandler(RemotePlayerConfigMessage.class, (msg, ctx) -> {
|
||||
this.networkClient.registerHandler(RemotePlayerConfigMessage.class, (msg, ctx) ->
|
||||
{
|
||||
|
||||
});
|
||||
|
||||
networkClient.registerAckHandler(RemotePlayerConfigMessage.class, ctx -> {
|
||||
|
||||
this.networkClient.registerAckHandler(RemotePlayerConfigMessage.class, ctx ->
|
||||
{
|
||||
// TODO Actually request chunks
|
||||
// ctx.writeAndFlush(new ChunkRequestMessage(new DhSectionPos(new DhBlockPos2D(0, 0))));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//=========//
|
||||
// methods //
|
||||
//=========//
|
||||
|
||||
@Override
|
||||
public DhClientLevel getOrLoadLevel(ILevelWrapper wrapper)
|
||||
{
|
||||
@@ -136,7 +156,11 @@ public class DhClientWorld extends AbstractDhWorld implements IDhClientWorld
|
||||
@Override
|
||||
public void close()
|
||||
{
|
||||
this.networkClient.close();
|
||||
if (this.networkClient != null)
|
||||
{
|
||||
this.networkClient.close();
|
||||
}
|
||||
|
||||
|
||||
this.saveAndFlush();
|
||||
for (DhClientLevel dhClientLevel : this.levels.values())
|
||||
|
||||
Reference in New Issue
Block a user