|
| 1 | +# Holograms |
| 2 | + |
| 3 | +Caramel holograms are lightweight wrappers around Minecraft `TextDisplay` entities, designed for easy multi-line floating text. |
| 4 | +They use holograms |
| 5 | + |
| 6 | +--- |
| 7 | + |
| 8 | +## Creating a hologram |
| 9 | + |
| 10 | +You can create a hologram either empty, or pre-filled with lines. |
| 11 | + |
| 12 | +```java |
| 13 | +// Empty hologram as a base |
| 14 | +CaramelHologram hologram = new CaramelHologram(); |
| 15 | + |
| 16 | +// Hologram with initial lines |
| 17 | +CaramelHologram hologram = new CaramelHologram(List.of( |
| 18 | + new CaramelHologramLine(CaramelUtility.colorcomp("Hello")), |
| 19 | + new CaramelHologramLine(CaramelUtility.colorcomp("World")) |
| 20 | +)); |
| 21 | +```` |
| 22 | + |
| 23 | +Before spawning, you **must** set a location: |
| 24 | + |
| 25 | +```java |
| 26 | +hologram.setLocation(location); |
| 27 | +``` |
| 28 | + |
| 29 | +--- |
| 30 | + |
| 31 | +<br/><br/> |
| 32 | + |
| 33 | +## Managing lines |
| 34 | + |
| 35 | +You can fully control the hologram’s lines after creation. |
| 36 | + |
| 37 | +```java |
| 38 | +hologram.addLine(new CaramelHologramLine(Component.text("New Line"))); |
| 39 | +hologram.addFront(new CaramelHologramLine(Component.text("Top Line"))); |
| 40 | +hologram.addBack(new CaramelHologramLine(Component.text("Bottom Line"))); |
| 41 | +``` |
| 42 | + |
| 43 | +Removing lines: |
| 44 | + |
| 45 | +```java |
| 46 | +hologram.removeLine(0); // via index |
| 47 | +hologram.removeLine(line); // via direct line object |
| 48 | +hologram.clear(); // removes all lines, keeps it spawned if it is |
| 49 | +``` |
| 50 | + |
| 51 | +Replacing all lines: |
| 52 | + |
| 53 | +```java |
| 54 | +hologram.setLines(List.of( |
| 55 | + new CaramelHologramLine(Component.text("Replaced")) |
| 56 | +)); |
| 57 | +``` |
| 58 | + |
| 59 | +Retrieving lines: |
| 60 | + |
| 61 | +```java |
| 62 | +List<CaramelHologramLine> lines = hologram.getLines(); |
| 63 | +``` |
| 64 | + |
| 65 | +--- |
| 66 | + |
| 67 | +<br/><br/> |
| 68 | + |
| 69 | +## Line spacing |
| 70 | + |
| 71 | +Line spacing is controlled via `lineHeight`. |
| 72 | + |
| 73 | +```java |
| 74 | +hologram.setLineHeight(0.25); |
| 75 | +double spacing = hologram.getLineHeight(); |
| 76 | +``` |
| 77 | + |
| 78 | +Values are in **world units (blocks)**, not pixels. |
| 79 | +Typical values range from `0.22` to `0.30`. |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +<br/><br/> |
| 84 | + |
| 85 | +## Showing and hiding |
| 86 | + |
| 87 | +Once configured, the hologram can be shown or hidden without despawning: |
| 88 | + |
| 89 | +```java |
| 90 | +hologram.show(); |
| 91 | +hologram.hide(); |
| 92 | +``` |
| 93 | + |
| 94 | +* `show()` spawns the hologram if needed and makes it visible |
| 95 | +* `hide()` visually hides it without removing entities |
| 96 | + |
| 97 | +--- |
| 98 | + |
| 99 | +<br/><br/> |
| 100 | + |
| 101 | +## Updating holograms |
| 102 | + |
| 103 | +If line content or formatting changes, call `update()` to reapply settings: |
| 104 | + |
| 105 | +```java |
| 106 | +hologram.update(); |
| 107 | +``` |
| 108 | + |
| 109 | +This reapplies all `CaramelHologramLine` settings to their backing `TextDisplay` entities. |
| 110 | + |
| 111 | +--- |
| 112 | + |
| 113 | +<br/><br/> |
| 114 | + |
| 115 | +## Destroying holograms |
| 116 | + |
| 117 | +To fully remove the hologram and clean up entities: |
| 118 | + |
| 119 | +```java |
| 120 | +hologram.destroy(); |
| 121 | +``` |
| 122 | + |
| 123 | +This removes all spawned `TextDisplay` entities and clears internal state. |
| 124 | + |
| 125 | +--- |
| 126 | + |
| 127 | +<br/><br/> |
| 128 | + |
| 129 | +## Accessing entities |
| 130 | + |
| 131 | +If you need direct access to the underlying displays: |
| 132 | + |
| 133 | +```java |
| 134 | +List<TextDisplay> entities = hologram.getEntities(); |
| 135 | +``` |
| 136 | + |
| 137 | +This can be useful for advanced effects or debugging. |
| 138 | + |
| 139 | +--- |
| 140 | + |
| 141 | +<br/><br/> |
| 142 | + |
| 143 | +## Summary |
| 144 | + |
| 145 | +Typical usage flow: |
| 146 | + |
| 147 | +```java |
| 148 | +CaramelHologram hologram = new CaramelHologram(); |
| 149 | +hologram.setLocation(location); |
| 150 | + |
| 151 | +hologram.addLine(new CaramelHologramLine(Component.text("Line 1"))); |
| 152 | +hologram.addLine(new CaramelHologramLine(Component.text("Line 2"))); |
| 153 | + |
| 154 | +hologram.setLineHeight(0.25); |
| 155 | +hologram.show(); |
| 156 | +``` |
| 157 | + |
| 158 | +That’s all you need for clean, stable holograms. |
| 159 | + |
| 160 | +``` |
0 commit comments