Skip to content

Various multiplayer fixes #238

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/main/java/com/minecrafttas/tasmod/TASmodClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.minecrafttas.tasmod.registries.TASmodKeybinds;
import com.minecrafttas.tasmod.registries.TASmodPackets;
import com.minecrafttas.tasmod.savestates.SavestateHandlerClient;
import com.minecrafttas.tasmod.savestates.handlers.SavestatePlayerHandler;
import com.minecrafttas.tasmod.tickratechanger.TickrateChangerClient;
import com.minecrafttas.tasmod.ticksync.TickSyncClient;
import com.minecrafttas.tasmod.util.LoggerMarkers;
Expand Down Expand Up @@ -169,6 +170,7 @@ private void registerNetworkPacketHandlers() {
PacketHandlerRegistry.register(ticksyncClient);
PacketHandlerRegistry.register(tickratechanger);
PacketHandlerRegistry.register(savestateHandlerClient);
PacketHandlerRegistry.register(new SavestatePlayerHandler(null)); //TODO Split player handler into client and server
}

private void registerEventListeners() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ public static void loadstate(String nameOfSavestate) throws Exception {
*
* We expect to start at tick 10 WITHOUT clearing the controller.
* If we were to replace the controller, everything above tick 10 would be lost.
* So we only set the index to 10, preload and preload the inputs.
* So we only set the index to 10 and preload the inputs.
*
* VV
* 0 10 20
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ public void loadAndSendMotionToPlayer() {

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

if (nbttagcompound == null) {
continue;
}

int dimensionTo = 0;
if (nbttagcompound.hasKey("Dimension")) {
dimensionTo = nbttagcompound.getInteger("Dimension");
Expand Down Expand Up @@ -148,7 +152,6 @@ public void loadAndSendMotionToPlayer() {
public void changeDimensionDangerously(EntityPlayerMP player, int dimensionTo) {
int dimensionFrom = player.dimension;
WorldServer worldServerFrom = this.server.getWorld(dimensionFrom);
// WorldServer worldServerTo = this.server.getWorld(dimensionTo);

//@formatter:off
player.connection
Expand All @@ -163,10 +166,6 @@ public void changeDimensionDangerously(EntityPlayerMP player, int dimensionTo) {
//@formatter:on
worldServerFrom.removeEntityDangerously(player);
player.isDead = false;
// worldServerTo.spawnEntity(player);
// worldServerTo.updateEntityWithOptionalForce(player, false);
// player.setWorld(worldServerTo);
// player.interactionManager.setWorld(worldServerTo);
}

public void clearScoreboard() {
Expand Down Expand Up @@ -210,7 +209,7 @@ public void onClientPacket(PacketID id, ByteBuffer buf, String username) throws
compound = TASmodBufferBuilder.readNBTTagCompound(buf);
} catch (IOException e) {
e.printStackTrace();
return;
break;
}
/*
* Fair warning: Do NOT read the buffer inside an addScheduledTask. Read it
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.apache.logging.log4j.Logger;

import com.minecrafttas.mctcommon.events.EventListenerRegistry;
import com.minecrafttas.mctcommon.events.EventServer.EventPlayerJoinedServerSide;
import com.minecrafttas.mctcommon.events.EventServer.EventClientCompleteAuthentication;
import com.minecrafttas.mctcommon.events.EventServer.EventServerStop;
import com.minecrafttas.mctcommon.networking.Client.Side;
import com.minecrafttas.mctcommon.networking.exception.PacketNotImplementedException;
Expand All @@ -18,7 +18,6 @@
import com.minecrafttas.tasmod.registries.TASmodPackets;
import com.minecrafttas.tasmod.util.LoggerMarkers;

import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.server.MinecraftServer;

/**
Expand All @@ -39,7 +38,7 @@
* @author Scribble
*
*/
public class TickrateChangerServer implements EventServerStop, EventPlayerJoinedServerSide, ServerPacketHandler {
public class TickrateChangerServer implements EventServerStop, EventClientCompleteAuthentication, ServerPacketHandler {

/**
* The current tickrate of the client
Expand Down Expand Up @@ -208,12 +207,12 @@ private void advanceServerTick() {
* @param player The player that joins the server
*/
@Override
public void onPlayerJoinedServerSide(EntityPlayerMP player) {
if (TASmod.getServerInstance().isDedicatedServer()) {
log("Sending the current tickrate (" + ticksPerSecond + ") to " + player.getName());
public void onClientCompleteAuthentication(String username) {
if (TASmod.getServerInstance() != null && TASmod.getServerInstance().isDedicatedServer()) {
log("Sending the current tickrate (" + ticksPerSecond + ") to " + username);

try {
TASmod.server.sendTo(player, new TASmodBufferBuilder(TASmodPackets.TICKRATE_CHANGE).writeFloat(ticksPerSecond));
TASmod.server.sendTo(username, new TASmodBufferBuilder(TASmodPackets.TICKRATE_CHANGE).writeFloat(ticksPerSecond));
} catch (Exception e) {
e.printStackTrace();
}
Expand Down Expand Up @@ -292,5 +291,4 @@ public void onServerPacket(PacketID id, ByteBuffer buf, String username) throws
throw new PacketNotImplementedException(packet, this.getClass(), Side.SERVER);
}
}

}
Loading