Fix passengers getting stuck in unloaded chunks (fixes #606)

We need to update the vehicle before its passengers.
This commit is contained in:
Jonas Herzig
2021-11-29 15:10:50 +01:00
parent 88a23222b6
commit d6cd917d9d
3 changed files with 24 additions and 9 deletions

View File

@@ -55,6 +55,7 @@ import net.minecraft.network.packet.s2c.play.SignEditorOpenS2CPacket;
import net.minecraft.network.packet.s2c.play.StatisticsS2CPacket; import net.minecraft.network.packet.s2c.play.StatisticsS2CPacket;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
@@ -1205,15 +1206,7 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
for (Entity entity : entitiesInChunk) { for (Entity entity : entitiesInChunk) {
// Skip interpolation of position updates coming from server // Skip interpolation of position updates coming from server
// (See: newX in EntityLivingBase or otherPlayerMPX in EntityOtherPlayerMP) // (See: newX in EntityLivingBase or otherPlayerMPX in EntityOtherPlayerMP)
// Needs to be called at least 4 times thanks to forcePositionForVehicleAndSelf(entity);
// EntityOtherPlayerMP#otherPlayerMPPosRotationIncrements (max vanilla value is 3)
for (int i = 0; i < 4; i++) {
//#if MC>=11400
entity.tick();
//#else
//$$ entity.onUpdate();
//#endif
}
// Check whether the entity has left the chunk // Check whether the entity has left the chunk
//#if MC>=11700 //#if MC>=11700
@@ -1284,6 +1277,26 @@ public class FullReplaySender extends ChannelDuplexHandler implements ReplaySend
return p; // During synchronous playback everything is sent normally return p; // During synchronous playback everything is sent normally
} }
private void forcePositionForVehicleAndSelf(Entity entity) {
Entity vehicle = entity.getVehicle();
if (vehicle != null) {
forcePositionForVehicleAndSelf(vehicle);
}
// Skip interpolation of position updates coming from server
// (See: newX in EntityLivingBase or otherPlayerMPX in EntityOtherPlayerMP)
int ticks = 0;
Vec3d prevPos;
do {
prevPos = entity.getPos();
if (vehicle != null) {
entity.tickRiding();
} else {
entity.tick();
}
} while (prevPos.squaredDistanceTo(entity.getPos()) > 0.0001 && ticks++ < 100);
}
private static final class PacketData { private static final class PacketData {
private static final com.github.steveice10.netty.buffer.ByteBuf byteBuf = com.github.steveice10.netty.buffer.Unpooled.buffer(); private static final com.github.steveice10.netty.buffer.ByteBuf byteBuf = com.github.steveice10.netty.buffer.Unpooled.buffer();
private static final NetOutput netOutput = new ByteBufNetOutput(byteBuf); private static final NetOutput netOutput = new ByteBufNetOutput(byteBuf);

View File

@@ -27,6 +27,7 @@ net.minecraft.client.gui.GuiYesNoCallback confirmResult() confirmClicked()
net.minecraft.util.text.ITextComponent getString() getUnformattedText() net.minecraft.util.text.ITextComponent getString() getUnformattedText()
net.minecraft.network.play.server.SPacketRespawn func_212643_b() getDimensionID() net.minecraft.network.play.server.SPacketRespawn func_212643_b() getDimensionID()
net.minecraft.client.Minecraft getPackFinder() getResourcePackRepository() net.minecraft.client.Minecraft getPackFinder() getResourcePackRepository()
net.minecraft.entity.Entity getPositionVec() getPositionVector()
net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent addWidget() addButton() net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent addWidget() addButton()
net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent removeWidget() removeButton() net.minecraftforge.client.event.GuiScreenEvent.InitGuiEvent removeWidget() removeButton()

View File

@@ -1,5 +1,6 @@
net.minecraft.stats.StatisticsManager net.minecraft.stats.StatFileWriter net.minecraft.stats.StatisticsManager net.minecraft.stats.StatFileWriter
net.minecraft.init.MobEffects net.minecraft.potion.Potion net.minecraft.init.MobEffects net.minecraft.potion.Potion
net.minecraft.util.math.Vec3d net.minecraft.util.Vec3
net.minecraft.util.text.TextComponentString net.minecraft.util.ChatComponentText net.minecraft.util.text.TextComponentString net.minecraft.util.ChatComponentText
net.minecraft.util.text.TextComponentTranslation net.minecraft.util.ChatComponentTranslation net.minecraft.util.text.TextComponentTranslation net.minecraft.util.ChatComponentTranslation
net.minecraft.util.text.Style net.minecraft.util.ChatStyle net.minecraft.util.text.Style net.minecraft.util.ChatStyle