MCPcopy Index your code
hub / github.com/cabaletta/baritone / calculateSpeedVsBlock

Method calculateSpeedVsBlock

src/main/java/baritone/utils/ToolSet.java:207–239  ·  view source on GitHub ↗

Calculates how long would it take to mine the specified block given the best tool in this toolset is used. A negative value is returned if the specified block is unbreakable. @param item the item to mine it with @param state the blockstate to be mined @return how long it would take in ticks

(ItemStack item, BlockState state)

Source from the content-addressed store, hash-verified

205 * @return how long it would take in ticks
206 */
207 public static double calculateSpeedVsBlock(ItemStack item, BlockState state) {
208 float hardness;
209 try {
210 hardness = state.getDestroySpeed(null, null);
211 } catch (NullPointerException npe) {
212 // can't easily determine the hardness so treat it as unbreakable
213 return -1;
214 }
215 if (hardness < 0) {
216 return -1;
217 }
218
219 float speed = item.getDestroySpeed(state);
220 if (speed > 1) {
221 final ItemEnchantments itemEnchantments = item.getEnchantments();
222 OUTER: for (Holder<Enchantment> enchant : itemEnchantments.keySet()) {
223 List<EnchantmentAttributeEffect> effects = enchant.value().getEffects(EnchantmentEffectComponents.ATTRIBUTES);
224 for (EnchantmentAttributeEffect e : effects) {
225 if (e.attribute().is(Attributes.MINING_EFFICIENCY.unwrapKey().get())) {
226 speed += e.amount().calculate(itemEnchantments.getLevel(enchant));
227 break OUTER;
228 }
229 }
230 }
231 }
232
233 speed /= hardness;
234 if (!state.requiresCorrectToolForDrops() || (!item.isEmpty() && item.isCorrectToolForDrops(state))) {
235 return speed / 30;
236 } else {
237 return speed / 100;
238 }
239 }
240
241 /**
242 * Calculates any modifier to breaking time based on status effects.

Callers 3

getBestSlotMethod · 0.95
bestToolAgainstMethod · 0.95

Calls 5

getLevelMethod · 0.80
isMethod · 0.65
getMethod · 0.65
calculateMethod · 0.65
isEmptyMethod · 0.65

Tested by

no test coverage detected