Working Restrictions

This commit is contained in:
2022-10-01 16:58:27 +02:00
parent b5468b1fe9
commit 4bdb3f94d5
20 changed files with 244 additions and 46 deletions

View File

@ -1,6 +1,7 @@
package eu.mhsl.minenet.minigames.shared.entity;
import eu.mhsl.minenet.minigames.instance.Spawnable;
import net.minestom.server.coordinate.Pos;
import net.minestom.server.entity.EntityCreature;
import net.minestom.server.entity.EntityType;
import net.minestom.server.entity.Player;
@ -36,26 +37,22 @@ public class InteractableEntity extends EntityCreature {
private void setInstanceEvent(@NotNull AddEntityToInstanceEvent addEntityToInstanceEvent) {
if(addEntityToInstanceEvent.getInstance() instanceof Spawnable instance) {
scheduleNextTick((unused) -> {
this.lookAt(instance.getSpawn()); //TODO only works someitmes?
this.teleport(this.position.withPitch(180).withYaw(0));
});
}
addEntityToInstanceEvent.getInstance().eventNode()
.addListener(PlayerEntityInteractEvent.class, playerEntityInteractEvent -> {
if(playerEntityInteractEvent.getTarget() == this) onInteract(playerEntityInteractEvent);
if(playerEntityInteractEvent.getTarget() == this) {
onInteract(playerEntityInteractEvent);
this.lookAt(playerEntityInteractEvent.getPlayer());
}
})
.addListener(EntityAttackEvent.class, entityAttackEvent -> {
if(entityAttackEvent.getTarget() == this) onAttack(entityAttackEvent);
})
.addListener(PlayerMoveEvent.class, playerMoveEvent -> {
//TODO this is heavy in production
//maybe store the player and update to the closest Entity only periodic
scheduler().submitTask(() -> {
setTarget(new ClosestEntityTarget(this, 5, entity -> entity instanceof Player).findTarget());
if(getTarget() != null) lookAt(getTarget());
return TaskSchedule.stop();
}, ExecutionType.ASYNC);
if(entityAttackEvent.getTarget() == this) {
onAttack(entityAttackEvent);
this.lookAt(entityAttackEvent.getEntity());
}
});
}