use of com.github.dirtpowered.dirtmv.data.protocol.objects.BlockLocation in project DirtMultiversion by DirtPowered.
the class PositionArrayDataType method read.
@Override
public BlockLocation[] read(PacketInput packetInput) {
int blockAmount = packetInput.readInt();
BlockLocation[] blockLocations = new BlockLocation[blockAmount];
for (int i = 0; i < blockAmount; i++) {
int locX = packetInput.readByte();
int locY = packetInput.readByte();
int locZ = packetInput.readByte();
blockLocations[i] = new BlockLocation(locX, locY, locZ);
}
return blockLocations;
}
use of com.github.dirtpowered.dirtmv.data.protocol.objects.BlockLocation in project DirtMultiversion by DirtPowered.
the class MetadataDataType method read.
@Override
public WatchableObject[] read(PacketInput packetInput) throws IOException {
ArrayList<WatchableObject> dataMap = new ArrayList<>();
for (byte b = packetInput.readByte(); b != 127; b = packetInput.readByte()) {
MetadataType type = MetadataType.fromType((b & 224) >> 5);
int index = b & 31;
WatchableObject value = null;
switch(type) {
case BYTE:
value = new WatchableObject(type, index, BaseProtocol.BYTE.read(packetInput));
break;
case SHORT:
value = new WatchableObject(type, index, BaseProtocol.SHORT.read(packetInput));
break;
case INT:
value = new WatchableObject(type, index, BaseProtocol.INT.read(packetInput));
break;
case FLOAT:
value = new WatchableObject(type, index, BaseProtocol.FLOAT.read(packetInput));
break;
case STRING:
if (getType() == Type.V1_7R_METADATA || getType() == Type.V1_8R_METADATA) {
value = new WatchableObject(type, index, V1_7_2RProtocol.STRING.read(packetInput));
} else {
value = new WatchableObject(type, index, BaseProtocol.STRING.read(packetInput));
}
break;
case ITEM:
ItemStack itemStack;
if (getType() == Type.V1_4R_METADATA || getType() == Type.V1_7R_METADATA) {
itemStack = V1_3_1RProtocol.ITEM.read(packetInput);
} else if (getType() == Type.V1_8R_METADATA) {
itemStack = V1_8RProtocol.ITEM.read(packetInput);
} else {
itemStack = V1_3BProtocol.ITEM.read(packetInput);
}
value = new WatchableObject(type, index, itemStack);
break;
case POSITION:
int x = packetInput.readInt();
int y = packetInput.readInt();
int z = packetInput.readInt();
value = new WatchableObject(type, index, new BlockLocation(x, y, z));
break;
case ROTATION:
float rX = packetInput.readFloat();
float rY = packetInput.readFloat();
float rZ = packetInput.readFloat();
value = new WatchableObject(type, index, new Rotation(rX, rY, rZ));
break;
}
dataMap.add(value);
}
return dataMap.toArray(new WatchableObject[0]);
}
use of com.github.dirtpowered.dirtmv.data.protocol.objects.BlockLocation in project DirtMultiversion by DirtPowered.
the class MetadataDataType method write.
@Override
public void write(TypeHolder typeHolder, PacketOutput packetOutput) throws IOException {
WatchableObject[] watchableObjects = (WatchableObject[]) typeHolder.getObject();
if (watchableObjects == null || watchableObjects.length == 0) {
packetOutput.writeByte(127);
return;
}
for (WatchableObject watchableObject : watchableObjects) {
int header = (watchableObject.getType().getType() << 5 | watchableObject.getIndex() & 31) & 255;
packetOutput.writeByte(header);
switch(watchableObject.getType()) {
case BYTE:
BaseProtocol.BYTE.write(new TypeHolder(Type.BYTE, watchableObject.getValue()), packetOutput);
break;
case SHORT:
BaseProtocol.SHORT.write(new TypeHolder(Type.SHORT, watchableObject.getValue()), packetOutput);
break;
case INT:
BaseProtocol.INT.write(new TypeHolder(Type.INT, watchableObject.getValue()), packetOutput);
break;
case FLOAT:
BaseProtocol.FLOAT.write(new TypeHolder(Type.FLOAT, watchableObject.getValue()), packetOutput);
break;
case STRING:
if (getType() == Type.V1_7R_METADATA || getType() == Type.V1_8R_METADATA) {
V1_7_2RProtocol.STRING.write(new TypeHolder(Type.V1_7_STRING, watchableObject.getValue()), packetOutput);
} else {
BaseProtocol.STRING.write(new TypeHolder(Type.STRING, watchableObject.getValue()), packetOutput);
}
break;
case ITEM:
if (getType() == Type.V1_4R_METADATA || getType() == Type.V1_7R_METADATA) {
V1_3_1RProtocol.ITEM.write(new TypeHolder(Type.V1_3R_ITEM, watchableObject.getValue()), packetOutput);
} else if (getType() == Type.V1_8R_METADATA) {
V1_8RProtocol.ITEM.write(new TypeHolder(Type.V1_8R_ITEM, watchableObject.getValue()), packetOutput);
} else {
V1_3BProtocol.ITEM.write(new TypeHolder(Type.V1_3B_ITEM, watchableObject.getValue()), packetOutput);
}
break;
case POSITION:
BlockLocation location = (BlockLocation) watchableObject.getValue();
packetOutput.writeInt(location.getX());
packetOutput.writeInt(location.getY());
packetOutput.writeInt(location.getZ());
break;
case ROTATION:
Rotation rotation = (Rotation) watchableObject.getValue();
packetOutput.writeFloat(rotation.getX());
packetOutput.writeFloat(rotation.getY());
packetOutput.writeFloat(rotation.getZ());
break;
}
}
packetOutput.writeByte(127);
}
Aggregations