Search in sources :

Example 1 with ProtocolStorage

use of com.github.dirtpowered.dirtmv.data.user.ProtocolStorage in project DirtMultiversion by DirtPowered.

the class ProtocolRelease39To29 method onConnect.

@Override
public void onConnect(ServerSession session) {
    ProtocolStorage storage = session.getStorage();
    storage.set(UpdateTask.class, new UpdateTask(session));
    storage.set(OpenChestTracker.class, new OpenChestTracker());
    if (!storage.hasObject(BlockStorage.class)) {
        storage.set(BlockStorage.class, new BlockStorage(MinecraftVersion.R1_2_4));
    }
    if (!storage.hasObject(EntityTracker.class)) {
        storage.set(EntityTracker.class, new EntityTracker());
    }
}
Also used : UpdateTask(com.github.dirtpowered.dirtmv.network.versions.Release39To29.sound.UpdateTask) BlockStorage(com.github.dirtpowered.dirtmv.network.versions.Beta17To14.storage.BlockStorage) ProtocolStorage(com.github.dirtpowered.dirtmv.data.user.ProtocolStorage) EntityTracker(com.github.dirtpowered.dirtmv.network.versions.Release39To29.entity.EntityTracker) OpenChestTracker(com.github.dirtpowered.dirtmv.network.versions.Release39To29.sound.OpenChestTracker)

Example 2 with ProtocolStorage

use of com.github.dirtpowered.dirtmv.data.user.ProtocolStorage in project DirtMultiversion by DirtPowered.

the class WorldPackets method registerTranslators.

