Skip to content

Commit

Permalink
Read and write entity eye height in Vibration particle wrapper
Browse files Browse the repository at this point in the history
Fixes joshuaprince/CoordinateOffset#9

Vibration particle data for vibrations emitted by entities contains
an "entity eye height" field. The ParticleVibrationData wrapper for
WrapperPlayServerParticle did not read or write this field, so any
usage of this wrapper would corrupt the packet and cause players to
be kicked when they moved near an entity that can receive vibrations
(i.e. Wardens).

Tested on 1.19.4 and 1.20.4. This field has been present and unchanged
since 1.19's changes to the Vibration particle (which is also the
first fully-released version to add Wardens):
https://wiki.vg/index.php?title=Data_types&oldid=17608#Particle
  • Loading branch information
joshuaprince committed Jan 21, 2024
1 parent 6f0f6ea commit 9af7f42
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public int getId(ClientVersion version) {
private PositionType type;
private @Nullable Vector3i blockPosition;
private @Nullable Integer entityId;
private @Nullable Float entityEyeHeight;
private int ticks;

public ParticleVibrationData(Vector3i startingPosition, @Nullable Vector3i blockPosition, int ticks) {
Expand All @@ -90,11 +91,12 @@ public ParticleVibrationData(Vector3i startingPosition, @Nullable Vector3i block
this.ticks = ticks;
}

public ParticleVibrationData(Vector3i startingPosition, int entityId, int ticks) {
public ParticleVibrationData(Vector3i startingPosition, int entityId, float entityEyeHeight, int ticks) {
this.startingPosition = startingPosition;
this.type = PositionType.ENTITY;
this.blockPosition = null;
this.entityId = entityId;
this.entityEyeHeight = entityEyeHeight;
this.ticks = ticks;
}

Expand Down Expand Up @@ -126,6 +128,14 @@ public void setEntityId(int entityId) {
this.entityId = entityId;
}

public Optional<Float> getEntityEyeHeight() {
return Optional.ofNullable(entityEyeHeight);
}

public void setEntityEyeHeight(float entityEyeHeight) {
this.entityEyeHeight = entityEyeHeight;
}

public int getTicks() {
return ticks;
}
Expand Down Expand Up @@ -153,7 +163,7 @@ public static ParticleVibrationData read(PacketWrapper<?> wrapper) {
case BLOCK:
return new ParticleVibrationData(startingPos, wrapper.readBlockPosition(), wrapper.readVarInt());
case ENTITY:
return new ParticleVibrationData(startingPos, wrapper.readVarInt(), wrapper.readVarInt());
return new ParticleVibrationData(startingPos, wrapper.readVarInt(), wrapper.readFloat(), wrapper.readVarInt());
default:
throw new IllegalArgumentException("Illegal position type: " + positionType);
}
Expand All @@ -174,6 +184,7 @@ public static void write(PacketWrapper<?> wrapper, ParticleVibrationData data) {
wrapper.writeBlockPosition(data.getBlockPosition().get());
} else if (data.getType() == PositionType.ENTITY) {
wrapper.writeVarInt(data.getEntityId().get());
wrapper.writeFloat(data.getEntityEyeHeight().get());
}
wrapper.writeVarInt(data.getTicks());
}
Expand Down

0 comments on commit 9af7f42

Please sign in to comment.