/
EntityHeight.java
58 lines (49 loc) · 2.01 KB
/
EntityHeight.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package com.denizenscript.denizen.objects.properties.entity;
import com.denizenscript.denizen.objects.EntityTag;
import com.denizenscript.denizencore.objects.Mechanism;
import com.denizenscript.denizencore.objects.core.ElementTag;
import org.bukkit.entity.Display;
import org.bukkit.entity.Interaction;
public class EntityHeight extends EntityProperty<ElementTag> {
// <--[property]
// @object EntityTag
// @name height
// @input ElementTag(Decimal)
// @description
// For a display entity, this is the height of it's culling box. The box will span from the entity's y to the entity's y + the height.
// The default value for these is 0, which disables culling entirely.
// For an interaction entity, this is the height of it's bounding box (the area that can be interacted with).
// -->
public static boolean describes(EntityTag entity) {
return entity.getBukkitEntity() instanceof Display || entity.getBukkitEntity() instanceof Interaction;
}
@Override
public ElementTag getPropertyValue() {
if (getEntity() instanceof Display display) {
return new ElementTag(display.getDisplayHeight());
}
return new ElementTag(as(Interaction.class).getInteractionHeight());
}
@Override
public boolean isDefaultValue(ElementTag value) {
return value.asFloat() == (getEntity() instanceof Display ? 0f : 1f);
}
@Override
public void setPropertyValue(ElementTag value, Mechanism mechanism) {
if (!mechanism.requireFloat()) {
return;
}
if (getEntity() instanceof Display display) {
display.setDisplayHeight(value.asFloat());
return;
}
as(Interaction.class).setInteractionHeight(value.asFloat());
}
@Override
public String getPropertyId() {
return "height";
}
public static void register() {
autoRegister("height", EntityHeight.class, ElementTag.class, false);
}
}