mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2026-11-04 08:52:10 -05:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3a71841eff |
+19
-8
@@ -17,6 +17,7 @@
|
||||
*/
|
||||
package com.viaversion.viaversion.protocols.v26_2to26_3.rewriter;
|
||||
|
||||
import com.viaversion.viaversion.api.connection.UserConnection;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
|
||||
import com.viaversion.viaversion.api.minecraft.entities.EntityTypes26_3;
|
||||
import com.viaversion.viaversion.api.minecraft.entitydata.types.EntityDataTypes26_3;
|
||||
@@ -35,9 +36,11 @@ import com.viaversion.viaversion.rewriter.EntityRewriter;
|
||||
public final class EntityPacketRewriter26_3 extends EntityRewriter<ClientboundPacket26_1, Protocol26_2To26_3> {
|
||||
|
||||
private static final int SINGLE_STEP = 1 << 1;
|
||||
// All entities that care about steps use 3 steps in 26.2. 26.3 still lerps every tick within each step, so this
|
||||
// is equivalent
|
||||
// Only living entities interpolate with the steps from the packet, and 26.3 paces their interpolation by the update
|
||||
// interval of the entity type, so the step ticks have to match it to avoid a growing backlog
|
||||
private static final int INTERPOLATION_STEP_TICKS = 3;
|
||||
// Allay, mannequin and player are the only living entities updating every 2 ticks
|
||||
private static final int SHORT_INTERPOLATION_STEP_TICKS = 2;
|
||||
private static final int MAIN_HAND = 0;
|
||||
private static final int OFF_HAND = 1;
|
||||
private static final int CHANGE_DESTROY_DIRECTION_ACTION = 1;
|
||||
@@ -50,20 +53,20 @@ public final class EntityPacketRewriter26_3 extends EntityRewriter<ClientboundPa
|
||||
@Override
|
||||
public void registerPackets() {
|
||||
protocol.registerClientbound(ClientboundPackets26_1.MOVE_ENTITY_POS, wrapper -> {
|
||||
wrapper.passthrough(Types.VAR_INT); // Entity id
|
||||
final int entityId = wrapper.passthrough(Types.VAR_INT);
|
||||
final short xa = wrapper.read(Types.SHORT);
|
||||
final short ya = wrapper.read(Types.SHORT);
|
||||
final short za = wrapper.read(Types.SHORT);
|
||||
final boolean onGround = wrapper.read(Types.BOOLEAN);
|
||||
wrapper.write(Types.VAR_INT, (onGround ? 1 : 0) | SINGLE_STEP); // Only the first bit set, otherwise empty = no step count
|
||||
wrapper.write(Types.VAR_INT, INTERPOLATION_STEP_TICKS);
|
||||
wrapper.write(Types.VAR_INT, interpolationStepTicks(wrapper.user(), entityId));
|
||||
wrapper.write(Types.SHORT, xa);
|
||||
wrapper.write(Types.SHORT, ya);
|
||||
wrapper.write(Types.SHORT, za);
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets26_1.MOVE_ENTITY_POS_ROT, wrapper -> {
|
||||
wrapper.passthrough(Types.VAR_INT); // Entity id
|
||||
final int entityId = wrapper.passthrough(Types.VAR_INT);
|
||||
final short xa = wrapper.read(Types.SHORT);
|
||||
final short ya = wrapper.read(Types.SHORT);
|
||||
final short za = wrapper.read(Types.SHORT);
|
||||
@@ -71,7 +74,7 @@ public final class EntityPacketRewriter26_3 extends EntityRewriter<ClientboundPa
|
||||
final byte xRot = wrapper.read(Types.BYTE);
|
||||
final boolean onGround = wrapper.read(Types.BOOLEAN);
|
||||
wrapper.write(Types.VAR_INT, (onGround ? 1 : 0) | SINGLE_STEP); // Only the first bit set, otherwise empty = no extra steps
|
||||
wrapper.write(Types.VAR_INT, INTERPOLATION_STEP_TICKS);
|
||||
wrapper.write(Types.VAR_INT, interpolationStepTicks(wrapper.user(), entityId));
|
||||
wrapper.write(Types.SHORT, xa);
|
||||
wrapper.write(Types.SHORT, ya);
|
||||
wrapper.write(Types.SHORT, za);
|
||||
@@ -89,7 +92,7 @@ public final class EntityPacketRewriter26_3 extends EntityRewriter<ClientboundPa
|
||||
});
|
||||
|
||||
protocol.registerClientbound(ClientboundPackets26_1.ENTITY_POSITION_SYNC, wrapper -> {
|
||||
wrapper.passthrough(Types.VAR_INT); // Entity ID
|
||||
final int entityId = wrapper.passthrough(Types.VAR_INT);
|
||||
|
||||
wrapper.write(Types.VAR_INT, 1); // Stepped
|
||||
wrapper.write(Types.VAR_INT, 1); // 1 step
|
||||
@@ -97,7 +100,7 @@ public final class EntityPacketRewriter26_3 extends EntityRewriter<ClientboundPa
|
||||
wrapper.passthrough(Types.DOUBLE); // X
|
||||
wrapper.passthrough(Types.DOUBLE); // Y
|
||||
wrapper.passthrough(Types.DOUBLE); // Z
|
||||
wrapper.write(Types.VAR_INT, INTERPOLATION_STEP_TICKS);
|
||||
wrapper.write(Types.VAR_INT, interpolationStepTicks(wrapper.user(), entityId));
|
||||
|
||||
wrapper.read(Types.DOUBLE); // Delta x
|
||||
wrapper.read(Types.DOUBLE); // Delta y
|
||||
@@ -194,6 +197,14 @@ public final class EntityPacketRewriter26_3 extends EntityRewriter<ClientboundPa
|
||||
);
|
||||
}
|
||||
|
||||
private int interpolationStepTicks(final UserConnection connection, final int entityId) {
|
||||
final EntityType type = tracker(connection).entityType(entityId);
|
||||
if (type == null) {
|
||||
return INTERPOLATION_STEP_TICKS;
|
||||
}
|
||||
return type.isOrHasParent(EntityTypes26_3.AVATAR) || type == EntityTypes26_3.ALLAY ? SHORT_INTERPOLATION_STEP_TICKS : INTERPOLATION_STEP_TICKS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType typeFromId(final int type) {
|
||||
return EntityTypes26_3.getTypeFromId(type);
|
||||
|
||||
Reference in new issue
Block a user