Search in sources :

Example 6 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_10_R1.EnumItemSlot) Packet(net.minecraft.server.v1_10_R1.Packet) ItemStack(net.minecraft.server.v1_10_R1.ItemStack) PacketPlayOutEntityEquipment(net.minecraft.server.v1_10_R1.PacketPlayOutEntityEquipment) Location(org.bukkit.Location)

Example 7 with EnumItemSlot

use of net.minecraft.server.v1_16_R3.EnumItemSlot in project Denizen by DenizenScript.

the class PacketHelperImpl method resetEquipment.

@Override
public void resetEquipment(Player player, LivingEntity entity) {
    EntityEquipment equipment = entity.getEquipment();
    ArrayList<Pair<EnumItemSlot, net.minecraft.server.v1_16_R3.ItemStack>> pairList = new ArrayList<>();
    pairList.add(new Pair<>(EnumItemSlot.MAINHAND, CraftItemStack.asNMSCopy(equipment.getItemInMainHand())));
    pairList.add(new Pair<>(EnumItemSlot.OFFHAND, CraftItemStack.asNMSCopy(equipment.getItemInOffHand())));
    pairList.add(new Pair<>(EnumItemSlot.HEAD, CraftItemStack.asNMSCopy(equipment.getHelmet())));
    pairList.add(new Pair<>(EnumItemSlot.CHEST, CraftItemStack.asNMSCopy(equipment.getChestplate())));
    pairList.add(new Pair<>(EnumItemSlot.LEGS, CraftItemStack.asNMSCopy(equipment.getLeggings())));
    pairList.add(new Pair<>(EnumItemSlot.FEET, CraftItemStack.asNMSCopy(equipment.getBoots())));
    sendPacket(player, new PacketPlayOutEntityEquipment(entity.getEntityId(), pairList));
}
Also used : net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) EntityEquipment(org.bukkit.inventory.EntityEquipment) Pair(com.mojang.datafixers.util.Pair)

Example 8 with EnumItemSlot

use of net.minecraft.server.v1_16_R3.EnumItemSlot in project Denizen-For-Bukkit by DenizenScript.

the class PacketHelperImpl method resetEquipment.

@Override
public void resetEquipment(Player player, LivingEntity entity) {
    EntityEquipment equipment = entity.getEquipment();
    ArrayList<Pair<EnumItemSlot, net.minecraft.server.v1_16_R3.ItemStack>> pairList = new ArrayList<>();
    pairList.add(new Pair<>(EnumItemSlot.MAINHAND, CraftItemStack.asNMSCopy(equipment.getItemInMainHand())));
    pairList.add(new Pair<>(EnumItemSlot.OFFHAND, CraftItemStack.asNMSCopy(equipment.getItemInOffHand())));
    pairList.add(new Pair<>(EnumItemSlot.HEAD, CraftItemStack.asNMSCopy(equipment.getHelmet())));
    pairList.add(new Pair<>(EnumItemSlot.CHEST, CraftItemStack.asNMSCopy(equipment.getChestplate())));
    pairList.add(new Pair<>(EnumItemSlot.LEGS, CraftItemStack.asNMSCopy(equipment.getLeggings())));
    pairList.add(new Pair<>(EnumItemSlot.FEET, CraftItemStack.asNMSCopy(equipment.getBoots())));
    sendPacket(player, new PacketPlayOutEntityEquipment(entity.getEntityId(), pairList));
}
Also used : net.minecraft.server.v1_16_R3(net.minecraft.server.v1_16_R3) EntityEquipment(org.bukkit.inventory.EntityEquipment) Pair(com.mojang.datafixers.util.Pair)

Example 9 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_12_R1.EnumItemSlot) Packet(net.minecraft.server.v1_12_R1.Packet) ItemStack(net.minecraft.server.v1_12_R1.ItemStack) PacketPlayOutEntityEquipment(net.minecraft.server.v1_12_R1.PacketPlayOutEntityEquipment) Location(org.bukkit.Location)

Example 10 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[1];
    List<Pair<EnumItemSlot, ItemStack>> vals = Lists.newArrayList();
    for (EnumItemSlot slot : EnumItemSlot.values()) {
        vals.add(new Pair<EnumItemSlot, ItemStack>(slot, getEquipment(slot)));
    }
    packets[0] = new PacketPlayOutEntityEquipment(getId(), vals);
    NMSImpl.sendPacketsNearby(getBukkitEntity(), current, packets);
}
Also used : EnumItemSlot(net.minecraft.server.v1_16_R3.EnumItemSlot) Packet(net.minecraft.server.v1_16_R3.Packet) ItemStack(net.minecraft.server.v1_16_R3.ItemStack) PacketPlayOutEntityEquipment(net.minecraft.server.v1_16_R3.PacketPlayOutEntityEquipment) Location(org.bukkit.Location) 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