21 Changing the lines
filoghost edited this page 2022-06-04 19:12:02 +02:00

"hologram" is a Hologram object we've already created (read the basic tutorial if you haven't yet).

Let's start by adding five lines to the hologram:

for (int i = 1; i <= 5; i++) {
	hologram.getLines().appendText(Integer.toString(i));
}

Let's insert a bedrock block before the first line, then change it to grass:

ItemLine itemLine = hologram.getLines().insertItem(0, new ItemStack(Material.BEDROCK));
itemLine.setItemStack(new ItemStack(Material.GRASS));

This is how our hologram looks like now:

Modified hologram

We want to change the last line with a sponge now:

hologram.getLines().remove(hologram.size() - 1); // Remember how arrays work, it's the same here
hologram.getLines().appendItem(new ItemStack(Material.SPONGE));

Result:

Final result

Use the javadocs to see all the methods. These are just some basic ones.

Notes:

  • Indexes start from 0, as in normal arrays.
  • if you specify an invalid index, an ArrayOutOfBoundsException will be raised.