Search in sources :

Example 6 with EnumItemSlot

use of net.minecraft.server.v1_15_R1.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_15_R1.EnumItemSlot in project solinia3-core by mixxit.

the class ItemStackUtils method getWeaponDamageFromItemStack.

public static int getWeaponDamageFromItemStack(ItemStack itemStack, EnumItemSlot itemSlot) {
    double attackDamage = 1.0;
    UUID uuid = UUID.fromString("CB3F55D3-645C-4F38-A497-9C13A33DB5CF");
    net.minecraft.server.v1_15_R1.ItemStack craftItemStack = CraftItemStack.asNMSCopy(itemStack);
    net.minecraft.server.v1_15_R1.Item item = craftItemStack.getItem();
    if (item instanceof net.minecraft.server.v1_15_R1.ItemSword || item instanceof net.minecraft.server.v1_15_R1.ItemTool || item instanceof net.minecraft.server.v1_15_R1.ItemHoe) {
        Multimap<String, AttributeModifier> map = item.a(itemSlot);
        Collection<AttributeModifier> attributes = map.get(GenericAttributes.ATTACK_DAMAGE.getName());
        if (!attributes.isEmpty()) {
            for (AttributeModifier am : attributes) {
                if (am.getUniqueId().toString().equalsIgnoreCase(uuid.toString()) && am.getOperation() == AttributeModifier.Operation.ADDITION)
                    attackDamage += am.getAmount();
            }
            double y = 1;
            for (AttributeModifier am : attributes) {
                if (am.getUniqueId().toString().equalsIgnoreCase(uuid.toString()) && am.getOperation() == AttributeModifier.Operation.MULTIPLY_BASE)
                    y += am.getAmount();
            }
            attackDamage *= y;
            for (AttributeModifier am : attributes) {
                if (am.getUniqueId().toString().equalsIgnoreCase(uuid.toString()) && am.getOperation() == AttributeModifier.Operation.MULTIPLY_TOTAL)
                    attackDamage *= (1 + am.getAmount());
            }
        }
    }
    Long rounded = Math.round(attackDamage);
    if (rounded > Integer.MAX_VALUE)
        rounded = (long) Integer.MAX_VALUE;
    int damage = Integer.valueOf(rounded.intValue());
    return damage;
}
Also used : AttributeModifier(net.minecraft.server.v1_15_R1.AttributeModifier) UUID(java.util.UUID)

Example 8 with EnumItemSlot

use of net.minecraft.server.v1_15_R1.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 9 with EnumItemSlot

use of net.minecraft.server.v1_15_R1.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)

Example 10 with EnumItemSlot

use of net.minecraft.server.v1_15_R1.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)

Aggregations

Location (org.bukkit.Location)7 Pair (com.mojang.datafixers.util.Pair)4 PacketContainer (com.comphenix.protocol.events.PacketContainer)3 ArrayList (java.util.ArrayList)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 UUID (java.util.UUID)1 EnumItemSlot (net.minecraft.server.v1_10_R1.EnumItemSlot)1 ItemStack (net.minecraft.server.v1_10_R1.ItemStack)1 Packet (net.minecraft.server.v1_10_R1.Packet)1 PacketPlayOutEntityEquipment (net.minecraft.server.v1_10_R1.PacketPlayOutEntityEquipment)1 EnumItemSlot (net.minecraft.server.v1_11_R1.EnumItemSlot)1 ItemStack (net.minecraft.server.v1_11_R1.ItemStack)1 Packet (net.minecraft.server.v1_11_R1.Packet)1 PacketPlayOutEntityEquipment (net.minecraft.server.v1_11_R1.PacketPlayOutEntityEquipment)1 EnumItemSlot (net.minecraft.server.v1_12_R1.EnumItemSlot)1 ItemStack (net.minecraft.server.v1_12_R1.ItemStack)1 Packet (net.minecraft.server.v1_12_R1.Packet)1