Search in sources :

Example 1 with Position

use of com.github.steveice10.mc.protocol.data.game.entity.metadata.Position in project CyanBot by XjCyan1de.

the class PacketWorldListener method packetReceived.

@Override
public void packetReceived(PacketReceivedEvent event) {
    try {
        Packet packetHandle = event.getPacket();
        if (packetHandle instanceof ServerJoinGamePacket) {
            ServerJoinGamePacket packet = (ServerJoinGamePacket) packetHandle;
            bot.setEntityId(packet.getEntityId());
        } else if (packetHandle instanceof ServerPlayerPositionRotationPacket) {
            ServerPlayerPositionRotationPacket packet = (ServerPlayerPositionRotationPacket) packetHandle;
            Location location = new Location(packet.getX(), packet.getY(), packet.getZ(), packet.getYaw(), packet.getPitch());
            bot.setLoc(location);
            // bot.sendMessage("Меня тпхнуло: "+location);
            // System.out.println(" \nТелепортируем : ["+location.getX()+" "+location.getY()+" "+location.getZ()+"]");
            bot.sendPacket(new ClientTeleportConfirmPacket(packet.getTeleportId()));
        // bot.groundHandler.move(location);
        } else if (packetHandle instanceof ServerChunkDataPacket) {
            ServerChunkDataPacket packet = (ServerChunkDataPacket) packetHandle;
            bot.getWorld().onLoadChunk(bot, packet.getColumn());
        } else if (packetHandle instanceof ServerUnloadChunkPacket) {
            ServerUnloadChunkPacket packet = (ServerUnloadChunkPacket) packetHandle;
            bot.getWorld().onUnloadChunk(bot, packet.getX(), packet.getZ());
        } else if (packetHandle instanceof ServerPlayerHealthPacket) {
            ServerPlayerHealthPacket packet = (ServerPlayerHealthPacket) packetHandle;
            if (packet.getHealth() == 0) {
                Schedule.later(() -> {
                    bot.sendPacket(new ClientRequestPacket(ClientRequest.RESPAWN));
                }, 500);
            }
        } else if (packetHandle instanceof ServerBlockChangePacket) {
            ServerBlockChangePacket packet = (ServerBlockChangePacket) packetHandle;
            BlockState blockState = packet.getRecord().getBlock();
            if (blockState != null) {
                Position position = packet.getRecord().getPosition();
                Block block = bot.getWorld().getBlockAt(position.getX(), position.getY(), position.getZ());
                if (block != null) {
                    block.setIdAndData(blockState.getId(), blockState.getData());
                // System.out.println("Новый блок = " + block);
                } else {
                    System.out.println("Чё за хуйня у нас блок == Null" + position.getX() + " " + position.getY() + " " + position.getZ());
                }
            }
        } else {
        /*if (packetHandle instanceof ServerUpdateTimePacket ||
                        packetHandle instanceof ServerKeepAlivePacket ||
                        packetHandle instanceof ServerPlaySoundPacket ||
                        packetHandle instanceof ServerEntityEffectPacket

                        ) {
                } else {
                    //System.out.println(bot.getUsername()+" <- "+packetHandle);
                }*/
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : ClientRequestPacket(com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket) ServerJoinGamePacket(com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket) ClientTeleportConfirmPacket(com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket) Packet(com.github.steveice10.packetlib.packet.Packet) ServerPlayerPositionRotationPacket(com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket) ServerPlayerHealthPacket(com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerHealthPacket) ServerPlayerHealthPacket(com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerHealthPacket) Position(com.github.steveice10.mc.protocol.data.game.entity.metadata.Position) ServerJoinGamePacket(com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket) ClientTeleportConfirmPacket(com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket) ServerPlayerPositionRotationPacket(com.github.steveice10.mc.protocol.packet.ingame.server.entity.player.ServerPlayerPositionRotationPacket) BlockState(com.github.steveice10.mc.protocol.data.game.world.block.BlockState) Block(me.xjcyan1de.cyanbot.world.Block) ClientRequestPacket(com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket) Location(me.xjcyan1de.cyanbot.world.Location)

Example 2 with Position

use of com.github.steveice10.mc.protocol.data.game.entity.metadata.Position in project CyanBot by XjCyan1de.

the class CommandEvents method on.

@EventHandler
public void on(CommandEvent event) {
    // если игрок не авторизировался
    if (!event.hasAccessSender()) {
        return;
    }
    final String[] args = event.getArgs();
    switch(event.getCommand().toLowerCase()) {
        case "say":
        case "напиши":
        case "скажи":
            {
                final String arguments = event.getArguments(0);
                if (!arguments.isEmpty()) {
                    bot.sendMessage(arguments);
                }
                break;
            }
        case "flood":
        case "флуди":
            {
                final String arguments = event.getArguments(0);
                if (!arguments.isEmpty()) {
                    Schedule.timer(() -> {
                        bot.sendMessage(arguments);
                    }, 1000, 1000);
                }
                break;
            }
        case "walk":
        case "иди":
            {
                if (args.length != 3)
                    return;
                double x = Double.parseDouble(args[0]);
                double y = Double.parseDouble(args[1]);
                double z = Double.parseDouble(args[2]);
                bot.getLoc().add(x, y, z);
                break;
            }
        case "spin":
        case "кружись":
            {
                final int[] yaw = { 0 };
                Schedule.timer(() -> {
                    bot.getLoc().setYaw(yaw[0]);
                    yaw[0] += 30;
                }, 50, 50);
                break;
            }
        case "drop":
        case "выкинь":
            {
                bot.sendPacket(new ClientPlayerActionPacket(PlayerAction.DROP_ITEM, new Position(bot.getLoc().getBlockX(), bot.getLoc().getBlockY(), bot.getLoc().getBlockZ()), BlockFace.UP));
                break;
            }
        case "swap":
        case "переложи":
            {
                bot.sendPacket(new ClientPlayerActionPacket(PlayerAction.SWAP_HANDS, new Position(bot.getLoc().getBlockX(), bot.getLoc().getBlockY(), bot.getLoc().getBlockZ()), BlockFace.UP));
                break;
            }
        case "swapping":
        case "перехватывай":
            {
                if (args.length != 1)
                    return;
                int delay = Integer.parseInt(args[0]);
                Schedule.timer(() -> {
                    bot.sendPacket(new ClientPlayerActionPacket(PlayerAction.SWAP_HANDS, new Position(bot.getLoc().getBlockX(), bot.getLoc().getBlockY(), bot.getLoc().getBlockZ()), BlockFace.UP));
                }, delay, delay);
                break;
            }
        case "rightclick":
        case "пкм":
            {
                bot.sendPacket(new ClientPlayerUseItemPacket(Hand.MAIN_HAND));
                break;
            }
        case "deus":
            {
                if (event.has(0, "vult")) {
                    bot.sendMessage("Ave Maria!");
                }
                break;
            }
        case "слава":
            {
                if (event.has(0, "украине")) {
                    bot.sendMessage("ГЕРОЯМ СЛАВА!");
                }
                break;
            }
        default:
            return;
    }
    // если обработали команду, тогда дальше не пускаем
    event.setCancelled(true);
}
Also used : ClientPlayerUseItemPacket(com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket) Position(com.github.steveice10.mc.protocol.data.game.entity.metadata.Position) ClientPlayerActionPacket(com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket) EventHandler(me.xjcyan1de.cyanbot.listeners.event.EventHandler)

Example 3 with Position

use of com.github.steveice10.mc.protocol.data.game.entity.metadata.Position in project DragonProxy by DragonetMC.

the class EntityMetaTranslator method translateToPE.

public static EntityMetaData translateToPE(UpstreamSession session, EntityMetadata[] pcMeta, EntityType type) {
    /*
     * Following format was fetched from http://wiki.vg/Entities#Entity_meta_Format
         */
    EntityMetaData peMeta = EntityMetaData.createDefault();
    // try (Timing timing = Timings.getEntityTiming(type.name())) {
    if (pcMeta == null || type == EntityType.NONE) {
        // timing.stopTiming();
        return peMeta;
    }
    // System.out.println("Entity + " + type);
    for (EntityMetadata m : pcMeta) {
        // System.out.println(m);
        boolean handle = true;
        try {
            if (m == null)
                continue;
            switch(m.getId()) {
                case // Flags
                0:
                    byte pcFlags = ((byte) m.getValue());
                    // System.out.println("PC flag: " + pcFlags);
                    peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_ONFIRE, (pcFlags & 0x01) > 0);
                    peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_SNEAKING, (pcFlags & 0x02) > 0);
                    peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_RIDING, (pcFlags & 0x04) > 0);
                    peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_SPRINTING, (pcFlags & 0x08) > 0);
                    peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_ACTION, (pcFlags & 0x10) > 0);
                    peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_INVISIBLE, (pcFlags & 0x20) > 0);
                    // peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_GLOWING, (pcFlags & 0x40) > 0); //Not implemented (possible with potions)
                    peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_GLIDING, (pcFlags & 0x80) > 0);
                    break;
                case // Air
                1:
                    peMeta.set(EntityMetaData.Constants.DATA_AIR, new ShortMeta(((Integer) m.getValue()).shortValue()));
                    break;
                case // Name tag
                2:
                    if (!m.getValue().equals("")) {
                        peMeta.set(EntityMetaData.Constants.DATA_NAMETAG, new ByteArrayMeta((String) m.getValue()));
                    }
                    break;
                case // Always show name tag
                3:
                    byte data;
                    if (m.getType() == MetadataType.BYTE) {
                        data = (byte) m.getValue();
                    } else if (m.getType() == MetadataType.INT) {
                        data = (byte) (((int) m.getValue()) & 0xFF);
                    } else {
                        data = 1;
                    }
                    peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_CAN_SHOW_NAMETAG, data > 0);
                    break;
                case // Boolean : Is silent
                4:
                    peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_SILENT, ((boolean) m.getValue()));
                    break;
                case // Boolean : No gravity
                5:
                    peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_AFFECTED_BY_GRAVITY, (!((boolean) m.getValue())));
                    break;
                case 6:
                    switch(type) {
                        case // VarInt : Shaking power
                        MINECART:
                            peMeta.set(EntityMetaData.Constants.DATA_HURT_TIME, new IntegerMeta((int) m.getValue()));
                            break;
                        case // VarInt : Fuse time
                        PRIMED_TNT:
                            peMeta.set(EntityMetaData.Constants.DATA_FUSE_LENGTH, new IntegerMeta((int) m.getValue()));
                            break;
                        case // Slot : Potion which is thrown
                        POTION:
                            peMeta.set(EntityMetaData.Constants.DATA_TYPE_SLOT, new SlotMeta(ItemBlockTranslator.translateSlotToPE((ItemStack) m.getValue())));
                            break;
                        case // Position : spawn position
                        FALLING_BLOCK:
                            peMeta.set(EntityMetaData.Constants.DATA_BLOCK_TARGET, new BlockPositionMeta(new BlockPosition((Position) m.getValue())));
                            break;
                        case // Float : Radius
                        AREA_EFFECT_CLOUD:
                            peMeta.set(EntityMetaData.Constants.DATA_AREA_EFFECT_CLOUD_RADIUS, new FloatMeta((float) m.getValue()));
                            break;
                        case // VarInt : Hooked entity id + 1, or 0 if there is no hooked entity
                        FISHING_HOOK:
                            break;
                        case // Byte : is critical
                        ARROW:
                            peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_CRITICAL, ((byte) m.getValue() & 0x01) > 0);
                            break;
                        // case TIPPED_ARROW: //VarInt : Color (-1 for no particles)
                        case // VarInt : Time since last hit
                        BOAT:
                            peMeta.set(EntityMetaData.Constants.DATA_HURT_TIME, new IntegerMeta((int) m.getValue()));
                            break;
                        case // OptPosition : Beam target
                        ENDER_CRYSTAL:
                            if (m.getValue() != null) {
                                peMeta.set(EntityMetaData.Constants.DATA_BLOCK_TARGET, new BlockPositionMeta(new BlockPosition((Position) m.getValue())));
                            }
                            break;
                        case // Boolean Invulnerable
                        WITHER_SKULL:
                            peMeta.set(EntityMetaData.Constants.DATA_WITHER_INVULNERABLE_TICKS, new IntegerMeta((int) m.getValue()));
                            break;
                        case // Slot : Firework info
                        FIREWORKS_ROCKET:
                            peMeta.set(EntityMetaData.Constants.DATA_TYPE_SLOT, new SlotMeta(ItemBlockTranslator.translateSlotToPE((ItemStack) m.getValue())));
                            break;
                        // case ITEM_FRAME: //Slot : Item
                        case // Slot : Item
                        ITEM:
                            peMeta.set(EntityMetaData.Constants.DATA_TYPE_SLOT, new SlotMeta(ItemBlockTranslator.translateSlotToPE((ItemStack) m.getValue())));
                            break;
                        default:
                            // (all LIVING) Byte : Hand states, used to trigger blocking/eating/drinking animation.
                            if (m.getValue() instanceof Byte) {
                                peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_ACTION, ((byte) m.getValue() & 0x01) > 0);
                            } else
                                handle = false;
                            // System.out.println("case 6 " + type.name() + " " + m.getValue());
                            break;
                    }
                    break;
                case 7:
                    switch(type) {
                        // VarInt : Forward direction
                        case BOAT:
                        case // VarInt : Shaking direction
                        MINECART:
                            peMeta.set(EntityMetaData.Constants.DATA_HURT_DIRECTION, new IntegerMeta((int) m.getValue()));
                            break;
                        case // VarInt : Color (only for mob spell particle)
                        AREA_EFFECT_CLOUD:
                            peMeta.set(EntityMetaData.Constants.DATA_AREA_EFFECT_CLOUD_WAITING, new IntegerMeta((int) m.getValue()));
                            break;
                        case // Boolean : Show bottom
                        ENDER_CRYSTAL:
                            break;
                        case // VarInt : Entity ID of entity which used firework (for elytra boosting)
                        FIREWORKS_ROCKET:
                            peMeta.set(EntityMetaData.Constants.DATA_OWNER_EID, new IntegerMeta((int) m.getValue()));
                            break;
                        case ARROW:
                            break;
                        // break;
                        default:
                            // (all LIVING) Float : Health
                            if (m.getValue() instanceof Float) {
                                peMeta.set(EntityMetaData.Constants.DATA_HEALTH, new IntegerMeta((int) ((float) m.getValue())));
                            } else
                                handle = false;
                            // System.out.println("case 7 " + type.name() + " " + m.getValue());
                            break;
                    }
                    break;
                case 8:
                    switch(type) {
                        case // Boolean : Ignore radius and show effect as single point, not area
                        AREA_EFFECT_CLOUD:
                            break;
                        // Float : Shaking multiplier
                        case MINECART:
                        case // Float : Damage taken
                        BOAT:
                            break;
                        default:
                            // (all LIVING) VarInt : Potion effect color (or 0 if there is no effect)
                            peMeta.set(EntityMetaData.Constants.DATA_POTION_COLOR, new ByteMeta((byte) ((int) m.getValue() & 0xFF)));
                            // System.out.println("case 8 " + type.name() + " " + m.getValue());
                            break;
                    }
                    break;
                case 9:
                    switch(type) {
                        case // VarInt : Custom block ID and damage
                        MINECART:
                            peMeta.set(EntityMetaData.Constants.DATA_MINECART_DISPLAY_BLOCK, new IntegerMeta((int) m.getValue()));
                            break;
                        case // VarInt : Particle ID
                        AREA_EFFECT_CLOUD:
                            peMeta.set(EntityMetaData.Constants.DATA_AREA_EFFECT_CLOUD_PARTICLE_ID, new IntegerMeta((int) m.getValue()));
                            break;
                        case // VarInt : Type (0=oak, 1=spruce, 2=birch, 3=jungle, 4=acacia, 5=dark oak)
                        BOAT:
                            peMeta.set(20, /* woodID */
                            new ByteMeta((byte) ((Integer) m.getValue()).byteValue()));
                            break;
                        default:
                            // (all LIVING) Boolean : Is potion effect ambient: reduces the number of particles generated by potions to 1/5 the normal amount
                            peMeta.set(EntityMetaData.Constants.DATA_POTION_AMBIENT, new ByteMeta((byte) (((boolean) m.getValue()) ? 0x01 : 0x00)));
                            // System.out.println("case 9 " + type.name() + " " + m.getValue());
                            break;
                    }
                    break;
                case 10:
                    switch(type) {
                        case // VarInt : Custom block Y position (in 16ths of a block)
                        MINECART:
                            peMeta.set(EntityMetaData.Constants.DATA_MINECART_DISPLAY_OFFSET, new IntegerMeta((int) m.getValue()));
                            break;
                        case // VarInt : Particle parameter 1
                        AREA_EFFECT_CLOUD:
                            break;
                        case // Boolean : Right paddle turning
                        BOAT:
                            peMeta.set(EntityMetaData.Constants.DATA_PADDLE_TIME_RIGHT, new IntegerMeta(20));
                            break;
                        default:
                            // Not supported yet
                            break;
                    }
                    break;
                case 11:
                    switch(type) {
                        case // Boolean : Show custom block
                        MINECART:
                            peMeta.set(EntityMetaData.Constants.DATA_MINECART_HAS_DISPLAY, new ByteMeta((byte) (((boolean) m.getValue()) ? 0x01 : 0x00)));
                            break;
                        case // VarInt : Particle parameter 2
                        AREA_EFFECT_CLOUD:
                            break;
                        case // Boolean : Left paddle turning
                        BOAT:
                            peMeta.set(EntityMetaData.Constants.DATA_PADDLE_TIME_LEFT, new IntegerMeta(20));
                            break;
                        case // Byte : see http://wiki.vg/Entity_metadata#ArmorStand
                        ARMOR_STAND:
                            break;
                        case // Float : Additional Hearts
                        PLAYER:
                            // Not supported yet
                            break;
                        default:
                            // System.out.println("case 11 " + type.name() + " " + m.getValue());
                            break;
                    }
                    break;
                case 12:
                    switch(type) {
                        case MINECART:
                            if (m.getValue() instanceof Boolean) {
                                // Boolean : Is powered
                                peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_POWERED, ((boolean) m.getValue()));
                            }
                            if (m.getValue() instanceof String) {
                            // String : Command
                            // 
                            }
                            break;
                        case // Rotation : Head rotation
                        ARMOR_STAND:
                            break;
                        case // Byte : Is hanging
                        BAT:
                            // peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_SITTING, (((byte) m.getValue()) ? 0x01 : 0x00)); //wrong data
                            break;
                        // Byte : Is player-created
                        case IRON_GOLEM:
                        // Byte : has no pumpkin hat
                        case SNOWMAN:
                        case // Direction : Facing direction
                        SHULKER:
                            break;
                        case // Byte : 0x01 = Is on fire
                        BLAZE:
                            peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_ONFIRE, ((byte) m.getValue()) == 0x01);
                            break;
                        // VarInt	State (-1 = idle, 1 = fuse)
                        case CREEPER:
                        // Byte	Spell (0: none, 1: summon vex, 2: attack, 3: wololo)
                        case EVOCATION_ILLAGER:
                        // Byte : 0x01 = Is in attack mode
                        case VEX:
                        // Byte : 0x01 = Has target (aggressive state)
                        case VINDICATOR:
                        case // Boolean : Is swinging arms
                        SKELETON:
                            break;
                        case // Byte : 0x01 = Is climbing
                        SPIDER:
                            peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_WALLCLIMBING, ((byte) m.getValue()) == 0x01);
                            break;
                        // Boolean : Is drinking potion
                        case WITCH:
                        // VarInt : Center head's target (entity ID, or 0 if no target)
                        case WITHER:
                        // Opt BlockID : Carried block
                        case ENDERMAN:
                        // VarInt : Dragon phase
                        case ENDER_DRAGON:
                        case // Boolean : Is attacking
                        GHAST:
                            break;
                        // VarInt : Size
                        case SLIME:
                        case // VarInt : Size
                        MAGMA_CUBE:
                            peMeta.set(EntityMetaData.Constants.DATA_SCALE, new FloatMeta((int) m.getValue()));
                            break;
                        case // VarInt : Score
                        PLAYER:
                            // Not supported yet
                            break;
                        default:
                            // ZOMBIE, AGEABLE //Boolean Is baby
                            {
                                if (m.getValue() instanceof Boolean) {
                                    peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_BABY, ((boolean) m.getValue()));
                                    if ((boolean) m.getValue()) {
                                        peMeta.set(EntityMetaData.Constants.DATA_SCALE, new FloatMeta(0.5f));
                                    }
                                } else
                                    handle = false;
                                break;
                            }
                    }
                    break;
                case 13:
                    switch(type) {
                        case // Chat : Last output
                        MINECART:
                            if (m.getValue() instanceof String) {
                            // 
                            }
                        case // Rotation : Body rotation
                        ARMOR_STAND:
                            break;
                        case // Byte : see http://wiki.vg/Entity_metadata#AbstractHorse
                        HORSE:
                            break;
                        case // Byte 0x0F Color (matches dye damage values) //0x10 Is sheared
                        SHEEP:
                            if (((byte) (m.getValue()) & 0x10) == 0) {
                                peMeta.set(EntityMetaData.Constants.DATA_COLOR, new ByteMeta((byte) (m.getValue())));
                            } else {
                                peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_SHEARED, true);
                            }
                            break;
                        case // VarInt : Type
                        RABBIT:
                            peMeta.set(EntityMetaData.Constants.DATA_VARIANT, new IntegerMeta((int) m.getValue()));
                            break;
                        case // Boolean : Has saddle
                        PIG:
                            peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_SADDLED, ((boolean) m.getValue()));
                            break;
                        // Boolean : Standing up
                        case POLAR_BEAR:
                        // VarInt : Profession (Farmer = 0, Librarian = 1, Priest = 2, Blacksmith = 3, Butcher = 4, Nitwit = 5)
                        case VILLAGER:
                        case // OptPosition : Attachment position
                        SHULKER:
                            break;
                        case // Boolean : Is charged
                        CREEPER:
                            peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_CHARGED, ((boolean) m.getValue()));
                            break;
                        // VarInt : Left(?) head's target (entity ID, or 0 if no target)
                        case WITHER:
                        // VarInt : Unused (previously type)
                        case ZOMBIE:
                        case // Boolean : Is screaming
                        ENDERMAN:
                            break;
                        case // Byte : The Displayed Skin Parts bit mask that is sent in Client Settings
                        PLAYER:
                            // Not supported yet
                            break;
                        default:
                            // System.out.println("case 13 " + type.name() + " " + m.getValue());
                            break;
                    }
                    break;
                case 14:
                    switch(type) {
                        // Rotation : Left arm rotation
                        case ARMOR_STAND:
                        // OptUUID : Owner
                        case HORSE:
                        // VarInt : Total time to "boost" with a carrot on a stick for
                        case PIG:
                        case // Byte : Shield height
                        SHULKER:
                            break;
                        case // Boolean : Is ignited
                        CREEPER:
                            peMeta.setGenericFlag(EntityMetaData.Constants.DATA_FLAG_IGNITED, ((boolean) m.getValue()));
                            break;
                        // VarInt : Right(?) head's target (entity ID, or 0 if no target)
                        case WITHER:
                        case // Boolean : Are hands held up
                        ZOMBIE:
                            break;
                        case // Byte : Main hand (0 : Left, 1 : Right)
                        PLAYER:
                            // Not supported yet
                            break;
                        default:
                            // System.out.println("case 14 " + type.name() + " " + m.getValue());
                            break;
                    }
                    break;
                case 15:
                    switch(type) {
                        case // Rotation : Right arm rotation
                        ARMOR_STAND:
                            break;
                        case HORSE:
                            if (m.getValue() instanceof Integer) {
                                // VarInt : Variant (Color & Style)
                                peMeta.set(EntityMetaData.Constants.DATA_VARIANT, new IntegerMeta((int) m.getValue()));
                            }
                            if (m.getValue() instanceof Boolean) {
                            // Boolean : Has Chest
                            // 
                            }
                            break;
                        case // VarInt	Type (0 = untamed, 1 = tuxedo, 2 = tabby, 3 = siamese). Used to render regardless as to whether it is tamed or not.
                        OCELOT:
                            peMeta.set(EntityMetaData.Constants.DATA_VARIANT, new IntegerMeta((int) m.getValue()));
                            break;
                        case // Float : Damage taken (used for tail rotation)
                        WOLF:
                            break;
                        case // VarInt	Variant (0: red/blue, 1: blue, 2: green, 3: yellow/blue, 4: silver)
                        PARROT:
                            peMeta.set(EntityMetaData.Constants.DATA_VARIANT, new IntegerMeta((int) m.getValue()));
                            break;
                        case // Byte : Color (dye color)
                        SHULKER:
                            peMeta.set(EntityMetaData.Constants.DATA_VARIANT, new ByteMeta((byte) m.getValue()));
                            break;
                        case // VarInt : Invulnerable time
                        WITHER:
                            // case ZOMBIE_VILLAGER: //Boolean : Is converting
                            break;
                        case // NBT Tag : Left shoulder entity data (for occupying parrot)
                        PLAYER:
                            // Not supported yet
                            break;
                    }
                    break;
                case 16:
                    switch(type) {
                        // Rotation : Left leg rotation
                        case ARMOR_STAND:
                        // VarInt : Armor (0: none, 1: iron, 2: gold, 3: diamond)
                        case HORSE:
                        // Boolean : Is begging
                        case WOLF:
                        // case ZOMBIE_VILLAGER: //VarInt : Profession
                        case // NBT Tag : Right shoulder entity data (for occupying parrot)
                        PLAYER:
                            // Not supported yet
                            break;
                    }
                case 17:
                    switch(type) {
                        // Rotation : Right leg rotation
                        case ARMOR_STAND:
                        case // VarInt : Collar color (values are those used with dyes)
                        WOLF:
                            break;
                    }
                    break;
            }
            if (type == EntityType.GIANT_ZOMBIE) {
                peMeta.set(EntityMetaData.Constants.DATA_SCALE, new FloatMeta(6));
            }
            if (!handle)
                DragonProxy.getInstance().getLogger().debug("Not supported entity meta (" + type.name() + ") : " + m.toString());
        } catch (Exception p_Ex) {
            // timing.stopTiming();
            p_Ex.printStackTrace();
        }
    }
    // }
    return peMeta;
}
Also used : IntegerMeta(org.dragonet.common.data.entity.meta.type.IntegerMeta) BlockPosition(org.dragonet.common.maths.BlockPosition) ByteMeta(org.dragonet.common.data.entity.meta.type.ByteMeta) EntityMetaData(org.dragonet.common.data.entity.meta.EntityMetaData) BlockPositionMeta(org.dragonet.common.data.entity.meta.type.BlockPositionMeta) ShortMeta(org.dragonet.common.data.entity.meta.type.ShortMeta) ByteArrayMeta(org.dragonet.common.data.entity.meta.type.ByteArrayMeta) SlotMeta(org.dragonet.common.data.entity.meta.type.SlotMeta) EntityMetadata(com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata) FloatMeta(org.dragonet.common.data.entity.meta.type.FloatMeta)

