Skip to content

Commit 3fd12f1

Browse files
authored
Various multiplayer fixes (#238)
- [Tickrate] Fixed initial tickrate not being sent, when a player joins the server - [Savestate] Fixed savestates failing when player does not have playerdata - [Savestate] Fixed player not getting motion applied in multiplayer
2 parents 130312e + 1e83342 commit 3fd12f1

File tree

4 files changed

+14
-15
lines changed

4 files changed

+14
-15
lines changed

src/main/java/com/minecrafttas/tasmod/TASmodClient.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
import com.minecrafttas.tasmod.registries.TASmodKeybinds;
4040
import com.minecrafttas.tasmod.registries.TASmodPackets;
4141
import com.minecrafttas.tasmod.savestates.SavestateHandlerClient;
42+
import com.minecrafttas.tasmod.savestates.handlers.SavestatePlayerHandler;
4243
import com.minecrafttas.tasmod.tickratechanger.TickrateChangerClient;
4344
import com.minecrafttas.tasmod.ticksync.TickSyncClient;
4445
import com.minecrafttas.tasmod.util.LoggerMarkers;
@@ -169,6 +170,7 @@ private void registerNetworkPacketHandlers() {
169170
PacketHandlerRegistry.register(ticksyncClient);
170171
PacketHandlerRegistry.register(tickratechanger);
171172
PacketHandlerRegistry.register(savestateHandlerClient);
173+
PacketHandlerRegistry.register(new SavestatePlayerHandler(null)); //TODO Split player handler into client and server
172174
}
173175

174176
private void registerEventListeners() {

src/main/java/com/minecrafttas/tasmod/savestates/SavestateHandlerClient.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public static void loadstate(String nameOfSavestate) throws Exception {
222222
*
223223
* We expect to start at tick 10 WITHOUT clearing the controller.
224224
* If we were to replace the controller, everything above tick 10 would be lost.
225-
* So we only set the index to 10, preload and preload the inputs.
225+
* So we only set the index to 10 and preload the inputs.
226226
*
227227
* VV
228228
* 0 10 20

src/main/java/com/minecrafttas/tasmod/savestates/handlers/SavestatePlayerHandler.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@ public void loadAndSendMotionToPlayer() {
112112

113113
NBTTagCompound nbttagcompound = server.getPlayerList().readPlayerDataFromFile(player);
114114

115+
if (nbttagcompound == null) {
116+
continue;
117+
}
118+
115119
int dimensionTo = 0;
116120
if (nbttagcompound.hasKey("Dimension")) {
117121
dimensionTo = nbttagcompound.getInteger("Dimension");
@@ -148,7 +152,6 @@ public void loadAndSendMotionToPlayer() {
148152
public void changeDimensionDangerously(EntityPlayerMP player, int dimensionTo) {
149153
int dimensionFrom = player.dimension;
150154
WorldServer worldServerFrom = this.server.getWorld(dimensionFrom);
151-
// WorldServer worldServerTo = this.server.getWorld(dimensionTo);
152155

153156
//@formatter:off
154157
player.connection
@@ -163,10 +166,6 @@ public void changeDimensionDangerously(EntityPlayerMP player, int dimensionTo) {
163166
//@formatter:on
164167
worldServerFrom.removeEntityDangerously(player);
165168
player.isDead = false;
166-
// worldServerTo.spawnEntity(player);
167-
// worldServerTo.updateEntityWithOptionalForce(player, false);
168-
// player.setWorld(worldServerTo);
169-
// player.interactionManager.setWorld(worldServerTo);
170169
}
171170

172171
public void clearScoreboard() {
@@ -210,7 +209,7 @@ public void onClientPacket(PacketID id, ByteBuffer buf, String username) throws
210209
compound = TASmodBufferBuilder.readNBTTagCompound(buf);
211210
} catch (IOException e) {
212211
e.printStackTrace();
213-
return;
212+
break;
214213
}
215214
/*
216215
* Fair warning: Do NOT read the buffer inside an addScheduledTask. Read it

src/main/java/com/minecrafttas/tasmod/tickratechanger/TickrateChangerServer.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import org.apache.logging.log4j.Logger;
66

77
import com.minecrafttas.mctcommon.events.EventListenerRegistry;
8-
import com.minecrafttas.mctcommon.events.EventServer.EventPlayerJoinedServerSide;
8+
import com.minecrafttas.mctcommon.events.EventServer.EventClientCompleteAuthentication;
99
import com.minecrafttas.mctcommon.events.EventServer.EventServerStop;
1010
import com.minecrafttas.mctcommon.networking.Client.Side;
1111
import com.minecrafttas.mctcommon.networking.exception.PacketNotImplementedException;
@@ -18,7 +18,6 @@
1818
import com.minecrafttas.tasmod.registries.TASmodPackets;
1919
import com.minecrafttas.tasmod.util.LoggerMarkers;
2020

21-
import net.minecraft.entity.player.EntityPlayerMP;
2221
import net.minecraft.server.MinecraftServer;
2322

2423
/**
@@ -39,7 +38,7 @@
3938
* @author Scribble
4039
*
4140
*/
42-
public class TickrateChangerServer implements EventServerStop, EventPlayerJoinedServerSide, ServerPacketHandler {
41+
public class TickrateChangerServer implements EventServerStop, EventClientCompleteAuthentication, ServerPacketHandler {
4342

4443
/**
4544
* The current tickrate of the client
@@ -208,12 +207,12 @@ private void advanceServerTick() {
208207
* @param player The player that joins the server
209208
*/
210209
@Override
211-
public void onPlayerJoinedServerSide(EntityPlayerMP player) {
212-
if (TASmod.getServerInstance().isDedicatedServer()) {
213-
log("Sending the current tickrate (" + ticksPerSecond + ") to " + player.getName());
210+
public void onClientCompleteAuthentication(String username) {
211+
if (TASmod.getServerInstance() != null && TASmod.getServerInstance().isDedicatedServer()) {
212+
log("Sending the current tickrate (" + ticksPerSecond + ") to " + username);
214213

215214
try {
216-
TASmod.server.sendTo(player, new TASmodBufferBuilder(TASmodPackets.TICKRATE_CHANGE).writeFloat(ticksPerSecond));
215+
TASmod.server.sendTo(username, new TASmodBufferBuilder(TASmodPackets.TICKRATE_CHANGE).writeFloat(ticksPerSecond));
217216
} catch (Exception e) {
218217
e.printStackTrace();
219218
}
@@ -292,5 +291,4 @@ public void onServerPacket(PacketID id, ByteBuffer buf, String username) throws
292291
throw new PacketNotImplementedException(packet, this.getClass(), Side.SERVER);
293292
}
294293
}
295-
296294
}

0 commit comments

Comments
 (0)