Search in sources :

Example 1 with PacketPlayOutEntityEquipment

use of net.minecraft.server.v1_14_R1.PacketPlayOutEntityEquipment in project InteractionVisualizer by LOOHP.

the class V1_16 method createEntityEquipmentPacket.

@Override
public PacketContainer[] createEntityEquipmentPacket(int entityId, List<ValuePairs<EquipmentSlot, ItemStack>> equipments) {
    List<Pair<EnumItemSlot, net.minecraft.server.v1_16_R1.ItemStack>> nmsList = new ArrayList<>();
    for (ValuePairs<EquipmentSlot, ItemStack> pair : equipments) {
        EnumItemSlot nmsSlot;
        switch(pair.getFirst()) {
            case CHEST:
                nmsSlot = EnumItemSlot.CHEST;
                break;
            case FEET:
                nmsSlot = EnumItemSlot.FEET;
                break;
            case HEAD:
                nmsSlot = EnumItemSlot.HEAD;
                break;
            case LEGS:
                nmsSlot = EnumItemSlot.LEGS;
                break;
            case OFF_HAND:
                nmsSlot = EnumItemSlot.OFFHAND;
                break;
            case HAND:
            default:
                nmsSlot = EnumItemSlot.MAINHAND;
                break;
        }
        net.minecraft.server.v1_16_R1.ItemStack nmsItem = CraftItemStack.asNMSCopy(pair.getSecond());
        nmsList.add(new Pair<>(nmsSlot, nmsItem));
    }
    PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsList);
    return new PacketContainer[] { PacketContainer.fromPacket(packet) };
}
Also used : PacketContainer(com.comphenix.protocol.events.PacketContainer) ArrayList(java.util.ArrayList) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) EnumItemSlot(net.minecraft.server.v1_16_R1.EnumItemSlot) CraftItemStack(org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) PacketPlayOutEntityEquipment(net.minecraft.server.v1_16_R1.PacketPlayOutEntityEquipment) Pair(com.mojang.datafixers.util.Pair)

Example 2 with PacketPlayOutEntityEquipment

use of net.minecraft.server.v1_14_R1.PacketPlayOutEntityEquipment in project InteractionVisualizer by LOOHP.

the class V1_16_2 method createEntityEquipmentPacket.

@Override
public PacketContainer[] createEntityEquipmentPacket(int entityId, List<ValuePairs<EquipmentSlot, ItemStack>> equipments) {
    List<Pair<EnumItemSlot, net.minecraft.server.v1_16_R2.ItemStack>> nmsList = new ArrayList<>();
    for (ValuePairs<EquipmentSlot, ItemStack> pair : equipments) {
        EnumItemSlot nmsSlot;
        switch(pair.getFirst()) {
            case CHEST:
                nmsSlot = EnumItemSlot.CHEST;
                break;
            case FEET:
                nmsSlot = EnumItemSlot.FEET;
                break;
            case HEAD:
                nmsSlot = EnumItemSlot.HEAD;
                break;
            case LEGS:
                nmsSlot = EnumItemSlot.LEGS;
                break;
            case OFF_HAND:
                nmsSlot = EnumItemSlot.OFFHAND;
                break;
            case HAND:
            default:
                nmsSlot = EnumItemSlot.MAINHAND;
                break;
        }
        net.minecraft.server.v1_16_R2.ItemStack nmsItem = CraftItemStack.asNMSCopy(pair.getSecond());
        nmsList.add(new Pair<>(nmsSlot, nmsItem));
    }
    PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsList);
    return new PacketContainer[] { PacketContainer.fromPacket(packet) };
}
Also used : PacketContainer(com.comphenix.protocol.events.PacketContainer) ArrayList(java.util.ArrayList) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) EnumItemSlot(net.minecraft.server.v1_16_R2.EnumItemSlot) CraftItemStack(org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) PacketPlayOutEntityEquipment(net.minecraft.server.v1_16_R2.PacketPlayOutEntityEquipment) Pair(com.mojang.datafixers.util.Pair)

