mirror of
https://github.com/darksaid98/Flashback.git
synced 2026-12-01 22:16:01 +00:00
0.3.0
This commit is contained in:
1 parent
d2a217509f
commit
4d8f896cdf
90 files changed
+2345
-720
No files matched your search
@@ -0,0 +1,43 @@
|
||||
package com.moulberry.flashback.playback;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.moulberry.flashback.ext.ServerLevelExt;
|
||||
import net.minecraft.network.chat.ChatType;
|
||||
import net.minecraft.network.chat.OutgoingChatMessage;
|
||||
import net.minecraft.network.protocol.game.CommonPlayerSpawnInfo;
|
||||
import net.minecraft.network.protocol.status.ServerStatus;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ClientInformation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.stats.Stat;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
|
||||
public class FakePlayer extends ServerPlayer {
|
||||
|
||||
public FakePlayer(MinecraftServer minecraftServer, ServerLevel serverLevel, GameProfile gameProfile, ClientInformation clientInformation) {
|
||||
super(minecraftServer, serverLevel, gameProfile, clientInformation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendChatMessage(OutgoingChatMessage outgoingChatMessage, boolean bl, ChatType.Bound bound) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendServerStatus(ServerStatus serverStatus) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public int awardRecipes(Collection<RecipeHolder<?>> collection) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void awardStat(Stat<?> stat, int i) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,11 +5,14 @@ import com.moulberry.flashback.Flashback;
|
||||
import com.moulberry.flashback.PacketHelper;
|
||||
import com.moulberry.flashback.exception.UnsupportedPacketException;
|
||||
import com.moulberry.flashback.ext.LevelChunkExt;
|
||||
import com.moulberry.flashback.ext.ServerLevelExt;
|
||||
import com.moulberry.flashback.ext.ThreadedLevelLightEngineExt;
|
||||
import io.netty.channel.embedded.EmbeddedChannel;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import net.minecraft.client.multiplayer.PlayerInfo;
|
||||
import net.minecraft.client.player.KeyboardInput;
|
||||
import net.minecraft.client.player.LocalPlayer;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.Holder;
|
||||
@@ -66,6 +69,7 @@ import net.minecraft.world.level.chunk.LevelChunk;
|
||||
import net.minecraft.world.level.chunk.status.ChunkStatus;
|
||||
import net.minecraft.world.level.dimension.LevelStem;
|
||||
import net.minecraft.world.level.lighting.LevelLightEngine;
|
||||
import net.minecraft.world.level.saveddata.maps.MapItemSavedData;
|
||||
import net.minecraft.world.level.storage.DerivedLevelData;
|
||||
import net.minecraft.world.level.storage.PrimaryLevelData;
|
||||
import net.minecraft.world.level.storage.ServerLevelData;
|
||||
@@ -112,7 +116,6 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
||||
private void setBlockState(ServerLevel level, BlockPos blockPos, BlockState blockState) {
|
||||
LevelChunk levelChunk = level.getChunkAt(blockPos);
|
||||
((LevelChunkExt)levelChunk).flashback$setBlockStateWithoutUpdates(blockPos, blockState);
|
||||
level.getChunkSource().blockChanged(blockPos);
|
||||
}
|
||||
|
||||
public void flushPendingEntities() {
|
||||
@@ -184,12 +187,12 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
||||
}
|
||||
}
|
||||
|
||||
private void spawnPlayer(ClientboundAddEntityPacket addEntityPacket, GameProfile gameProfile, GameType gameType) {
|
||||
private ServerPlayer spawnPlayer(ClientboundAddEntityPacket addEntityPacket, GameProfile gameProfile, GameType gameType) {
|
||||
this.flushPendingEntities();
|
||||
gameProfile.getProperties().removeAll("IsReplayViewer");
|
||||
|
||||
CommonListenerCookie commonListenerCookie = CommonListenerCookie.createInitial(gameProfile, false);
|
||||
ServerPlayer serverPlayer = new ServerPlayer(this.replayServer, this.level(), commonListenerCookie.gameProfile(), commonListenerCookie.clientInformation()){
|
||||
ServerPlayer serverPlayer = new FakePlayer(this.replayServer, this.level(), commonListenerCookie.gameProfile(), commonListenerCookie.clientInformation()){
|
||||
@Override
|
||||
public boolean isSpectator() {
|
||||
return false;
|
||||
@@ -220,6 +223,8 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
||||
serverPlayer.recreateFromPacket(addEntityPacket);
|
||||
this.replayServer.getPlayerList().placeNewPlayer(connection, serverPlayer, commonListenerCookie);
|
||||
serverPlayer.setGameMode(gameType);
|
||||
|
||||
return serverPlayer;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -326,6 +331,7 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
||||
public void handleBlockUpdate(ClientboundBlockUpdatePacket clientboundBlockUpdatePacket) {
|
||||
this.setBlockState(this.level(), clientboundBlockUpdatePacket.getPos(),
|
||||
clientboundBlockUpdatePacket.getBlockState());
|
||||
forward(clientboundBlockUpdatePacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -354,11 +360,24 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
||||
clientboundSectionBlocksUpdatePacket.runUpdates((blockPos, blockState) -> {
|
||||
this.setBlockState(level, blockPos, blockState);
|
||||
});
|
||||
forward(clientboundSectionBlocksUpdatePacket);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMapItemData(ClientboundMapItemDataPacket clientboundMapItemDataPacket) {
|
||||
forward(clientboundMapItemDataPacket);
|
||||
|
||||
ServerLevel level = this.level();
|
||||
if (level == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
MapItemSavedData mapItemSavedData = level.getMapData(clientboundMapItemDataPacket.mapId());
|
||||
if (mapItemSavedData == null) {
|
||||
mapItemSavedData = MapItemSavedData.createForClient(clientboundMapItemDataPacket.scale(), clientboundMapItemDataPacket.locked(), level.dimension());
|
||||
level.setMapData(clientboundMapItemDataPacket.mapId(), mapItemSavedData);
|
||||
}
|
||||
clientboundMapItemDataPacket.applyToMap(mapItemSavedData);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -482,6 +501,7 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
||||
this.applyLightData(levelLightEngine, x, z, lightData);
|
||||
|
||||
ChunkPos chunkPos = chunk.getPos();
|
||||
((ServerLevelExt)this.level()).flashback$markChunkAsSendable(chunkPos.toLong());
|
||||
for (ServerPlayer serverPlayer : this.replayServer.getReplayViewers()) {
|
||||
if (serverPlayer.getChunkTrackingView().contains(chunkPos)) {
|
||||
serverPlayer.connection.chunkSender.markChunkPendingToSend(chunk);
|
||||
@@ -657,6 +677,7 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
||||
}
|
||||
|
||||
ServerLevel newLevel = this.replayServer.getLevel(dimension);
|
||||
((ServerLevelExt) newLevel).flashback$setSeedHash(commonPlayerSpawnInfo.seed());
|
||||
|
||||
if (newLevel == oldLevel) {
|
||||
// Change to new dimension
|
||||
@@ -832,6 +853,30 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
||||
}
|
||||
|
||||
this.ensureWorldCreated(clientboundRespawnPacket.commonPlayerSpawnInfo(), localPlayer, false);
|
||||
|
||||
if (localPlayer instanceof ServerPlayer oldServerPlayer) {
|
||||
ClientboundAddEntityPacket addEntityPacket = new ClientboundAddEntityPacket(oldServerPlayer.getId(), oldServerPlayer.getUUID(),
|
||||
oldServerPlayer.getX(), oldServerPlayer.getY(), oldServerPlayer.getZ(), oldServerPlayer.getXRot(), oldServerPlayer.getYRot(), EntityType.PLAYER,
|
||||
0, Vec3.ZERO, oldServerPlayer.getYHeadRot());
|
||||
|
||||
ServerPlayer newServerPlayer = this.spawnPlayer(addEntityPacket, oldServerPlayer.getGameProfile(), oldServerPlayer.gameMode.getGameModeForPlayer());
|
||||
|
||||
if (clientboundRespawnPacket.shouldKeep((byte)2)) {
|
||||
newServerPlayer.setShiftKeyDown(oldServerPlayer.isShiftKeyDown());
|
||||
newServerPlayer.setSprinting(oldServerPlayer.isSprinting());
|
||||
|
||||
var oldEntityData = oldServerPlayer.getEntityData().getNonDefaultValues();
|
||||
if (oldEntityData != null) {
|
||||
newServerPlayer.getEntityData().assignValues(oldEntityData);
|
||||
}
|
||||
}
|
||||
|
||||
if (clientboundRespawnPacket.shouldKeep((byte)1)) {
|
||||
newServerPlayer.getAttributes().assignAllValues(oldServerPlayer.getAttributes());
|
||||
} else {
|
||||
newServerPlayer.getAttributes().assignBaseValues(oldServerPlayer.getAttributes());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -861,10 +906,12 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
|
||||
return;
|
||||
}
|
||||
|
||||
// Note: SynchedEntityData#assignValues isn't used because it doesn't mark the value as dirty
|
||||
|
||||
SynchedEntityData entityData = entity.getEntityData();
|
||||
for (SynchedEntityData.DataValue<?> dataValue : clientboundSetEntityDataPacket.packedItems()) {
|
||||
SynchedEntityData.DataItem<?> dataItem = entityData.itemsById[dataValue.id()];
|
||||
entityData.set((EntityDataAccessor) dataItem.getAccessor(), dataValue.value());
|
||||
entityData.set((EntityDataAccessor) dataItem.getAccessor(), dataValue.value(), true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
package com.moulberry.flashback.playback;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.moulberry.flashback.ext.ServerLevelExt;
|
||||
import net.minecraft.network.protocol.game.CommonPlayerSpawnInfo;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ClientInformation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.stats.Stat;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.item.crafting.RecipeHolder;
|
||||
import net.minecraft.world.level.biome.BiomeManager;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.UUID;
|
||||
@@ -19,6 +23,14 @@ public class ReplayPlayer extends ServerPlayer {
|
||||
super(minecraftServer, serverLevel, gameProfile, clientInformation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonPlayerSpawnInfo createCommonSpawnInfo(ServerLevel serverLevel) {
|
||||
return new CommonPlayerSpawnInfo(serverLevel.dimensionTypeRegistration(), serverLevel.dimension(),
|
||||
((ServerLevelExt)serverLevel).flashback$getSeedHash(), this.gameMode.getGameModeForPlayer(),
|
||||
this.gameMode.getPreviousGameModeForPlayer(),
|
||||
serverLevel.isDebug(), serverLevel.isFlat(), this.getLastDeathLocation(), this.getPortalCooldown());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int awardRecipes(Collection<RecipeHolder<?>> collection) {
|
||||
return 0;
|
||||
@@ -28,5 +40,21 @@ public class ReplayPlayer extends ServerPlayer {
|
||||
public void awardStat(Stat<?> stat, int i) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void indicateDamage(double d, double e) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleDamageEvent(DamageSource damageSource) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hurt(DamageSource damageSource, float f) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInvulnerableTo(DamageSource damageSource) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -21,8 +21,10 @@ import com.moulberry.flashback.record.FlashbackMeta;
|
||||
import com.moulberry.flashback.record.Recorder;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import io.netty.handler.codec.DecoderException;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.longs.LongSet;
|
||||
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
|
||||
import net.minecraft.Util;
|
||||
import net.minecraft.client.Minecraft;
|
||||
@@ -45,10 +47,12 @@ import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.server.level.TicketType;
|
||||
import net.minecraft.server.level.progress.ChunkProgressListenerFactory;
|
||||
import net.minecraft.server.network.ConfigurationTask;
|
||||
import net.minecraft.server.network.ServerGamePacketListenerImpl;
|
||||
import net.minecraft.server.packs.repository.PackRepository;
|
||||
import net.minecraft.server.players.PlayerList;
|
||||
import net.minecraft.world.BossEvent;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.flag.FeatureFlagSet;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
@@ -72,14 +76,12 @@ import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.TreeMap;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import java.util.function.BooleanSupplier;
|
||||
import java.util.function.Function;
|
||||
import java.util.zip.ZipEntry;
|
||||
|
||||
public class ReplayServer extends IntegratedServer {
|
||||
|
||||
@@ -109,6 +111,8 @@ public class ReplayServer extends IntegratedServer {
|
||||
private boolean processedSnapshot = false;
|
||||
private volatile boolean fastForwarding = false;
|
||||
|
||||
private int printFailedDecodePacketCount = 8;
|
||||
|
||||
private final UUID playbackUUID;
|
||||
private final FlashbackMeta metadata;
|
||||
private final TreeMap<Integer, PlayableChunk> playableChunksByStart = new TreeMap<>();
|
||||
@@ -124,6 +128,7 @@ public class ReplayServer extends IntegratedServer {
|
||||
|
||||
private Component shutdownReason = null;
|
||||
private FileSystem playbackFileSystem = null;
|
||||
private boolean initializedWithSnapshot = false;
|
||||
|
||||
public ReplayServer(Thread thread, Minecraft minecraft, LevelStorageSource.LevelStorageAccess levelStorageAccess, PackRepository packRepository, WorldStem worldStem, Services services,
|
||||
ChunkProgressListenerFactory chunkProgressListenerFactory, UUID playbackUUID, Path path) {
|
||||
@@ -254,6 +259,22 @@ public class ReplayServer extends IntegratedServer {
|
||||
public void broadcastSystemMessage(Component component, Function<ServerPlayer, Component> function, boolean bl) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendPlayerPermissionLevel(ServerPlayer serverPlayer) {
|
||||
if (serverPlayer instanceof FakePlayer) {
|
||||
return;
|
||||
}
|
||||
super.sendPlayerPermissionLevel(serverPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendAllPlayerInfo(ServerPlayer serverPlayer) {
|
||||
if (serverPlayer instanceof FakePlayer) {
|
||||
return;
|
||||
}
|
||||
super.sendAllPlayerInfo(serverPlayer);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void broadcast(@Nullable Player player, double x, double y, double z, double distance, ResourceKey<Level> resourceKey, Packet<?> packet) {
|
||||
UUID audioSourceEntity = null;
|
||||
@@ -286,6 +307,10 @@ public class ReplayServer extends IntegratedServer {
|
||||
|
||||
@Override
|
||||
public void sendLevelInfo(ServerPlayer serverPlayer, ServerLevel serverLevel) {
|
||||
if (serverPlayer instanceof FakePlayer) {
|
||||
return;
|
||||
}
|
||||
|
||||
super.sendLevelInfo(serverPlayer, serverLevel);
|
||||
|
||||
// Send all resource packs
|
||||
@@ -323,10 +348,6 @@ public class ReplayServer extends IntegratedServer {
|
||||
this.loadLevel();
|
||||
this.overworld().noSave = true;
|
||||
|
||||
// Play initial snapshot
|
||||
ReplayReader replayReader = this.playableChunksByStart.get(0).getOrLoadReplayReader(this.registryAccess());
|
||||
replayReader.handleSnapshot(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -500,7 +521,20 @@ public class ReplayServer extends IntegratedServer {
|
||||
public void handleGamePacket(RegistryFriendlyByteBuf friendlyByteBuf) {
|
||||
this.configurationPacketHandler.flushPendingConfiguration();
|
||||
|
||||
Packet<? super ClientGamePacketListener> packet = this.gamePacketCodec.decode(friendlyByteBuf);
|
||||
Packet<? super ClientGamePacketListener> packet;
|
||||
try {
|
||||
packet = this.gamePacketCodec.decode(friendlyByteBuf);
|
||||
} catch (DecoderException decoderException) {
|
||||
// Failed to decode packet, lets try ignoring it
|
||||
if (printFailedDecodePacketCount > 0) {
|
||||
Flashback.LOGGER.error("Failed to decode packet from replay stream", decoderException);
|
||||
printFailedDecodePacketCount -= 1;
|
||||
}
|
||||
|
||||
this.gamePacketHandler.flushPendingEntities();
|
||||
friendlyByteBuf.readerIndex(friendlyByteBuf.writerIndex());
|
||||
return;
|
||||
}
|
||||
if (!AllowPendingEntityPacketSet.allowPendingEntity(packet)) {
|
||||
this.gamePacketHandler.flushPendingEntities();
|
||||
}
|
||||
@@ -623,6 +657,14 @@ public class ReplayServer extends IntegratedServer {
|
||||
|
||||
@Override
|
||||
public void tickServer(BooleanSupplier booleanSupplier) {
|
||||
if (!this.initializedWithSnapshot) {
|
||||
this.initializedWithSnapshot = true;
|
||||
|
||||
// Play initial snapshot
|
||||
ReplayReader replayReader = this.playableChunksByStart.get(0).getOrLoadReplayReader(this.registryAccess());
|
||||
replayReader.handleSnapshot(this);
|
||||
}
|
||||
|
||||
this.lastReplayTick = this.currentTick;
|
||||
this.lastTickTimeNanos = this.nextTickTimeNanos - this.tickRateManager().nanosecondsPerTick();
|
||||
|
||||
|
||||
Reference in new issue
Block a user