55import org .broken .arrow .library .itemcreator .meta .map .color .parser .ColorParser ;
66import org .broken .arrow .library .itemcreator .meta .map .cursor .MapCursorAdapter ;
77import org .broken .arrow .library .itemcreator .meta .map .cursor .MapCursorWrapper ;
8- import org .broken .arrow .library .itemcreator .meta .map .font .customdraw .MapTextRenderer ;
98import org .broken .arrow .library .itemcreator .meta .map .font .customdraw .RenderState ;
109import org .broken .arrow .library .itemcreator .meta .map .pixel .ImageOverlay ;
1110import org .broken .arrow .library .itemcreator .meta .map .pixel .MapPixel ;
2221import java .util .List ;
2322import java .util .Map ;
2423import java .util .Objects ;
24+ import java .util .function .Supplier ;
2525import java .util .stream .Collectors ;
2626
2727/**
@@ -41,11 +41,14 @@ public class MapRendererData {
4141 private static int id ;
4242 private final int mapRenderId ;
4343 private final MapRenderer mapRenderer ;
44- private MapCursorAdapter mapCursors = new MapCursorAdapter ();
4544 private final List <MapPixel > pixels = new ArrayList <>();
45+ private MapCursorAdapter mapCursors = new MapCursorAdapter ();
46+
4647 private MapRenderHandler dynamicRenderer ;
48+
4749 private char [] fontChars = Characters .getFontCharsArray ();
4850 private ColorParser colorParser = new AmpersandHexColorParser ();
51+ private boolean contextual ;
4952
5053 /**
5154 * Constructs a new MapRendererData instance with no associated {@link MapRenderer}.
@@ -75,6 +78,7 @@ public void setDynamicRenderer(MapRenderHandler handler) {
7578 this .dynamicRenderer = handler ;
7679 }
7780
81+
7882 /**
7983 * Adds a colored pixel overlay to the map at the specified coordinates.
8084 *
@@ -103,7 +107,7 @@ public void addPixel(@Nonnull final MapColoredPixel mapColoredPixel) {
103107 * @param text The text to display.
104108 * @return returns the newly created text overlay, so you could set some of the options after.
105109 */
106- public TextOverlay addText (final int x , int y , final String text ) {
110+ public TextOverlay addText (final int x , int y ,@ Nonnull final String text ) {
107111 return this .addText (x , y , text , null , null );
108112 }
109113
@@ -117,7 +121,7 @@ public TextOverlay addText(final int x, int y, final String text) {
117121 * @param font The font for the character.
118122 * @return returns the newly created text overlay, so you could set some of the options after.
119123 */
120- public TextOverlay addText (final int x , int y , final String text , @ Nullable final Font font ) {
124+ public TextOverlay addText (final int x , int y ,@ Nonnull final String text , @ Nullable final Font font ) {
121125 return this .addText (x , y , text , null , font );
122126 }
123127
@@ -240,6 +244,52 @@ public MapCursorWrapper addCursor(@Nonnull final MapCursorWrapper cursorWrapper)
240244 return cursorWrapper ;
241245 }
242246
247+ /**
248+ * Adds a collection of map overlays (pixels, text, or images) to this renderer.
249+ * <p>
250+ * This method appends the provided overlays to the existing pixel list
251+ * without clearing previous entries. It can be used to add multiple
252+ * overlay types at once or to batch-apply preprocessed render data.
253+ * </p>
254+ *
255+ * <p><strong>Note:</strong> For most use cases, prefer the more specific
256+ * methods such as {@link #addPixel(int, int, Color)},{@link #addText(int, int, String)}
257+ * or {@link #addImage(int, int, Image)} for clarity.</p>
258+ *
259+ * @param mapPixels the list of {@link MapPixel} instances to add
260+ */
261+ public void addAll (List <MapPixel > mapPixels ) {
262+ this .pixels .addAll (mapPixels );
263+ }
264+
265+ /**
266+ * Clear the list of set pixels.
267+ */
268+ public void clear () {
269+ this .pixels .clear ();
270+ }
271+
272+ /**
273+ * Set whether the renderer is contextual, i.e. has different canvases for
274+ * different players.
275+ *
276+ * @param contextual Whether the renderer is contextual. See {@link
277+ * #isContextual()}.
278+ */
279+ public void setContextual (boolean contextual ) {
280+ this .contextual = contextual ;
281+ }
282+
283+ /**
284+ * Get whether the renderer is contextual, i.e. has different canvases for
285+ * different players.
286+ *
287+ * @return True if contextual, false otherwise.
288+ */
289+ public final boolean isContextual () {
290+ return contextual ;
291+ }
292+
243293 /**
244294 * Returns the unique ID assigned to this map renderer data instance.
245295 *
@@ -277,20 +327,20 @@ public MapRenderer getMapRenderer() {
277327 if (this .mapRenderer != null ) {
278328 return mapRenderer ;
279329 }
280- return new MapRenderer () {
330+ return new MapRenderer (this . contextual ) {
281331 @ Override
282332 public void render (@ Nonnull MapView map , @ Nonnull MapCanvas canvas , @ Nonnull Player player ) {
283333 if (dynamicRenderer != null && dynamicRenderer .render (map , canvas , player ))
284334 return ;
285335 canvas .setCursors (mapCursors .getMapCursorCollection ());
336+
286337 if (!getPixels ().isEmpty ()) {
287338 setPixels (canvas );
288339 }
289340 }
290341 };
291342 }
292343
293-
294344 @ Override
295345 public boolean equals (Object o ) {
296346 if (o == null || getClass () != o .getClass ()) return false ;
@@ -365,4 +415,5 @@ private void setPixels(@Nonnull final MapCanvas canvas) {
365415 getPixels ().forEach (mapPixel -> mapPixel .render (this , canvas ));
366416 }
367417
418+
368419}
0 commit comments