Search in sources :

Example 1 with OnGroundTracker

use of com.github.dirtpowered.dirtmv.network.versions.Release47To5.entity.OnGroundTracker in project DirtMultiversion by DirtPowered.

the class MovementPackets method registerTranslators.

@Override
public void registerTranslators() {
    // entity
    addTranslator(0x14, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            return PacketUtil.createPacket(0x14, new TypeHolder[] { set(Type.VAR_INT, data.read(Type.INT, 0)) });
        }
    });
    // entity relative move
    addTranslator(0x15, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            OnGroundTracker groundTracker = session.getUserData().getProtocolStorage().get(OnGroundTracker.class);
            int entityId = data.read(Type.INT, 0);
            double y = data.read(Type.BYTE, 2) / 32.0D;
            boolean onGround = !(y < 0.0D);
            groundTracker.setGroundStateFor(entityId, onGround);
            return PacketUtil.createPacket(0x15, new TypeHolder[] { set(Type.VAR_INT, data.read(Type.INT, 0)), data.read(1), data.read(2), data.read(3), set(Type.BOOLEAN, onGround) });
        }
    });
    // entity look
    addTranslator(0x16, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            OnGroundTracker groundTracker = session.getUserData().getProtocolStorage().get(OnGroundTracker.class);
            int entityId = data.read(Type.INT, 0);
            boolean onGround = groundTracker.isOnGround(entityId);
            return PacketUtil.createPacket(0x16, new TypeHolder[] { set(Type.VAR_INT, data.read(Type.INT, 0)), data.read(1), data.read(2), set(Type.BOOLEAN, onGround) });
        }
    });
    // entity look move
    addTranslator(0x17, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            OnGroundTracker groundTracker = session.getUserData().getProtocolStorage().get(OnGroundTracker.class);
            int entityId = data.read(Type.INT, 0);
            double y = data.read(Type.BYTE, 2) / 32.0D;
            boolean onGround = !(y < 0.0D);
            groundTracker.setGroundStateFor(entityId, onGround);
            return PacketUtil.createPacket(0x17, new TypeHolder[] { set(Type.VAR_INT, data.read(Type.INT, 0)), data.read(1), data.read(2), data.read(3), data.read(4), data.read(5), set(Type.BOOLEAN, onGround) });
        }
    });
    // entity teleport
    addTranslator(0x18, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            ProtocolStorage storage = session.getStorage();
            OnGroundTracker groundTracker = storage.get(OnGroundTracker.class);
            int entityId = data.read(Type.INT, 0);
            boolean onGround = groundTracker.isOnGround(entityId);
            return PacketUtil.createPacket(0x18, new TypeHolder[] { set(Type.VAR_INT, data.read(Type.INT, 0)), data.read(1), data.read(2), data.read(3), data.read(4), data.read(5), set(Type.BOOLEAN, onGround) });
        }
    });
    // entity head look
    addTranslator(0x19, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            return PacketUtil.createPacket(0x19, new TypeHolder[] { set(Type.VAR_INT, data.read(Type.INT, 0)), data.read(1) });
        }
    });
    // position and look
    addTranslator(0x08, ProtocolState.PLAY, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            return PacketUtil.createPacket(0x08, new TypeHolder[] { data.read(0), set(Type.DOUBLE, data.read(Type.DOUBLE, 1) - 1.62D), data.read(2), data.read(3), data.read(4), set(Type.BYTE, (byte) 0) });
        }
    });
    // player
    addTranslator(0x03, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            ProtocolStorage s = session.getStorage();
            if (s.hasObject(PlayerMovementTracker.class)) {
                s.get(PlayerMovementTracker.class).setLastLocationUpdate(System.currentTimeMillis());
            }
            return PacketUtil.createPacket(0x03, new TypeHolder[] { set(Type.BYTE, data.read(Type.UNSIGNED_BYTE, 0).byteValue()) });
        }
    });
    // player position
    addTranslator(0x04, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            ProtocolStorage s = session.getStorage();
            if (s.hasObject(PlayerMovementTracker.class)) {
                s.get(PlayerMovementTracker.class).setLastLocationUpdate(System.currentTimeMillis());
            }
            return PacketUtil.createPacket(0x04, new TypeHolder[] { data.read(0), data.read(1), // stance
            set(Type.DOUBLE, data.read(Type.DOUBLE, 1) + 1.62D), data.read(2), set(Type.BYTE, data.read(Type.UNSIGNED_BYTE, 3).byteValue()) });
        }
    });
    // player look
    addTranslator(0x05, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            ProtocolStorage s = session.getStorage();
            if (s.hasObject(PlayerMovementTracker.class)) {
                s.get(PlayerMovementTracker.class).setLastLocationUpdate(System.currentTimeMillis());
            }
            return PacketUtil.createPacket(0x05, new TypeHolder[] { data.read(0), data.read(1), set(Type.BYTE, data.read(Type.UNSIGNED_BYTE, 2).byteValue()) });
        }
    });
    // player pos look
    addTranslator(0x06, ProtocolState.PLAY, PacketDirection.TO_SERVER, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            ProtocolStorage s = session.getStorage();
            if (s.hasObject(PlayerMovementTracker.class)) {
                s.get(PlayerMovementTracker.class).setLastLocationUpdate(System.currentTimeMillis());
            }
            return PacketUtil.createPacket(0x06, new TypeHolder[] { data.read(0), data.read(1), set(Type.DOUBLE, data.read(Type.DOUBLE, 1) + 1.62D), data.read(2), data.read(3), data.read(4), set(Type.BYTE, data.read(Type.UNSIGNED_BYTE, 5).byteValue()) });
        }
    });
}
Also used : TypeHolder(com.github.dirtpowered.dirtmv.data.protocol.TypeHolder) ServerSession(com.github.dirtpowered.dirtmv.network.server.ServerSession) ProtocolStorage(com.github.dirtpowered.dirtmv.data.user.ProtocolStorage) PacketTranslator(com.github.dirtpowered.dirtmv.data.translator.PacketTranslator) OnGroundTracker(com.github.dirtpowered.dirtmv.network.versions.Release47To5.entity.OnGroundTracker) PacketData(com.github.dirtpowered.dirtmv.data.protocol.PacketData) PlayerMovementTracker(com.github.dirtpowered.dirtmv.network.versions.Release47To5.entity.PlayerMovementTracker)

