24package com.dreamfirestudios.dreamcore.DreamBlockDisplay;
27import org.bukkit.block.data.BlockData;
28import org.bukkit.entity.BlockDisplay;
29import org.bukkit.entity.Display;
30import org.bukkit.util.Transformation;
31import org.joml.Vector3f;
33import java.util.function.Consumer;
61 private Location location;
62 private double itemScale = 1.0;
63 private Vector3f leftRotation =
new Vector3f(0f, 0f, 0f);
64 private float viewRange = 0.1f;
65 private float shadowRadius = 0.3f;
66 private float shadowStrength = 5f;
67 private float displayWidth = 50f;
68 private float displayHeight = 50f;
69 private Display.Billboard billboard = Display.Billboard.CENTER;
70 private Color itemGlowColor = Color.RED;
71 private Display.Brightness itemBrightness =
new Display.Brightness(15, 15);
72 private Consumer<Transformation> customTransformation;
79 this.world = Bukkit.getWorld(
"world");
80 if (this.world ==
null)
throw new IllegalStateException(
"Default world 'world' is not available.");
81 this.location = this.world.getSpawnLocation();
88 if (world ==
null)
throw new IllegalArgumentException(
"World cannot be null");
97 if (location ==
null)
throw new IllegalArgumentException(
"Location cannot be null");
98 this.location = location;
106 if (itemScale <= 0)
throw new IllegalArgumentException(
"Item scale must be greater than zero");
107 this.itemScale = itemScale;
115 if (leftRotation ==
null)
throw new IllegalArgumentException(
"Rotation vector cannot be null");
116 this.leftRotation = leftRotation;
124 if (customTransformation ==
null)
throw new IllegalArgumentException(
"Custom transformation cannot be null");
125 this.customTransformation = customTransformation;
133 if (viewRange < 0)
throw new IllegalArgumentException(
"View range must be non-negative");
134 this.viewRange = viewRange;
142 if (shadowRadius < 0)
throw new IllegalArgumentException(
"Shadow radius must be non-negative");
143 this.shadowRadius = shadowRadius;
151 if (shadowStrength < 0)
throw new IllegalArgumentException(
"Shadow strength must be non-negative");
152 this.shadowStrength = shadowStrength;
160 if (displayHeight <= 0)
throw new IllegalArgumentException(
"Display height must be greater than zero");
161 this.displayHeight = displayHeight;
169 if (displayWidth <= 0)
throw new IllegalArgumentException(
"Display width must be greater than zero");
170 this.displayWidth = displayWidth;
178 this.billboard = billboard;
186 if (itemGlowColor ==
null)
throw new IllegalArgumentException(
"Glow color cannot be null");
187 this.itemGlowColor = itemGlowColor;
195 if (itemBrightness ==
null)
throw new IllegalArgumentException(
"Brightness cannot be null");
196 this.itemBrightness = itemBrightness;
203 public BlockDisplay
spawn(Material material) {
204 if (material ==
null)
throw new IllegalArgumentException(
"Material cannot be null");
205 BlockData blockData = Bukkit.createBlockData(material);
206 return spawn(blockData);
212 public BlockDisplay
spawn(BlockData blockData) {
213 if (blockData ==
null)
throw new IllegalArgumentException(
"BlockData cannot be null");
214 BlockDisplay blockDisplay = world.spawn(location, BlockDisplay.class);
215 blockDisplay.setBlock(blockData);
216 return configureBlockDisplay(blockDisplay);
224 private BlockDisplay configureBlockDisplay(BlockDisplay blockDisplay) {
225 Transformation transformation = blockDisplay.getTransformation();
226 transformation.getScale().set((
float) itemScale);
227 transformation.getLeftRotation().x = leftRotation.x;
228 transformation.getLeftRotation().y = leftRotation.y;
229 transformation.getLeftRotation().z = leftRotation.z;
231 if (customTransformation !=
null) {
232 customTransformation.accept(transformation);
235 blockDisplay.setTransformation(transformation);
236 blockDisplay.setViewRange(viewRange);
237 blockDisplay.setShadowRadius(shadowRadius);
238 blockDisplay.setShadowStrength(shadowStrength);
239 blockDisplay.setDisplayHeight(displayHeight);
240 blockDisplay.setDisplayWidth(displayWidth);
241 blockDisplay.setBillboard(billboard);
242 blockDisplay.setGlowColorOverride(itemGlowColor);
243 blockDisplay.setBrightness(itemBrightness);
246 Bukkit.getPluginManager().callEvent(event);
Event triggered when a BlockDisplay entity is created.
Fluent builder for configuring and spawning BlockDisplay entities.
BlockDisplayBuilder itemGlowColor(Color itemGlowColor)
Sets glow color override for the display.
BlockDisplayBuilder displayHeight(float displayHeight)
Sets the logical display height.
BlockDisplayBuilder viewRange(float viewRange)
Sets the render view range.
BlockDisplayBuilder displayWidth(float displayWidth)
Sets the logical display width.
BlockDisplay spawn(Material material)
Spawns a BlockDisplay using a Material.
BlockDisplayBuilder billboard(Display.Billboard billboard)
Sets billboard mode.
BlockDisplayBuilder world(World world)
Sets the world for the display.
BlockDisplayBuilder location(Location location)
Sets the spawn location for the display.
BlockDisplayBuilder shadowRadius(float shadowRadius)
Sets the shadow radius.
BlockDisplayBuilder leftRotation(Vector3f leftRotation)
Sets the left rotation (applied in transformation matrix).
BlockDisplayBuilder itemBrightness(Display.Brightness itemBrightness)
Sets emissive brightness.
BlockDisplayBuilder customTransformation(Consumer< Transformation > customTransformation)
Provides a custom per-spawn transformation mutator.
BlockDisplayBuilder itemScale(double itemScale)
Sets a uniform item scale (applied to X/Y/Z).
BlockDisplayBuilder()
Initializes a builder using the default world "world" and its spawn location.
BlockDisplay spawn(BlockData blockData)
Spawns a BlockDisplay using a BlockData.
BlockDisplayBuilder shadowStrength(float shadowStrength)
Sets the shadow strength.
Utility wrapper for building and spawning BlockDisplay entities with a fluent API.