Handle some additional cases for non-standard modded entities

This commit is contained in:
Moulberry committed 2024-11-14 21:10:23 +08:00
1 parent 51986d4af5
commit 2c38d27e5d
5 files changed
+64 -15

No files matched your search

@@ -14,6 +14,8 @@ import com.moulberry.flashback.packet.FlashbackRemoteSetSlot;
import io.netty.channel.embedded.EmbeddedChannel;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.client.multiplayer.PlayerInfo;
import net.minecraft.core.BlockPos;
@@ -111,11 +113,11 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
private void forward(Entity entity, Packet<?> packet) {
if (entity == null) {
return;
this.forward(packet);
} else {
ServerChunkCache serverChunkCache = this.level().getChunkSource();
serverChunkCache.broadcast(entity, packet);
}
ServerChunkCache serverChunkCache = this.level().getChunkSource();
serverChunkCache.broadcast(entity, packet);
}
private void setBlockState(ServerLevel level, BlockPos blockPos, BlockState blockState) {
@@ -473,11 +475,20 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
@Override
public void handleEntityLinkPacket(ClientboundSetEntityLinkPacket clientboundSetEntityLinkPacket) {
Entity source = this.level().getEntity(clientboundSetEntityLinkPacket.getSourceId());
if (source == null) {
forward(clientboundSetEntityLinkPacket);
return;
}
if (source instanceof Leashable leashable) {
if (clientboundSetEntityLinkPacket.getDestId() == 0) {
leashable.setLeashedTo(null, true);
} else {
Entity dest = this.level().getEntity(clientboundSetEntityLinkPacket.getDestId());
if (dest == null) {
forward(clientboundSetEntityLinkPacket);
return;
}
leashable.setLeashedTo(dest, true);
}
}
@@ -887,22 +898,28 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
@Override
public void handleRemoveEntities(ClientboundRemoveEntitiesPacket clientboundRemoveEntitiesPacket) {
IntList forwardRemoveUnknown = new IntArrayList();
clientboundRemoveEntitiesPacket.getEntityIds().forEach(i -> {
Entity entity = this.level().getEntity(i);
if (entity != null) {
if (entity instanceof ServerPlayer serverPlayer) {
serverPlayer.connection.disconnect(Component.empty());
} else {
entity.discard();
}
if (entity == null) {
forwardRemoveUnknown.add(i);
} else if (entity instanceof ServerPlayer serverPlayer) {
serverPlayer.connection.disconnect(Component.empty());
} else {
entity.discard();
}
});
if (!forwardRemoveUnknown.isEmpty()) {
forward(new ClientboundRemoveEntitiesPacket(forwardRemoveUnknown));
}
}
@Override
public void handleRemoveMobEffect(ClientboundRemoveMobEffectPacket clientboundRemoveMobEffectPacket) {
Entity entity = clientboundRemoveMobEffectPacket.getEntity(this.level());
if (entity instanceof LivingEntity livingEntity) {
Entity entity = this.getEntityOrPending(clientboundRemoveMobEffectPacket.entityId());
if (entity == null) {
forward(clientboundRemoveMobEffectPacket);
} else if (entity instanceof LivingEntity livingEntity) {
livingEntity.removeEffect(clientboundRemoveMobEffectPacket.effect());
}
}
@@ -1141,6 +1158,7 @@ public class ReplayGamePacketHandler implements ClientGamePacketListener {
public void handleSoundEntityEvent(ClientboundSoundEntityPacket clientboundSoundEntityPacket) {
Entity entity = this.level().getEntity(clientboundSoundEntityPacket.getId());
if (entity == null) {
forward(clientboundSoundEntityPacket);
return;
}
@@ -10,6 +10,7 @@ import com.moulberry.flashback.ext.LevelChunkExt;
import com.moulberry.flashback.TempFolderProvider;
import com.moulberry.flashback.keyframe.handler.ReplayServerKeyframeHandler;
import com.moulberry.flashback.packet.FlashbackAccurateEntityPosition;
import com.moulberry.flashback.packet.FlashbackClearEntities;
import com.moulberry.flashback.packet.FlashbackClearParticles;
import com.moulberry.flashback.packet.FlashbackForceClientTick;
import com.moulberry.flashback.packet.FlashbackInstantlyLerp;
@@ -727,6 +728,12 @@ public class ReplayServer extends IntegratedServer {
}
}
serverLevel.setDayTime(0);
for (ServerPlayer player : serverLevel.players()) {
if (player instanceof ReplayPlayer replayPlayer) {
ServerPlayNetworking.send(replayPlayer, FlashbackClearEntities.INSTANCE);
}
}
}
@Override