Example 4 with Position

use of com.github.steveice10.mc.protocol.data.game.entity.metadata.Position in project DragonProxy by DragonetMC.

the class PCPlayerPositionRotationPacketTranslator method translate.

@Override
public PEPacket[] translate(UpstreamSession session, ServerPlayerPositionRotationPacket packet) {
    CachedEntity entityPlayer = session.getEntityCache().getClientEntity();
    if (entityPlayer == null) {
    // disconnect (important missing data)
    }
    if (!session.isSpawned()) {
        if (session.getDataCache().get(CacheKey.PACKET_JOIN_GAME_PACKET) == null) {
            session.disconnect(session.getProxy().getLang().get(Lang.MESSAGE_REMOTE_ERROR));
            return null;
        }
        ServerJoinGamePacket restored = (ServerJoinGamePacket) session.getDataCache().remove(CacheKey.PACKET_JOIN_GAME_PACKET);
        if (!session.getProxy().getAuthMode().equalsIgnoreCase("online")) {
            StartGamePacket ret = new StartGamePacket();
            ret.rtid = entityPlayer.proxyEid;
            ret.eid = entityPlayer.proxyEid;
            ret.dimension = entityPlayer.dimention;
            ret.seed = 0;
            ret.generator = 1;
            ret.gamemode = restored.getGameMode() == GameMode.CREATIVE ? 1 : 0;
            ret.spawnPosition = new BlockPosition((int) packet.getX(), (int) packet.getY(), (int) packet.getZ());
            ret.position = new Vector3F((float) packet.getX(), (float) packet.getY() + EntityType.PLAYER.getOffset() + 0.1f, (float) packet.getZ());
            ret.yaw = packet.getYaw();
            ret.pitch = packet.getPitch();
            ret.levelId = "";
            ret.worldName = "World";
            ret.commandsEnabled = true;
            ret.defaultPlayerPermission = 2;
            ret.premiumWorldTemplateId = "";
            ret.difficulty = restored.getDifficulty();
            session.sendPacket(ret, true);
        }
        entityPlayer.absoluteMove(packet.getX(), packet.getY() + entityPlayer.peType.getOffset() + 0.1f, packet.getZ(), packet.getYaw(), packet.getPitch());
        session.getChunkCache().sendOrderedChunks();
        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeUTF("DragonProxy");
        ClientPluginMessagePacket clientPluginMessagePacket = new ClientPluginMessagePacket("MC|Brand", out.toByteArray());
        ((PCDownstreamSession) session.getDownstream()).send(clientPluginMessagePacket);
        LoginPacket loginpacket = (LoginPacket) session.getDataCache().remove(CacheKey.PACKET_LOGIN_PACKET);
        String clientLanguage = loginpacket.decoded.clientData.has("LanguageCode") ? loginpacket.decoded.clientData.get("LanguageCode").getAsString() : "en_US";
        session.getDataCache().put(CacheKey.PLAYER_LANGUAGE, clientLanguage);
        ClientSettingsPacket clientSettingsPacket = new ClientSettingsPacket(clientLanguage, (int) session.getDataCache().getOrDefault(CacheKey.PLAYER_REQUESTED_CHUNK_RADIUS, 5), ChatVisibility.FULL, false, new SkinPart[] {}, Hand.OFF_HAND);
        ((PCDownstreamSession) session.getDownstream()).send(clientSettingsPacket);
        UpdateAttributesPacket attr = new UpdateAttributesPacket();
        attr.rtid = entityPlayer.proxyEid;
        if (entityPlayer.attributes.isEmpty()) {
            attr.entries = new ArrayList();
            attr.entries.addAll(PEEntityAttribute.getDefault());
        } else
            attr.entries = entityPlayer.attributes.values();
        session.sendPacket(attr, true);
        AdventureSettingsPacket adv = new AdventureSettingsPacket();
        // flags
        adv.setFlag(AdventureSettingsPacket.WORLD_IMMUTABLE, restored.getGameMode().equals(GameMode.ADVENTURE));
        // adv.setFlag(AdventureSettingsPacket.NO_PVP, true);
        // adv.setFlag(AdventureSettingsPacket.AUTO_JUMP, true);
        adv.setFlag(AdventureSettingsPacket.ALLOW_FLIGHT, restored.getGameMode().equals(GameMode.CREATIVE) || restored.getGameMode().equals(GameMode.SPECTATOR));
        adv.setFlag(AdventureSettingsPacket.NO_CLIP, restored.getGameMode().equals(GameMode.SPECTATOR));
        adv.setFlag(AdventureSettingsPacket.WORLD_BUILDER, !restored.getGameMode().equals(GameMode.SPECTATOR) || !restored.getGameMode().equals(GameMode.ADVENTURE));
        adv.setFlag(AdventureSettingsPacket.FLYING, restored.getGameMode().equals(GameMode.SPECTATOR));
        adv.setFlag(AdventureSettingsPacket.MUTED, false);
        // custom permission flags (not necessary for now when using LEVEL_PERMISSION setting)
        // adv.setFlag(AdventureSettingsPacket.BUILD_AND_MINE, true);adv.setFlag(AdventureSettingsPacket.BUILD_AND_MINE, true);
        // adv.setFlag(AdventureSettingsPacket.DOORS_AND_SWITCHES, true);
        // adv.setFlag(AdventureSettingsPacket.OPEN_CONTAINERS, true);
        // adv.setFlag(AdventureSettingsPacket.ATTACK_PLAYERS, true);
        // adv.setFlag(AdventureSettingsPacket.ATTACK_MOBS, true);
        // adv.setFlag(AdventureSettingsPacket.OPERATOR, true);
        // adv.setFlag(AdventureSettingsPacket.TELEPORT, true);
        adv.eid = entityPlayer.proxyEid;
        // TODO update this with server configiration
        adv.commandsPermission = AdventureSettingsPacket.PERMISSION_NORMAL;
        // TODO update this with server configiration
        adv.playerPermission = AdventureSettingsPacket.LEVEL_PERMISSION_MEMBER;
        session.sendPacket(adv, true);
        SetEntityDataPacket entityData = new SetEntityDataPacket();
        entityData.rtid = entityPlayer.proxyEid;
        entityData.meta = EntityMetaData.createDefault();
        session.sendPacket(entityData, true);
        if (restored.getGameMode().equals(GameMode.CREATIVE))
            session.sendCreativeInventory();
        if (session.getProxy().getAuthMode().equalsIgnoreCase("online")) {
            MovePlayerPacket pk = new MovePlayerPacket();
            pk.rtid = entityPlayer.proxyEid;
            pk.mode = MovePlayerPacket.MODE_TELEPORT;
            pk.position = new Vector3F((float) packet.getX(), (float) packet.getY() + EntityType.PLAYER.getOffset() + 0.1f, (float) packet.getZ());
            pk.yaw = packet.getYaw();
            pk.pitch = packet.getPitch();
            pk.headYaw = packet.getYaw();
            if (entityPlayer.riding != 0) {
                CachedEntity vehicle = session.getEntityCache().getByLocalEID(entityPlayer.riding);
                if (vehicle != null)
                    pk.ridingRuntimeId = vehicle.eid;
            }
            session.sendPacket(pk, true);
        }
        // Notify the server
        BinaryStream bis = new BinaryStream();
        // command
        bis.putString("Notification");
        ClientPluginMessagePacket pluginMessage = new ClientPluginMessagePacket("DragonProxy", bis.get());
        session.getDownstream().send(pluginMessage);
        session.setSpawned();
        DragonProxy.getInstance().getLogger().info("Spawning " + session.getUsername() + " in world " + entityPlayer.dimention + " at " + entityPlayer.x + "/" + entityPlayer.y + "/" + entityPlayer.z);
        // send the confirmation
        ClientTeleportConfirmPacket confirm = new ClientTeleportConfirmPacket(packet.getTeleportId());
        ((PCDownstreamSession) session.getDownstream()).send(confirm);
        PlayerListPacket playerListPacket = new PlayerListPacket();
        Set<org.dragonet.protocol.type.PlayerListEntry> peEntries = new HashSet();
        for (CachedEntity entity : session.getEntityCache().getEntities().values()) {
            if (entity.peType == EntityType.PLAYER) {
                PlayerListEntry playerListEntry = session.getPlayerInfoCache().get(entity.playerUniqueId);
                org.dragonet.protocol.type.PlayerListEntry peEntry = new org.dragonet.protocol.type.PlayerListEntry();
                peEntry.uuid = entity.playerUniqueId;
                peEntry.eid = entity.eid;
                peEntry.username = playerListEntry.getProfile().getName();
                peEntry.skin = Skin.DEFAULT_SKIN_STEVE;
                peEntry.xboxUserId = "null";
                peEntries.add(peEntry);
            }
            entity.spawn(session);
        }
        playerListPacket.type = PlayerListPacket.TYPE_ADD;
        playerListPacket.entries = peEntries.toArray(new org.dragonet.protocol.type.PlayerListEntry[peEntries.size()]);
        session.sendPacket(playerListPacket);
        entityPlayer.spawned = true;
        return null;
    }
    entityPlayer.absoluteMove(packet.getX(), packet.getY() + entityPlayer.peType.getOffset() + 0.1f, packet.getZ(), packet.getYaw(), packet.getPitch());
    session.getChunkCache().sendOrderedChunks();
    float offset = 0.01f;
    byte mode = MovePlayerPacket.MODE_NORMAL;
    ChunkPos chunk = new ChunkPos(NukkitMath.ceilDouble(packet.getX()) >> 4, NukkitMath.ceilDouble(packet.getZ()) >> 4);
    // check if destination is out of range
    if (!session.getChunkCache().getLoadedChunks().contains(chunk)) {
        mode = MovePlayerPacket.MODE_TELEPORT;
        offset = 0.2f;
        // System.out.println(packet.getX() + " " + packet.getZ());
        // System.out.println("out of range !" + chunk.toString());
        session.getChunkCache().sendOrderedChunks();
    // session.getChunkCache().getDebugGrid();
    }
    MovePlayerPacket pk = new MovePlayerPacket();
    pk.rtid = entityPlayer.proxyEid;
    pk.mode = mode;
    pk.position = new Vector3F((float) packet.getX(), (float) packet.getY() + EntityType.PLAYER.getOffset() + offset, (float) packet.getZ());
    pk.yaw = packet.getYaw();
    pk.pitch = packet.getPitch();
    pk.headYaw = packet.getYaw();
    if (entityPlayer.riding != 0) {
        CachedEntity vehicle = session.getEntityCache().getByLocalEID(entityPlayer.riding);
        if (vehicle != null)
            pk.ridingRuntimeId = vehicle.eid;
    }
    // System.out.println("From server " + packet.getX() + " " + packet.getY() + " " + packet.getZ() + " ");
    // System.out.println("Entity position " + entityPlayer.x + " " + (entityPlayer.y - EntityType.PLAYER.getOffset()) + " " + entityPlayer.z + " ");
    session.sendPacket(pk);
    // send the confirmation
    ClientTeleportConfirmPacket confirm = new ClientTeleportConfirmPacket(packet.getTeleportId());
    ((PCDownstreamSession) session.getDownstream()).send(confirm);
    return null;
}
Also used : ArrayList(java.util.ArrayList) PlayerListEntry(com.github.steveice10.mc.protocol.data.game.PlayerListEntry) ClientSettingsPacket(com.github.steveice10.mc.protocol.packet.ingame.client.ClientSettingsPacket) Vector3F(org.dragonet.common.maths.Vector3F) ChunkPos(org.dragonet.common.maths.ChunkPos) HashSet(java.util.HashSet) CachedEntity(org.dragonet.proxy.network.cache.CachedEntity) BlockPosition(org.dragonet.common.maths.BlockPosition) ServerJoinGamePacket(com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket) BinaryStream(org.dragonet.common.utilities.BinaryStream) ClientTeleportConfirmPacket(com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket) ClientPluginMessagePacket(com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket) ByteArrayDataOutput(com.google.common.io.ByteArrayDataOutput) PCDownstreamSession(org.dragonet.proxy.network.PCDownstreamSession)

