Sponge.Holograms - Year4000/Utilities GitHub Wiki

This hologram system allows for developers to create holograms with out the hassle of handling the entities manually. Our system uses a technique used in video chips to display the frames. The FrameBuffer is used to create the display then sends out the frame all at once so there is little to no flickering of the hologram.

Get the service

Packets uses Sponge's Service Manager to provide a simple interface to interact with.

Note - The all services from Utilities are registered during GamePreInitializationEvent.

Holograms holograms = Sponge.getServiceManager()
    .provide(Holograms.class)
    .orElseThrow(RuntimeException::new);

Creating a hologram

You can create a hologram from two ways, using generic Text object or from an ImageInputStream. If the image input stream is of an animated gif the hologram will animate. The location will be in the center of the location, so if there will be 8 lines the center will be at line 4. The Hologram reference that is returned from the add is used for the Holograms.

Note - Images must match the Minecraft text color plate.

Note - Animated holograms will keep the reference of the Hologram as long as the viewers of the hologram are still online.

Player player = ...;
Location<World> location = ...;
Text lineOne = Text.of("First line");
Text lineTwo = Text.of("Second line");
// Text hologram
{
    Hologram hologram = holograms.add(player, location, lineOne, lineTwo);
}

// Picture hologram
try {
    File file = new File("location/to/image");
    ImageInputStream stream = ImageIO.createImageInputStream(file)
    Hologram hologram = holograms.add(player, location, stream);
} catch (IOException error) {
    // Image failed to load
}

Removing a hologram

To remove a hologram you must have the reference of Hologram when adding a hologram through Holograms.

Player player = ...;
Hologram hologram = ...;
holograms.remove(player, hologram);

Sending a already created hologram

You can send a hologram that was already created to other players as long as you have the reference of Hologram when adding a hologram through Holograms.

Player player = ...;
Hologram hologram = ...;
holograms.send(player, hologram);
⚠️ **GitHub.com Fallback** ⚠️