Skip to content
This repository has been archived by the owner on Jun 21, 2024. It is now read-only.

Floating items

filoghost edited this page May 1, 2023 · 11 revisions

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);