Skip to content

Commit 013c1de

Browse files
authored
Tool property builder, magnetic stat (#1401)
1 parent be7e588 commit 013c1de

10 files changed

Lines changed: 162 additions & 98 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ default ItemStack get(Material material) {
174174
behaviourTag.setInteger(AOE_LAYER_KEY, aoeDefinition.layer);
175175
}
176176

177-
if (material.hasFlag(MaterialFlags.IS_MAGNETIC)) {
177+
if (toolProperty.isMagnetic()) {
178178
behaviourTag.setBoolean(RELOCATE_MINED_BLOCKS_KEY, true);
179179
}
180180

src/main/java/gregtech/api/unification/crafttweaker/CTMaterialBuilder.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import gregtech.api.unification.material.info.MaterialFlag;
1111
import gregtech.api.unification.material.info.MaterialIconSet;
1212
import gregtech.api.unification.material.properties.BlastProperty;
13+
import gregtech.api.unification.material.properties.ToolProperty;
1314
import gregtech.api.unification.stack.MaterialStack;
1415
import net.minecraft.enchantment.Enchantment;
1516
import stanhebben.zenscript.annotations.Optional;
@@ -145,11 +146,9 @@ public CTMaterialBuilder element(Element element) {
145146
}
146147

147148
@ZenMethod
148-
public CTMaterialBuilder toolStats(float speed, float damage, int durability, @Optional int enchantability) {
149-
if (enchantability == 0) {
150-
enchantability = 21; // Lowest enchantability by default
151-
}
152-
backingBuilder.toolStats(speed, damage, durability, enchantability);
149+
public CTMaterialBuilder toolStats(float speed, float damage, int durability, int harvestLevel, @Optional int enchantability) {
150+
if (enchantability == 0) enchantability = 10;
151+
backingBuilder.toolStats(ToolProperty.Builder.of(speed, damage, durability, harvestLevel).enchantability(enchantability).build());
153152
return this;
154153
}
155154
@ZenMethod

src/main/java/gregtech/api/unification/crafttweaker/MaterialPropertyExpansion.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ public static void addPlasma(Material m) {
187187
}
188188

189189
@ZenMethod
190-
public static void addTools(Material m, float toolSpeed, float toolAttackDamage, float toolAttackSpeed, int toolDurability, @Optional int toolHarvestLevel, @Optional int toolEnchantability, @Optional boolean shouldIgnoreCraftingTools) {
190+
public static void addTools(Material m, float toolSpeed, float toolAttackDamage, float toolAttackSpeed, int toolDurability, @Optional int toolHarvestLevel, @Optional int toolEnchantability) {
191191
if (checkFrozen("add Tools to a material")) return;
192192
if (toolEnchantability == 0) toolEnchantability = 10;
193193
if (m.hasProperty(PropertyKey.TOOL)) {
@@ -197,8 +197,8 @@ public static void addTools(Material m, float toolSpeed, float toolAttackDamage,
197197
m.getProperty(PropertyKey.TOOL).setToolDurability(toolDurability);
198198
m.getProperty(PropertyKey.TOOL).setToolHarvestLevel(toolHarvestLevel);
199199
m.getProperty(PropertyKey.TOOL).setToolEnchantability(toolEnchantability);
200-
m.getProperty(PropertyKey.TOOL).setShouldIgnoreCraftingTools(shouldIgnoreCraftingTools);
201-
} else m.setProperty(PropertyKey.TOOL, new ToolProperty(toolSpeed, toolAttackDamage, toolAttackSpeed, toolDurability, toolHarvestLevel, toolEnchantability, shouldIgnoreCraftingTools));
200+
} else m.setProperty(PropertyKey.TOOL, ToolProperty.Builder.of(toolSpeed, toolAttackDamage, toolDurability, toolHarvestLevel)
201+
.attackSpeed(toolAttackSpeed).enchantability(toolEnchantability).build());
202202
}
203203

204204
@ZenMethod

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

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -718,20 +718,12 @@ public Builder element(Element element) {
718718
return this;
719719
}
720720

721-
public Builder toolStats(float speed, float damage, int durability, int harvestLevel) {
722-
return toolStats(speed, damage, 0.0F, durability, harvestLevel, 22, false);
723-
}
724-
725-
public Builder toolStats(float speed, float damage, int durability, int harvestLevel, int enchantability) {
726-
return toolStats(speed, damage, 0.0F, durability, harvestLevel, enchantability, false);
727-
}
728-
729-
public Builder toolStats(float speed, float damage, float attackSpeed, int durability, int harvestLevel, int enchantability) {
730-
return toolStats(speed, damage, attackSpeed, durability, harvestLevel, enchantability, false);
731-
}
732-
733-
public Builder toolStats(float speed, float damage, float attackSpeed, int durability, int harvestLevel, int enchantability, boolean ignoreCraftingTools) {
734-
properties.setProperty(PropertyKey.TOOL, new ToolProperty(speed, damage, attackSpeed, durability, harvestLevel, enchantability, ignoreCraftingTools));
721+
/**
722+
* Replaced the old toolStats methods which took many parameters.
723+
* Use {@link ToolProperty.Builder} instead to create a Tool Property.
724+
*/
725+
public Builder toolStats(ToolProperty toolProperty) {
726+
properties.setProperty(PropertyKey.TOOL, toolProperty);
735727
return this;
736728
}
737729

@@ -873,6 +865,8 @@ public Builder itemPipeProperties(int priority, float stacksPerSec) {
873865
return this;
874866
}
875867

868+
// TODO Clean this up post 2.5 release
869+
@Deprecated
876870
public Builder addDefaultEnchant(Enchantment enchant, int level) {
877871
if (!properties.hasProperty(PropertyKey.TOOL)) // cannot assign default here
878872
throw new IllegalArgumentException("Material cannot have an Enchant without Tools!");

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import gregtech.api.unification.Elements;
66
import gregtech.api.unification.material.Material;
77
import gregtech.api.unification.material.properties.BlastProperty.GasTier;
8+
import gregtech.api.unification.material.properties.ToolProperty;
89

910
import static gregtech.api.GTValues.*;
1011
import static gregtech.api.unification.material.Materials.*;
@@ -24,7 +25,8 @@ public static void register() {
2425
.color(0x80C8F0)
2526
.flags(EXT2_METAL, GENERATE_GEAR, GENERATE_SMALL_GEAR, GENERATE_RING, GENERATE_FRAME, GENERATE_SPRING, GENERATE_SPRING_SMALL, GENERATE_FINE_WIRE)
2627
.element(Elements.Al)
27-
.toolStats(6.0f, 7.5f, 768, 2, 14)
28+
.toolStats(ToolProperty.Builder.of(6.0F, 7.5F, 768, 2)
29+
.enchantability(14).build())
2830
.rotorStats(10.0f, 2.0f, 128)
2931
.cableProperties(GTValues.V[4], 1, 1)
3032
.fluidPipeProperties(1166, 100, true)
@@ -342,7 +344,8 @@ public static void register() {
342344
.color(0xC8C8C8).iconSet(METALLIC)
343345
.flags(EXT2_METAL, MORTAR_GRINDABLE, GENERATE_ROTOR, GENERATE_SMALL_GEAR, GENERATE_GEAR, GENERATE_SPRING_SMALL, GENERATE_SPRING, EXCLUDE_BLOCK_CRAFTING_BY_HAND_RECIPES, BLAST_FURNACE_CALCITE_TRIPLE)
344346
.element(Elements.Fe)
345-
.toolStats(2.0f, 2.0f, 256, 2, 14)
347+
.toolStats(ToolProperty.Builder.of(2.0F, 2.0F, 256, 2)
348+
.enchantability(14).build())
346349
.rotorStats(7.0f, 2.5f, 256)
347350
.cableProperties(GTValues.V[2], 2, 3)
348351
.fluidTemp(1811)
@@ -750,7 +753,8 @@ public static void register() {
750753
.color(0xDCA0F0).iconSet(METALLIC)
751754
.flags(EXT2_METAL, GENERATE_ROTOR, GENERATE_SMALL_GEAR, GENERATE_GEAR, GENERATE_FRAME)
752755
.element(Elements.Ti)
753-
.toolStats(8.0f, 6.0f, 1536, 3, 14)
756+
.toolStats(ToolProperty.Builder.of(8.0F, 6.0F, 1536, 3)
757+
.enchantability(14).build())
754758
.rotorStats(7.0f, 3.0f, 1600)
755759
.fluidPipeProperties(2426, 150, true)
756760
.blastTemp(1941, GasTier.MID, VA[HV], 1500)
@@ -860,7 +864,8 @@ public static void register() {
860864
.color(0xFAFAFA)
861865
.flags(EXT_METAL, GENERATE_BOLT_SCREW, GENERATE_FRAME)
862866
.element(Elements.Nt)
863-
.toolStats(180.0f, 100.0f, 0.5f, 65535, 6, 33)
867+
.toolStats(ToolProperty.Builder.of(180.0F, 100.0F, 65535, 6)
868+
.attackSpeed(0.5F).enchantability(33).magnetic().unbreakable().build())
864869
.rotorStats(24.0f, 12.0f, 655360)
865870
.fluidPipeProperties(100_000, 5000, true, true, true, true)
866871
.fluidTemp(100_000)
@@ -881,7 +886,8 @@ public static void register() {
881886
.color(0x4BAFAF).iconSet(BRIGHT)
882887
.flags(EXT_METAL, GENERATE_FOIL, GENERATE_GEAR)
883888
.element(Elements.Dr)
884-
.toolStats(14.0f, 12.0f, 0.3f, 8192, 5, 33)
889+
.toolStats(ToolProperty.Builder.of(14.0F, 12.0F, 8192, 5)
890+
.attackSpeed(0.3F).enchantability(33).magnetic().build())
885891
.fluidPipeProperties(9625, 500, true, true, true, true)
886892
.fluidTemp(7500)
887893
.build();

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

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import gregtech.api.unification.material.Material;
66
import gregtech.api.unification.material.properties.BlastProperty.GasTier;
77
import gregtech.api.unification.material.properties.PropertyKey;
8+
import gregtech.api.unification.material.properties.ToolProperty;
89
import net.minecraft.init.Enchantments;
910

1011
import static gregtech.api.GTValues.*;
@@ -93,7 +94,8 @@ public static void register() {
9394
.color(0xFF8000).iconSet(METALLIC)
9495
.flags(EXT2_METAL, MORTAR_GRINDABLE, GENERATE_ROTOR, GENERATE_FRAME, GENERATE_SMALL_GEAR, GENERATE_FOIL, GENERATE_GEAR)
9596
.components(Tin, 1, Copper, 3)
96-
.toolStats(3.0f, 2.0f, 192, 2, 18)
97+
.toolStats(ToolProperty.Builder.of(3.0F, 2.0F, 192, 2)
98+
.enchantability(18).build())
9799
.rotorStats(6.0f, 2.5f, 192)
98100
.fluidPipeProperties(1696, 20, true)
99101
.fluidTemp(1357)
@@ -208,7 +210,8 @@ public static void register() {
208210
.flags(GENERATE_BOLT_SCREW, GENERATE_LENS, GENERATE_GEAR, NO_SMASHING, NO_SMELTING,
209211
HIGH_SIFTER_OUTPUT, DISABLE_DECOMPOSITION, EXCLUDE_BLOCK_CRAFTING_BY_HAND_RECIPES)
210212
.components(Carbon, 1)
211-
.toolStats(6.0f, 7.0f, 0.1f, 768, 3, 18)
213+
.toolStats(ToolProperty.Builder.of(6.0F, 7.0F, 768, 3)
214+
.attackSpeed(0.1F).enchantability(18).build())
212215
.build();
213216

214217
Electrum = new Material.Builder(277, "electrum")
@@ -288,10 +291,11 @@ public static void register() {
288291
.color(0xB4B478).iconSet(METALLIC)
289292
.flags(EXT2_METAL, MORTAR_GRINDABLE, GENERATE_FRAME, GENERATE_GEAR)
290293
.components(Iron, 2, Nickel, 1)
291-
.toolStats(4.0f, 3.0f, 384, 2, 18)
294+
.toolStats(ToolProperty.Builder.of(4.0F, 3.0F, 384, 2)
295+
.enchantability(18)
296+
.enchantment(Enchantments.BANE_OF_ARTHROPODS, 3)
297+
.enchantment(Enchantments.EFFICIENCY, 1).build())
292298
.rotorStats(7.0f, 3.0f, 512)
293-
.addDefaultEnchant(Enchantments.BANE_OF_ARTHROPODS, 3)
294-
.addDefaultEnchant(Enchantments.EFFICIENCY, 1)
295299
.fluidTemp(1916)
296300
.build();
297301

@@ -396,8 +400,9 @@ public static void register() {
396400
.color(0xFADCE1).iconSet(SHINY)
397401
.flags(EXT2_METAL)
398402
.components(Copper, 1, Silver, 4)
399-
.toolStats(3.0f, 8.0f, 0.3f, 768, 2, 33)
400-
.addDefaultEnchant(Enchantments.SMITE, 3)
403+
.toolStats(ToolProperty.Builder.of(3.0F, 8.0F, 768, 2)
404+
.attackSpeed(0.3F).enchantability(33)
405+
.enchantment(Enchantments.SMITE, 3).build())
401406
.rotorStats(13.0f, 2.0f, 196)
402407
.itemPipeProperties(1024, 2)
403408
.blastTemp(1700, GasTier.LOW, VA[MV], 1000)
@@ -409,9 +414,10 @@ public static void register() {
409414
.color(0xFFE61E).iconSet(SHINY)
410415
.flags(EXT2_METAL, GENERATE_RING)
411416
.components(Copper, 1, Gold, 4)
412-
.toolStats(12.0f, 2.0f, 768, 2, 33)
417+
.toolStats(ToolProperty.Builder.of(12.0F, 2.0F, 768, 2)
418+
.enchantability(33)
419+
.enchantment(Enchantments.FORTUNE, 2).build())
413420
.rotorStats(14.0f, 2.0f, 152)
414-
.addDefaultEnchant(Enchantments.FORTUNE, 2)
415421
.itemPipeProperties(1024, 2)
416422
.blastTemp(1600, GasTier.LOW, VA[MV], 1000)
417423
.fluidTemp(1341)
@@ -571,7 +577,8 @@ public static void register() {
571577
.color(0xC8C8DC).iconSet(SHINY)
572578
.flags(EXT2_METAL, GENERATE_ROTOR, GENERATE_SMALL_GEAR, GENERATE_FRAME, GENERATE_LONG_ROD, GENERATE_FOIL, GENERATE_GEAR)
573579
.components(Iron, 6, Chrome, 1, Manganese, 1, Nickel, 1)
574-
.toolStats(7.0f, 5.0f, 1024, 3, 14)
580+
.toolStats(ToolProperty.Builder.of(7.0F, 5.0F, 1024, 3)
581+
.enchantability(14).build())
575582
.rotorStats(7.0f, 4.0f, 480)
576583
.fluidPipeProperties(2428, 75, true, true, true, false)
577584
.blastTemp(1700, GasTier.LOW, VA[HV], 1100)
@@ -584,7 +591,8 @@ public static void register() {
584591
.flags(EXT2_METAL, MORTAR_GRINDABLE, GENERATE_ROTOR, GENERATE_SMALL_GEAR, GENERATE_SPRING,
585592
GENERATE_SPRING_SMALL, GENERATE_FRAME, DISABLE_DECOMPOSITION, GENERATE_FINE_WIRE, GENERATE_GEAR)
586593
.components(Iron, 1)
587-
.toolStats(5.0f, 3.0f, 512, 3, 14)
594+
.toolStats(ToolProperty.Builder.of(5.0F, 3.0F, 512, 3)
595+
.enchantability(14).build())
588596
.rotorStats(6.0f, 3.0f, 512)
589597
.fluidPipeProperties(1855, 75, true)
590598
.cableProperties(GTValues.V[4], 2, 2)
@@ -636,7 +644,8 @@ public static void register() {
636644
.color(0xB4B4E6).iconSet(SHINY)
637645
.flags(EXT2_METAL, GENERATE_GEAR)
638646
.components(Cobalt, 5, Chrome, 2, Nickel, 1, Molybdenum, 1)
639-
.toolStats(10.0f, 7.0f, 0.1f, 2048, 4, 21)
647+
.toolStats(ToolProperty.Builder.of(10.0F, 7.0F, 2048, 4)
648+
.attackSpeed(0.1F).enchantability(21).build())
640649
.rotorStats(9.0f, 4.0f, 2048)
641650
.itemPipeProperties(128, 16)
642651
.blastTemp(2700, GasTier.MID, VA[HV], 1300)
@@ -672,7 +681,8 @@ public static void register() {
672681
.color(0xC8B4B4).iconSet(METALLIC)
673682
.flags(EXT_METAL, GENERATE_GEAR, GENERATE_FOIL, MORTAR_GRINDABLE, GENERATE_RING, GENERATE_LONG_ROD, GENERATE_BOLT_SCREW, DISABLE_DECOMPOSITION, BLAST_FURNACE_CALCITE_TRIPLE)
674683
.components(Iron, 1)
675-
.toolStats(2.0f, 2.0f, -0.2f, 384, 2, 5)
684+
.toolStats(ToolProperty.Builder.of(2.0F, 2.0F, 384, 2)
685+
.attackSpeed(-0.2F).enchantability(5).build())
676686
.rotorStats(6.0f, 3.5f, 384)
677687
.fluidTemp(2011)
678688
.build();
@@ -1060,7 +1070,8 @@ public static void register() {
10601070
.color(0x330066).iconSet(METALLIC)
10611071
.flags(EXT2_METAL, GENERATE_FOIL, GENERATE_GEAR, DECOMPOSITION_BY_CENTRIFUGING)
10621072
.components(Tungsten, 1, Carbon, 1)
1063-
.toolStats(60.0f, 2.0f, 1024, 4, 21)
1073+
.toolStats(ToolProperty.Builder.of(60.0F, 2.0F, 1024, 4)
1074+
.enchantability(21).build())
10641075
.rotorStats(12.0f, 4.0f, 1280)
10651076
.fluidPipeProperties(3837, 200, true)
10661077
.blastTemp(3058, GasTier.MID, VA[HV], 1500)

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import gregtech.api.GTValues;
44
import gregtech.api.unification.material.Material;
55
import gregtech.api.unification.material.properties.BlastProperty.GasTier;
6+
import gregtech.api.unification.material.properties.ToolProperty;
67

78
import static gregtech.api.GTValues.*;
89
import static gregtech.api.unification.material.Materials.*;
@@ -37,7 +38,8 @@ public static void register() {
3738
.color(0x8C6464).iconSet(METALLIC)
3839
.flags(EXT_METAL, GENERATE_GEAR)
3940
.components(SterlingSilver, 1, BismuthBronze, 1, Steel, 2, BlackSteel, 4)
40-
.toolStats(7.0f, 6.0f, 0.1f, 2560, 3, 21)
41+
.toolStats(ToolProperty.Builder.of(7.0F, 6.0F, 2560, 3)
42+
.attackSpeed(0.1F).enchantability(21).build())
4143
.blastTemp(1300, GasTier.LOW, VA[HV], 1000)
4244
.build();
4345

@@ -46,7 +48,8 @@ public static void register() {
4648
.color(0x64648C).iconSet(METALLIC)
4749
.flags(EXT_METAL, GENERATE_FRAME, GENERATE_GEAR)
4850
.components(RoseGold, 1, Brass, 1, Steel, 2, BlackSteel, 4)
49-
.toolStats(15.0f, 6.0f, 0.1f, 1024, 3, 33)
51+
.toolStats(ToolProperty.Builder.of(15.0F, 6.0F, 1024, 3)
52+
.attackSpeed(0.1F).enchantability(33).build())
5053
.blastTemp(1400, GasTier.LOW, VA[HV], 1000)
5154
.build();
5255

@@ -109,7 +112,8 @@ public static void register() {
109112
.color(0x336600).iconSet(METALLIC)
110113
.flags(EXT2_METAL, GENERATE_FRAME, GENERATE_RING)
111114
.components(HSSG, 6, Cobalt, 1, Manganese, 1, Silicon, 1)
112-
.toolStats(5.0f, 10.0f, 0.3f, 3072, 4, 33)
115+
.toolStats(ToolProperty.Builder.of(5.0F, 10.0F, 3072, 4)
116+
.attackSpeed(0.3F).enchantability(33).build())
113117
.rotorStats(10.0f, 8.0f, 5120)
114118
.blastTemp(5000, GasTier.HIGH, VA[EV], 1400)
115119
.build();

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
import gregtech.api.unification.material.properties.OreProperty;
44
import gregtech.api.unification.material.properties.PropertyKey;
5-
import gregtech.api.unification.material.properties.ToolProperty;
65

76
import static gregtech.api.unification.material.Materials.*;
87

@@ -405,8 +404,5 @@ public static void register() {
405404

406405
oreProp = Pyrochlore.getProperty(PropertyKey.ORE);
407406
oreProp.setOreByProducts(Apatite, Calcium, Niobium);
408-
409-
ToolProperty toolProp = Neutronium.getProperty(PropertyKey.TOOL);
410-
toolProp.setUnbreakable(true);
411407
}
412408
}

0 commit comments

Comments
 (0)