@Override
public void registerTranslators() {
    // block change
    addTranslator(0x35, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            BlockStorage blockStorage = session.getStorage().get(BlockStorage.class);
            if (blockStorage.getVersion() == getTo()) {
                int x = data.read(Type.INT, 0);
                byte y = data.read(Type.BYTE, 1);
                int z = data.read(Type.INT, 2);
                int chunkX = x >> 4;
                int chunkZ = z >> 4;
                byte blockId = data.read(Type.BYTE, 3);
                if (shouldCache(blockId)) {
                    blockStorage.setBlockAt(chunkX, chunkZ, x, y, z, blockId);
                }
            }
            return PacketUtil.createPacket(0x35, new TypeHolder[] { data.read(0), data.read(1), data.read(2), set(Type.SHORT, data.read(Type.BYTE, 3).shortValue()), data.read(4) });
        }
    });
    // multi block change
    addTranslator(0x34, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            BlockStorage blockStorage = session.getStorage().get(BlockStorage.class);
            if (blockStorage.getVersion() == getTo()) {
                int chunkX = data.read(Type.INT, 0);
                int chunkZ = data.read(Type.INT, 1);
                V1_2MultiBlockArray blocks = data.read(Type.V1_2MULTIBLOCK_ARRAY, 2);
                DataInput dis = new DataInputStream(new ByteArrayInputStream(blocks.getData()));
                for (int i = 0; i < blocks.getRecordCount(); i++) {
                    try {
                        short pos = dis.readShort();
                        int x = pos >> 12 & 15;
                        int y = pos & 255;
                        int z = pos >> 8 & 15;
                        int xPos = x + (chunkX << 4);
                        int zPos = z + (chunkZ << 4);
                        int blockId = dis.readShort() >> 4 & 4095;
                        if (shouldCache(blockId)) {
                            blockStorage.setBlockAt(chunkX, chunkZ, xPos, y, zPos, blockId);
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
            return data;
        }
    });
    // chunk data
    addTranslator(0x33, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            BlockStorage blockStorage = session.getStorage().get(BlockStorage.class);
            V1_2Chunk chunk = data.read(Type.V1_2_CHUNK, 0);
            if (blockStorage.getVersion() == getTo()) {
                List<ExtendedBlockStorage> parts = new ArrayList<>();
                V1_2RChunkStorage storage;
                if (chunk.getStorage() != null) {
                    storage = chunk.getStorage();
                } else {
                    // create chunk storage
                    storage = new V1_2RChunkStorage(true, true, chunk.getChunkX(), chunk.getChunkZ());
                    storage.readChunk(chunk.isGroundUp(), chunk.getPrimaryBitmap(), chunk.getUncompressedData());
                    // cache for later use (r1.8 -> r1.7)
                    chunk.setStorage(storage);
                }
                ExtendedBlockStorage[] columns = storage.getColumnStorage();
                for (int i = 0; i < columns.length; ++i) {
                    ExtendedBlockStorage e = columns[i];
                    boolean f = e != null && !columns[i].isEmpty();
                    if (e != null && (chunk.getPrimaryBitmap() & 1 << i) != 0 && (!chunk.isGroundUp() || f)) {
                        parts.add(e);
                    }
                }
                for (int i = 0; i < parts.size(); ++i) {
                    byte[] blockArray = parts.get(i).getBlockLSBArray();
                    for (int j = 0; j < blockArray.length; ++j) {
                        int x = j & 15;
                        int y = (j >> 8) + i * 16 & 255;
                        int z = j >> 4 & 15;
                        int blockId = blockArray[j] & 255;
                        if (shouldCache(blockId)) {
                            blockStorage.setBlockAt(chunk.getChunkX(), chunk.getChunkZ(), x, y, z, blockId);
                        }
                    }
                }
            }
            return PacketUtil.createPacket(0x33, new TypeHolder[] { set(Type.V1_3_CHUNK, chunk) });
        }
    });
    // pre chunk
    addTranslator(0x32, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            ProtocolStorage storage = session.getStorage();
            byte mode = data.read(Type.BYTE, 2);
            if (mode == 1) {
                return cancel();
            }
            int chunkX = data.read(Type.INT, 0);
            int chunkZ = data.read(Type.INT, 1);
            OpenChestTracker chestTracker = storage.get(OpenChestTracker.class);
            for (BlockLocation entry : chestTracker.getChestStates().keySet()) {
                int x = entry.getX() >> 4;
                int z = entry.getZ() >> 4;
                if (chunkX == x && chunkZ == z) {
                    chestTracker.remove(entry);
                }
            }
            BlockStorage blockStorage = storage.get(BlockStorage.class);
            if (blockStorage.getVersion() == getTo()) {
                blockStorage.removeChunk(chunkX, chunkZ);
            }
            V1_2Chunk chunk = new V1_2Chunk(chunkX, chunkZ, true, (short) 0, (short) 0, 0, new byte[0], new byte[0], null);
            return PacketUtil.createPacket(0x33, new TypeHolder[] { set(Type.V1_3_CHUNK, chunk) });
        }
    });
    // play noteblock
    addTranslator(0x36, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            int x = data.read(Type.INT, 0);
            int y = data.read(Type.SHORT, 1);
            int z = data.read(Type.INT, 2);
            byte type = data.read(Type.BYTE, 3);
            byte pitch = data.read(Type.BYTE, 4);
            ProtocolStorage storage = session.getStorage();
            short blockId = (short) storage.get(BlockStorage.class).getBlockAt(x, y, z);
            WorldSound worldSound;
            OpenChestTracker chestTracker = storage.get(OpenChestTracker.class);
            switch(type) {
                case 0:
                    if (blockId == 33 || blockId == 29) {
                        worldSound = WorldSound.PISTON_OUT;
                    } else {
                        worldSound = WorldSound.NOTE_HARP;
                    }
                    break;
                case 1:
                    if (blockId == 54) {
                        BlockLocation loc = new BlockLocation(x, y, z);
                        if (pitch == 1) {
                            if (!chestTracker.getState(loc)) {
                                chestTracker.setOpen(loc, true);
                                worldSound = WorldSound.CHEST_OPEN;
                                pitch = 12;
                            } else {
                                worldSound = WorldSound.NO_SOUND;
                            }
                        } else {
                            if (chestTracker.getState(loc)) {
                                worldSound = WorldSound.CHEST_CLOSE;
                                chestTracker.setOpen(loc, false);
                            } else {
                                worldSound = WorldSound.NO_SOUND;
                            }
                        }
                    } else if (blockId == 33 || blockId == 29) {
                        worldSound = WorldSound.PISTON_IN;
                    } else {
                        worldSound = WorldSound.NOTE_CLICK;
                    }
                    break;
                case 2:
                    worldSound = WorldSound.NOTE_SNARE;
                    break;
                case 3:
                    worldSound = WorldSound.NOTE_HAT;
                    break;
                case 4:
                    worldSound = WorldSound.NOTE_BASS_ATTACK;
                    break;
                default:
                    worldSound = WorldSound.NOTE_HARP;
                    break;
            }
            float correctedPitch = (float) (0.5f * (Math.pow(2, pitch / 12.0f)));
            WorldEntityEvent.playSoundAt(session, new Location(x, y, z), worldSound, 3.0f, correctedPitch);
            return PacketUtil.createPacket(0x36, new TypeHolder[] { data.read(0), data.read(1), data.read(2), data.read(3), data.read(4), set(Type.SHORT, blockId) });
        }
    });
}
Also used : ServerSession(com.github.dirtpowered.dirtmv.network.server.ServerSession) ProtocolStorage(com.github.dirtpowered.dirtmv.data.user.ProtocolStorage) PacketTranslator(com.github.dirtpowered.dirtmv.data.translator.PacketTranslator) V1_2Chunk(com.github.dirtpowered.dirtmv.data.protocol.objects.V1_2Chunk) V1_2RChunkStorage(com.github.dirtpowered.dirtmv.data.chunk.storage.V1_2RChunkStorage) IOException(java.io.IOException) DataInputStream(java.io.DataInputStream) ExtendedBlockStorage(com.github.dirtpowered.dirtmv.data.chunk.storage.ExtendedBlockStorage) BlockLocation(com.github.dirtpowered.dirtmv.data.protocol.objects.BlockLocation) OpenChestTracker(com.github.dirtpowered.dirtmv.network.versions.Release39To29.sound.OpenChestTracker) WorldSound(com.github.dirtpowered.dirtmv.network.versions.Release39To29.sound.WorldSound) V1_2MultiBlockArray(com.github.dirtpowered.dirtmv.data.protocol.objects.V1_2MultiBlockArray) TypeHolder(com.github.dirtpowered.dirtmv.data.protocol.TypeHolder) DataInput(java.io.DataInput) ExtendedBlockStorage(com.github.dirtpowered.dirtmv.data.chunk.storage.ExtendedBlockStorage) BlockStorage(com.github.dirtpowered.dirtmv.network.versions.Beta17To14.storage.BlockStorage) ByteArrayInputStream(java.io.ByteArrayInputStream) ArrayList(java.util.ArrayList) List(java.util.List) PacketData(com.github.dirtpowered.dirtmv.data.protocol.PacketData) BlockLocation(com.github.dirtpowered.dirtmv.data.protocol.objects.BlockLocation) Location(com.github.dirtpowered.dirtmv.data.protocol.objects.Location)