Example 5 with Position

use of com.github.steveice10.mc.protocol.data.game.entity.metadata.Position in project DragonProxy by DragonetMC.

the class ChunkCache method update.

public void update(Position position, BlockState block) {
    ChunkPos columnPos = new ChunkPos(position.getX() >> 4, position.getZ() >> 4);
    // System.out.println("translateBlock Position " + position.toString());
    if (chunkCache.containsKey(columnPos))
        try {
            Column column = chunkCache.get(columnPos);
            BlockPosition blockPos = columnPos.getBlockInChunk(position.getX(), position.getY(), position.getZ());
            Chunk chunk = column.getChunks()[position.getY() >> 4];
            if (chunk != null)
                chunk.getBlocks().set(blockPos.x, blockPos.y, blockPos.z, block);
        } catch (java.lang.ArrayIndexOutOfBoundsException ex) {
            this.session.getProxy().getLogger().info("update(" + position.toString() + ", " + block.toString() + ")) fail to get chunk " + (position.getX() >> 4) + "/" + (position.getY() >> 4) + "/" + (position.getZ() >> 4));
            ex.printStackTrace();
        }
// enqueue block update
}
Also used : Column(com.github.steveice10.mc.protocol.data.game.chunk.Column) BlockPosition(org.dragonet.common.maths.BlockPosition) ChunkPos(org.dragonet.common.maths.ChunkPos) Chunk(com.github.steveice10.mc.protocol.data.game.chunk.Chunk)