Example 3 with PacketPlayOutEntityEquipment

use of net.minecraft.server.v1_14_R1.PacketPlayOutEntityEquipment in project InteractionVisualizer by LOOHP.

the class V1_16_4 method createEntityEquipmentPacket.

@Override
public PacketContainer[] createEntityEquipmentPacket(int entityId, List<ValuePairs<EquipmentSlot, ItemStack>> equipments) {
    List<Pair<EnumItemSlot, net.minecraft.server.v1_16_R3.ItemStack>> nmsList = new ArrayList<>();
    for (ValuePairs<EquipmentSlot, ItemStack> pair : equipments) {
        EnumItemSlot nmsSlot;
        switch(pair.getFirst()) {
            case CHEST:
                nmsSlot = EnumItemSlot.CHEST;
                break;
            case FEET:
                nmsSlot = EnumItemSlot.FEET;
                break;
            case HEAD:
                nmsSlot = EnumItemSlot.HEAD;
                break;
            case LEGS:
                nmsSlot = EnumItemSlot.LEGS;
                break;
            case OFF_HAND:
                nmsSlot = EnumItemSlot.OFFHAND;
                break;
            case HAND:
            default:
                nmsSlot = EnumItemSlot.MAINHAND;
                break;
        }
        net.minecraft.server.v1_16_R3.ItemStack nmsItem = CraftItemStack.asNMSCopy(pair.getSecond());
        nmsList.add(new Pair<>(nmsSlot, nmsItem));
    }
    PacketPlayOutEntityEquipment packet = new PacketPlayOutEntityEquipment(entityId, nmsList);
    return new PacketContainer[] { PacketContainer.fromPacket(packet) };
}
Also used : PacketContainer(com.comphenix.protocol.events.PacketContainer) ArrayList(java.util.ArrayList) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) EnumItemSlot(net.minecraft.server.v1_16_R3.EnumItemSlot) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) PacketPlayOutEntityEquipment(net.minecraft.server.v1_16_R3.PacketPlayOutEntityEquipment) Pair(com.mojang.datafixers.util.Pair)

Example 4 with PacketPlayOutEntityEquipment

use of net.minecraft.server.v1_14_R1.PacketPlayOutEntityEquipment in project CokesAddon by Cokes86.

the class v1_14_R1 method injectPlayer.

