Search in sources :

Example 6 with BlockLocation

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;
}
Also used : BlockLocation(com.github.dirtpowered.dirtmv.data.protocol.objects.BlockLocation)

Example 7 with BlockLocation

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]);
}
Also used : ArrayList(java.util.ArrayList) MetadataType(com.github.dirtpowered.dirtmv.data.protocol.objects.MetadataType) ItemStack(com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack) BlockLocation(com.github.dirtpowered.dirtmv.data.protocol.objects.BlockLocation) WatchableObject(com.github.dirtpowered.dirtmv.data.protocol.objects.WatchableObject) Rotation(com.github.dirtpowered.dirtmv.data.protocol.objects.Rotation)

Example 8 with BlockLocation

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);
}
Also used : TypeHolder(com.github.dirtpowered.dirtmv.data.protocol.TypeHolder) BlockLocation(com.github.dirtpowered.dirtmv.data.protocol.objects.BlockLocation) WatchableObject(com.github.dirtpowered.dirtmv.data.protocol.objects.WatchableObject) Rotation(com.github.dirtpowered.dirtmv.data.protocol.objects.Rotation)

Aggregations

BlockLocation (com.github.dirtpowered.dirtmv.data.protocol.objects.BlockLocation)8 TypeHolder (com.github.dirtpowered.dirtmv.data.protocol.TypeHolder)4 ProtocolStorage (com.github.dirtpowered.dirtmv.data.user.ProtocolStorage)4 BlockStorage (com.github.dirtpowered.dirtmv.network.versions.Beta17To14.storage.BlockStorage)4 ArrayList (java.util.ArrayList)4 PacketData (com.github.dirtpowered.dirtmv.data.protocol.PacketData)3 PacketTranslator (com.github.dirtpowered.dirtmv.data.translator.PacketTranslator)3 ServerSession (com.github.dirtpowered.dirtmv.network.server.ServerSession)3 DirtMultiVersion (com.github.dirtpowered.dirtmv.DirtMultiVersion)2 MinecraftVersion (com.github.dirtpowered.dirtmv.data.MinecraftVersion)2 ItemStack (com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack)2 Rotation (com.github.dirtpowered.dirtmv.data.protocol.objects.Rotation)2 V1_2Chunk (com.github.dirtpowered.dirtmv.data.protocol.objects.V1_2Chunk)2 V1_2MultiBlockArray (com.github.dirtpowered.dirtmv.data.protocol.objects.V1_2MultiBlockArray)2 WatchableObject (com.github.dirtpowered.dirtmv.data.protocol.objects.WatchableObject)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInput (java.io.DataInput)2 DataInputStream (java.io.DataInputStream)2 IOException (java.io.IOException)2 List (java.util.List)2