Commits
Parker Hawke authored and md_5 committed 4c6c8586bb8
1 + | package org.bukkit.inventory.meta.components; |
2 + | |
3 + | import java.util.Collection; |
4 + | import java.util.List; |
5 + | import org.bukkit.Material; |
6 + | import org.bukkit.Tag; |
7 + | import org.bukkit.configuration.serialization.ConfigurationSerializable; |
8 + | import org.jetbrains.annotations.ApiStatus; |
9 + | import org.jetbrains.annotations.NotNull; |
10 + | import org.jetbrains.annotations.Nullable; |
11 + | |
12 + | /** |
13 + | * Represents a component which can turn any item into a tool. |
14 + | */ |
15 + | Experimental | .
16 + | public interface ToolComponent extends ConfigurationSerializable { |
17 + | |
18 + | /** |
19 + | * Get the default mining speed of this tool. This value is used by the tool |
20 + | * if no rule explicitly overrides it. 1.0 is standard mining speed. |
21 + | * |
22 + | * @return the default mining speed |
23 + | * @see ToolRule#getSpeed() |
24 + | */ |
25 + | float getDefaultMiningSpeed(); |
26 + | |
27 + | /** |
28 + | * Set the default mining speed of this tool. This value is used by the tool |
29 + | * if no rule explicitly overrides it. 1.0 is standard mining speed. |
30 + | * |
31 + | * @param speed the speed to set |
32 + | */ |
33 + | void setDefaultMiningSpeed(float speed); |
34 + | |
35 + | /** |
36 + | * Get the amount of durability to be removed from the tool each time a |
37 + | * block is broken. |
38 + | * |
39 + | * @return the damage per block |
40 + | */ |
41 + | int getDamagePerBlock(); |
42 + | |
43 + | /** |
44 + | * Set the amount of durability to be removed from the tool each time a |
45 + | * block is broken. |
46 + | * |
47 + | * @param damage the damage to set. Must be 0 or a positive integer |
48 + | */ |
49 + | void setDamagePerBlock(int damage); |
50 + | |
51 + | /** |
52 + | * Get the list of {@link ToolRule ToolRules} that apply to this tool. |
53 + | * |
54 + | * @return all tool rules. The mutability of the returned list cannot be |
55 + | * guaranteed, but its contents are mutable and can have their values |
56 + | * changed |
57 + | */ |
58 + | |
59 + | List<ToolRule> getRules(); |
60 + | |
61 + | /** |
62 + | * Set the list of {@link ToolRule ToolRules} to apply to this tool. This |
63 + | * will remove any existing tool rules. |
64 + | * |
65 + | * @param rules the rules to set |
66 + | */ |
67 + | void setRules( List<ToolRule> rules); |
68 + | |
69 + | /** |
70 + | * Add a new rule to this tool component, which provides further information |
71 + | * about a specific block type. |
72 + | * |
73 + | * @param block the block type to which the rule applies |
74 + | * @param speed the mining speed to use when mining the block, or null to |
75 + | * use the default mining speed |
76 + | * @param correctForDrops whether or not this tool, when mining the block, |
77 + | * is considered the optimal tool for the block and will drop its items when |
78 + | * broken, or null to use the default tool checking behavior defined by |
79 + | * Minecraft |
80 + | * @return the {@link ToolRule} instance that was added to this tool |
81 + | */ |
82 + | |
83 + | ToolRule addRule( Material block, Float speed, Boolean correctForDrops); |
84 + | |
85 + | /** |
86 + | * Add a new rule to this tool component, which provides further information |
87 + | * about a collection of block types. |
88 + | * |
89 + | * @param blocks the block types to which the rule applies |
90 + | * @param speed the mining speed to use when mining one of the blocks, or |
91 + | * null to use the default mining speed |
92 + | * @param correctForDrops whether or not this tool, when mining one of the |
93 + | * blocks, is considered the optimal tool for the block and will drop its |
94 + | * items when broken, or null to use the default tool checking behavior |
95 + | * defined by Minecraft |
96 + | * @return the {@link ToolRule} instance that was added to this tool |
97 + | */ |
98 + | |
99 + | ToolRule addRule( Collection<Material> blocks, Float speed, Boolean correctForDrops); |
100 + | |
101 + | /** |
102 + | * Add a new rule to this tool component, which provides further information |
103 + | * about a collection of block types represented by a block {@link Tag}. |
104 + | * |
105 + | * @param tag the block tag containing block types to which the rule |
106 + | * applies. |
107 + | * @param speed the mining speed to use when mining one of the blocks, or |
108 + | * null to use the default mining speed |
109 + | * @param correctForDrops whether or not this tool, when mining one of the |
110 + | * blocks, is considered the optimal tool for the block and will drop its |
111 + | * items when broken, or null to use the default tool checking behavior |
112 + | * defined by Minecraft |
113 + | * @return the {@link ToolRule} instance that was added to this tool |
114 + | * @throws IllegalArgumentException if the passed {@code tag} is not a block |
115 + | * tag |
116 + | */ |
117 + | |
118 + | ToolRule addRule( Tag<Material> tag, Float speed, Boolean correctForDrops); |
119 + | |
120 + | /** |
121 + | * Remove the given {@link ToolRule} from this tool. |
122 + | * |
123 + | * @param rule the rule to remove |
124 + | * @return true if the rule was removed, false if this component did not |
125 + | * contain a matching rule |
126 + | */ |
127 + | boolean removeRule( ToolRule rule); |
128 + | |
129 + | /** |
130 + | * A rule governing use of this tool and overriding attributes per-block. |
131 + | */ |
132 + | public interface ToolRule extends ConfigurationSerializable { |
133 + | |
134 + | /** |
135 + | * Get a collection of the block types to which this tool rule applies. |
136 + | * |
137 + | * @return the blocks |
138 + | */ |
139 + | |
140 + | Collection<Material> getBlocks(); |
141 + | |
142 + | /** |
143 + | * Set the block type to which this rule applies. |
144 + | * |
145 + | * @param block the block type |
146 + | */ |
147 + | void setBlocks( Material block); |
148 + | |
149 + | /** |
150 + | * Set the block types to which this rule applies. |
151 + | * |
152 + | * @param blocks the block types |
153 + | */ |
154 + | void setBlocks( Collection<Material> blocks); |
155 + | |
156 + | /** |
157 + | * Set the block types (represented as a block {@link Tag}) to which |
158 + | * this rule applies. |
159 + | * |
160 + | * @param tag the block tag |
161 + | * @throws IllegalArgumentException if the passed {@code tag} is not a |
162 + | * block tag |
163 + | */ |
164 + | void setBlocks( Tag<Material> tag); |
165 + | |
166 + | /** |
167 + | * Get the mining speed of this rule. If non-null, this speed value is |
168 + | * used in lieu of the default speed value of the tool. 1.0 is standard |
169 + | * mining speed. |
170 + | * |
171 + | * @return the mining speed, or null if the default speed is used |
172 + | */ |
173 + | |
174 + | Float getSpeed(); |
175 + | |
176 + | /** |
177 + | * Set the mining speed of this rule. 1.0 is standard mining speed. |
178 + | * |
179 + | * @param speed the mining speed, or null to use the default speed |
180 + | */ |
181 + | void setSpeed( Float speed); |
182 + | |
183 + | /** |
184 + | * Get whether or not this rule is considered the optimal tool for the |
185 + | * blocks listed by this rule and will drop items. If non-null, this |
186 + | * value is used in lieu of the default tool checking behavior defined |
187 + | * by Minecraft. |
188 + | * |
189 + | * @return true if correct for drops, false otherwise, or null to |
190 + | * fallback to vanilla tool checking behavior |
191 + | */ |
192 + | |
193 + | Boolean isCorrectForDrops(); |
194 + | |
195 + | /** |
196 + | * Set whether or not this rule is considered the optimal tool for the |
197 + | * blocks listed by this rule and will drop items. |
198 + | * |
199 + | * @param correct whether or not this rule is correct for drops, or null |
200 + | * to fallback to vanilla tool checking behavior |
201 + | */ |
202 + | void setCorrectForDrops( Boolean correct); |
203 + | } |
204 + | } |