Cant set location for ENTITY_TELEPORT (or ENTITY_POSITION_SYNC on 5.4.0), "FieldAccessException: Field index 0 is out of bounds for length 0"
madmagic007 opened this issue ยท 2 comments
- This issue is not solved in a development build
Describe the bug
Trying to create a ENTITY_POSITION_SYNC on 5.4.0, or ENTITY_TELEPORT on 5.3.0, when trying to set the location in the following way:
CSEnt entity = //get ent
Location location = CSEnt.getLocation()
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_POSITION_SYNC);
packet.getIntegers().write(0, entity.entityId());
packet.getDoubles()
.write(0, location.getX()) -- this line gives error "FieldAccessException: Field index 0 is out of bounds for length 0"
.write(1, location.getY())
.write(2, location.getZ());
To Reproduce
Code example above
Expected behavior
I expect to be able to write doubles, as per the packet structure below:
Version Info
https://pastebin.com/47FpgZ0Y
Additional context
i tried multiple entity teleport/move packets, all give same error.
i tried other things than getDoubles, but i dont seem to be able to set the location in any way.
@ByteExceptionM
It took me a while to figure it out, the lack of any documentation didnt make it any easier.
I figured out now i have to do this
PacketContainer packet = new PacketContainer(PacketType.Play.Server.ENTITY_TELEPORT);
Location location = entity.getLocation();
packet.getIntegers().write(0, entity.entityId());
InternalStructure is = packet.getStructures().getValues().get(0);
is.getVectors()
.write(0, new Vector(location.getX(), location.getY(), location.getZ()))
.write(1, new Vector(0, 0, 0));
is.getFloat()
.write(0, location.getYaw());
Got the same problem on 1.21.3, using latest ci build.
Packet has been fundamentally changed:
public record ClientboundTeleportEntityPacket(int id, PositionMoveRotation change, Set<Relative> relatives, boolean onGround)
implements Packet<ClientGamePacketListener> {
public static final StreamCodec<FriendlyByteBuf, ClientboundTeleportEntityPacket> STREAM_CODEC = StreamCodec.composite(
ByteBufCodecs.VAR_INT,
ClientboundTeleportEntityPacket::id,
PositionMoveRotation.STREAM_CODEC,
ClientboundTeleportEntityPacket::change,
Relative.SET_STREAM_CODEC,
ClientboundTeleportEntityPacket::relatives,
ByteBufCodecs.BOOL,
ClientboundTeleportEntityPacket::onGround,
ClientboundTeleportEntityPacket::new
);
public static ClientboundTeleportEntityPacket teleport(int p_360951_, PositionMoveRotation p_369497_, Set<Relative> p_362690_, boolean p_361553_) {
return new ClientboundTeleportEntityPacket(p_360951_, p_369497_, p_362690_, p_361553_);
}
@Override
public PacketType<ClientboundTeleportEntityPacket> type() {
return GamePacketTypes.CLIENTBOUND_TELEPORT_ENTITY;
}
public void handle(ClientGamePacketListener p_133544_) {
p_133544_.handleTeleportEntity(this);
}
}