Search in sources :

Example 1 with Section

use of org.dragonet.protocol.type.chunk.Section in project DragonProxy by DragonetMC.

the class ChunkCache method translateChunk.

public final ChunkData translateChunk(int columnX, int columnZ) {
    ChunkPos columnPos = new ChunkPos(columnX, columnZ);
    if (chunkCache.containsKey(columnPos)) {
        Column column = chunkCache.get(columnPos);
        ChunkData chunk = new ChunkData();
        chunk.sections = new Section[16];
        for (int i = 0; i < 16; i++) chunk.sections[i] = new Section();
        // Blocks
        for (int y = 0; y < 256; y++) {
            int cy = y >> 4;
            Chunk c = null;
            try {
                c = column.getChunks()[cy];
            } catch (Exception ex) {
                DragonProxy.getInstance().getLogger().info("Chunk " + columnX + ", " + cy + ", " + columnZ + " not exist !");
            }
            if (c == null || c.isEmpty())
                continue;
            BlockStorage blocks = c.getBlocks();
            for (int x = 0; x < 16; x++) for (int z = 0; z < 16; z++) {
                BlockState block = blocks.get(x, y & 0xF, z);
                ItemEntry entry = ItemBlockTranslator.translateToPE(block.getId(), block.getData());
                Section section = chunk.sections[cy];
                // Block id
                section.blockIds[index(x, y, z)] = (byte) (entry.getId() & 0xFF);
                // Data value
                int i = dataIndex(x, y, z);
                byte data = section.blockMetas[i];
                int newValue = entry.getPEDamage().byteValue();
                if ((y & 1) == 0)
                    data = (byte) ((data & 0xf0) | (newValue & 0x0f));
                else
                    data = (byte) (((newValue & 0x0f) << 4) | (data & 0x0f));
                section.blockMetas[i] = data;
            }
        }
        // Blocks entities
        try {
            List<CompoundTag> blockEntities = new ArrayList<>();
            for (int i = 0; i < column.getTileEntities().length; i++) {
                CompoundTag peTag = ItemBlockTranslator.translateBlockEntityToPE(column.getTileEntities()[i]);
                if (// filter non handled blocks entities
                peTag != null)
                    blockEntities.add(peTag);
            // else // debug
            // DragonProxy.getInstance().getLogger().debug("NBT null for " + pc.getTileEntities()[i].toString());
            }
            chunk.blockEntities = NBTIO.write(blockEntities, ByteOrder.LITTLE_ENDIAN, true);
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        chunk.encode();
        return chunk;
    }
    // System.out.println("Chunk " + columnX + ", " + columnZ + " not in cache !!!!!!!!!!!!!");
    return null;
}
Also used : ChunkData(org.dragonet.protocol.type.chunk.ChunkData) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Chunk(com.github.steveice10.mc.protocol.data.game.chunk.Chunk) Section(org.dragonet.protocol.type.chunk.Section) IOException(java.io.IOException) BlockStorage(com.github.steveice10.mc.protocol.data.game.chunk.BlockStorage) BlockState(com.github.steveice10.mc.protocol.data.game.world.block.BlockState) Column(com.github.steveice10.mc.protocol.data.game.chunk.Column) ChunkPos(org.dragonet.common.maths.ChunkPos) ItemEntry(org.dragonet.common.data.itemsblocks.ItemEntry) CompoundTag(org.dragonet.common.data.nbt.tag.CompoundTag)

Example 2 with Section

use of org.dragonet.protocol.type.chunk.Section in project DragonProxy by DragonetMC.

the class UpstreamSession method postLogin.

public void postLogin() {
    sendPacket(new ResourcePackStackPacket(), true);
    loggedIn = true;
    proxy.getLogger().info(proxy.getLang().get(Lang.MESSAGE_CLIENT_CONNECTED, username, remoteAddress));
    PlayerAuthenticationEvent authEvent = new PlayerAuthenticationEvent(this);
    proxy.getEventManager().callEvent(authEvent);
    if (authEvent.isCancelled​())
        return;
    if (proxy.getAuthMode().equals("online")) {
        proxy.getLogger().debug("Login online mode, sending placeholder datas");
        StartGamePacket pkStartGame = new StartGamePacket();
        // well we use 1 now
        pkStartGame.eid = getEntityCache().getClientEntity().proxyEid;
        pkStartGame.rtid = getEntityCache().getClientEntity().proxyEid;
        pkStartGame.dimension = 0;
        pkStartGame.seed = 0;
        pkStartGame.generator = 1;
        pkStartGame.difficulty = Difficulty.PEACEFUL;
        pkStartGame.spawnPosition = new BlockPosition(0, 72, 0);
        pkStartGame.position = new Vector3F(0f, 72f + EntityType.PLAYER.getOffset(), 0f);
        pkStartGame.levelId = "";
        pkStartGame.worldName = "World";
        pkStartGame.defaultPlayerPermission = 2;
        pkStartGame.commandsEnabled = true;
        pkStartGame.premiumWorldTemplateId = "";
        sendPacket(pkStartGame, true);
        SetSpawnPositionPacket pkSpawn = new SetSpawnPositionPacket();
        pkSpawn.position = new BlockPosition(0, 72, 0);
        sendPacket(pkSpawn, true);
        ChunkData data = new ChunkData();
        data.sections = new Section[16];
        for (int cy = 0; cy < 16; cy++) {
            data.sections[cy] = new Section();
            if (cy < 6)
                Arrays.fill(data.sections[cy].blockIds, (byte) 1);
        }
        data.encode();
        sendPacket(new FullChunkDataPacket(0, 0, data.getBuffer()), true);
        sendPacket(new FullChunkDataPacket(0, -1, data.getBuffer()), true);
        sendPacket(new FullChunkDataPacket(-1, 0, data.getBuffer()), true);
        sendPacket(new FullChunkDataPacket(-1, -1, data.getBuffer()), true);
        dataCache.put(CacheKey.AUTHENTICATION_STATE, "online_login_wait");
        PlayStatusPacket pkStat = new PlayStatusPacket();
        pkStat.status = PlayStatusPacket.PLAYER_SPAWN;
        sendPacket(pkStat, true);
        sendChat(proxy.getLang().get(Lang.MESSAGE_LOGIN_PROMPT));
    } else if (proxy.getAuthMode().equals("cls")) {
        // CLS LOGIN!
        if (!CLSAuthenticationService.getInstance().authenticate(this)) {
            if (getDataCache().containsKey("cls_link_server") && getDataCache().containsKey("cls_link_pin")) {
                disconnect("You must link your Mojang account, please visit :\n" + (String) getDataCache().get("cls_link_server") + "\n" + "Your pin code is: " + (String) getDataCache().get("cls_link_pin"));
                return;
            }
            disconnect(proxy.getLang().get(Lang.MESSAGE_SERVER_ERROR, proxy.getLang().get(Lang.ERROR_CLS_UNREACHABLE)));
            proxy.getLogger().severe(proxy.getLang().get(Lang.MESSAGE_SERVER_ERROR, proxy.getLang().get(Lang.ERROR_CLS_UNREACHABLE)).replace("§c", "").replace("§0", ""));
            return;
        }
        AuthenticationService authSvc = new AuthenticationService((String) dataCache.get("mojang_clientToken"));
        authSvc.setUsername((String) dataCache.get("mojang_displayName"));
        authSvc.setAccessToken((String) dataCache.get("mojang_accessToken"));
        try {
            authSvc.login();
            getDataCache().put("mojang_accessToken", authSvc.getAccessToken());
        } catch (RequestException ex) {
            ex.printStackTrace();
            disconnect(proxy.getLang().get(Lang.MESSAGE_SERVER_ERROR, proxy.getLang().get(Lang.ERROR_CLS_ERROR)));
            return;
        }
        username = authSvc.getSelectedProfile().getName();
        CLSAuthenticationService.getInstance().refresh(this, authSvc.getAccessToken());
        protocol = new MinecraftProtocol(authSvc.getSelectedProfile(), authSvc.getAccessToken());
        proxy.getLogger().debug("Initially joining [" + proxy.getConfig().remote_server_addr + "]... ");
        connectToServer(proxy.getConfig().remote_server_addr, proxy.getConfig().remote_server_port);
    } else {
        protocol = new MinecraftProtocol(username);
        proxy.getLogger().debug("Initially joining [" + proxy.getConfig().remote_server_addr + "]... ");
        connectToServer(proxy.getConfig().remote_server_addr, proxy.getConfig().remote_server_port);
    }
}
Also used : ChunkData(org.dragonet.protocol.type.chunk.ChunkData) PlayStatusPacket(org.dragonet.protocol.packets.PlayStatusPacket) BlockPosition(org.dragonet.common.maths.BlockPosition) MinecraftProtocol(com.github.steveice10.mc.protocol.MinecraftProtocol) StartGamePacket(org.dragonet.protocol.packets.StartGamePacket) Section(org.dragonet.protocol.type.chunk.Section) RequestException(com.github.steveice10.mc.auth.exception.request.RequestException) SetSpawnPositionPacket(org.dragonet.protocol.packets.SetSpawnPositionPacket) Vector3F(org.dragonet.common.maths.Vector3F) FullChunkDataPacket(org.dragonet.protocol.packets.FullChunkDataPacket) PlayerAuthenticationEvent(org.dragonet.proxy.events.defaults.player.PlayerAuthenticationEvent) ResourcePackStackPacket(org.dragonet.protocol.packets.ResourcePackStackPacket) AuthenticationService(com.github.steveice10.mc.auth.service.AuthenticationService) CLSAuthenticationService(org.dragonet.proxy.utilities.CLSAuthenticationService)

Example 3 with Section

use of org.dragonet.protocol.type.chunk.Section in project DragonProxy by DragonetMC.

the class TestCommand method execute.

public void execute(DragonProxy proxy, String[] args) {
    if (args.length == 0) {
        System.out.println("This is a developer's command! ");
        return;
    }
    UpstreamSession player = proxy.getSessionRegister().getAll().values().toArray(new UpstreamSession[1])[0];
    if (args[0].equalsIgnoreCase("status")) {
        PlayStatusPacket s = new PlayStatusPacket();
        s.status = PlayStatusPacket.PLAYER_SPAWN;
        player.sendPacket(s);
    } else if (args[0].equalsIgnoreCase("res")) {
        player.sendPacket(new ResourcePacksInfoPacket());
    } else if (args[0].equalsIgnoreCase("pos")) {
        player.sendChat("pos at: " + player.getEntityCache().getClientEntity().x + ", " + player.getEntityCache().getClientEntity().y + ", " + player.getEntityCache().getClientEntity().z);
    } else if (args[0].equalsIgnoreCase("respawn")) {
        RespawnPacket resp = new RespawnPacket();
        resp.position = new Vector3F(Float.parseFloat(args[1]), Float.parseFloat(args[2]), Float.parseFloat(args[3]));
        player.sendPacket(resp);
    } else if (args[0].equalsIgnoreCase("chunkradius")) {
        player.sendPacket(new ChunkRadiusUpdatedPacket(8));
    } else if (args[0].equalsIgnoreCase("setspawnpos")) {
        SetSpawnPositionPacket packetSetSpawnPosition = new SetSpawnPositionPacket();
        packetSetSpawnPosition.position = new BlockPosition(Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3]));
        player.sendPacket(packetSetSpawnPosition);
    } else if (args[0].equalsIgnoreCase("motion")) {
        SetEntityMotionPacket mot = new SetEntityMotionPacket();
        mot.rtid = 1L;
        mot.motion = new Vector3F(0f, 0f, 0f);
        player.sendPacket(mot);
    } else if (args[0].equalsIgnoreCase("die")) {
        player.sendPacket(new SetHealthPacket(0));
    } else if (args[0].equalsIgnoreCase("tp")) {
        Vector3F dest = new Vector3F(Float.parseFloat(args[1]), Float.parseFloat(args[2]), Float.parseFloat(args[3]));
        MovePlayerPacket m = new MovePlayerPacket();
        m.rtid = 1L;
        m.mode = (byte) (Integer.parseInt(args[4]) & 0xFF);
        m.position = dest;
        player.sendPacket(m);
        player.sendChat("\u00a7bTeleported to: " + dest.toString());
    } else if (args[0].equalsIgnoreCase("moveentity")) {
        Vector3F dest = new Vector3F(Float.parseFloat(args[1]), Float.parseFloat(args[2]), Float.parseFloat(args[3]));
        MoveEntityPacket m = new MoveEntityPacket();
        m.rtid = 1L;
        m.teleported = args[4].equalsIgnoreCase("true");
        m.position = dest;
        player.sendPacket(m);
        player.sendChat("\u00a7bTeleported to: " + dest.toString());
    } else if (args[0].equalsIgnoreCase("chunk")) {
        /*
             * FullChunkData chunk = new FullChunkData(Integer.parseInt(args[1]),
			 * Integer.parseInt(args[2])); Arrays.fill(chunk.ids, (byte)1);
             */
        ChunkData data = new ChunkData();
        data.sections = new Section[16];
        for (int cy = 0; cy < 16; cy++) {
            data.sections[cy] = new Section();
            Arrays.fill(data.sections[cy].blockIds, (byte) 1);
        }
        FullChunkDataPacket chunk = new FullChunkDataPacket();
        chunk.x = Integer.parseInt(args[1]);
        chunk.z = Integer.parseInt(args[2]);
        data.encode();
        chunk.payload = data.getBuffer();
        player.sendPacket(chunk);
    } else if (args[0].equalsIgnoreCase("form")) {
        testForm(player);
    } else if (args[0].equalsIgnoreCase("sound")) {
        int id = Integer.parseInt(args[1]);
        LevelSoundEventPacket pk = new LevelSoundEventPacket();
        CachedEntity self = player.getEntityCache().getClientEntity();
        pk.position = new Vector3F((float) self.x, (float) self.y, (float) self.z);
        pk.sound = LevelSoundEventPacket.Sound.fromID(id);
        player.sendPacket(pk);
        player.sendChat("\u00a7bSound ID " + pk.sound.soundID + " (" + pk.sound.name() + ") sent");
    } else if (args[0].equalsIgnoreCase("painting")) {
        AddPaintingPacket pk = new AddPaintingPacket();
        pk.rtid = player.getEntityCache().getNextAtomicLong().incrementAndGet();
        pk.eid = pk.rtid;
        pk.pos = new BlockPosition(Integer.parseInt(args[1]), Integer.parseInt(args[2]), Integer.parseInt(args[3]));
        pk.direction = Integer.parseInt(args[4]);
        pk.title = args[5];
        player.sendPacket(pk);
        player.sendChat("\u00a7bPainting " + pk.title + " spawned at " + pk.pos.toString());
    }
}
Also used : ChunkData(org.dragonet.protocol.type.chunk.ChunkData) BlockPosition(org.dragonet.common.maths.BlockPosition) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) Section(org.dragonet.protocol.type.chunk.Section) Vector3F(org.dragonet.common.maths.Vector3F) UpstreamSession(org.dragonet.proxy.network.UpstreamSession)