Example 3 with ProtocolStorage

use of com.github.dirtpowered.dirtmv.data.user.ProtocolStorage in project DirtMultiversion by DirtPowered.

the class ProtocolBeta17to14 method registerTranslators.

@Override
public void registerTranslators() {
    // keep-alive
    addTranslator(0x00, PacketDirection.TO_SERVER, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            return PacketUtil.createPacket(0x00, new TypeHolder[0]);
        }
    });
    // ping request
    addTranslator(0xFE, PacketDirection.TO_SERVER, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            String message = session.getMain().getConfiguration().preReleaseMOTD();
            message = ChatUtils.stripColor(message);
            int max = session.getMain().getConfiguration().getMaxOnline();
            int online = session.getConnectionCount();
            PacketData packetData = PacketUtil.createPacket(0xFF, new TypeHolder[] { set(Type.STRING, message + "§" + online + "§" + max) });
            // I wanna know who broke server latency calculation in release 1.8, really
            if (session.getUserData().getClientVersion() == MinecraftVersion.R1_8) {
                new Timer().schedule(new TimerTask() {

                    @Override
                    public void run() {
                        session.sendPacket(packetData, PacketDirection.TO_CLIENT, getFrom());
                    }
                }, session.getMain().getSharedRandom().nextInt(70));
            } else {
                session.sendPacket(packetData, PacketDirection.TO_CLIENT, getFrom());
            }
            // cancel sending
            return cancel();
        }
    });
    // login
    addTranslator(0x01, PacketDirection.TO_SERVER, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            return PacketUtil.createPacket(0x01, new TypeHolder[] { // INT
            set(Type.INT, 14), // STRING
            data.read(1), // LONG
            data.read(2), // BYTE
            data.read(4) });
        }
    });
    // login
    addTranslator(0x01, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            session.getMain().getSessionRegistry().getSessions().forEach((uuid, multiSession) -> {
                String s = multiSession.getServerSession().getUserData().getUsername();
                session.queuePacket(createTabEntryPacket(s, true), PacketDirection.TO_CLIENT, getFrom());
            });
            int max = session.getMain().getConfiguration().getMaxOnline();
            // b1.8 client is rendering tablist grid wrong when above 100
            if (max > 100)
                max = 100;
            return PacketUtil.createPacket(0x01, new TypeHolder[] { // INT - entityId
            data.read(0), // STRING - empty
            data.read(1), // LONG - world seed
            data.read(2), // INT - gameMode
            set(Type.INT, 0), // BYTE - dimension
            data.read(3), // BYTE - difficulty
            set(Type.BYTE, (byte) 1), // BYTE - world height
            set(Type.BYTE, (byte) -128), // BYTE - maxPlayers
            set(Type.BYTE, (byte) max) });
        }
    });
    // update health
    addTranslator(0x08, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            ProtocolStorage storage = session.getStorage();
            if (storage.hasObject(PlayerHealthTracker.class)) {
                storage.get(PlayerHealthTracker.class).setHealth(data.read(Type.SHORT, 0));
            }
            return PacketUtil.createPacket(0x08, new TypeHolder[] { data.read(0), set(Type.SHORT, (short) 6), set(Type.FLOAT, 0.0F) });
        }
    });
    // 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) });
        }
    });
    // 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), set(Type.BYTE, (byte) 1), set(Type.BYTE, (byte) 0), set(Type.SHORT, (short) 128), set(Type.LONG, 0L) });
        }
    });
    // open window
    addTranslator(0x64, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            return PacketUtil.createPacket(0x64, new TypeHolder[] { data.read(0), data.read(1), set(Type.STRING, data.read(Type.STRING, 2)), data.read(3) });
        }
    });
    // game state
    addTranslator(0x46, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            return PacketUtil.createPacket(0x46, new TypeHolder[] { data.read(0), set(Type.BYTE, (byte) 0) });
        }
    });
    // block place
    addTranslator(0x0F, PacketDirection.TO_SERVER, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            ProtocolStorage storage = session.getStorage();
            if (storage.hasObject(PlayerHealthTracker.class)) {
                PacketData updateHealth = PacketUtil.createPacket(0x08, new TypeHolder[] { set(Type.SHORT, storage.get(PlayerHealthTracker.class).getHealth()), set(Type.SHORT, (short) 6), set(Type.FLOAT, 0.0F) });
                session.sendPacket(updateHealth, PacketDirection.TO_CLIENT, getFrom());
            }
            return data;
        }
    });
    // entity action
    addTranslator(0x13, PacketDirection.TO_SERVER, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            byte state = data.read(Type.BYTE, 1);
            if (state == 5 || state == 4) {
                // cancel sending
                return cancel();
            }
            return data;
        }
    });
    // named entity spawn
    addTranslator(0x14, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            int entityId = data.read(Type.INT, 0);
            String username = data.read(Type.STRING, 1);
            if (!isConnectedThroughProxy(session.getMain(), username)) {
                PlayerTabListCache cache = session.getStorage().get(PlayerTabListCache.class);
                if (cache != null) {
                    session.sendPacket(createTabEntryPacket(username, true), PacketDirection.TO_CLIENT, getFrom());
                    cache.getTabPlayers().put(entityId, username);
                }
            }
            return data;
        }
    });
    // entity destroy
    addTranslator(0x1D, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            int entityId = data.read(Type.INT, 0);
            PlayerTabListCache cache = session.getStorage().get(PlayerTabListCache.class);
            if (cache != null && cache.getTabPlayers().containsKey(entityId)) {
                String username = cache.getTabPlayers().get(entityId);
                session.sendPacket(createTabEntryPacket(username, false), PacketDirection.TO_CLIENT, getFrom());
                cache.getTabPlayers().remove(entityId);
            }
            return data;
        }
    });
    // mob spawn
    addTranslator(0x18, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            byte entityType = data.read(Type.BYTE, 1);
            if (entityType == EntityType.HUMAN_MOB.getEntityTypeId()) {
                PlayerTabListCache cache = session.getStorage().get(PlayerTabListCache.class);
                // cache empty name, so the tab entry will be removed after killing human mob
                cache.getTabPlayers().put(data.read(Type.INT, 0), StringUtil.EMPTY_STRING);
                return PacketUtil.createPacket(0x14, new TypeHolder[] { data.read(0), set(Type.STRING, StringUtil.EMPTY_STRING), data.read(2), data.read(3), data.read(4), data.read(5), data.read(6), set(Type.SHORT, (short) 0) });
            }
            return data;
        }
    });
    // block change
    addTranslator(0x35, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            int x = data.read(Type.INT, 0);
            byte y = data.read(Type.BYTE, 1);
            int z = data.read(Type.INT, 2);
            byte blockId = data.read(Type.BYTE, 3);
            byte blockData = data.read(Type.BYTE, 4);
            BlockStorage blockStorage = session.getStorage().get(BlockStorage.class);
            if (blockStorage != null) {
                blockStorage.setBlockAt(x >> 4, z >> 4, x, y, z, blockId);
                if (blockId == 54) {
                    blockData = RotationUtil.fixBlockRotation(session, x, y, z);
                }
            }
            return PacketUtil.createPacket(0x35, new TypeHolder[] { data.read(0), data.read(1), data.read(2), data.read(3), set(Type.BYTE, blockData) });
        }
    });
    // unload chunk
    addTranslator(0x32, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            BlockStorage blockStorage = session.getStorage().get(BlockStorage.class);
            if (blockStorage != null) {
                byte mode = data.read(Type.BYTE, 2);
                if (mode == 0) {
                    int chunkX = data.read(Type.INT, 0);
                    int chunkZ = data.read(Type.INT, 1);
                    blockStorage.removeChunk(chunkX, chunkZ);
                }
            }
            return data;
        }
    });
    // chunk data
    addTranslator(0x33, PacketDirection.TO_CLIENT, new PacketTranslator() {

        @Override
        public PacketData translate(ServerSession session, PacketData data) {
            V1_3BChunk chunk = data.read(Type.V1_3B_CHUNK, 0);
            int chunkX = chunk.getX() >> 4;
            int chunkZ = chunk.getZ() >> 4;
            // skip non-full chunk updates
            if (chunk.getXSize() * chunk.getYSize() * chunk.getZSize() != 32768) {
                return data;
            }
            BlockStorage blockStorage = session.getStorage().get(BlockStorage.class);
            boolean reduceBlockStorageMemory = session.getMain().getConfiguration().reduceBlockStorageMemory();
            if (blockStorage != null) {
                List<BlockLocation> locationList = new ArrayList<>();
                try {
                    byte[] chunkData = chunk.getChunk();
                    for (int x = 0; x < 16; x++) {
                        for (int y = reduceBlockStorageMemory ? 20 : 0; y < 128; y++) {
                            for (int z = 0; z < 16; z++) {
                                int blockId = chunkData[getBlockIndexAt(x, y, z)];
                                if (SolidBlockList.isSolid(blockId) || HardnessTable.needsToBeCached(session, blockId) || blockId == 85 || blockId == 29 || blockId == 33) {
                                    if (blockId == 54) {
                                        locationList.add(new BlockLocation(x, y, z));
                                    }
                                    blockStorage.setBlockAt(chunkX, chunkZ, chunk.getX() + x, chunk.getY() + y, chunk.getZ() + z, blockId);
                                }
                            }
                        }
                    }
                    for (BlockLocation location : locationList) {
                        int x = location.getX();
                        int y = location.getY();
                        int z = location.getZ();
                        byte rotation = RotationUtil.fixBlockRotation(session, chunk.getX() + x, chunk.getY() + y, chunk.getZ() + z);
                        int blockLightOffset = 65536;
                        setNibble(chunkData, x, y, z, (byte) 15, blockLightOffset);
                        sendDelayedBlockUpdate(session, chunk.getX() + x, chunk.getY() + y, chunk.getZ() + z, rotation);
                    }
                    chunk.setChunk(chunkData);
                } catch (ArrayIndexOutOfBoundsException ignored) {
                }
            }
            return PacketUtil.createPacket(0x33, new TypeHolder[] { set(Type.V1_3B_CHUNK, chunk) });
        }
    });
}
Also used : BlockStorage(com.github.dirtpowered.dirtmv.network.versions.Beta17To14.storage.BlockStorage) KeepAliveTask(com.github.dirtpowered.dirtmv.network.versions.Beta17To14.other.KeepAliveTask) ProtocolStorage(com.github.dirtpowered.dirtmv.data.user.ProtocolStorage) ChatUtils(com.github.dirtpowered.dirtmv.data.utils.ChatUtils) RotationUtil(com.github.dirtpowered.dirtmv.network.versions.Beta17To14.block.RotationUtil) Timer(java.util.Timer) StringUtil(io.netty.util.internal.StringUtil) ArrayList(java.util.ArrayList) PacketDirection(com.github.dirtpowered.dirtmv.data.translator.PacketDirection) PacketUtil(com.github.dirtpowered.dirtmv.data.utils.PacketUtil) PacketData(com.github.dirtpowered.dirtmv.data.protocol.PacketData) EntityType(com.github.dirtpowered.dirtmv.data.entity.EntityType) TimerTask(java.util.TimerTask) PacketTranslator(com.github.dirtpowered.dirtmv.data.translator.PacketTranslator) Type(com.github.dirtpowered.dirtmv.data.protocol.Type) SolidBlockList(com.github.dirtpowered.dirtmv.network.versions.Beta17To14.block.SolidBlockList) PlayerHealthTracker(com.github.dirtpowered.dirtmv.network.versions.Beta17To14.other.PlayerHealthTracker) V1_3BChunk(com.github.dirtpowered.dirtmv.data.protocol.objects.V1_3BChunk) DirtMultiVersion(com.github.dirtpowered.dirtmv.DirtMultiVersion) TypeHolder(com.github.dirtpowered.dirtmv.data.protocol.TypeHolder) ServerProtocol(com.github.dirtpowered.dirtmv.data.translator.ServerProtocol) BlockLocation(com.github.dirtpowered.dirtmv.data.protocol.objects.BlockLocation) List(java.util.List) MinecraftVersion(com.github.dirtpowered.dirtmv.data.MinecraftVersion) HardnessTable(com.github.dirtpowered.dirtmv.network.versions.Release47To5.other.HardnessTable) ServerSession(com.github.dirtpowered.dirtmv.network.server.ServerSession) ServerSession(com.github.dirtpowered.dirtmv.network.server.ServerSession) ProtocolStorage(com.github.dirtpowered.dirtmv.data.user.ProtocolStorage) PacketTranslator(com.github.dirtpowered.dirtmv.data.translator.PacketTranslator) V1_3BChunk(com.github.dirtpowered.dirtmv.data.protocol.objects.V1_3BChunk) PlayerHealthTracker(com.github.dirtpowered.dirtmv.network.versions.Beta17To14.other.PlayerHealthTracker) BlockLocation(com.github.dirtpowered.dirtmv.data.protocol.objects.BlockLocation) TypeHolder(com.github.dirtpowered.dirtmv.data.protocol.TypeHolder) BlockStorage(com.github.dirtpowered.dirtmv.network.versions.Beta17To14.storage.BlockStorage) Timer(java.util.Timer) TimerTask(java.util.TimerTask) ArrayList(java.util.ArrayList) SolidBlockList(com.github.dirtpowered.dirtmv.network.versions.Beta17To14.block.SolidBlockList) List(java.util.List) PacketData(com.github.dirtpowered.dirtmv.data.protocol.PacketData)

