Merge pull request #4307 from ewoudje/mc1.18/dev

Fix accuracy over network
This commit is contained in:
simibubi 2023-01-14 14:06:07 +01:00 committed by GitHub
commit f62815547e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 21 deletions

View file

@ -12,31 +12,32 @@ import net.minecraftforge.network.NetworkEvent.Context;
public class ContraptionStallPacket extends SimplePacketBase {
int entityID;
float x;
float y;
float z;
double x;
double y;
double z;
float angle;
public ContraptionStallPacket(int entityID, double posX, double posY, double posZ, float angle) {
this.entityID = entityID;
this.x = (float) posX;
this.y = (float) posY;
this.z = (float) posZ;
this.x = posX;
this.y = posY;
this.z = posZ;
this.angle = angle;
}
public ContraptionStallPacket(FriendlyByteBuf buffer) {
entityID = buffer.readInt();
x = buffer.readFloat();
y = buffer.readFloat();
z = buffer.readFloat();
x = buffer.readDouble();
y = buffer.readDouble();
z = buffer.readDouble();
angle = buffer.readFloat();
}
@Override
public void write(FriendlyByteBuf buffer) {
buffer.writeInt(entityID);
writeAll(buffer, x, y, z, angle);
writeAll(buffer, x, y, z);
buffer.writeFloat(angle);
}
@Override
@ -46,9 +47,9 @@ public class ContraptionStallPacket extends SimplePacketBase {
context.get().setPacketHandled(true);
}
private void writeAll(FriendlyByteBuf buffer, float... floats) {
for (float f : floats)
buffer.writeFloat(f);
private void writeAll(FriendlyByteBuf buffer, double... doubles) {
for (double d : doubles)
buffer.writeDouble(d);
}
}

View file

@ -26,16 +26,16 @@ public class LimbSwingUpdatePacket extends SimplePacketBase {
public LimbSwingUpdatePacket(FriendlyByteBuf buffer) {
entityId = buffer.readInt();
position = new Vec3(buffer.readFloat(), buffer.readFloat(), buffer.readFloat());
position = new Vec3(buffer.readDouble(), buffer.readDouble(), buffer.readDouble());
limbSwing = buffer.readFloat();
}
@Override
public void write(FriendlyByteBuf buffer) {
buffer.writeInt(entityId);
buffer.writeFloat((float) position.x);
buffer.writeFloat((float) position.y);
buffer.writeFloat((float) position.z);
buffer.writeDouble(position.x);
buffer.writeDouble(position.y);
buffer.writeDouble(position.z);
buffer.writeFloat(limbSwing);
}

View file

@ -46,7 +46,7 @@ public class TrackNodeLocation extends Vec3i {
}
public Vec3 getLocation() {
return new Vec3(getX() / 2f, getY() / 2f, getZ() / 2f);
return new Vec3(getX() / 2.0, getY() / 2.0, getZ() / 2.0);
}
public ResourceKey<Level> getDimension() {
@ -58,7 +58,7 @@ public class TrackNodeLocation extends Vec3i {
return equalsIgnoreDim(pOther) && pOther instanceof TrackNodeLocation tnl
&& Objects.equals(tnl.dimension, dimension);
}
public boolean equalsIgnoreDim(Object pOther) {
return super.equals(pOther);
}
@ -83,12 +83,18 @@ public class TrackNodeLocation extends Vec3i {
}
public void send(FriendlyByteBuf buffer, DimensionPalette dimensions) {
buffer.writeBlockPos(new BlockPos(this));
buffer.writeVarInt(this.getX());
buffer.writeShort(this.getY());
buffer.writeVarInt(this.getZ());
buffer.writeVarInt(dimensions.encode(dimension));
}
public static TrackNodeLocation receive(FriendlyByteBuf buffer, DimensionPalette dimensions) {
TrackNodeLocation location = fromPackedPos(buffer.readBlockPos());
TrackNodeLocation location = fromPackedPos(new BlockPos(
buffer.readVarInt(),
buffer.readShort(),
buffer.readVarInt()
));
location.dimension = dimensions.decode(buffer.readVarInt());
return location;
}