Search in sources :

Example 6 with BehaviorResult

use of org.lanternpowered.server.behavior.BehaviorResult in project LanternServer by LanternPowered.

the class SimpleBreakBehavior method tryBreak.

@Override
public BehaviorResult tryBreak(BehaviorPipeline<Behavior> pipeline, BehaviorContext context) {
    final BlockSnapshotBuilder builder = BlockSnapshotBuilder.create();
    // Apply the creator and notifier to the block
    context.populateBlockSnapshot(builder, BehaviorContext.PopulationFlags.CREATOR_AND_NOTIFIER);
    builder.location(context.requireContext(ContextKeys.BLOCK_LOCATION));
    // The block should be replaced with air
    builder.blockState(BlockTypes.AIR.getDefaultState());
    // Add the block change
    context.addBlockChange(builder.build());
    context.getContext(EventContextKeys.PLAYER).ifPresent(p -> p.get(Keys.EXHAUSTION).ifPresent(value -> p.offer(Keys.EXHAUSTION, value + 0.005)));
    context.process(pipeline.pipeline(BlockDropsProviderBehavior.class), (ctx, behavior) -> {
        behavior.tryAddDrops(pipeline, context);
        return BehaviorResult.CONTINUE;
    });
    return BehaviorResult.CONTINUE;
}
Also used : ContextKeys(org.lanternpowered.server.behavior.ContextKeys) BreakBlockBehavior(org.lanternpowered.server.block.behavior.types.BreakBlockBehavior) BehaviorContext(org.lanternpowered.server.behavior.BehaviorContext) BlockSnapshotBuilder(org.lanternpowered.server.block.BlockSnapshotBuilder) Keys(org.spongepowered.api.data.key.Keys) EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) BlockTypes(org.spongepowered.api.block.BlockTypes) BehaviorResult(org.lanternpowered.server.behavior.BehaviorResult) BehaviorPipeline(org.lanternpowered.server.behavior.pipeline.BehaviorPipeline) Behavior(org.lanternpowered.server.behavior.Behavior) BlockDropsProviderBehavior(org.lanternpowered.server.block.behavior.types.BlockDropsProviderBehavior) BlockSnapshotBuilder(org.lanternpowered.server.block.BlockSnapshotBuilder) BlockDropsProviderBehavior(org.lanternpowered.server.block.behavior.types.BlockDropsProviderBehavior)

Aggregations

BehaviorResult (org.lanternpowered.server.behavior.BehaviorResult)6 BehaviorContext (org.lanternpowered.server.behavior.BehaviorContext)4 ContextKeys (org.lanternpowered.server.behavior.ContextKeys)4 InteractWithItemBehavior (org.lanternpowered.server.item.behavior.types.InteractWithItemBehavior)4 Keys (org.spongepowered.api.data.key.Keys)4 Direction (org.spongepowered.api.util.Direction)4 World (org.spongepowered.api.world.World)4 Optional (java.util.Optional)3 Behavior (org.lanternpowered.server.behavior.Behavior)3 BehaviorPipeline (org.lanternpowered.server.behavior.pipeline.BehaviorPipeline)3 LanternBlockType (org.lanternpowered.server.block.LanternBlockType)3 BlockState (org.spongepowered.api.block.BlockState)3 GameModes (org.spongepowered.api.entity.living.player.gamemode.GameModes)3 Location (org.spongepowered.api.world.Location)3 BlockSnapshotBuilder (org.lanternpowered.server.block.BlockSnapshotBuilder)2 BreakBlockBehavior (org.lanternpowered.server.block.behavior.types.BreakBlockBehavior)2 LanternItemType (org.lanternpowered.server.item.LanternItemType)2 BlockType (org.spongepowered.api.block.BlockType)2 BlockTypes (org.spongepowered.api.block.BlockTypes)2 ReplaceableProperty (org.spongepowered.api.data.property.block.ReplaceableProperty)2