rename some ByteBuffer functions

This commit is contained in:
Bixilon 2021-03-31 20:37:27 +02:00
parent a910122ce2
commit 9cfda63e36
No known key found for this signature in database
GPG Key ID: 5CAD791931B09AC4
20 changed files with 32 additions and 33 deletions

View File

@ -15,7 +15,7 @@ package de.bixilon.minosoft.data.mappings.blocks.actions;
public class BeaconAction implements BlockAction { public class BeaconAction implements BlockAction {
public BeaconAction(short status, short ignored) { public BeaconAction(int status, int ignored) {
// only 1 action (id 1) // only 1 action (id 1)
} }

View File

@ -14,9 +14,9 @@
package de.bixilon.minosoft.data.mappings.blocks.actions; package de.bixilon.minosoft.data.mappings.blocks.actions;
public class ChestAction implements BlockAction { public class ChestAction implements BlockAction {
private final short playersLookingInChest; private final int playersLookingInChest;
public ChestAction(short unused, short playersLookingInChest) { public ChestAction(int unused, int playersLookingInChest) {
this.playersLookingInChest = playersLookingInChest; this.playersLookingInChest = playersLookingInChest;
} }

View File

@ -15,7 +15,7 @@ package de.bixilon.minosoft.data.mappings.blocks.actions;
public class EndGatewayAction implements BlockAction { public class EndGatewayAction implements BlockAction {
public EndGatewayAction(short status, short ignored) { public EndGatewayAction(int status, int ignored) {
// only 1 action (id 1) // only 1 action (id 1)
} }

View File

@ -15,7 +15,7 @@ package de.bixilon.minosoft.data.mappings.blocks.actions;
public class MobSpawnerAction implements BlockAction { public class MobSpawnerAction implements BlockAction {
public MobSpawnerAction(short status, short ignored) { public MobSpawnerAction(int status, int ignored) {
// only 1 action (id 1) // only 1 action (id 1)
} }

View File

@ -15,9 +15,9 @@ package de.bixilon.minosoft.data.mappings.blocks.actions;
public class NoteBlockAction implements BlockAction { public class NoteBlockAction implements BlockAction {
private final Instruments instrument; private final Instruments instrument;
private final short pitch; private final int pitch;
public NoteBlockAction(short instrument, short pitch) { public NoteBlockAction(int instrument, int pitch) {
this.instrument = Instruments.byId(instrument); this.instrument = Instruments.byId(instrument);
this.pitch = pitch; this.pitch = pitch;
} }

View File

@ -19,7 +19,7 @@ public class PistonAction implements BlockAction {
private final PistonStates status; private final PistonStates status;
private final Directions direction; private final Directions direction;
public PistonAction(short status, short direction) { public PistonAction(int status, int direction) {
this.status = PistonStates.byId(status); this.status = PistonStates.byId(status);
this.direction = Directions.byId(direction); this.direction = Directions.byId(direction);
} }

View File

@ -35,8 +35,8 @@ public class PacketBlockAction extends ClientboundPacket {
} else { } else {
this.position = buffer.readBlockPosition(); this.position = buffer.readBlockPosition();
} }
short byte1 = buffer.readUnsignedByte(); int byte1 = buffer.readUnsignedByte();
short byte2 = buffer.readUnsignedByte(); int byte2 = buffer.readUnsignedByte();
Block blockId = buffer.getConnection().getMapping().getBlockRegistry().get(buffer.readVarInt()); Block blockId = buffer.getConnection().getMapping().getBlockRegistry().get(buffer.readVarInt());
if (blockId == null) { if (blockId == null) {
this.data = null; this.data = null;

View File

@ -36,7 +36,7 @@ public class PacketEntityTeleport extends ClientboundPacket {
if (buffer.getVersionId() < V_16W06A) { if (buffer.getVersionId() < V_16W06A) {
this.position = new Vec3(buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt()); this.position = new Vec3(buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt());
} else { } else {
this.position = buffer.readLocation(); this.position = buffer.readEntityPosition();
} }
this.yaw = buffer.readAngle(); this.yaw = buffer.readAngle();
this.pitch = buffer.readAngle(); this.pitch = buffer.readAngle();

View File

@ -26,7 +26,7 @@ public class PacketFacePlayer extends ClientboundPacket {
public PacketFacePlayer(InByteBuffer buffer) { public PacketFacePlayer(InByteBuffer buffer) {
this.face = PlayerFaces.byId(buffer.readVarInt()); this.face = PlayerFaces.byId(buffer.readVarInt());
this.position = buffer.readLocation(); this.position = buffer.readEntityPosition();
if (buffer.readBoolean()) { if (buffer.readBoolean()) {
// entity present // entity present
this.entityId = buffer.readVarInt(); this.entityId = buffer.readVarInt();

View File

@ -107,16 +107,15 @@ public class PacketMapData extends ClientboundPacket {
this.pins.add(new MapPinSet(type, direction, x, z, displayName)); this.pins.add(new MapPinSet(type, direction, x, z, displayName));
} }
short columns = buffer.readUnsignedByte(); int columns = buffer.readUnsignedByte();
if (columns > 0) { if (columns > 0) {
short rows = buffer.readUnsignedByte(); int rows = buffer.readUnsignedByte();
short xOffset = buffer.readUnsignedByte(); int xOffset = buffer.readUnsignedByte();
short zOffset = buffer.readUnsignedByte(); int zOffset = buffer.readUnsignedByte();
int dataLength = buffer.readVarInt(); int dataLength = buffer.readVarInt();
this.data = buffer.readBytes(dataLength); this.data = buffer.readBytes(dataLength);
} }
return;
} }
@Override @Override

View File

@ -47,7 +47,7 @@ public class PacketParticle extends ClientboundPacket {
if (buffer.getVersionId() < V_1_15_PRE4) { if (buffer.getVersionId() < V_1_15_PRE4) {
this.position = buffer.readFloatPosition(); this.position = buffer.readFloatPosition();
} else { } else {
this.position = buffer.readLocation(); this.position = buffer.readEntityPosition();
} }
// offset // offset

View File

@ -33,7 +33,7 @@ public class PacketPlayerPositionAndRotation extends ClientboundPacket {
private boolean dismountVehicle = true; private boolean dismountVehicle = true;
public PacketPlayerPositionAndRotation(InByteBuffer buffer) { public PacketPlayerPositionAndRotation(InByteBuffer buffer) {
this.position = buffer.readLocation(); this.position = buffer.readEntityPosition();
this.rotation = new EntityRotation(buffer.readFloat(), buffer.readFloat(), 0); this.rotation = new EntityRotation(buffer.readFloat(), buffer.readFloat(), 0);
if (buffer.getVersionId() < V_14W03B) { if (buffer.getVersionId() < V_14W03B) {
this.onGround = buffer.readBoolean(); this.onGround = buffer.readBoolean();

View File

@ -33,7 +33,7 @@ public class PacketSpawnExperienceOrb extends ClientboundPacket {
if (buffer.getVersionId() < V_16W06A) { if (buffer.getVersionId() < V_16W06A) {
position = new Vec3(buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt()); position = new Vec3(buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt());
} else { } else {
position = buffer.readLocation(); position = buffer.readEntityPosition();
} }
int count = buffer.readUnsignedShort(); int count = buffer.readUnsignedShort();
this.entity = new ExperienceOrb(buffer.getConnection(), position, count); this.entity = new ExperienceOrb(buffer.getConnection(), position, count);

View File

@ -54,7 +54,7 @@ public class PacketSpawnMob extends ClientboundPacket {
if (buffer.getVersionId() < V_16W06A) { if (buffer.getVersionId() < V_16W06A) {
position = new Vec3(buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt()); position = new Vec3(buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt());
} else { } else {
position = buffer.readLocation(); position = buffer.readEntityPosition();
} }
EntityRotation rotation = new EntityRotation(buffer.readAngle(), buffer.readAngle(), buffer.readAngle()); EntityRotation rotation = new EntityRotation(buffer.readAngle(), buffer.readAngle(), buffer.readAngle());
this.velocity = new Velocity(buffer.readShort(), buffer.readShort(), buffer.readShort()); this.velocity = new Velocity(buffer.readShort(), buffer.readShort(), buffer.readShort());

View File

@ -59,7 +59,7 @@ public class PacketSpawnObject extends ClientboundPacket {
if (buffer.getVersionId() < V_16W06A) { if (buffer.getVersionId() < V_16W06A) {
position = new Vec3(buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt()); position = new Vec3(buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt());
} else { } else {
position = buffer.readLocation(); position = buffer.readEntityPosition();
} }
EntityRotation rotation = new EntityRotation(buffer.readAngle(), buffer.readAngle(), 0); EntityRotation rotation = new EntityRotation(buffer.readAngle(), buffer.readAngle(), 0);
int data = buffer.readInt(); int data = buffer.readInt();

View File

@ -55,7 +55,7 @@ public class PacketSpawnPlayer extends ClientboundPacket {
if (buffer.getVersionId() < V_16W06A) { if (buffer.getVersionId() < V_16W06A) {
position = new Vec3(buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt()); position = new Vec3(buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt());
} else { } else {
position = buffer.readLocation(); position = buffer.readEntityPosition();
} }
short yaw = buffer.readAngle(); short yaw = buffer.readAngle();
short pitch = buffer.readAngle(); short pitch = buffer.readAngle();

View File

@ -35,7 +35,7 @@ public class PacketSpawnWeatherEntity extends ClientboundPacket {
if (buffer.getVersionId() < V_16W06A) { if (buffer.getVersionId() < V_16W06A) {
position = new Vec3(buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt()); position = new Vec3(buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt(), buffer.readFixedPointNumberInt());
} else { } else {
position = buffer.readLocation(); position = buffer.readEntityPosition();
} }
this.entity = new LightningBolt(buffer.getConnection(), this.entityId, position); this.entity = new LightningBolt(buffer.getConnection(), this.entityId, position);
} }

View File

@ -24,7 +24,7 @@ public class PacketVehicleMovement extends ClientboundPacket {
private final float pitch; private final float pitch;
public PacketVehicleMovement(InByteBuffer buffer) { public PacketVehicleMovement(InByteBuffer buffer) {
this.position = buffer.readLocation(); this.position = buffer.readEntityPosition();
this.yaw = buffer.readFloat(); this.yaw = buffer.readFloat();
this.pitch = buffer.readFloat(); this.pitch = buffer.readFloat();
} }

View File

@ -135,11 +135,11 @@ public class InByteBuffer {
return readByte() == 1; return readByte() == 1;
} }
public int[] readUnsignedLEShorts(int num) { public int[] readUnsignedShortsLE(int count) {
if (num > ProtocolDefinition.PROTOCOL_PACKET_MAX_SIZE) { if (count > ProtocolDefinition.PROTOCOL_PACKET_MAX_SIZE) {
throw new IllegalArgumentException("Trying to allocate to much memory"); throw new IllegalArgumentException("Trying to allocate to much memory");
} }
int[] ret = new int[num]; int[] ret = new int[count];
for (int i = 0; i < ret.length; i++) { for (int i = 0; i < ret.length; i++) {
ret[i] = ((readUnsignedByte()) | (readUnsignedByte() << 8)); ret[i] = ((readUnsignedByte()) | (readUnsignedByte() << 8));
} }
@ -198,8 +198,8 @@ public class InByteBuffer {
} }
@IntRange(from = 0, to = ((int) Byte.MAX_VALUE) * 2 + 1) @IntRange(from = 0, to = ((int) Byte.MAX_VALUE) * 2 + 1)
public short readUnsignedByte() { public int readUnsignedByte() {
return (short) (this.bytes[this.position++] & 0xFF); return (this.bytes[this.position++] & 0xFF);
} }
public Vec3i readBlockPosition() { public Vec3i readBlockPosition() {
@ -356,7 +356,7 @@ public class InByteBuffer {
return (short) (readByte() * ProtocolDefinition.ANGLE_CALCULATION_CONSTANT); return (short) (readByte() * ProtocolDefinition.ANGLE_CALCULATION_CONSTANT);
} }
public Vec3 readLocation() { public Vec3 readEntityPosition() {
return new Vec3(readDouble(), readDouble(), readDouble()); return new Vec3(readDouble(), readDouble(), readDouble());
} }
@ -448,7 +448,7 @@ public class InByteBuffer {
EntityMetaData.MetaDataHashMap sets = metaData.getSets(); EntityMetaData.MetaDataHashMap sets = metaData.getSets();
if (this.versionId < V_15W31A) { // ToDo: This version was 48, but this one does not exist! if (this.versionId < V_15W31A) { // ToDo: This version was 48, but this one does not exist!
short item = readUnsignedByte(); int item = readUnsignedByte();
while (item != 0x7F) { while (item != 0x7F) {
byte index = (byte) (item & 0x1F); byte index = (byte) (item & 0x1F);
EntityMetaData.EntityMetaDataDataTypes type = this.connection.getMapping().getEntityMetaDataDataDataTypesRegistry().get((item & 0xFF) >> 5); EntityMetaData.EntityMetaDataDataTypes type = this.connection.getMapping().getEntityMetaDataDataDataTypesRegistry().get((item & 0xFF) >> 5);

View File

@ -114,7 +114,7 @@ object ChunkUtil {
val totalEntries: Int = ProtocolDefinition.BLOCKS_PER_SECTION * sectionBitMask.cardinality() val totalEntries: Int = ProtocolDefinition.BLOCKS_PER_SECTION * sectionBitMask.cardinality()
val totalHalfEntries = totalEntries / 2 val totalHalfEntries = totalEntries / 2
val blockData = buffer.readUnsignedLEShorts(totalEntries) // blocks >>> 4, data & 0xF val blockData = buffer.readUnsignedShortsLE(totalEntries) // blocks >>> 4, data & 0xF
val light = buffer.readBytes(totalHalfEntries) val light = buffer.readBytes(totalHalfEntries)