24package com.dreamfirestudios.dreamcore.DreamItemDisplay;
26import org.bukkit.Bukkit;
27import org.bukkit.Color;
28import org.bukkit.Location;
29import org.bukkit.Material;
30import org.bukkit.World;
31import org.bukkit.entity.Display;
32import org.bukkit.entity.ItemDisplay;
33import org.bukkit.inventory.ItemStack;
34import org.bukkit.util.Transformation;
35import org.joml.Quaternionf;
36import org.joml.Vector3f;
75 private World world = Bukkit.getWorlds().isEmpty() ? null : Bukkit.getWorlds().get(0);
76 private Location location = (world ==
null) ?
null : world.getSpawnLocation();
78 private float uniformScale = 1.0f;
79 private Vector3f scale =
null;
80 private Quaternionf leftRotation =
new Quaternionf();
81 private Quaternionf rightRotation =
new Quaternionf();
82 private Vector3f translation =
new Vector3f(0f, 0f, 0f);
86 private float viewRange = 16.0f;
89 private float shadowRadius = 0.3f;
92 private float shadowStrength = 0.5f;
95 private float displayWidth = 1f;
98 private float displayHeight = 1f;
100 private Display.Billboard billboard = Display.Billboard.CENTER;
101 private Color itemGlowColor =
null;
102 private Display.Brightness itemBrightness =
null;
116 if (world ==
null)
throw new IllegalArgumentException(
"World cannot be null");
118 if (this.location ==
null) this.location = world.getSpawnLocation();
133 if (location ==
null)
throw new IllegalArgumentException(
"Location cannot be null");
134 this.location = location;
135 if (location.getWorld() !=
null) this.world = location.getWorld();
149 if (translation ==
null)
throw new IllegalArgumentException(
"translation cannot be null");
150 this.translation =
new Vector3f(translation);
166 if (uniform <= 0f)
throw new IllegalArgumentException(
"Scale must be > 0");
167 this.uniformScale = uniform;
182 if (scale ==
null)
throw new IllegalArgumentException(
"scale cannot be null");
183 if (scale.x <= 0f || scale.y <= 0f || scale.z <= 0f)
184 throw new IllegalArgumentException(
"scale components must be > 0");
185 this.scale =
new Vector3f(scale);
202 if (q ==
null)
throw new IllegalArgumentException(
"leftRotation cannot be null");
203 this.leftRotation =
new Quaternionf(q);
217 if (q ==
null)
throw new IllegalArgumentException(
"rightRotation cannot be null");
218 this.rightRotation =
new Quaternionf(q);
236 final float yaw = (float) Math.toRadians(yawDeg);
237 final float pitch = (float) Math.toRadians(pitchDeg);
238 final float roll = (float) Math.toRadians(rollDeg);
240 this.leftRotation =
new Quaternionf()
259 if (viewRange < 0f)
throw new IllegalArgumentException(
"viewRange must be >= 0");
260 this.viewRange = viewRange;
271 if (shadowRadius < 0f)
throw new IllegalArgumentException(
"shadowRadius must be >= 0");
272 this.shadowRadius = shadowRadius;
282 this.shadowStrength = shadowStrength;
293 if (displayHeight <= 0f)
throw new IllegalArgumentException(
"displayHeight must be > 0");
294 this.displayHeight = displayHeight;
305 if (displayWidth <= 0f)
throw new IllegalArgumentException(
"displayWidth must be > 0");
306 this.displayWidth = displayWidth;
319 this.billboard = (billboard ==
null) ? Display.Billboard.CENTER : billboard;
329 this.itemGlowColor = color;
360 public ItemDisplay
spawn(ItemStack itemStack) {
361 if (itemStack ==
null || itemStack.getType() == Material.AIR)
362 throw new IllegalArgumentException(
"ItemStack cannot be null or AIR");
364 throw new IllegalStateException(
"No world available to spawn ItemDisplay");
365 if (location ==
null)
366 location = world.getSpawnLocation();
368 final ItemDisplay display = world.spawn(location, ItemDisplay.class);
369 display.setItemStack(itemStack);
372 final Vector3f sc = (scale !=
null) ?
new Vector3f(scale) :
new Vector3f(uniformScale);
373 final Transformation tf =
new Transformation(
374 new Vector3f(translation),
375 new Quaternionf(leftRotation),
377 new Quaternionf(rightRotation)
379 display.setTransformation(tf);
382 display.setViewRange(Math.max(0f, viewRange));
383 display.setShadowRadius(Math.max(0f, shadowRadius));
384 display.setShadowStrength(Math.max(0f, Math.min(1f, shadowStrength)));
385 display.setDisplayWidth(Math.max(0.0001f, displayWidth));
386 display.setDisplayHeight(Math.max(0.0001f, displayHeight));
387 display.setBillboard(billboard);
389 if (itemGlowColor !=
null) display.setGlowColorOverride(itemGlowColor);
390 if (itemBrightness !=
null) display.setBrightness(itemBrightness);
Builder for a single ItemDisplay instance.
ItemDisplayBuilder rightRotation(Quaternionf q)
Sets the right rotation quaternion.
ItemDisplayBuilder billboard(Display.Billboard billboard)
Sets the billboard mode for the display.
ItemDisplayBuilder shadowRadius(float shadowRadius)
Sets the display's shadow radius.
ItemDisplayBuilder world(World world)
Sets the world where the display will be spawned.
ItemDisplayBuilder displayWidth(float displayWidth)
Sets the display width (world units).
ItemDisplayBuilder displayHeight(float displayHeight)
Sets the display height (world units).
ItemDisplayBuilder brightness(Display.Brightness brightness)
Sets the display brightness override (or clears if null).
ItemDisplayBuilder scale(Vector3f scale)
Sets a non-uniform scale vector.
ItemDisplayBuilder glowColor(Color color)
Sets the glow color override (or clears it if null).
ItemDisplay spawn(ItemStack itemStack)
Spawns the ItemDisplay with the configured properties.
ItemDisplayBuilder shadowStrength(float shadowStrength)
Sets the display's shadow strength.
ItemDisplayBuilder leftRotation(Quaternionf q)
Sets the left rotation quaternion.
ItemDisplayBuilder viewRange(float viewRange)
Sets the render distance in blocks (>= 0).
ItemDisplayBuilder scale(float uniform)
Sets a uniform scale (x=y=z).
ItemDisplayBuilder translation(Vector3f translation)
Applies a local translation (pre-rotation) in the display's local space.
ItemDisplayBuilder eulerDegrees(float yawDeg, float pitchDeg, float rollDeg)
Convenience method to set the left rotation using Euler angles in degrees.
ItemDisplayBuilder location(Location location)
Sets the spawn location (must be in the same world as world(World)).
Fluent builder utilities for spawning configured ItemDisplay entities.
Event fired immediately after an ItemDisplay is spawned and configured by DreamItemDisplay....