Aggregations

BlockPosition (org.dragonet.common.maths.BlockPosition)7 Position (com.github.steveice10.mc.protocol.data.game.entity.metadata.Position)5 Packet (com.github.steveice10.packetlib.packet.Packet)4 ChunkPos (org.dragonet.common.maths.ChunkPos)4 Chunk (com.github.steveice10.mc.protocol.data.game.chunk.Chunk)3 Column (com.github.steveice10.mc.protocol.data.game.chunk.Column)3 BlockState (com.github.steveice10.mc.protocol.data.game.world.block.BlockState)3 ClientPlayerActionPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerActionPacket)3 CachedEntity (org.dragonet.proxy.network.cache.CachedEntity)3 ItemStack (com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack)2 ClientRequestPacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientRequestPacket)2 ClientPlayerUseItemPacket (com.github.steveice10.mc.protocol.packet.ingame.client.player.ClientPlayerUseItemPacket)2 ClientTeleportConfirmPacket (com.github.steveice10.mc.protocol.packet.ingame.client.world.ClientTeleportConfirmPacket)2 ServerJoinGamePacket (com.github.steveice10.mc.protocol.packet.ingame.server.ServerJoinGamePacket)2 PlayerListEntry (com.github.steveice10.mc.protocol.data.game.PlayerListEntry)1 EntityMetadata (com.github.steveice10.mc.protocol.data.game.entity.metadata.EntityMetadata)1 InteractAction (com.github.steveice10.mc.protocol.data.game.entity.player.InteractAction)1 BlockFace (com.github.steveice10.mc.protocol.data.game.world.block.BlockFace)1 ClientPluginMessagePacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientPluginMessagePacket)1 ClientSettingsPacket (com.github.steveice10.mc.protocol.packet.ingame.client.ClientSettingsPacket)1