diff --git a/src/main/java/net/minestom/server/entity/Entity.java b/src/main/java/net/minestom/server/entity/Entity.java
index 0ac56c6be..3a6bd4a2e 100644
--- a/src/main/java/net/minestom/server/entity/Entity.java
+++ b/src/main/java/net/minestom/server/entity/Entity.java
@@ -82,7 +82,8 @@ import java.util.function.UnaryOperator;
*
* To create your own entity you probably want to extends {@link LivingEntity} or {@link EntityCreature} instead.
*/
-public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, EventHandler, Taggable, PermissionHandler, HoverEventSource, Sound.Emitter {
+public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, EventHandler, Taggable,
+ PermissionHandler, HoverEventSource, Sound.Emitter {
private static final Int2ObjectSyncMap ENTITY_BY_ID = Int2ObjectSyncMap.hashmap();
private static final Map ENTITY_BY_UUID = new ConcurrentHashMap<>();
@@ -1618,7 +1619,7 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
/**
* Raycasts current entity's eye position to target eye position.
*
- * @param entity the entity to be checked.
+ * @param entity the entity to be checked.
* @param exactView if set to TRUE, checks whether target is IN the line of sight of the current one;
* otherwise checks if the current entity can rotate so that target will be in its line of sight.
* @return true if the ray reaches the target bounding box before hitting a block.
@@ -1639,9 +1640,9 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
}
/**
- * @see Entity#hasLineOfSight(Entity, boolean)
* @param entity the entity to be checked.
* @return if the current entity has line of sight to the given one.
+ * @see Entity#hasLineOfSight(Entity, boolean)
*/
public boolean hasLineOfSight(Entity entity) {
return hasLineOfSight(entity, false);
@@ -1650,7 +1651,7 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
/**
* Gets first entity on the line of sight of the current one that matches the given predicate.
*
- * @param range max length of the line of sight of the current entity to be checked.
+ * @param range max length of the line of sight of the current entity to be checked.
* @param predicate optional predicate
* @return resulting entity whether there're any, null otherwise.
*/
@@ -1666,7 +1667,7 @@ public class Entity implements Viewable, Tickable, Schedulable, Snapshotable, Ev
&& e.boundingBox.boundingBoxRayIntersectionCheck(startAsVec, position.direction(), e.getPosition())
&& predicate.test(e)
&& CollisionUtils.isLineOfSightReachingShape(instance, currentChunk, start,
- e.position.withY(e.position.y() + e.getEyeHeight()), e.boundingBox);
+ e.position.withY(e.position.y() + e.getEyeHeight()), e.boundingBox);
Optional nearby = instance.getNearbyEntities(position, range).stream()
.filter(finalPredicate)
diff --git a/src/main/java/net/minestom/server/instance/Instance.java b/src/main/java/net/minestom/server/instance/Instance.java
index e842377cd..798a49837 100644
--- a/src/main/java/net/minestom/server/instance/Instance.java
+++ b/src/main/java/net/minestom/server/instance/Instance.java
@@ -4,6 +4,7 @@ import it.unimi.dsi.fastutil.objects.ObjectArraySet;
import net.kyori.adventure.identity.Identity;
import net.kyori.adventure.pointer.Pointers;
import net.minestom.server.MinecraftServer;
+import net.minestom.server.ServerProcess;
import net.minestom.server.Tickable;
import net.minestom.server.adventure.audience.PacketGroupingAudience;
import net.minestom.server.coordinate.Point;
@@ -13,7 +14,11 @@ import net.minestom.server.entity.ExperienceOrb;
import net.minestom.server.entity.Player;
import net.minestom.server.entity.pathfinding.PFInstanceSpace;
import net.minestom.server.event.EventDispatcher;
+import net.minestom.server.event.EventFilter;
+import net.minestom.server.event.EventHandler;
+import net.minestom.server.event.EventNode;
import net.minestom.server.event.instance.InstanceTickEvent;
+import net.minestom.server.event.trait.InstanceEvent;
import net.minestom.server.instance.block.Block;
import net.minestom.server.instance.block.BlockHandler;
import net.minestom.server.instance.generator.Generator;
@@ -58,7 +63,8 @@ import java.util.stream.Collectors;
* with {@link InstanceManager#registerInstance(Instance)}, and
* you need to be sure to signal the {@link ThreadDispatcher} of every partition/element changes.
*/
-public abstract class Instance implements Block.Getter, Block.Setter, Tickable, Schedulable, Snapshotable, Taggable, PacketGroupingAudience {
+public abstract class Instance implements Block.Getter, Block.Setter,
+ Tickable, Schedulable, Snapshotable, EventHandler, Taggable, PacketGroupingAudience {
private boolean registered;
@@ -87,8 +93,8 @@ public abstract class Instance implements Block.Getter, Block.Setter, Tickable,
// instance custom data
private final TagHandler tagHandler = TagHandler.newHandler();
-
private final Scheduler scheduler = Scheduler.newScheduler();
+ private final EventNode eventNode;
// the explosion supplier
private ExplosionSupplier explosionSupplier;
@@ -116,6 +122,14 @@ public abstract class Instance implements Block.Getter, Block.Setter, Tickable,
this.pointers = Pointers.builder()
.withDynamic(Identity.UUID, this::getUniqueId)
.build();
+
+ final ServerProcess process = MinecraftServer.process();
+ if (process != null) {
+ this.eventNode = process.eventHandler().map(this, EventFilter.INSTANCE);
+ } else {
+ // Local nodes require a server process
+ this.eventNode = null;
+ }
}
/**
@@ -617,6 +631,12 @@ public abstract class Instance implements Block.Getter, Block.Setter, Tickable,
return scheduler;
}
+ @Override
+ @ApiStatus.Experimental
+ public @NotNull EventNode eventNode() {
+ return eventNode;
+ }
+
@Override
public @NotNull InstanceSnapshot updateSnapshot(@NotNull SnapshotUpdater updater) {
final Map> chunksMap = updater.referencesMapLong(getChunks(), ChunkUtils::getChunkIndex);