-
Notifications
You must be signed in to change notification settings - Fork 6
/
EntityStartsStopsRenderingScriptEvent.java
62 lines (53 loc) · 1.95 KB
/
EntityStartsStopsRenderingScriptEvent.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
59
60
61
62
package com.denizenscript.clientizen.events;
import com.denizenscript.clientizen.objects.EntityTag;
import com.denizenscript.denizencore.events.ScriptEvent;
import com.denizenscript.denizencore.objects.ObjectTag;
import com.denizenscript.denizencore.objects.core.ElementTag;
import net.minecraft.entity.Entity;
public class EntityStartsStopsRenderingScriptEvent extends ScriptEvent {
// <--[event]
// @Events
// <entity> starts|stops rendering
//
// @Triggers when an entity is rendered by the client. This does not mean the entity will always be visible, but within the camera's viewing frustum.
//
// @Context
// <context.entity> returns an EntityTag of the entity being rendered.
// <context.rendering> returns an ElementTag(Boolean) of whether the entity is being rendered.
//
// @Warning This event may fire very rapidly when the client's camera moves around a lot.
// -->
public static EntityStartsStopsRenderingScriptEvent instance;
public EntityTag entity;
public boolean rendering;
public EntityStartsStopsRenderingScriptEvent() {
registerCouldMatcher("<entity> starts|stops rendering");
instance = this;
}
@Override
public boolean matches(ScriptPath path) {
if (!path.tryArgObject(0, entity)) {
return false;
}
if (rendering != path.eventArgLowerAt(1).equals("starts")) {
return false;
}
return super.matches(path);
}
@Override
public ObjectTag getContext(String name) {
return switch (name) {
case "entity" -> entity;
case "rendering" -> new ElementTag(rendering);
default -> super.getContext(name);
};
}
public void handleEntityRendered(Entity entity, boolean rendering) {
if (!eventData.isEnabled) {
return;
}
this.entity = new EntityTag(entity);
this.rendering = rendering;
fire();
}
}