Aggregations

ChunkData (org.dragonet.protocol.type.chunk.ChunkData)3 Section (org.dragonet.protocol.type.chunk.Section)3 BlockPosition (org.dragonet.common.maths.BlockPosition)2 Vector3F (org.dragonet.common.maths.Vector3F)2 RequestException (com.github.steveice10.mc.auth.exception.request.RequestException)1 AuthenticationService (com.github.steveice10.mc.auth.service.AuthenticationService)1 MinecraftProtocol (com.github.steveice10.mc.protocol.MinecraftProtocol)1 BlockStorage (com.github.steveice10.mc.protocol.data.game.chunk.BlockStorage)1 Chunk (com.github.steveice10.mc.protocol.data.game.chunk.Chunk)1 Column (com.github.steveice10.mc.protocol.data.game.chunk.Column)1 BlockState (com.github.steveice10.mc.protocol.data.game.world.block.BlockState)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 ItemEntry (org.dragonet.common.data.itemsblocks.ItemEntry)1 CompoundTag (org.dragonet.common.data.nbt.tag.CompoundTag)1 ChunkPos (org.dragonet.common.maths.ChunkPos)1 FullChunkDataPacket (org.dragonet.protocol.packets.FullChunkDataPacket)1 PlayStatusPacket (org.dragonet.protocol.packets.PlayStatusPacket)1 ResourcePackStackPacket (org.dragonet.protocol.packets.ResourcePackStackPacket)1 SetSpawnPositionPacket (org.dragonet.protocol.packets.SetSpawnPositionPacket)1