reformatted project
This commit is contained in:
@@ -15,47 +15,44 @@ public class InteractableEntity extends EntityCreature {
|
||||
|
||||
/**
|
||||
* Declares an Entity with direct callbacks on interaction
|
||||
*
|
||||
* @param entityType type of entity
|
||||
*/
|
||||
public InteractableEntity(@NotNull EntityType entityType) {
|
||||
super(entityType);
|
||||
|
||||
eventNode()
|
||||
.addListener(AddEntityToInstanceEvent.class, this::setInstanceEvent)
|
||||
|
||||
.addListener(AddEntityToInstanceEvent.class, this::onSpawn)
|
||||
.addListener(RemoveEntityFromInstanceEvent.class, this::onDespawn)
|
||||
.addListener(PlayerEntityInteractEvent.class, this::onInteract) //TODO Why are some of these listeners not working?
|
||||
|
||||
.addListener(EntityAttackEvent.class, this::onAttack);
|
||||
this.eventNode()
|
||||
.addListener(AddEntityToInstanceEvent.class, this::setInstanceEvent)
|
||||
.addListener(AddEntityToInstanceEvent.class, this::onSpawn)
|
||||
.addListener(RemoveEntityFromInstanceEvent.class, this::onDespawn)
|
||||
.addListener(PlayerEntityInteractEvent.class, this::onInteract)
|
||||
.addListener(EntityAttackEvent.class, this::onAttack);
|
||||
}
|
||||
|
||||
private void setInstanceEvent(@NotNull AddEntityToInstanceEvent addEntityToInstanceEvent) {
|
||||
if(addEntityToInstanceEvent.getInstance() instanceof Spawnable instance) {
|
||||
scheduleNextTick((unused) -> this.teleport(this.position.withPitch(180).withYaw(0)));
|
||||
if(addEntityToInstanceEvent.getInstance() instanceof Spawnable) {
|
||||
this.scheduleNextTick((unused) -> this.teleport(this.position.withPitch(180).withYaw(0)));
|
||||
}
|
||||
|
||||
addEntityToInstanceEvent.getInstance().eventNode()
|
||||
.addListener(PlayerMoveEvent.class, playerMoveEvent -> {
|
||||
//TODO might be expensive
|
||||
if(this.position.distance(playerMoveEvent.getNewPosition()) < 5)
|
||||
this.lookAt(playerMoveEvent.getPlayer());
|
||||
})
|
||||
.addListener(PlayerEntityInteractEvent.class, playerEntityInteractEvent -> {
|
||||
if(playerEntityInteractEvent.getTarget() == this) {
|
||||
onInteract(playerEntityInteractEvent);
|
||||
}
|
||||
})
|
||||
.addListener(EntityAttackEvent.class, entityAttackEvent -> {
|
||||
if(entityAttackEvent.getTarget() == this) {
|
||||
onAttack(entityAttackEvent);
|
||||
}
|
||||
});
|
||||
.addListener(PlayerMoveEvent.class, playerMoveEvent -> {
|
||||
if(this.position.distance(playerMoveEvent.getNewPosition()) < 5)
|
||||
this.lookAt(playerMoveEvent.getPlayer());
|
||||
})
|
||||
.addListener(PlayerEntityInteractEvent.class, playerEntityInteractEvent -> {
|
||||
if(playerEntityInteractEvent.getTarget() == this) {
|
||||
this.onInteract(playerEntityInteractEvent);
|
||||
}
|
||||
})
|
||||
.addListener(EntityAttackEvent.class, entityAttackEvent -> {
|
||||
if(entityAttackEvent.getTarget() == this) {
|
||||
this.onAttack(entityAttackEvent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when instance of entity is set
|
||||
* @param addEntityToInstanceEvent
|
||||
*/
|
||||
protected void onSpawn(@NotNull AddEntityToInstanceEvent addEntityToInstanceEvent) {
|
||||
|
||||
@@ -63,7 +60,6 @@ public class InteractableEntity extends EntityCreature {
|
||||
|
||||
/**
|
||||
* Called when instance of entity is unset
|
||||
* @param removeEntityFromInstanceEvent
|
||||
*/
|
||||
protected void onDespawn(@NotNull RemoveEntityFromInstanceEvent removeEntityFromInstanceEvent) {
|
||||
|
||||
@@ -71,7 +67,6 @@ public class InteractableEntity extends EntityCreature {
|
||||
|
||||
/**
|
||||
* Called when a Player interacts with the entity
|
||||
* @param playerEntityInteractEvent
|
||||
*/
|
||||
protected void onInteract(@NotNull PlayerEntityInteractEvent playerEntityInteractEvent) {
|
||||
|
||||
@@ -79,7 +74,6 @@ public class InteractableEntity extends EntityCreature {
|
||||
|
||||
/**
|
||||
* Called when a Player attacks the entity
|
||||
* @param entityAttackEvent
|
||||
*/
|
||||
protected void onAttack(@NotNull EntityAttackEvent entityAttackEvent) {
|
||||
|
||||
|
||||
Reference in New Issue
Block a user