use of org.lanternpowered.server.block.LanternBlockType in project LanternServer by LanternPowered.
the class LanternWorld method interactBlock.
private boolean interactBlock(int x, int y, int z, Direction side, @Nullable GameProfile profile, @Nullable ItemStack itemStack) {
checkNotNull(side, "side");
final LanternBlockType blockType = ((LanternBlockType) getBlockType(x, y, z));
final BehaviorPipeline<Behavior> pipeline = blockType.getPipeline();
final CauseStack causeStack = CauseStack.current();
try (CauseStack.Frame frame = causeStack.pushCauseFrame()) {
frame.addContext(ContextKeys.INTERACTION_FACE, side);
frame.addContext(ContextKeys.BLOCK_LOCATION, new Location<>(this, x, y, z));
frame.addContext(ContextKeys.BLOCK_TYPE, blockType);
if (profile != null) {
frame.addContext(EventContextKeys.PLAYER_SIMULATED, profile);
}
if (itemStack != null) {
frame.addContext(ContextKeys.USED_ITEM_STACK, itemStack);
}
final BehaviorContextImpl context = new BehaviorContextImpl(causeStack);
// Just pass an object trough to make sure that a value is present when successful
if (context.process(pipeline.pipeline(InteractWithBlockBehavior.class), (ctx, behavior) -> behavior.tryInteract(pipeline, ctx)).isSuccess()) {
context.accept();
return true;
}
context.revert();
return false;
}
}
Aggregations