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);
}
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();
}
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);
}
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);
}
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;
}
Aggregations