Search in sources :

Example 1 with V1_6_1EntityAttributes

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

the class V1_6_1REntityAttributesDataType method write.

@Override
public void write(TypeHolder typeHolder, PacketOutput packetOutput) throws IOException {
    V1_6_1EntityAttributes attributes = (V1_6_1EntityAttributes) typeHolder.getObject();
    packetOutput.writeInt(attributes.getAttributes().size());
    for (String key : attributes.getAttributes().keySet()) {
        BaseProtocol.STRING.write(new TypeHolder(Type.STRING, key), packetOutput);
        packetOutput.writeDouble(attributes.getAttributes().get(key));
    }
}
Also used : TypeHolder(com.github.dirtpowered.dirtmv.data.protocol.TypeHolder) V1_6_1EntityAttributes(com.github.dirtpowered.dirtmv.data.protocol.objects.V1_6_1EntityAttributes)

Example 2 with V1_6_1EntityAttributes

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

the class ProtocolRelease74To73 method registerTranslators.

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

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            return PacketUtil.createPacket(0x02, new TypeHolder[] { set(Type.BYTE, (byte) 73), data.read(1), data.read(2), data.read(3) });
        }
    });
    // entity attributes/properties
    addTranslator(0x2C, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            V1_6_1EntityAttributes attrObj = data.read(Type.V1_6_1_ENTITY_ATTRIBUTES, 1);
            List<EntityAttribute> entityAttributes = new ArrayList<>();
            for (Map.Entry<String, Double> entry : attrObj.getAttributes().entrySet()) {
                entityAttributes.add(new EntityAttribute(entry.getKey(), entry.getValue()));
            }
            V1_6_2EntityAttributes attrObjModern = new V1_6_2EntityAttributes(entityAttributes);
            return PacketUtil.createPacket(0x2C, new TypeHolder[] { data.read(0), set(Type.V1_6_2_ENTITY_ATTRIBUTES, attrObjModern) });
        }
    });
    // kick disconnect
    addTranslator(0xFF, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            if (session.getUserData().getPreNettyProtocolState() != PreNettyProtocolState.STATUS)
                return data;
            String reason = data.read(Type.STRING, 0);
            ServerMotd pingMessage = ServerMotd.deserialize(reason);
            pingMessage.setVersionName("1.6.2");
            pingMessage.setProtocol(session.getUserData().getClientVersion().getRegistryId());
            return PacketUtil.createPacket(0xFF, new TypeHolder[] { set(Type.STRING, ServerMotd.serialize(pingMessage)) });
        }
    });
    // 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_3R_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_3R_ITEM, item) });
        }
    });
    // block place
    addTranslator(0x0F, PacketDirection.TO_SERVER, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            int x = data.read(Type.INT, 0);
            int y = data.read(Type.UNSIGNED_BYTE, 1);
            int z = data.read(Type.INT, 2);
            ItemStack item = data.read(Type.V1_3R_ITEM, 4);
            if (item == null)
                return data;
            int itemId = item.getItemId();
            int face = data.read(Type.BYTE, 3);
            if (face == 1) {
                ++y;
            } else if (face == 2) {
                --z;
            } else if (face == 3) {
                ++z;
            } else if (face == 4) {
                --x;
            } else if (face == 5) {
                ++x;
            }
            if (itemId == 323 && data.read(Type.SHORT, 5) > 0) {
                PacketData signEditor = PacketUtil.createPacket(0x85, new TypeHolder[] { // ignored
                set(Type.BYTE, (byte) 0), // x
                set(Type.INT, x), // y
                set(Type.INT, y), // z
                set(Type.INT, z) });
                session.sendPacket(signEditor, PacketDirection.TO_CLIENT, getFrom());
            }
            return data;
        }
    });
}
Also used : ServerSession(com.github.dirtpowered.dirtmv.network.server.ServerSession) EntityAttribute(com.github.dirtpowered.dirtmv.data.protocol.objects.EntityAttribute) PacketTranslator(com.github.dirtpowered.dirtmv.data.translator.PacketTranslator) ServerMotd(com.github.dirtpowered.dirtmv.network.versions.Release73To61.ping.ServerMotd) TypeHolder(com.github.dirtpowered.dirtmv.data.protocol.TypeHolder) V1_6_2EntityAttributes(com.github.dirtpowered.dirtmv.data.protocol.objects.V1_6_2EntityAttributes) ArrayList(java.util.ArrayList) List(java.util.List) V1_6_1EntityAttributes(com.github.dirtpowered.dirtmv.data.protocol.objects.V1_6_1EntityAttributes) ItemStack(com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack) PacketData(com.github.dirtpowered.dirtmv.data.protocol.PacketData)

Example 3 with V1_6_1EntityAttributes

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

the class ProtocolRelease73To61 method getDefaultAttributes.

private PacketData getDefaultAttributes(int entityId) {
    Map<String, Double> map = new HashMap<>();
    map.put("generic.movementSpeed", 0.10000000149011612D);
    V1_6_1EntityAttributes attrObj = new V1_6_1EntityAttributes(map);
    return PacketUtil.createPacket(0x2C, new TypeHolder[] { set(Type.INT, entityId), set(Type.V1_6_1_ENTITY_ATTRIBUTES, attrObj) });
}
Also used : HashMap(java.util.HashMap) V1_6_1EntityAttributes(com.github.dirtpowered.dirtmv.data.protocol.objects.V1_6_1EntityAttributes)

Aggregations

V1_6_1EntityAttributes (com.github.dirtpowered.dirtmv.data.protocol.objects.V1_6_1EntityAttributes)3 TypeHolder (com.github.dirtpowered.dirtmv.data.protocol.TypeHolder)2 PacketData (com.github.dirtpowered.dirtmv.data.protocol.PacketData)1 EntityAttribute (com.github.dirtpowered.dirtmv.data.protocol.objects.EntityAttribute)1 ItemStack (com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack)1 V1_6_2EntityAttributes (com.github.dirtpowered.dirtmv.data.protocol.objects.V1_6_2EntityAttributes)1 PacketTranslator (com.github.dirtpowered.dirtmv.data.translator.PacketTranslator)1 ServerSession (com.github.dirtpowered.dirtmv.network.server.ServerSession)1 ServerMotd (com.github.dirtpowered.dirtmv.network.versions.Release73To61.ping.ServerMotd)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1