Example 4 with ProtocolStorage

use of com.github.dirtpowered.dirtmv.data.user.ProtocolStorage in project DirtMultiversion by DirtPowered.

the class ProtocolRelease28To23 method onConnect.

@Override
public void onConnect(ServerSession session) {
    ProtocolStorage storage = session.getStorage();
    storage.set(LoadedChunkTracker.class, new LoadedChunkTracker());
}
Also used : ProtocolStorage(com.github.dirtpowered.dirtmv.data.user.ProtocolStorage) LoadedChunkTracker(com.github.dirtpowered.dirtmv.network.versions.Release28To23.chunk.LoadedChunkTracker)

Example 5 with ProtocolStorage

use of com.github.dirtpowered.dirtmv.data.user.ProtocolStorage in project DirtMultiversion by DirtPowered.

the class WorldEntityEvent method playSound.

private static void playSound(ServerSession session, int entityId, SoundType type) {
    ProtocolStorage storage = session.getStorage();
    if (!storage.hasObject(EntityTracker.class)) {
        return;
    }
    EntityTracker tracker = storage.get(EntityTracker.class);
    if (tracker.isEntityTracked(entityId)) {
        AbstractEntity e = tracker.getEntity(entityId);
        Sound sound = SoundEmulation.getEntitySound(type, e.getEntityType());
        if (sound.getSoundName().isEmpty())
            return;
        Location loc = e.getLocation();
        Random shared = session.getMain().getSharedRandom();
        sound.setPitch((shared.nextFloat() - shared.nextFloat()) * 0.2F + 1.0F);
        if (tracker.isEntityTracked(-999)) {
            Location l = tracker.getEntity(-999).getLocation();
            playSoundAt(session, loc, l, sound);
        }
    }
}
Also used : ProtocolStorage(com.github.dirtpowered.dirtmv.data.user.ProtocolStorage) Random(java.util.Random) AbstractEntity(com.github.dirtpowered.dirtmv.network.versions.Release39To29.entity.model.AbstractEntity) Sound(com.github.dirtpowered.dirtmv.network.versions.Release39To29.sound.Sound) WorldSound(com.github.dirtpowered.dirtmv.network.versions.Release39To29.sound.WorldSound) Location(com.github.dirtpowered.dirtmv.data.protocol.objects.Location)

