use of org.lanternpowered.server.entity.living.player.LanternPlayer in project LanternServer by LanternPowered.
the class EnderChestInteractionBehavior method tryInteract.
@Override
public BehaviorResult tryInteract(BehaviorPipeline<Behavior> pipeline, BehaviorContext context) {
final LanternPlayer player = (LanternPlayer) context.getContext(ContextKeys.PLAYER).orElse(null);
if (player == null) {
return BehaviorResult.CONTINUE;
}
final List<Runnable> tasks = new ArrayList<>();
if (!ChestInteractionBehavior.validateOpenableChestSpace(context, context.requireContext(ContextKeys.BLOCK_LOCATION), tasks)) {
return BehaviorResult.CONTINUE;
}
final Location<World> location = context.requireContext(ContextKeys.INTERACTION_LOCATION);
final AbstractInventory inventory = player.getEnderChestInventory();
final Optional<TileEntity> optTileEntity = location.getTileEntity();
if (optTileEntity.isPresent() && optTileEntity.get() instanceof InventoryViewerListener) {
inventory.addViewListener((InventoryViewerListener) optTileEntity.get());
}
if (!player.openInventory(inventory).isPresent()) {
tasks.forEach(Runnable::run);
return BehaviorResult.CONTINUE;
}
return BehaviorResult.SUCCESS;
}
use of org.lanternpowered.server.entity.living.player.LanternPlayer in project LanternServer by LanternPowered.
the class HorizontalRotationPlacementBehavior method tryPlace.
@Override
public BehaviorResult tryPlace(BehaviorPipeline<Behavior> pipeline, BehaviorContext context) {
final LanternPlayer player = (LanternPlayer) context.getContext(ContextKeys.PLAYER).orElse(null);
// Get the direction the chest should face
final Direction facing;
if (player != null) {
facing = player.getHorizontalDirection(Direction.Division.CARDINAL).getOpposite();
} else {
facing = Direction.NORTH;
}
context.transformBlockChanges((snapshot, builder) -> builder.add(Keys.DIRECTION, facing));
return BehaviorResult.CONTINUE;
}
use of org.lanternpowered.server.entity.living.player.LanternPlayer in project LanternServer by LanternPowered.
the class RotationPlacementBehavior method tryPlace.
@Override
public BehaviorResult tryPlace(BehaviorPipeline<Behavior> pipeline, BehaviorContext context) {
final LanternPlayer player = (LanternPlayer) context.getContext(ContextKeys.PLAYER).orElse(null);
// Get the direction the chest should face
final Direction facing;
if (player != null) {
if (player.getPosition().getY() - context.requireContext(ContextKeys.BLOCK_LOCATION).getBlockPosition().getY() >= 0.5) {
facing = player.getDirection(Direction.Division.CARDINAL).getOpposite();
} else {
facing = player.getHorizontalDirection(Direction.Division.CARDINAL).getOpposite();
}
} else {
facing = Direction.NORTH;
}
context.transformBlockChanges((snapshot, builder) -> builder.add(Keys.DIRECTION, facing));
return BehaviorResult.CONTINUE;
}
Aggregations