Search in sources :

Example 11 with EnumItemSlot

use of net.minecraft.server.v1_16_R3.EnumItemSlot in project Citizens2 by CitizensDev.

the class EntityHumanNPC method updatePackets.

private void updatePackets(boolean navigating) {
    updateCounter++;
    boolean itemChanged = false;
    for (EnumItemSlot slot : EnumItemSlot.values()) {
        ItemStack equipment = getEquipment(slot);
        ItemStack cache = equipmentCache.get(slot);
        if (!(cache == null && equipment == null) && (cache == null ^ equipment == null || !ItemStack.equals(cache, equipment))) {
            itemChanged = true;
        }
        equipmentCache.put(slot, equipment);
    }
    if (updateCounter++ <= npc.data().<Integer>get(NPC.Metadata.PACKET_UPDATE_DELAY, Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
        return;
    updateCounter = 0;
    Location current = getBukkitEntity().getLocation(packetLocationCache);
    Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
    int i = 0;
    for (EnumItemSlot slot : EnumItemSlot.values()) {
        packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot));
    }
    NMSImpl.sendPacketsNearby(getBukkitEntity(), current, packets);
}
Also used : EnumItemSlot(net.minecraft.server.v1_15_R1.EnumItemSlot) Packet(net.minecraft.server.v1_15_R1.Packet) ItemStack(net.minecraft.server.v1_15_R1.ItemStack) PacketPlayOutEntityEquipment(net.minecraft.server.v1_15_R1.PacketPlayOutEntityEquipment) Location(org.bukkit.Location)

Example 12 with EnumItemSlot

use of net.minecraft.server.v1_16_R3.EnumItemSlot in project Citizens2 by CitizensDev.

the class EntityHumanNPC method updatePackets.

private void updatePackets(boolean navigating) {
    updateCounter++;
    boolean itemChanged = false;
    for (EnumItemSlot slot : EnumItemSlot.values()) {
        ItemStack equipment = getEquipment(slot);
        ItemStack cache = equipmentCache.get(slot);
        if (!(cache == null && equipment == null) && (cache == null ^ equipment == null || !ItemStack.equals(cache, equipment))) {
            itemChanged = true;
        }
        equipmentCache.put(slot, equipment);
    }
    if (updateCounter++ <= npc.data().<Integer>get(NPC.Metadata.PACKET_UPDATE_DELAY, Setting.PACKET_UPDATE_DELAY.asInt()) && !itemChanged)
        return;
    updateCounter = 0;
    Location current = getBukkitEntity().getLocation(packetLocationCache);
    Packet<?>[] packets = new Packet[EnumItemSlot.values().length];
    int i = 0;
    for (EnumItemSlot slot : EnumItemSlot.values()) {
        packets[i++] = new PacketPlayOutEntityEquipment(getId(), slot, getEquipment(slot));
    }
    NMSImpl.sendPacketsNearby(getBukkitEntity(), current, packets);
}
Also used : EnumItemSlot(net.minecraft.server.v1_14_R1.EnumItemSlot) Packet(net.minecraft.server.v1_14_R1.Packet) ItemStack(net.minecraft.server.v1_14_R1.ItemStack) PacketPlayOutEntityEquipment(net.minecraft.server.v1_14_R1.PacketPlayOutEntityEquipment) Location(org.bukkit.Location)

Example 13 with EnumItemSlot

use of net.minecraft.server.v1_16_R3.EnumItemSlot in project UltraCosmetics by iSach.

the class EntityUtil method sendBlizzard.

