-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathExtraToolProperty.java
More file actions
164 lines (130 loc) · 5.54 KB
/
ExtraToolProperty.java
File metadata and controls
164 lines (130 loc) · 5.54 KB
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package gregtech.api.unification.material.properties;
import net.minecraft.enchantment.Enchantment;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
import java.util.Map;
public class ExtraToolProperty implements IMaterialProperty {
/**
* Special override for certain kinds of tools.
*/
private final Map<String, OverrideToolProperty> overrideMap;
public static class OverrideToolProperty extends ToolProperty {
public OverrideToolProperty() {
this.setToolSpeed(Float.NaN);
this.setToolAttackSpeed(Float.NaN);
this.setToolAttackDamage(Float.NaN);
this.setToolDurability(-1);
this.setToolHarvestLevel(-1);
this.setToolEnchantability(-1);
this.setDurabilityMultiplier(-1);
}
// It does not make much sense to set these overrides:
public OverrideToolProperty setShouldIgnoreCraftingTools(boolean ignore) {
throw new UnsupportedOperationException();
}
public OverrideToolProperty setUnbreakable(boolean isUnbreakable) {
throw new UnsupportedOperationException();
}
public boolean isMagnetic() {
throw new UnsupportedOperationException();
}
private ToolProperty override(@NotNull ToolProperty property) {
// copy to prevent the previous map is produced
ToolProperty result = new ToolProperty(property);
// Set the floating point number fields
if (!Float.isNaN(this.getToolSpeed()))
result.setToolSpeed(this.getToolSpeed());
if (!Float.isNaN(this.getToolAttackSpeed()))
result.setToolAttackSpeed(this.getToolAttackSpeed());
if (!Float.isNaN(this.getToolAttackDamage()))
result.setToolAttackDamage(this.getToolAttackDamage());
// Set the integer fields
if (this.getToolDurability() != -1)
result.setToolDurability(this.getToolDurability());
if (this.getToolHarvestLevel() != -1)
result.setToolHarvestLevel(this.getToolHarvestLevel());
if (this.getToolEnchantability() != -1)
result.setToolEnchantability(this.getToolEnchantability());
if (this.getDurabilityMultiplier() != -1)
result.setDurabilityMultiplier(this.getDurabilityMultiplier());
// Merge the enchantment map
result.getEnchantments().putAll(this.getEnchantments());
return result;
}
}
public ExtraToolProperty() {
this.overrideMap = new HashMap<>();
}
public void setOverrideProperty(String toolId, OverrideToolProperty overrideProperty) {
this.overrideMap.put(toolId, overrideProperty);
}
@Nullable
public OverrideToolProperty getOverrideProperty(String toolId) {
return this.overrideMap.get(toolId);
}
public boolean hasOverrideProperty(String toolId) {
return this.overrideMap.containsKey(toolId);
}
public ToolProperty getOverriddenResult(String toolId, @Nullable MaterialToolProperty materialToolProperty) {
if (materialToolProperty == null) materialToolProperty = new MaterialToolProperty();
return overrideMap.getOrDefault(toolId, new OverrideToolProperty())
.override(materialToolProperty);
}
@Override
public void verifyProperty(MaterialProperties properties) {
// No check here, since these recipes should be self-generated.
// If they are overriding ToolProperty, then it is already generated.
}
public static class Builder {
private final OverrideToolProperty toolProperty;
public static Builder of() {
return new Builder();
}
public static Builder of(int durability) {
Builder builder = new Builder();
builder.durability(durability);
return builder;
}
public static Builder of(float harvestSpeed, float attackDamage, int durability, int harvestLevel) {
Builder builder = new Builder();
builder.harvestSpeed(harvestSpeed).attackDamage(attackDamage).durability(durability)
.harvestLevel(harvestLevel);
return builder;
}
public Builder() {
this.toolProperty = new OverrideToolProperty();
}
public Builder harvestSpeed(float harvestSpeed) {
toolProperty.setToolSpeed(harvestSpeed);
return this;
}
public Builder attackDamage(float attackDamage) {
toolProperty.setToolAttackDamage(attackDamage);
return this;
}
public Builder durability(int durability) {
toolProperty.setToolDurability(durability);
return this;
}
public Builder attackSpeed(float attackSpeed) {
toolProperty.setToolAttackSpeed(attackSpeed);
return this;
}
public Builder harvestLevel(int harvestLevel) {
toolProperty.setToolHarvestLevel(harvestLevel);
return this;
}
public Builder enchantment(Enchantment enchantment, int level) {
toolProperty.addEnchantmentForTools(enchantment, level);
return this;
}
public Builder durabilityMultiplier(int multiplier) {
toolProperty.setDurabilityMultiplier(multiplier);
return this;
}
public OverrideToolProperty build() {
return this.toolProperty;
}
}
}