Search in sources :

Example 16 with PacketPlayOutEntityMetadata

use of net.minecraft.server.v1_13_R2.PacketPlayOutEntityMetadata in project MechanicsMain by WeaponMechanics.

the class FakeEntity_1_13_R2 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, 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_13_R2.PacketPlayOutEntity.PacketPlayOutEntityLook)

Example 17 with PacketPlayOutEntityMetadata

use of net.minecraft.server.v1_13_R2.PacketPlayOutEntityMetadata in project WLib by WizardlyBump17.

the class PacketListener method entityMetadata.

@SuppressWarnings("unchecked")
@SneakyThrows
private void entityMetadata(World world, PacketContainer packet, PacketPlayOutEntityMetadata handle) {
    final Entity entity = packet.getEntityModifier(world).read(0);
    if (!(entity instanceof org.bukkit.entity.Item))
        return;
    final ItemStack itemStack = ((org.bukkit.entity.Item) entity).getItemStack().clone();
    if (isInvalid(itemStack))
        return;
    final Field field = handle.getClass().getDeclaredField("b");
    field.setAccessible(true);
    List<DataWatcher.Item<?>> items = new ArrayList<>((List<DataWatcher.Item<?>>) field.get(handle));
    final DataWatcher.Item<?> item;
    int index;
    if (items.size() == 8)
        // new item
        item = items.get(index = 6).d();
    else
        // item merge
        item = items.get(index = 0).d();
    final Field itemField = item.getClass().getDeclaredField("b");
    itemField.setAccessible(true);
    itemField.set(item, CraftItemStack.asNMSCopy(fixItem(itemStack)));
    items.set(index, item);
    field.set(handle, items);
}
Also used : Entity(org.bukkit.entity.Entity) Field(java.lang.reflect.Field) ArrayList(java.util.ArrayList) CraftItemStack(org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) DataWatcher(net.minecraft.server.v1_13_R2.DataWatcher) SneakyThrows(lombok.SneakyThrows)

Aggregations

MemoryNPCDataStore (net.citizensnpcs.api.npc.MemoryNPCDataStore)8 NPC (net.citizensnpcs.api.npc.NPC)8 NPCRegistry (net.citizensnpcs.api.npc.NPCRegistry)8 NPCHolder (net.citizensnpcs.npc.ai.NPCHolder)8 ArmorStandTrait (net.citizensnpcs.trait.ArmorStandTrait)8 FixedMetadataValue (org.bukkit.metadata.FixedMetadataValue)8 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)8 PacketPlayOutEntityMetadata (net.minecraft.server.v1_16_R3.PacketPlayOutEntityMetadata)4 ArrayList (java.util.ArrayList)3 PacketPlayOutEntityLook (net.minecraft.server.v1_13_R2.PacketPlayOutEntity.PacketPlayOutEntityLook)2 Item (net.minecraft.server.v1_16_R2.DataWatcher.Item)2 PacketPlayOutEntityMetadata (net.minecraft.server.v1_16_R2.PacketPlayOutEntityMetadata)2 Item (net.minecraft.server.v1_16_R3.DataWatcher.Item)2 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelOutboundHandlerAdapter (io.netty.channel.ChannelOutboundHandlerAdapter)1 ChannelPromise (io.netty.channel.ChannelPromise)1 Field (java.lang.reflect.Field)1 SneakyThrows (lombok.SneakyThrows)1 BlockPosition (net.minecraft.server.v1_10_R1.BlockPosition)1 EntityPlayer (net.minecraft.server.v1_10_R1.EntityPlayer)1