@Override
public void sendBlizzard(final Player player, Location loc, boolean affectPlayers, Vector v) {
    try {
        if (!fakeArmorStandsMap.containsKey(player))
            fakeArmorStandsMap.put(player, new ArrayList<>());
        if (!cooldownJumpMap.containsKey(player))
            cooldownJumpMap.put(player, new ArrayList<>());
        final List<EntityArmorStand> fakeArmorStands = fakeArmorStandsMap.get(player);
        final List<org.bukkit.entity.Entity> cooldownJump = cooldownJumpMap.get(player);
        final EntityArmorStand as = new EntityArmorStand(EntityTypes.ARMOR_STAND, ((CraftWorld) player.getWorld()).getHandle());
        as.setInvisible(true);
        as.setFlag(5, true);
        as.setSmall(true);
        as.setNoGravity(true);
        as.setArms(true);
        as.setHeadPose(new Vector3f((float) (r.nextInt(360)), (float) (r.nextInt(360)), (float) (r.nextInt(360))));
        as.setLocation(loc.getX() + MathUtils.randomDouble(-1.5, 1.5), loc.getY() + MathUtils.randomDouble(0, .5) - 0.75, loc.getZ() + MathUtils.randomDouble(-1.5, 1.5), 0, 0);
        fakeArmorStands.add(as);
        for (Player players : player.getWorld().getPlayers()) {
            PacketSender.send(players, new PacketPlayOutSpawnEntityLiving(as));
            PacketSender.send(players, new PacketPlayOutEntityMetadata(as.getId(), as.getDataWatcher(), false));
            List<Pair<EnumItemSlot, ItemStack>> list = new ArrayList<>();
            list.add(new Pair(EnumItemSlot.HEAD, CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(org.bukkit.Material.PACKED_ICE))));
            PacketSender.send(players, new PacketPlayOutEntityEquipment(as.getId(), list));
        }
        UtilParticles.display(Particles.CLOUD, loc.clone().add(MathUtils.randomDouble(-1.5, 1.5), MathUtils.randomDouble(0, .5) - 0.75, MathUtils.randomDouble(-1.5, 1.5)), 2, 0.4f);
        Bukkit.getScheduler().runTaskLater(UltraCosmeticsData.get().getPlugin(), () -> {
            for (Player pl : player.getWorld().getPlayers()) PacketSender.send(pl, new PacketPlayOutEntityDestroy(as.getId()));
            fakeArmorStands.remove(as);
        }, 20);
        if (affectPlayers)
            as.getBukkitEntity().getNearbyEntities(0.5, 0.5, 0.5).stream().filter(ent -> !cooldownJump.contains(ent) && ent != player).forEachOrdered(ent -> {
                MathUtils.applyVelocity(ent, new Vector(0, 1, 0).add(v));
                cooldownJump.add(ent);
                Bukkit.getScheduler().runTaskLater(UltraCosmeticsData.get().getPlugin(), () -> cooldownJump.remove(ent), 20);
            });
    } catch (Exception exc) {
    }
}
Also used : CraftInventory(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventory) MathUtils(be.isach.ultracosmetics.util.MathUtils) java.util(java.util) Wither(org.bukkit.entity.Wither) UtilParticles(be.isach.ultracosmetics.util.UtilParticles) Player(org.bukkit.entity.Player) net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) Inventory(org.bukkit.inventory.Inventory) Block(org.bukkit.block.Block) Location(org.bukkit.Location) UltraCosmeticsData(be.isach.ultracosmetics.UltraCosmeticsData) Math(java.lang.Math) Particles(be.isach.ultracosmetics.util.Particles) TreasureChestDesign(be.isach.ultracosmetics.treasurechests.TreasureChestDesign) Creature(org.bukkit.entity.Creature) Bukkit(org.bukkit.Bukkit) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld) Field(java.lang.reflect.Field) Pair(com.mojang.datafixers.util.Pair) Vector(org.bukkit.util.Vector) CustomPathFinderGoalPanic(be.isach.ultracosmetics.v1_16_R3.pathfinders.CustomPathFinderGoalPanic) org.bukkit.craftbukkit.v1_16_R3.entity(org.bukkit.craftbukkit.v1_16_R3.entity) IEntityUtil(be.isach.ultracosmetics.version.IEntityUtil) ChestType(be.isach.ultracosmetics.treasurechests.ChestType) PacketSender(be.isach.ultracosmetics.util.PacketSender) Player(org.bukkit.entity.Player) Vector(org.bukkit.util.Vector) Pair(com.mojang.datafixers.util.Pair)

Aggregations

Location (org.bukkit.Location)8 Pair (com.mojang.datafixers.util.Pair)7 PacketContainer (com.comphenix.protocol.events.PacketContainer)3 ArrayList (java.util.ArrayList)3 net.minecraft.server.v1_16_R3 (net.minecraft.server.v1_16_R3)3 EquipmentSlot (org.bukkit.inventory.EquipmentSlot)3 ItemStack (org.bukkit.inventory.ItemStack)3 EnumItemSlot (net.minecraft.server.v1_16_R3.EnumItemSlot)2 PacketPlayOutEntityEquipment (net.minecraft.server.v1_16_R3.PacketPlayOutEntityEquipment)2 CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)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_16_R3.pathfinders.CustomPathFinderGoalPanic)1 IEntityUtil (be.isach.ultracosmetics.version.IEntityUtil)1 Math (java.lang.Math)1