Properly save and replay FMLProxyPackets

During recording FMLProxyPackets are converted to S3FPacketCustomPayload
During playback the normal Forge network stack is used to handle these packets
This commit is contained in:
CrushedPixel
2016-09-04 14:25:33 +02:00
committed by johni0702
parent 2a73faed6c
commit 79bc6a8a7b
3 changed files with 14 additions and 5 deletions

View File

@@ -68,8 +68,11 @@ public class ConnectionEventHandler {
String worldName;
if(event.isLocal) {
worldName = MinecraftServer.getServer().getWorldName();
} else {
} else if (Minecraft.getMinecraft().getCurrentServerData() != null) {
worldName = Minecraft.getMinecraft().getCurrentServerData().serverIP;
} else {
logger.info("Recording not started as the world is neither local nor remote (probably a replay).");
return;
}
Channel channel = nm.channel();
ChannelPipeline pipeline = channel.pipeline();

View File

@@ -165,6 +165,7 @@ public class PacketListener extends ChannelInboundHandlerAdapter {
if (packet instanceof FMLProxyPacket) {
// This packet requires special handling
((FMLProxyPacket) packet).toS3FPackets().forEach(this::save);
super.channelRead(ctx, msg);
return;
}

View File

@@ -23,6 +23,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.EnumPacketDirection;
import net.minecraft.network.NetworkManager;
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.common.network.handshake.NetworkDispatcher;
import org.lwjgl.opengl.Display;
@@ -135,13 +136,17 @@ public class ReplayHandler {
t.printStackTrace();
}
};
networkManager.setNetHandler(new NetHandlerPlayClient(
mc, null, networkManager, new GameProfile(UUID.randomUUID(), "Player")));
NetHandlerPlayClient netHandlerPlayClient =
new NetHandlerPlayClient(mc, null, networkManager, new GameProfile(UUID.randomUUID(), "Player"));
networkManager.setNetHandler(netHandlerPlayClient);
FMLClientHandler.instance().setPlayClient(netHandlerPlayClient);
channel = new EmbeddedChannel(networkManager);
channel.attr(NetworkDispatcher.FML_DISPATCHER).set(new NetworkDispatcher(networkManager));
NetworkDispatcher networkDispatcher = new NetworkDispatcher(networkManager);
channel.attr(NetworkDispatcher.FML_DISPATCHER).set(networkDispatcher);
channel.pipeline().addFirst(replaySender);
channel.pipeline().addFirst("ReplayModReplay_replaySender", replaySender);
channel.pipeline().addAfter("ReplayModReplay_replaySender", "fml:packet_handler", networkDispatcher);
channel.pipeline().fireChannelActive();
}