public void injectPlayer(Player player) {
    CraftPlayer player1 = (CraftPlayer) player;
    if (!player.isValid())
        return;
    if (channelHandlers.containsKey(player.getUniqueId())) {
        final Pair<CraftPlayer, ChannelOutboundHandlerAdapter> pair = channelHandlers.get(player.getUniqueId());
        if (!pair.getLeft().isValid()) {
            try {
                pair.getLeft().getHandle().playerConnection.networkManager.channel.pipeline().remove(pair.getRight());
            } catch (NoSuchElementException ignored) {
            }
        } else
            return;
    }
    final ChannelOutboundHandlerAdapter handler = new ChannelOutboundHandlerAdapter() {

        @Override
        public void write(ChannelHandlerContext ctx, Object packet, ChannelPromise promise) throws Exception {
            if (packet instanceof PacketPlayOutEntityEquipment) {
                if ((int) ReflectionUtil.FieldUtil.getValue(packet, "a") == getPlayer().getEntityId()) {
                    ReflectionUtil.FieldUtil.setValue(packet, "c", ItemStack.a);
                }
            } else if (packet instanceof PacketPlayOutEntityMetadata) {
                if ((int) ReflectionUtil.FieldUtil.getValue(packet, "a") == getPlayer().getEntityId()) {
                    List<Item<?>> items = ReflectionUtil.FieldUtil.getValue(packet, "b");
                    if (items.size() != 0) {
                        Item<?> item = items.get(0);
                        if (BYTE_DATA_WATCHER_OBJECT.equals(item.a())) {
                            Item<Byte> byteItem = (Item<Byte>) item;
                            byteItem.a((byte) (byteItem.b() | 1 << 5));
                            ((CraftPlayer) getPlayer()).getHandle().setInvisible(true);
                        }
                    }
                }
            }
            super.write(ctx, packet, promise);
        }
    };
    channelHandlers.put(player.getUniqueId(), Pair.of(player1, handler));
    player1.getHandle().playerConnection.networkManager.channel.pipeline().addBefore("packet_handler", hashCode() + ":" + player.getName(), handler);
}
Also used : Item(net.minecraft.server.v1_14_R1.DataWatcher.Item) ChannelOutboundHandlerAdapter(io.netty.channel.ChannelOutboundHandlerAdapter) CraftPlayer(org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelPromise(io.netty.channel.ChannelPromise)

Example 5 with PacketPlayOutEntityEquipment

use of net.minecraft.server.v1_14_R1.PacketPlayOutEntityEquipment in project MechanicsMain by WeaponMechanics.

the class FakeEntity_1_14_R1 method show.

@Override
public void show(@NotNull Player player) {
    PlayerConnection connection = ((CraftPlayer) player).getHandle().playerConnection;
    if (connections.contains(connection))
        throw new IllegalArgumentException();
    connection.sendPacket(type.isAlive() ? new PacketPlayOutSpawnEntityLiving((EntityLiving) entity) : new PacketPlayOutSpawnEntity(entity, type == EntityType.FALLING_BLOCK ? Block.getCombinedId(block) : 0));
    connection.sendPacket(new PacketPlayOutEntityMetadata(cache, entity.getDataWatcher(), true));
    connection.sendPacket(new PacketPlayOutEntityLook(cache, convertYaw(getYaw()), convertPitch(getPitch()), false));
    connection.sendPacket(new PacketPlayOutEntityVelocity(cache, new Vec3D(motion.getX(), motion.getY(), motion.getZ())));
    connection.sendPacket(new PacketPlayOutEntityHeadRotation(entity, convertYaw(getYaw())));
    PacketPlayOutEntityEquipment[] equipment = getEquipmentPacket();
    if (equipment != null) {
        for (PacketPlayOutEntityEquipment packet : equipment) {
            connection.sendPacket(packet);
        }
    }
    // Inject the player's packet connection into this listener, so we can
    // show the player position/velocity/rotation changes
    connections.add(connection);
}
Also used : PacketPlayOutEntityLook(net.minecraft.server.v1_14_R1.PacketPlayOutEntity.PacketPlayOutEntityLook)

Aggregations

Location (org.bukkit.Location)9 Pair (com.mojang.datafixers.util.Pair)4 ArrayList (java.util.ArrayList)4 ItemStack (org.bukkit.inventory.ItemStack)4 PacketContainer (com.comphenix.protocol.events.PacketContainer)3 EquipmentSlot (org.bukkit.inventory.EquipmentSlot)3 PacketPlayOutEntityLook (net.minecraft.server.v1_14_R1.PacketPlayOutEntity.PacketPlayOutEntityLook)2 PacketPlayOutEntityEquipment (net.minecraft.server.v1_16_R3.PacketPlayOutEntityEquipment)2 Player (org.bukkit.entity.Player)2 UltraCosmeticsData (be.isach.ultracosmetics.UltraCosmeticsData)1 ChestType (be.isach.ultracosmetics.treasurechests.ChestType)1 TreasureChestDesign (be.isach.ultracosmetics.treasurechests.TreasureChestDesign)1 MathUtils (be.isach.ultracosmetics.util.MathUtils)1 PacketSender (be.isach.ultracosmetics.util.PacketSender)1 Particles (be.isach.ultracosmetics.util.Particles)1 UtilParticles (be.isach.ultracosmetics.util.UtilParticles)1 CustomPathFinderGoalPanic (be.isach.ultracosmetics.v1_14_R1.pathfinders.CustomPathFinderGoalPanic)1 IEntityUtil (be.isach.ultracosmetics.version.IEntityUtil)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelOutboundHandlerAdapter (io.netty.channel.ChannelOutboundHandlerAdapter)1