Aggregations

ProtocolStorage (com.github.dirtpowered.dirtmv.data.user.ProtocolStorage)21 PacketData (com.github.dirtpowered.dirtmv.data.protocol.PacketData)9 TypeHolder (com.github.dirtpowered.dirtmv.data.protocol.TypeHolder)9 PacketTranslator (com.github.dirtpowered.dirtmv.data.translator.PacketTranslator)8 ServerSession (com.github.dirtpowered.dirtmv.network.server.ServerSession)8 ItemStack (com.github.dirtpowered.dirtmv.data.protocol.objects.ItemStack)6 BlockLocation (com.github.dirtpowered.dirtmv.data.protocol.objects.BlockLocation)5 BlockStorage (com.github.dirtpowered.dirtmv.network.versions.Beta17To14.storage.BlockStorage)5 ArrayList (java.util.ArrayList)5 Location (com.github.dirtpowered.dirtmv.data.protocol.objects.Location)4 V1_2MultiBlockArray (com.github.dirtpowered.dirtmv.data.protocol.objects.V1_2MultiBlockArray)4 IOException (java.io.IOException)4 List (java.util.List)4 V1_2Chunk (com.github.dirtpowered.dirtmv.data.protocol.objects.V1_2Chunk)3 QuickBarTracker (com.github.dirtpowered.dirtmv.network.versions.Release47To5.inventory.QuickBarTracker)3 DirtMultiVersion (com.github.dirtpowered.dirtmv.DirtMultiVersion)2 Configuration (com.github.dirtpowered.dirtmv.api.Configuration)2 MinecraftVersion (com.github.dirtpowered.dirtmv.data.MinecraftVersion)2 OldChunkData (com.github.dirtpowered.dirtmv.data.chunk.biome.OldChunkData)2 ExtendedBlockStorage (com.github.dirtpowered.dirtmv.data.chunk.storage.ExtendedBlockStorage)2