-
Notifications
You must be signed in to change notification settings - Fork 1
/
ToolEntry.java
45 lines (35 loc) · 1.15 KB
/
ToolEntry.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
package de.melanx.toolswap;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.DiggerItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import javax.annotation.Nullable;
public record ToolEntry(TagKey<Block> type,
ItemStack stack) {
public TagKey<Block> getType() {
return this.type;
}
public ItemStack getStack() {
return this.stack;
}
@Nullable
public DiggerLike getToolItem() {
if (this.stack.getItem() instanceof DiggerLike diggerLike) {
return diggerLike;
}
return this.stack.getItem() instanceof DiggerItem diggerItem ? diggerItem::getTier : null;
}
public int getHarvestLevel() {
DiggerLike item = this.getToolItem();
//noinspection deprecation
return item != null ? item.getTier().getLevel() : -1;
}
public float getEfficiency() {
DiggerLike item = this.getToolItem();
return item != null ? item.getTier().getSpeed() : 0.0F;
}
@Override
public String toString() {
return this.getType().toString() + ": " + this.stack.toString();
}
}