Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import gregtech.api.unification.material.Materials;
import gregtech.api.unification.material.info.MaterialIconSet;
import gregtech.api.unification.material.properties.DustProperty;
import gregtech.api.unification.material.properties.MaterialToolProperty;
import gregtech.api.unification.material.properties.PropertyKey;
import gregtech.api.unification.material.properties.ToolProperty;
import gregtech.api.unification.material.registry.MaterialRegistry;
import gregtech.api.unification.ore.OrePrefix;
import gregtech.api.unification.stack.UnificationEntry;
Expand Down Expand Up @@ -235,7 +235,7 @@ public int getItemBurnTime(@NotNull ItemStack itemStack) {
public boolean isBeaconPayment(@NotNull ItemStack stack) {
Material material = getMaterial(stack);
if (material != null && this.prefix != OrePrefix.ingot && this.prefix != OrePrefix.gem) {
ToolProperty property = material.getProperty(PropertyKey.TOOL);
MaterialToolProperty property = material.getProperty(PropertyKey.TOOL);
return property != null && property.getToolHarvestLevel() >= 2;
}
return false;
Expand Down
47 changes: 35 additions & 12 deletions src/main/java/gregtech/api/items/toolitem/IGTTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import gregtech.api.unification.material.Material;
import gregtech.api.unification.material.Materials;
import gregtech.api.unification.material.properties.DustProperty;
import gregtech.api.unification.material.properties.MaterialToolProperty;
import gregtech.api.unification.material.properties.PropertyKey;
import gregtech.api.unification.material.properties.ToolProperty;
import gregtech.api.unification.ore.OrePrefix;
Expand Down Expand Up @@ -158,6 +159,10 @@ default ItemStack getRaw() {
return stack;
}

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

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

// Set other tool stats (durability)
ToolProperty toolProperty = material.getProperty(PropertyKey.TOOL);

ToolProperty finalToolProperty = getToolProperty(material);
// Durability formula we are working with:
// Final Durability = (material durability * material durability multiplier) + (tool definition durability *
// definition durability multiplier) - 1
// Subtracts 1 internally since Minecraft treats "0" as a valid durability, but we don't want to display this.

int durability = toolProperty.getToolDurability() * toolProperty.getDurabilityMultiplier();
// Tool material modifiers.
int durability = finalToolProperty.getToolDurability() * finalToolProperty.getDurabilityMultiplier();

// Tool type modifiers.
// Most Tool Definitions do not set a base durability, which will lead to ignoring the multiplier if present. So
// apply the multiplier to the material durability if that would happen
if (toolStats.getBaseDurability(stack) == 0) {
durability *= toolStats.getDurabilityMultiplier(stack);
durability = (int) (durability * toolStats.getDurabilityMultiplier(stack));
} else {
durability += toolStats.getBaseDurability(stack) * toolStats.getDurabilityMultiplier(stack);
durability += (int) (toolStats.getBaseDurability(stack) * toolStats.getDurabilityMultiplier(stack));
Comment on lines +199 to +201
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there any reason for the explicit casting and separating the *= apart? The += and *= operators implicitly perform the casting for integer types, iirc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, but the operands are floating point numbers, so I just wanted to be clear here.

}

toolTag.setInteger(MAX_DURABILITY_KEY, durability - 1);
durability -= 1; // Finally adjust for MC
toolTag.setInteger(MAX_DURABILITY_KEY, durability);
toolTag.setInteger(DURABILITY_KEY, 0);
if (toolProperty.getUnbreakable()) {

if (finalToolProperty.getUnbreakable()) {
stackCompound.setBoolean(UNBREAKABLE_KEY, true);
}

// Set tool and material enchantments
Object2IntMap<Enchantment> enchantments = new Object2IntOpenHashMap<>();
toolProperty.getEnchantments().forEach((enchantment, level) -> enchantments.put(enchantment,
level.getLevel(toolProperty.getToolHarvestLevel())));
finalToolProperty.getEnchantments().forEach((enchantment, level) -> enchantments.put(enchantment,
level.getLevel(finalToolProperty.getToolHarvestLevel())));
toolStats.getDefaultEnchantments(stack).forEach((enchantment, level) -> enchantments.put(enchantment,
level.getLevel(toolProperty.getToolHarvestLevel())));
level.getLevel(finalToolProperty.getToolHarvestLevel())));
enchantments.forEach((enchantment, level) -> {
if (stack.getItem().canApplyAtEnchantingTable(stack, enchantment)) {
stack.addEnchantment(enchantment, level);
Expand All @@ -226,7 +234,7 @@ default ItemStack get(Material material) {
behaviourTag.setInteger(AOE_LAYER_KEY, aoeDefinition.layer);
}

if (toolProperty.isMagnetic()) {
if (finalToolProperty.isMagnetic()) {
behaviourTag.setBoolean(RELOCATE_MINED_BLOCKS_KEY, true);
}

Expand Down Expand Up @@ -260,9 +268,24 @@ default Material getToolMaterial(ItemStack stack) {
return material;
}

@Nullable
default ToolProperty getToolProperty(Material material) {
ToolProperty finalToolProperty;
{
MaterialToolProperty materialToolProperty = material.getProperty(PropertyKey.TOOL);
if (material.hasProperty(PropertyKey.EXTRATOOL)) {
finalToolProperty = material.getProperty(PropertyKey.EXTRATOOL)
.getOverriddenResult(this.getToolId(), materialToolProperty);
} else {
finalToolProperty = materialToolProperty;
}
}
return finalToolProperty;
}

@Nullable
default ToolProperty getToolProperty(ItemStack stack) {
return getToolMaterial(stack).getProperty(PropertyKey.TOOL);
return getToolProperty(getToolMaterial(stack));
}

@Nullable
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/gregtech/api/items/toolitem/ToolHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
import gregtech.api.recipes.RecipeMaps;
import gregtech.api.unification.OreDictUnifier;
import gregtech.api.unification.material.Material;
import gregtech.api.unification.material.properties.MaterialToolProperty;
import gregtech.api.unification.material.properties.PropertyKey;
import gregtech.api.unification.material.properties.ToolProperty;
import gregtech.api.unification.ore.OrePrefix;
import gregtech.api.util.GTUtility;
import gregtech.api.util.function.QuintFunction;
Expand Down Expand Up @@ -230,11 +230,11 @@ public static ItemStack getAndSetToolData(IGTTool tool, Material material, int m
toolTag.setInteger(HARVEST_LEVEL_KEY, harvestLevel);
toolTag.setFloat(TOOL_SPEED_KEY, toolSpeed);
toolTag.setFloat(ATTACK_DAMAGE_KEY, attackDamage);
ToolProperty toolProperty = material.getProperty(PropertyKey.TOOL);
if (toolProperty != null) {
toolProperty.getEnchantments().forEach((enchantment, level) -> {
MaterialToolProperty materialToolProperty = material.getProperty(PropertyKey.TOOL);
if (materialToolProperty != null) {
materialToolProperty.getEnchantments().forEach((enchantment, level) -> {
if (stack.getItem().canApplyAtEnchantingTable(stack, enchantment)) {
stack.addEnchantment(enchantment, level.getLevel(toolProperty.getToolHarvestLevel()));
stack.addEnchantment(enchantment, level.getLevel(materialToolProperty.getToolHarvestLevel()));
}
});
}
Expand Down
36 changes: 23 additions & 13 deletions src/main/java/gregtech/api/unification/material/Material.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,19 @@
import gregtech.api.unification.material.info.MaterialIconSet;
import gregtech.api.unification.material.properties.BlastProperty;
import gregtech.api.unification.material.properties.DustProperty;
import gregtech.api.unification.material.properties.ExtraToolProperty;
import gregtech.api.unification.material.properties.FluidPipeProperties;
import gregtech.api.unification.material.properties.FluidProperty;
import gregtech.api.unification.material.properties.GemProperty;
import gregtech.api.unification.material.properties.IMaterialProperty;
import gregtech.api.unification.material.properties.IngotProperty;
import gregtech.api.unification.material.properties.ItemPipeProperties;
import gregtech.api.unification.material.properties.MaterialProperties;
import gregtech.api.unification.material.properties.MaterialToolProperty;
import gregtech.api.unification.material.properties.OreProperty;
import gregtech.api.unification.material.properties.PolymerProperty;
import gregtech.api.unification.material.properties.PropertyKey;
import gregtech.api.unification.material.properties.RotorProperty;
import gregtech.api.unification.material.properties.ToolProperty;
import gregtech.api.unification.material.properties.WireProperties;
import gregtech.api.unification.material.properties.WoodProperty;
import gregtech.api.unification.material.registry.MaterialRegistry;
Expand Down Expand Up @@ -637,7 +638,7 @@ public Builder dust() {
* Will be created with no Burn Time (Furnace Fuel).
*
* @param harvestLevel The Harvest Level of this block for Mining.<br>
* If this Material also has a {@link ToolProperty}, this value will
* If this Material also has a {@link MaterialToolProperty}, this value will
* also be used to determine the tool's Mining Level.
* @throws IllegalArgumentException If a {@link DustProperty} has already been added to this Material.
*/
Expand All @@ -649,7 +650,7 @@ public Builder dust(int harvestLevel) {
* Add a {@link DustProperty} to this Material.
*
* @param harvestLevel The Harvest Level of this block for Mining.<br>
* If this Material also has a {@link ToolProperty}, this value will
* If this Material also has a {@link MaterialToolProperty}, this value will
* also be used to determine the tool's Mining Level.
* @param burnTime The Burn Time (in ticks) of this Material as a Furnace Fuel.
* @throws IllegalArgumentException If a {@link DustProperty} has already been added to this Material.
Expand All @@ -672,7 +673,7 @@ public Builder wood() {
* Will be created with a Burn Time of 300 (Furnace Fuel).
*
* @param harvestLevel The Harvest Level of this block for Mining.<br>
* If this Material also has a {@link ToolProperty}, this value will
* If this Material also has a {@link MaterialToolProperty}, this value will
* also be used to determine the tool's Mining Level.
*/
public Builder wood(int harvestLevel) {
Expand All @@ -683,7 +684,7 @@ public Builder wood(int harvestLevel) {
* Add a {@link WoodProperty} to this Material.
*
* @param harvestLevel The Harvest Level of this block for Mining.<br>
* If this Material also has a {@link ToolProperty}, this value will
* If this Material also has a {@link MaterialToolProperty}, this value will
* also be used to determine the tool's Mining Level.
* @param burnTime The Burn Time (in ticks) of this Material as a Furnace Fuel.
*/
Expand Down Expand Up @@ -711,7 +712,7 @@ public Builder ingot() {
* Will automatically add a {@link DustProperty} to this Material if it does not already have one.
*
* @param harvestLevel The Harvest Level of this block for Mining. 2 will make it require a iron tool.<br>
* If this Material also has a {@link ToolProperty}, this value will
* If this Material also has a {@link MaterialToolProperty}, this value will
* also be used to determine the tool's Mining level (-1). So 2 will make the tool harvest
* diamonds.<br>
* If this Material already had a Harvest Level defined, it will be overridden.
Expand All @@ -726,7 +727,7 @@ public Builder ingot(int harvestLevel) {
* Will automatically add a {@link DustProperty} to this Material if it does not already have one.
*
* @param harvestLevel The Harvest Level of this block for Mining. 2 will make it require a iron tool.<br>
* If this Material also has a {@link ToolProperty}, this value will
* If this Material also has a {@link MaterialToolProperty}, this value will
* also be used to determine the tool's Mining level (-1). So 2 will make the tool harvest
* diamonds.<br>
* If this Material already had a Harvest Level defined, it will be overridden.
Expand Down Expand Up @@ -763,7 +764,7 @@ public Builder gem() {
* Will automatically add a {@link DustProperty} to this Material if it does not already have one.
*
* @param harvestLevel The Harvest Level of this block for Mining.<br>
* If this Material also has a {@link ToolProperty}, this value will
* If this Material also has a {@link MaterialToolProperty}, this value will
* also be used to determine the tool's Mining level.<br>
* If this Material already had a Harvest Level defined, it will be overridden.
* @throws IllegalArgumentException If a {@link GemProperty} has already been added to this Material.
Expand All @@ -777,7 +778,7 @@ public Builder gem(int harvestLevel) {
* Will automatically add a {@link DustProperty} to this Material if it does not already have one.
*
* @param harvestLevel The Harvest Level of this block for Mining.<br>
* If this Material also has a {@link ToolProperty}, this value will
* If this Material also has a {@link MaterialToolProperty}, this value will
* also be used to determine the tool's Mining level.<br>
* If this Material already had a Harvest Level defined, it will be overridden.
* @param burnTime The Burn Time (in ticks) of this Material as a Furnace Fuel.<br>
Expand Down Expand Up @@ -812,7 +813,7 @@ public Builder polymer() {
* Will have a burn time of 0
*
* @param harvestLevel The Harvest Level of this block for Mining.<br>
* If this Material also has a {@link ToolProperty}, this value will
* If this Material also has a {@link MaterialToolProperty}, this value will
* also be used to determine the tool's Mining level.<br>
* If this Material already had a Harvest Level defined, it will be overridden.
* @throws IllegalArgumentException If an {@link PolymerProperty} has already been added to this Material.
Expand Down Expand Up @@ -929,10 +930,19 @@ public Builder element(Element element) {

/**
* Replaced the old toolStats methods which took many parameters.
* Use {@link ToolProperty.Builder} instead to create a Tool Property.
* Use {@link MaterialToolProperty.Builder} instead to create a Tool Property.
*/
public Builder toolStats(ToolProperty toolProperty) {
properties.setProperty(PropertyKey.TOOL, toolProperty);
public Builder toolStats(MaterialToolProperty materialToolProperty) {
properties.setProperty(PropertyKey.TOOL, materialToolProperty);
return this;
}

/**
* Use {@link ExtraToolProperty.Builder} to create a Tool Property Override.
*/
public Builder overrideToolStats(String toolId, ExtraToolProperty.OverrideToolProperty toolProperty) {
properties.ensureSet(PropertyKey.EXTRATOOL);
properties.getProperty(PropertyKey.EXTRATOOL).setOverrideProperty(toolId, toolProperty);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ public static void register() {
Materials.DyeRed, Materials.DyeBlack
};

// Register soft tools
SoftToolAddition.register();

OrePrefix.init();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
import gregtech.api.unification.Elements;
import gregtech.api.unification.material.Material;
import gregtech.api.unification.material.properties.BlastProperty.GasTier;
import gregtech.api.unification.material.properties.MaterialToolProperty;
import gregtech.api.unification.material.properties.PropertyKey;
import gregtech.api.unification.material.properties.ToolProperty;

import static gregtech.api.GTValues.*;
import static gregtech.api.unification.material.Materials.*;
Expand All @@ -31,7 +31,7 @@ public static void register() {
.flags(EXT2_METAL, GENERATE_GEAR, GENERATE_SMALL_GEAR, GENERATE_RING, GENERATE_FRAME, GENERATE_SPRING,
GENERATE_SPRING_SMALL, GENERATE_FINE_WIRE, GENERATE_DOUBLE_PLATE)
.element(Elements.Al)
.toolStats(ToolProperty.Builder.of(6.0F, 7.5F, 768, 2)
.toolStats(MaterialToolProperty.Builder.of(6.0F, 7.5F, 768, 2)
.enchantability(14).build())
.rotorStats(10.0f, 2.0f, 128)
.cableProperties(V[EV], 1, 1)
Expand Down Expand Up @@ -386,7 +386,7 @@ public static void register() {
GENERATE_SPRING_SMALL, GENERATE_SPRING, EXCLUDE_BLOCK_CRAFTING_BY_HAND_RECIPES,
BLAST_FURNACE_CALCITE_TRIPLE)
.element(Elements.Fe)
.toolStats(ToolProperty.Builder.of(2.0F, 2.0F, 256, 2)
.toolStats(MaterialToolProperty.Builder.of(2.0F, 2.0F, 256, 2)
.enchantability(14).build())
.rotorStats(7.0f, 2.5f, 256)
.cableProperties(V[MV], 2, 3)
Expand Down Expand Up @@ -833,7 +833,7 @@ public static void register() {
.flags(EXT2_METAL, GENERATE_DOUBLE_PLATE, GENERATE_ROTOR, GENERATE_SMALL_GEAR, GENERATE_GEAR,
GENERATE_FRAME)
.element(Elements.Ti)
.toolStats(ToolProperty.Builder.of(8.0F, 6.0F, 1536, 3)
.toolStats(MaterialToolProperty.Builder.of(8.0F, 6.0F, 1536, 3)
.enchantability(14).build())
.rotorStats(7.0f, 3.0f, 1600)
.fluidPipeProperties(2426, 150, true, true, false, false)
Expand Down Expand Up @@ -970,7 +970,7 @@ public static void register() {
.flags(EXT_METAL, GENERATE_BOLT_SCREW, GENERATE_FRAME, GENERATE_GEAR, GENERATE_LONG_ROD,
GENERATE_DOUBLE_PLATE)
.element(Elements.Nt)
.toolStats(ToolProperty.Builder.of(180.0F, 100.0F, 65535, 6)
.toolStats(MaterialToolProperty.Builder.of(180.0F, 100.0F, 65535, 6)
.attackSpeed(0.5F).enchantability(33).magnetic().unbreakable().build())
.rotorStats(24.0f, 12.0f, 655360)
.fluidPipeProperties(100_000, 5000, true, true, true, true)
Expand All @@ -993,7 +993,7 @@ public static void register() {
.color(0x4BAFAF).iconSet(BRIGHT)
.flags(EXT_METAL, GENERATE_FOIL, GENERATE_GEAR, GENERATE_DOUBLE_PLATE)
.element(Elements.Dr)
.toolStats(ToolProperty.Builder.of(14.0F, 12.0F, 8192, 5)
.toolStats(MaterialToolProperty.Builder.of(14.0F, 12.0F, 8192, 5)
.attackSpeed(0.3F).enchantability(33).magnetic().build())
.fluidPipeProperties(9625, 500, true, true, true, true)
.build();
Expand Down
Loading