Example 2 with OnGroundTracker

use of com.github.dirtpowered.dirtmv.network.versions.Release47To5.entity.OnGroundTracker in project DirtMultiversion by DirtPowered.

the class ProtocolRelease47To5 method onConnect.

@Override
public void onConnect(ServerSession session) {
    ProtocolStorage storage = session.getStorage();
    storage.set(OnGroundTracker.class, new OnGroundTracker());
    storage.set(WindowTypeTracker.class, new WindowTypeTracker());
    storage.set(QuickBarTracker.class, new QuickBarTracker());
    // additional block storage (for nether portal rotation fix)
    storage.set(PortalFrameCache.class, new PortalFrameCache());
    if (session.getMain().getConfiguration().enableViaVersion()) {
        // it's not needed for 1.8->1.7, but ViaVersion will need that to fix issues
        // with eating, entering portals, effects (potions)
        storage.set(PlayerMovementTracker.class, new PlayerMovementTracker());
    }
    // check if 1.6 entity tracker exists - if not, create one
    if (!storage.hasObject(EntityTracker.class)) {
        storage.set(V1_7EntityTracker.class, new V1_7EntityTracker());
    }
    // fixes block hardness inconsistencies
    if (session.getMain().getConfiguration().getServerVersion() == MinecraftVersion.B1_7_3) {
        storage.set(BlockMiningTimeFixer.class, new BlockMiningTimeFixer(session));
    }
}
Also used : WindowTypeTracker(com.github.dirtpowered.dirtmv.network.versions.Release47To5.inventory.WindowTypeTracker) ProtocolStorage(com.github.dirtpowered.dirtmv.data.user.ProtocolStorage) PortalFrameCache(com.github.dirtpowered.dirtmv.network.versions.Release47To5.chunk.PortalFrameCache) V1_7EntityTracker(com.github.dirtpowered.dirtmv.network.versions.Release47To5.entity.V1_7EntityTracker) EntityTracker(com.github.dirtpowered.dirtmv.network.versions.Release73To61.entity.EntityTracker) OnGroundTracker(com.github.dirtpowered.dirtmv.network.versions.Release47To5.entity.OnGroundTracker) BlockMiningTimeFixer(com.github.dirtpowered.dirtmv.network.versions.Release47To5.other.BlockMiningTimeFixer) V1_7EntityTracker(com.github.dirtpowered.dirtmv.network.versions.Release47To5.entity.V1_7EntityTracker) QuickBarTracker(com.github.dirtpowered.dirtmv.network.versions.Release47To5.inventory.QuickBarTracker) PlayerMovementTracker(com.github.dirtpowered.dirtmv.network.versions.Release47To5.entity.PlayerMovementTracker)

Aggregations

ProtocolStorage (com.github.dirtpowered.dirtmv.data.user.ProtocolStorage)2 OnGroundTracker (com.github.dirtpowered.dirtmv.network.versions.Release47To5.entity.OnGroundTracker)2 PlayerMovementTracker (com.github.dirtpowered.dirtmv.network.versions.Release47To5.entity.PlayerMovementTracker)2 PacketData (com.github.dirtpowered.dirtmv.data.protocol.PacketData)1 TypeHolder (com.github.dirtpowered.dirtmv.data.protocol.TypeHolder)1 PacketTranslator (com.github.dirtpowered.dirtmv.data.translator.PacketTranslator)1 ServerSession (com.github.dirtpowered.dirtmv.network.server.ServerSession)1 PortalFrameCache (com.github.dirtpowered.dirtmv.network.versions.Release47To5.chunk.PortalFrameCache)1 V1_7EntityTracker (com.github.dirtpowered.dirtmv.network.versions.Release47To5.entity.V1_7EntityTracker)1 QuickBarTracker (com.github.dirtpowered.dirtmv.network.versions.Release47To5.inventory.QuickBarTracker)1 WindowTypeTracker (com.github.dirtpowered.dirtmv.network.versions.Release47To5.inventory.WindowTypeTracker)1 BlockMiningTimeFixer (com.github.dirtpowered.dirtmv.network.versions.Release47To5.other.BlockMiningTimeFixer)1 EntityTracker (com.github.dirtpowered.dirtmv.network.versions.Release73To61.entity.EntityTracker)1