Search in sources :

Example 16 with ItemStack

use of com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack in project DirtMultiversion by DirtPowered.

the class V1_8BItemDataType method write.

@Override
public void write(TypeHolder typeHolder, PacketOutput packetOutput) {
    ItemStack itemStack = (ItemStack) typeHolder.getObject();
    if (itemStack == null) {
        packetOutput.writeShort(-1);
    } else {
        packetOutput.writeShort(itemStack.getItemId());
        packetOutput.writeShort(itemStack.getAmount());
        packetOutput.writeShort(itemStack.getData());
    }
}
Also used : ItemStack(com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack)

Example 17 with ItemStack

use of com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack in project DirtMultiversion by DirtPowered.

the class V1_8RItemDataType method read.

@Override
public ItemStack read(PacketInput packetInput) {
    int itemId = packetInput.readShort();
    if (itemId >= 0) {
        int amount = packetInput.readByte();
        int data = packetInput.readShort();
        CompoundBinaryTag compoundTag = NBTUtils.readNBTUncompressed(packetInput);
        return new ItemStack(itemId, amount, data, compoundTag);
    }
    return null;
}
Also used : ItemStack(com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack) CompoundBinaryTag(net.kyori.adventure.nbt.CompoundBinaryTag)

Example 18 with ItemStack

use of com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack 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 19 with ItemStack

use of com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack in project DirtMultiversion by DirtPowered.

the class ItemArrayDataType method write.

@Override
public void write(TypeHolder typeHolder, PacketOutput packetOutput) throws IOException {
    ItemStack[] objArray = (ItemStack[]) typeHolder.getObject();
    packetOutput.writeShort(objArray.length);
    for (ItemStack item : objArray) {
        childInstruction.write(new TypeHolder(childInstruction.getType(), item), packetOutput);
    }
}
Also used : TypeHolder(com.github.dirtpowered.dirtmv.data.protocol.TypeHolder) ItemStack(com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack)

Example 20 with ItemStack

use of com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack in project DirtMultiversion by DirtPowered.

the class ProtocolRelease23To22 method registerTranslators.

@Override
public void registerTranslators() {
    // login
    addTranslator(0x01, PacketDirection.TO_SERVER, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            return PacketUtil.createPacket(0x01, new TypeHolder[] { // protocol version
            set(Type.INT, 22), data.read(1), data.read(2), data.read(4), data.read(5), data.read(6), data.read(7), data.read(8) });
        }
    });
    // login
    addTranslator(0x01, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            return PacketUtil.createPacket(0x01, new TypeHolder[] { data.read(0), data.read(1), data.read(2), // world type
            set(Type.STRING, "default"), data.read(3), data.read(4), data.read(5), data.read(6), data.read(7) });
        }
    });
    // respawn
    addTranslator(0x09, PacketDirection.TO_SERVER, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            return PacketUtil.createPacket(0x09, new TypeHolder[] { data.read(0), data.read(1), data.read(2), data.read(3), data.read(4) });
        }
    });
    // respawn
    addTranslator(0x09, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            return PacketUtil.createPacket(0x09, new TypeHolder[] { data.read(0), data.read(1), data.read(2), data.read(3), data.read(4), // world type
            set(Type.STRING, "default") });
        }
    });
    // custom payload
    addTranslator(0xFA, PacketDirection.TO_SERVER, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            // cancel packet
            return cancel();
        }
    });
    // chat
    addTranslator(0x03, PacketDirection.TO_SERVER, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            String filteredMessage = ChatFilter.filterChat(data.read(Type.STRING, 0));
            return PacketUtil.createPacket(0x03, new TypeHolder[] { set(Type.STRING, filteredMessage) });
        }
    });
    // creative item get
    addTranslator(0x6B, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            ItemStack item = data.read(Type.V1_0R_ITEM, 1);
            boolean notNull = item != null;
            if (notNull && !creativeTab.exists(item.getItemId())) {
                // replace all unknown items to stone
                item.setItemId(1);
                item.setData(0);
            }
            return PacketUtil.createPacket(0x6B, new TypeHolder[] { data.read(0), set(Type.V1_0R_ITEM, item) });
        }
    });
}
Also used : TypeHolder(com.github.dirtpowered.dirtmv.data.protocol.TypeHolder) ServerSession(com.github.dirtpowered.dirtmv.network.server.ServerSession) PacketTranslator(com.github.dirtpowered.dirtmv.data.translator.PacketTranslator) ItemStack(com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack) PacketData(com.github.dirtpowered.dirtmv.data.protocol.PacketData)

Aggregations

ItemStack (com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack)26 TypeHolder (com.github.dirtpowered.dirtmv.data.protocol.TypeHolder)15 PacketData (com.github.dirtpowered.dirtmv.data.protocol.PacketData)14 PacketTranslator (com.github.dirtpowered.dirtmv.data.translator.PacketTranslator)14 ServerSession (com.github.dirtpowered.dirtmv.network.server.ServerSession)14 ProtocolStorage (com.github.dirtpowered.dirtmv.data.user.ProtocolStorage)6 WatchableObject (com.github.dirtpowered.dirtmv.data.protocol.objects.WatchableObject)5 CompoundBinaryTag (net.kyori.adventure.nbt.CompoundBinaryTag)5 Motion (com.github.dirtpowered.dirtmv.data.protocol.objects.Motion)4 SneakyThrows (lombok.SneakyThrows)4 EntityType (com.github.dirtpowered.dirtmv.data.entity.EntityType)3 DimensionTracker (com.github.dirtpowered.dirtmv.network.versions.Release28To23.chunk.DimensionTracker)3 ServerMotd (com.github.dirtpowered.dirtmv.network.versions.Release73To61.ping.ServerMotd)3 List (java.util.List)3 MinecraftVersion (com.github.dirtpowered.dirtmv.data.MinecraftVersion)2 NettyInputWrapper (com.github.dirtpowered.dirtmv.data.protocol.io.NettyInputWrapper)2 NettyOutputWrapper (com.github.dirtpowered.dirtmv.data.protocol.io.NettyOutputWrapper)2 BlockLocation (com.github.dirtpowered.dirtmv.data.protocol.objects.BlockLocation)2 Location (com.github.dirtpowered.dirtmv.data.protocol.objects.Location)2 MetadataType (com.github.dirtpowered.dirtmv.data.protocol.objects.MetadataType)2