use of org.lanternpowered.server.inventory.InventoryViewerListener 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;
}
Aggregations