11 Floating items
filoghost edited this page 2023-05-01 14:04:38 +02:00

You can create floating items in the same way you create text lines, by using the method Hologram.getLines().appendItem(...).  

Example

A floating melon block created above a player's head, 5 seconds later the melon block turns into a melon slice.

Location loc = player.getLocation().add(0.0, 2.0, 0.0);
ItemStack itemStack = new ItemStack(Material.MELON_BLOCK);
HolographicDisplaysAPI api = HolographicDisplaysAPI.get(plugin);
final Hologram hologram = api.createHologram(loc);
ItemHologramLine itemLine = hologram.getLines().appendItem(itemStack);


Bukkit.getScheduler().runTaskLater(plugin, () -> {
	itemLine.setItemStack(new ItemStack(Material.MELON));
}, 5 * 20);