Skip to content

Commit 30136d9

Browse files
Added property for specially registered tools (#2693)
1 parent a95ea1d commit 30136d9

25 files changed

+478
-181
lines changed

src/main/java/gregtech/api/items/materialitem/MetaPrefixItem.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
import gregtech.api.unification.material.Materials;
1010
import gregtech.api.unification.material.info.MaterialIconSet;
1111
import gregtech.api.unification.material.properties.DustProperty;
12+
import gregtech.api.unification.material.properties.MaterialToolProperty;
1213
import gregtech.api.unification.material.properties.PropertyKey;
13-
import gregtech.api.unification.material.properties.ToolProperty;
1414
import gregtech.api.unification.material.registry.MaterialRegistry;
1515
import gregtech.api.unification.ore.OrePrefix;
1616
import gregtech.api.unification.stack.UnificationEntry;
@@ -235,7 +235,7 @@ public int getItemBurnTime(@NotNull ItemStack itemStack) {
235235
public boolean isBeaconPayment(@NotNull ItemStack stack) {
236236
Material material = getMaterial(stack);
237237
if (material != null && this.prefix != OrePrefix.ingot && this.prefix != OrePrefix.gem) {
238-
ToolProperty property = material.getProperty(PropertyKey.TOOL);
238+
MaterialToolProperty property = material.getProperty(PropertyKey.TOOL);
239239
return property != null && property.getToolHarvestLevel() >= 2;
240240
}
241241
return false;

src/main/java/gregtech/api/items/toolitem/IGTTool.java

Lines changed: 35 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import gregtech.api.unification.material.Material;
1717
import gregtech.api.unification.material.Materials;
1818
import gregtech.api.unification.material.properties.DustProperty;
19+
import gregtech.api.unification.material.properties.MaterialToolProperty;
1920
import gregtech.api.unification.material.properties.PropertyKey;
2021
import gregtech.api.unification.material.properties.ToolProperty;
2122
import gregtech.api.unification.ore.OrePrefix;
@@ -158,6 +159,10 @@ default ItemStack getRaw() {
158159
return stack;
159160
}
160161

162+
/**
163+
* @return A tool made from the given material. The tool property (at least overriding) for the material must be
164+
* set.
165+
*/
161166
default ItemStack get(Material material) {
162167
ItemStack stack = new ItemStack(get());
163168

@@ -178,35 +183,38 @@ default ItemStack get(Material material) {
178183
AoESymmetrical aoeDefinition = getToolStats().getAoEDefinition(stack);
179184

180185
// Set other tool stats (durability)
181-
ToolProperty toolProperty = material.getProperty(PropertyKey.TOOL);
182-
186+
ToolProperty finalToolProperty = getToolProperty(material);
183187
// Durability formula we are working with:
184188
// Final Durability = (material durability * material durability multiplier) + (tool definition durability *
185189
// definition durability multiplier) - 1
186190
// Subtracts 1 internally since Minecraft treats "0" as a valid durability, but we don't want to display this.
187191

188-
int durability = toolProperty.getToolDurability() * toolProperty.getDurabilityMultiplier();
192+
// Tool material modifiers.
193+
int durability = finalToolProperty.getToolDurability() * finalToolProperty.getDurabilityMultiplier();
189194

195+
// Tool type modifiers.
190196
// Most Tool Definitions do not set a base durability, which will lead to ignoring the multiplier if present. So
191197
// apply the multiplier to the material durability if that would happen
192198
if (toolStats.getBaseDurability(stack) == 0) {
193-
durability *= toolStats.getDurabilityMultiplier(stack);
199+
durability = (int) (durability * toolStats.getDurabilityMultiplier(stack));
194200
} else {
195-
durability += toolStats.getBaseDurability(stack) * toolStats.getDurabilityMultiplier(stack);
201+
durability += (int) (toolStats.getBaseDurability(stack) * toolStats.getDurabilityMultiplier(stack));
196202
}
197203

198-
toolTag.setInteger(MAX_DURABILITY_KEY, durability - 1);
204+
durability -= 1; // Finally adjust for MC
205+
toolTag.setInteger(MAX_DURABILITY_KEY, durability);
199206
toolTag.setInteger(DURABILITY_KEY, 0);
200-
if (toolProperty.getUnbreakable()) {
207+
208+
if (finalToolProperty.getUnbreakable()) {
201209
stackCompound.setBoolean(UNBREAKABLE_KEY, true);
202210
}
203211

204212
// Set tool and material enchantments
205213
Object2IntMap<Enchantment> enchantments = new Object2IntOpenHashMap<>();
206-
toolProperty.getEnchantments().forEach((enchantment, level) -> enchantments.put(enchantment,
207-
level.getLevel(toolProperty.getToolHarvestLevel())));
214+
finalToolProperty.getEnchantments().forEach((enchantment, level) -> enchantments.put(enchantment,
215+
level.getLevel(finalToolProperty.getToolHarvestLevel())));
208216
toolStats.getDefaultEnchantments(stack).forEach((enchantment, level) -> enchantments.put(enchantment,
209-
level.getLevel(toolProperty.getToolHarvestLevel())));
217+
level.getLevel(finalToolProperty.getToolHarvestLevel())));
210218
enchantments.forEach((enchantment, level) -> {
211219
if (stack.getItem().canApplyAtEnchantingTable(stack, enchantment)) {
212220
stack.addEnchantment(enchantment, level);
@@ -226,7 +234,7 @@ default ItemStack get(Material material) {
226234
behaviourTag.setInteger(AOE_LAYER_KEY, aoeDefinition.layer);
227235
}
228236

229-
if (toolProperty.isMagnetic()) {
237+
if (finalToolProperty.isMagnetic()) {
230238
behaviourTag.setBoolean(RELOCATE_MINED_BLOCKS_KEY, true);
231239
}
232240

@@ -260,9 +268,24 @@ default Material getToolMaterial(ItemStack stack) {
260268
return material;
261269
}
262270

271+
@Nullable
272+
default ToolProperty getToolProperty(Material material) {
273+
ToolProperty finalToolProperty;
274+
{
275+
MaterialToolProperty materialToolProperty = material.getProperty(PropertyKey.TOOL);
276+
if (material.hasProperty(PropertyKey.EXTRATOOL)) {
277+
finalToolProperty = material.getProperty(PropertyKey.EXTRATOOL)
278+
.getOverriddenResult(this.getToolId(), materialToolProperty);
279+
} else {
280+
finalToolProperty = materialToolProperty;
281+
}
282+
}
283+
return finalToolProperty;
284+
}
285+
263286
@Nullable
264287
default ToolProperty getToolProperty(ItemStack stack) {
265-
return getToolMaterial(stack).getProperty(PropertyKey.TOOL);
288+
return getToolProperty(getToolMaterial(stack));
266289
}
267290

268291
@Nullable

src/main/java/gregtech/api/items/toolitem/ToolHelper.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
import gregtech.api.recipes.RecipeMaps;
1111
import gregtech.api.unification.OreDictUnifier;
1212
import gregtech.api.unification.material.Material;
13+
import gregtech.api.unification.material.properties.MaterialToolProperty;
1314
import gregtech.api.unification.material.properties.PropertyKey;
14-
import gregtech.api.unification.material.properties.ToolProperty;
1515
import gregtech.api.unification.ore.OrePrefix;
1616
import gregtech.api.util.GTUtility;
1717
import gregtech.api.util.function.QuintFunction;
@@ -230,11 +230,11 @@ public static ItemStack getAndSetToolData(IGTTool tool, Material material, int m
230230
toolTag.setInteger(HARVEST_LEVEL_KEY, harvestLevel);
231231
toolTag.setFloat(TOOL_SPEED_KEY, toolSpeed);
232232
toolTag.setFloat(ATTACK_DAMAGE_KEY, attackDamage);
233-
ToolProperty toolProperty = material.getProperty(PropertyKey.TOOL);
234-
if (toolProperty != null) {
235-
toolProperty.getEnchantments().forEach((enchantment, level) -> {
233+
MaterialToolProperty materialToolProperty = material.getProperty(PropertyKey.TOOL);
234+
if (materialToolProperty != null) {
235+
materialToolProperty.getEnchantments().forEach((enchantment, level) -> {
236236
if (stack.getItem().canApplyAtEnchantingTable(stack, enchantment)) {
237-
stack.addEnchantment(enchantment, level.getLevel(toolProperty.getToolHarvestLevel()));
237+
stack.addEnchantment(enchantment, level.getLevel(materialToolProperty.getToolHarvestLevel()));
238238
}
239239
});
240240
}

src/main/java/gregtech/api/unification/material/Material.java

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,19 @@
1212
import gregtech.api.unification.material.info.MaterialIconSet;
1313
import gregtech.api.unification.material.properties.BlastProperty;
1414
import gregtech.api.unification.material.properties.DustProperty;
15+
import gregtech.api.unification.material.properties.ExtraToolProperty;
1516
import gregtech.api.unification.material.properties.FluidPipeProperties;
1617
import gregtech.api.unification.material.properties.FluidProperty;
1718
import gregtech.api.unification.material.properties.GemProperty;
1819
import gregtech.api.unification.material.properties.IMaterialProperty;
1920
import gregtech.api.unification.material.properties.IngotProperty;
2021
import gregtech.api.unification.material.properties.ItemPipeProperties;
2122
import gregtech.api.unification.material.properties.MaterialProperties;
23+
import gregtech.api.unification.material.properties.MaterialToolProperty;
2224
import gregtech.api.unification.material.properties.OreProperty;
2325
import gregtech.api.unification.material.properties.PolymerProperty;
2426
import gregtech.api.unification.material.properties.PropertyKey;
2527
import gregtech.api.unification.material.properties.RotorProperty;
26-
import gregtech.api.unification.material.properties.ToolProperty;
2728
import gregtech.api.unification.material.properties.WireProperties;
2829
import gregtech.api.unification.material.properties.WoodProperty;
2930
import gregtech.api.unification.material.registry.MaterialRegistry;
@@ -637,7 +638,7 @@ public Builder dust() {
637638
* Will be created with no Burn Time (Furnace Fuel).
638639
*
639640
* @param harvestLevel The Harvest Level of this block for Mining.<br>
640-
* If this Material also has a {@link ToolProperty}, this value will
641+
* If this Material also has a {@link MaterialToolProperty}, this value will
641642
* also be used to determine the tool's Mining Level.
642643
* @throws IllegalArgumentException If a {@link DustProperty} has already been added to this Material.
643644
*/
@@ -649,7 +650,7 @@ public Builder dust(int harvestLevel) {
649650
* Add a {@link DustProperty} to this Material.
650651
*
651652
* @param harvestLevel The Harvest Level of this block for Mining.<br>
652-
* If this Material also has a {@link ToolProperty}, this value will
653+
* If this Material also has a {@link MaterialToolProperty}, this value will
653654
* also be used to determine the tool's Mining Level.
654655
* @param burnTime The Burn Time (in ticks) of this Material as a Furnace Fuel.
655656
* @throws IllegalArgumentException If a {@link DustProperty} has already been added to this Material.
@@ -672,7 +673,7 @@ public Builder wood() {
672673
* Will be created with a Burn Time of 300 (Furnace Fuel).
673674
*
674675
* @param harvestLevel The Harvest Level of this block for Mining.<br>
675-
* If this Material also has a {@link ToolProperty}, this value will
676+
* If this Material also has a {@link MaterialToolProperty}, this value will
676677
* also be used to determine the tool's Mining Level.
677678
*/
678679
public Builder wood(int harvestLevel) {
@@ -683,7 +684,7 @@ public Builder wood(int harvestLevel) {
683684
* Add a {@link WoodProperty} to this Material.
684685
*
685686
* @param harvestLevel The Harvest Level of this block for Mining.<br>
686-
* If this Material also has a {@link ToolProperty}, this value will
687+
* If this Material also has a {@link MaterialToolProperty}, this value will
687688
* also be used to determine the tool's Mining Level.
688689
* @param burnTime The Burn Time (in ticks) of this Material as a Furnace Fuel.
689690
*/
@@ -711,7 +712,7 @@ public Builder ingot() {
711712
* Will automatically add a {@link DustProperty} to this Material if it does not already have one.
712713
*
713714
* @param harvestLevel The Harvest Level of this block for Mining. 2 will make it require a iron tool.<br>
714-
* If this Material also has a {@link ToolProperty}, this value will
715+
* If this Material also has a {@link MaterialToolProperty}, this value will
715716
* also be used to determine the tool's Mining level (-1). So 2 will make the tool harvest
716717
* diamonds.<br>
717718
* If this Material already had a Harvest Level defined, it will be overridden.
@@ -726,7 +727,7 @@ public Builder ingot(int harvestLevel) {
726727
* Will automatically add a {@link DustProperty} to this Material if it does not already have one.
727728
*
728729
* @param harvestLevel The Harvest Level of this block for Mining. 2 will make it require a iron tool.<br>
729-
* If this Material also has a {@link ToolProperty}, this value will
730+
* If this Material also has a {@link MaterialToolProperty}, this value will
730731
* also be used to determine the tool's Mining level (-1). So 2 will make the tool harvest
731732
* diamonds.<br>
732733
* If this Material already had a Harvest Level defined, it will be overridden.
@@ -763,7 +764,7 @@ public Builder gem() {
763764
* Will automatically add a {@link DustProperty} to this Material if it does not already have one.
764765
*
765766
* @param harvestLevel The Harvest Level of this block for Mining.<br>
766-
* If this Material also has a {@link ToolProperty}, this value will
767+
* If this Material also has a {@link MaterialToolProperty}, this value will
767768
* also be used to determine the tool's Mining level.<br>
768769
* If this Material already had a Harvest Level defined, it will be overridden.
769770
* @throws IllegalArgumentException If a {@link GemProperty} has already been added to this Material.
@@ -777,7 +778,7 @@ public Builder gem(int harvestLevel) {
777778
* Will automatically add a {@link DustProperty} to this Material if it does not already have one.
778779
*
779780
* @param harvestLevel The Harvest Level of this block for Mining.<br>
780-
* If this Material also has a {@link ToolProperty}, this value will
781+
* If this Material also has a {@link MaterialToolProperty}, this value will
781782
* also be used to determine the tool's Mining level.<br>
782783
* If this Material already had a Harvest Level defined, it will be overridden.
783784
* @param burnTime The Burn Time (in ticks) of this Material as a Furnace Fuel.<br>
@@ -812,7 +813,7 @@ public Builder polymer() {
812813
* Will have a burn time of 0
813814
*
814815
* @param harvestLevel The Harvest Level of this block for Mining.<br>
815-
* If this Material also has a {@link ToolProperty}, this value will
816+
* If this Material also has a {@link MaterialToolProperty}, this value will
816817
* also be used to determine the tool's Mining level.<br>
817818
* If this Material already had a Harvest Level defined, it will be overridden.
818819
* @throws IllegalArgumentException If an {@link PolymerProperty} has already been added to this Material.
@@ -929,10 +930,19 @@ public Builder element(Element element) {
929930

930931
/**
931932
* Replaced the old toolStats methods which took many parameters.
932-
* Use {@link ToolProperty.Builder} instead to create a Tool Property.
933+
* Use {@link MaterialToolProperty.Builder} instead to create a Tool Property.
933934
*/
934-
public Builder toolStats(ToolProperty toolProperty) {
935-
properties.setProperty(PropertyKey.TOOL, toolProperty);
935+
public Builder toolStats(MaterialToolProperty materialToolProperty) {
936+
properties.setProperty(PropertyKey.TOOL, materialToolProperty);
937+
return this;
938+
}
939+
940+
/**
941+
* Use {@link ExtraToolProperty.Builder} to create a Tool Property Override.
942+
*/
943+
public Builder overrideToolStats(String toolId, ExtraToolProperty.OverrideToolProperty toolProperty) {
944+
properties.ensureSet(PropertyKey.EXTRATOOL);
945+
properties.getProperty(PropertyKey.EXTRATOOL).setOverrideProperty(toolId, toolProperty);
936946
return this;
937947
}
938948

src/main/java/gregtech/api/unification/material/Materials.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ public static void register() {
110110
Materials.DyeRed, Materials.DyeBlack
111111
};
112112

113+
// Register soft tools
114+
SoftToolAddition.register();
115+
113116
OrePrefix.init();
114117
}
115118

src/main/java/gregtech/api/unification/material/materials/ElementMaterials.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
import gregtech.api.unification.Elements;
77
import gregtech.api.unification.material.Material;
88
import gregtech.api.unification.material.properties.BlastProperty.GasTier;
9+
import gregtech.api.unification.material.properties.MaterialToolProperty;
910
import gregtech.api.unification.material.properties.PropertyKey;
10-
import gregtech.api.unification.material.properties.ToolProperty;
1111

1212
import static gregtech.api.GTValues.*;
1313
import static gregtech.api.unification.material.Materials.*;
@@ -31,7 +31,7 @@ public static void register() {
3131
.flags(EXT2_METAL, GENERATE_GEAR, GENERATE_SMALL_GEAR, GENERATE_RING, GENERATE_FRAME, GENERATE_SPRING,
3232
GENERATE_SPRING_SMALL, GENERATE_FINE_WIRE, GENERATE_DOUBLE_PLATE)
3333
.element(Elements.Al)
34-
.toolStats(ToolProperty.Builder.of(6.0F, 7.5F, 768, 2)
34+
.toolStats(MaterialToolProperty.Builder.of(6.0F, 7.5F, 768, 2)
3535
.enchantability(14).build())
3636
.rotorStats(10.0f, 2.0f, 128)
3737
.cableProperties(V[EV], 1, 1)
@@ -386,7 +386,7 @@ public static void register() {
386386
GENERATE_SPRING_SMALL, GENERATE_SPRING, EXCLUDE_BLOCK_CRAFTING_BY_HAND_RECIPES,
387387
BLAST_FURNACE_CALCITE_TRIPLE)
388388
.element(Elements.Fe)
389-
.toolStats(ToolProperty.Builder.of(2.0F, 2.0F, 256, 2)
389+
.toolStats(MaterialToolProperty.Builder.of(2.0F, 2.0F, 256, 2)
390390
.enchantability(14).build())
391391
.rotorStats(7.0f, 2.5f, 256)
392392
.cableProperties(V[MV], 2, 3)
@@ -833,7 +833,7 @@ public static void register() {
833833
.flags(EXT2_METAL, GENERATE_DOUBLE_PLATE, GENERATE_ROTOR, GENERATE_SMALL_GEAR, GENERATE_GEAR,
834834
GENERATE_FRAME)
835835
.element(Elements.Ti)
836-
.toolStats(ToolProperty.Builder.of(8.0F, 6.0F, 1536, 3)
836+
.toolStats(MaterialToolProperty.Builder.of(8.0F, 6.0F, 1536, 3)
837837
.enchantability(14).build())
838838
.rotorStats(7.0f, 3.0f, 1600)
839839
.fluidPipeProperties(2426, 150, true, true, false, false)
@@ -970,7 +970,7 @@ public static void register() {
970970
.flags(EXT_METAL, GENERATE_BOLT_SCREW, GENERATE_FRAME, GENERATE_GEAR, GENERATE_LONG_ROD,
971971
GENERATE_DOUBLE_PLATE)
972972
.element(Elements.Nt)
973-
.toolStats(ToolProperty.Builder.of(180.0F, 100.0F, 65535, 6)
973+
.toolStats(MaterialToolProperty.Builder.of(180.0F, 100.0F, 65535, 6)
974974
.attackSpeed(0.5F).enchantability(33).magnetic().unbreakable().build())
975975
.rotorStats(24.0f, 12.0f, 655360)
976976
.fluidPipeProperties(100_000, 5000, true, true, true, true)
@@ -993,7 +993,7 @@ public static void register() {
993993
.color(0x4BAFAF).iconSet(BRIGHT)
994994
.flags(EXT_METAL, GENERATE_FOIL, GENERATE_GEAR, GENERATE_DOUBLE_PLATE)
995995
.element(Elements.Dr)
996-
.toolStats(ToolProperty.Builder.of(14.0F, 12.0F, 8192, 5)
996+
.toolStats(MaterialToolProperty.Builder.of(14.0F, 12.0F, 8192, 5)
997997
.attackSpeed(0.3F).enchantability(33).magnetic().build())
998998
.fluidPipeProperties(9625, 500, true, true, true, true)
999999
.build();

0 commit comments

Comments
 (0)