-
-
Notifications
You must be signed in to change notification settings - Fork 54
/
BlockBreaker.java
97 lines (82 loc) · 3 KB
/
BlockBreaker.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
package net.citizensnpcs.api.npc;
import java.util.function.BiConsumer;
import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import net.citizensnpcs.api.ai.tree.Behavior;
import net.citizensnpcs.api.ai.tree.BehaviorGoalAdapter;
/**
* A {@link Runnable} task that will break a block over time just as a normal Minecraft {@link Player} would. Should be
* run every tick until completed.
*
* This class also implements the {@link Behavior} interface for ease of use.
*
* Due to NMS constraints, this is currently implemented inside Citizens2.
*/
public abstract class BlockBreaker extends BehaviorGoalAdapter {
public static class BlockBreakerConfiguration {
private BiConsumer<Block, ItemStack> blockBreaker = (block, item) -> block.breakNaturally(item);
private Runnable callback;
private org.bukkit.inventory.ItemStack itemStack;
private float modifier = 1;
private double radius = 0;
public BiConsumer<Block, ItemStack> blockBreaker() {
return blockBreaker;
}
/**
* @param breaker
* The function that actually breaks the block. By default, this will call
* {@link Block#breakNaturally(ItemStack)}
*/
public void blockBreaker(BiConsumer<Block, ItemStack> breaker) {
blockBreaker = breaker;
}
public float blockStrengthModifier() {
return modifier;
}
/**
* @param modifier
* The block strength modifier
*/
public BlockBreakerConfiguration blockStrengthModifier(float modifier) {
this.modifier = modifier;
return this;
}
public Runnable callback() {
return callback;
}
/**
* @param callback
* A callback that is run on completion
*/
public BlockBreakerConfiguration callback(Runnable callback) {
this.callback = callback;
return this;
}
public org.bukkit.inventory.ItemStack item() {
return itemStack;
}
/**
*
* @param stack
* The item to simulate the NPC using to break the block (e.g. an axe for wood)
*/
public BlockBreakerConfiguration item(org.bukkit.inventory.ItemStack stack) {
itemStack = stack;
return this;
}
public double radius() {
return radius;
}
/**
* @param radius
* The maximum radius to be from the target block. The NPC will attempt to pathfind towards the
* target block if this is specified and it is outside of the radius.
*/
public BlockBreakerConfiguration radius(double radius) {
this.radius = radius;
return this;
}
}
public static final BlockBreakerConfiguration EMPTY_CONFIG = new BlockBreakerConfiguration();
}