Search in sources :

Example 91 with ItemStack

use of net.minecraft.server.v1_16_R1.ItemStack in project Citizens2 by CitizensDev.

the class EntityHumanNPC method updatePackets.

private void updatePackets(boolean navigating) {
    updateCounter++;
    boolean itemChanged = false;
    for (int slot = 0; slot < this.inventory.armor.length; slot++) {
        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[this.inventory.armor.length];
    for (int i = 0; i < this.inventory.armor.length; i++) {
        packets[i] = new PacketPlayOutEntityEquipment(getId(), i, getEquipment(i));
    }
    NMSImpl.sendPacketsNearby(getBukkitEntity(), current, packets);
}
Also used : Packet(net.minecraft.server.v1_8_R3.Packet) ItemStack(net.minecraft.server.v1_8_R3.ItemStack) PacketPlayOutEntityEquipment(net.minecraft.server.v1_8_R3.PacketPlayOutEntityEquipment) Location(org.bukkit.Location)

Example 92 with ItemStack

use of net.minecraft.server.v1_16_R1.ItemStack in project SSB-OneBlock by BG-Software-LLC.

the class NMSAdapter_v1_8_R3 method simulateToolBreak.

@Override
public void simulateToolBreak(Player bukkitPlayer, org.bukkit.block.Block bukkitBlock) {
    EntityPlayer entityPlayer = ((CraftPlayer) bukkitPlayer).getHandle();
    ItemStack itemStack = entityPlayer.bZ();
    WorldServer worldServer = ((CraftWorld) bukkitBlock.getWorld()).getHandle();
    BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
    IBlockData blockData = worldServer.getType(blockPosition);
    itemStack.a(worldServer, blockData.getBlock(), blockPosition, entityPlayer);
    if (itemStack.count == 0)
        entityPlayer.ca();
}
Also used : IBlockData(net.minecraft.server.v1_8_R3.IBlockData) BlockPosition(net.minecraft.server.v1_8_R3.BlockPosition) EntityPlayer(net.minecraft.server.v1_8_R3.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_8_R3.entity.CraftPlayer) WorldServer(net.minecraft.server.v1_8_R3.WorldServer) ItemStack(net.minecraft.server.v1_8_R3.ItemStack) CraftWorld(org.bukkit.craftbukkit.v1_8_R3.CraftWorld)

Example 93 with ItemStack

use of net.minecraft.server.v1_16_R1.ItemStack in project SSB-OneBlock by BG-Software-LLC.

the class NMSAdapter_v1_12_R1 method simulateToolBreak.

@Override
public void simulateToolBreak(Player bukkitPlayer, org.bukkit.block.Block bukkitBlock) {
    EntityPlayer entityPlayer = ((CraftPlayer) bukkitPlayer).getHandle();
    ItemStack itemStack = entityPlayer.getItemInMainHand();
    WorldServer worldServer = ((CraftWorld) bukkitBlock.getWorld()).getHandle();
    BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
    IBlockData blockData = worldServer.getType(blockPosition);
    assert itemStack != null;
    itemStack.a(worldServer, blockData, blockPosition, entityPlayer);
}
Also used : IBlockData(net.minecraft.server.v1_12_R1.IBlockData) BlockPosition(net.minecraft.server.v1_12_R1.BlockPosition) EntityPlayer(net.minecraft.server.v1_12_R1.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_12_R1.entity.CraftPlayer) WorldServer(net.minecraft.server.v1_12_R1.WorldServer) ItemStack(net.minecraft.server.v1_12_R1.ItemStack) CraftWorld(org.bukkit.craftbukkit.v1_12_R1.CraftWorld)

Example 94 with ItemStack

use of net.minecraft.server.v1_16_R1.ItemStack in project SSB-OneBlock by BG-Software-LLC.

the class NMSAdapter_v1_16_R3 method simulateToolBreak.

@Override
public void simulateToolBreak(Player bukkitPlayer, org.bukkit.block.Block bukkitBlock) {
    EntityPlayer entityPlayer = ((CraftPlayer) bukkitPlayer).getHandle();
    ItemStack itemStack = entityPlayer.getItemInMainHand();
    WorldServer worldServer = ((CraftWorld) bukkitBlock.getWorld()).getHandle();
    BlockPosition blockPosition = new BlockPosition(bukkitBlock.getX(), bukkitBlock.getY(), bukkitBlock.getZ());
    IBlockData blockData = worldServer.getType(blockPosition);
    assert itemStack != null;
    itemStack.a(worldServer, blockData, blockPosition, entityPlayer);
}
Also used : IBlockData(net.minecraft.server.v1_16_R3.IBlockData) BlockPosition(net.minecraft.server.v1_16_R3.BlockPosition) EntityPlayer(net.minecraft.server.v1_16_R3.EntityPlayer) CraftPlayer(org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer) WorldServer(net.minecraft.server.v1_16_R3.WorldServer) ItemStack(net.minecraft.server.v1_16_R3.ItemStack) CraftWorld(org.bukkit.craftbukkit.v1_16_R3.CraftWorld)

Example 95 with ItemStack

use of net.minecraft.server.v1_16_R1.ItemStack in project CitizensBooks by NicoNekoDev.

the class DistributionHandler method applyPlaceholders.

@SuppressWarnings({ "ConstantConditions", "unchecked" })
@Override
public ItemStack applyPlaceholders(Player player, ItemStack book, NPC npc) throws IllegalAccessException {
    Validate.notNull(book, "The ItemStack is null! This is not an error with CitizensBooks," + " so please don't report it. Make sure the plugins that uses CitizensBooks as dependency are correctly configured.");
    Validate.isTrue(book.getType() == Material.WRITTEN_BOOK, "The ItemStack is not a written book! This is not an error with CitizensBooks," + " so please don't report it. Make sure the plugins that uses CitizensBooks as dependency are correctly configured.");
    BookMeta bookMeta = (BookMeta) book.getItemMeta();
    List<String> pages = bookMeta.hasPages() ? super.papiReplaceStrList.apply(player, ((List<IChatBaseComponent>) this.pagesField.get(bookMeta)).stream().map(IChatBaseComponent.ChatSerializer::a).toList(), Optional.ofNullable(npc)) : new ArrayList<>();
    String author = bookMeta.hasAuthor() ? super.papiReplaceStr.apply(player, bookMeta.getAuthor(), Optional.ofNullable(npc)) : "Server";
    String title = bookMeta.hasTitle() ? super.papiReplaceStr.apply(player, bookMeta.getTitle(), Optional.ofNullable(npc)) : "Title";
    ItemStack newBook = new ItemStack(Material.WRITTEN_BOOK);
    bookMeta.setAuthor(author);
    bookMeta.setTitle(title);
    this.pagesField.set(bookMeta, pages.stream().map(IChatBaseComponent.ChatSerializer::a).toList());
    newBook.setItemMeta(bookMeta);
    return newBook;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) IChatBaseComponent(net.minecraft.server.v1_16_R1.IChatBaseComponent) ItemStack(org.bukkit.inventory.ItemStack) BookMeta(org.bukkit.inventory.meta.BookMeta)

Aggregations

CraftItemStack (org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack)30 ItemStack (net.minecraft.server.v1_12_R1.ItemStack)28 ItemStack (net.minecraft.server.v1_8_R3.ItemStack)27 InvocationTargetException (java.lang.reflect.InvocationTargetException)26 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)21 ItemStack (net.minecraft.server.v1_16_R3.ItemStack)20 Pair (com.mojang.datafixers.util.Pair)18 IconMenuItem (de.Keyle.MyPet.api.gui.IconMenuItem)18 net.minecraft.server.v1_16_R1 (net.minecraft.server.v1_16_R1)18 MyPetApi (de.Keyle.MyPet.MyPetApi)17 EntitySize (de.Keyle.MyPet.api.entity.EntitySize)17 MyPet (de.Keyle.MyPet.api.entity.MyPet)17 EntityMyPet (de.Keyle.MyPet.compat.v1_16_R1.entity.EntityMyPet)17 CraftItemStack (org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)17 Util (de.Keyle.MyPet.api.Util)16 EquipmentSlot (de.Keyle.MyPet.api.entity.EquipmentSlot)16 Arrays (java.util.Arrays)16 Bukkit (org.bukkit.Bukkit)16 CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)16 ENTITY_LIVING_broadcastItemBreak (de.Keyle.MyPet.compat.v1_16_R1.CompatManager.ENTITY_LIVING_broadcastItemBreak)14