-
Notifications
You must be signed in to change notification settings - Fork 204
Added property for specially registered tools #2693
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ALongStringOfNumbers
merged 15 commits into
GregTechCEu:master
from
littlecube8152:littlecube-soft-tool-fix
Feb 14, 2025
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
26c0c89
Added repairing recipe workaround for specially registered tools
littlecube8152 e908995
add ExtraToolProperty
littlecube8152 b180442
Fixed overriding issue
littlecube8152 05e56fc
Integrated soft tools using the new ExtraToolProperty
littlecube8152 9127765
Obtain markerItem of mallets and plungers from its own get method
littlecube8152 2cfcfdb
Spotless formatting
littlecube8152 c38866d
Change soft tool property registration to already existing method (en…
littlecube8152 09df4b3
Remove accidentally left debugging output
littlecube8152 d61efe3
Fix many properties are not properly overridden
littlecube8152 7169eb8
Add GroovyScript integration
littlecube8152 f1237eb
Fix misleading variable name (toolClass -> toolId)
littlecube8152 5e98391
Merge branch 'master' into littlecube-soft-tool-fix
littlecube8152 b7c6027
Merge branch 'master' into littlecube-soft-tool-fix
littlecube8152 f6ddb77
refactor ToolProperty -> MaterialToolProperty and SimpleToolProperty …
littlecube8152 c22f817
Use actual map methods
littlecube8152 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/gregtech/api/unification/material/materials/SoftToolAddition.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package gregtech.api.unification.material.materials; | ||
|
|
||
| import gregtech.api.items.toolitem.ToolClasses; | ||
| import gregtech.api.recipes.ModHandler; | ||
| import gregtech.api.unification.material.Material; | ||
| import gregtech.api.unification.material.Materials; | ||
| import gregtech.api.unification.material.properties.ExtraToolProperty; | ||
| import gregtech.api.unification.material.properties.PropertyKey; | ||
|
|
||
| public class SoftToolAddition { | ||
|
|
||
| public static final Material[] softMaterials = new Material[] { | ||
| Materials.Wood, Materials.Rubber, Materials.Polyethylene, | ||
| Materials.Polytetrafluoroethylene, Materials.Polybenzimidazole | ||
| }; | ||
|
|
||
| public static void register() { | ||
| for (int i = 0; i < softMaterials.length; i++) { | ||
|
|
||
| Material material = softMaterials[i]; | ||
|
|
||
| if (ModHandler.isMaterialWood(material)) { | ||
| material.getProperties().ensureSet(PropertyKey.EXTRATOOL); | ||
| ExtraToolProperty extraToolProperty = material.getProperty(PropertyKey.EXTRATOOL); | ||
|
|
||
| extraToolProperty.setOverrideProperty(ToolClasses.SOFT_MALLET, | ||
| ExtraToolProperty.Builder.of(4F, 1F, 48, 1).build()); | ||
| } else { | ||
| material.getProperties().ensureSet(PropertyKey.EXTRATOOL); | ||
| ExtraToolProperty extraToolProperty = material.getProperty(PropertyKey.EXTRATOOL); | ||
|
|
||
| extraToolProperty.setOverrideProperty(ToolClasses.SOFT_MALLET, | ||
| ExtraToolProperty.Builder.of(4F, 1F, 128 * (1 << i), 1).build()); | ||
| extraToolProperty.setOverrideProperty(ToolClasses.PLUNGER, | ||
| ExtraToolProperty.Builder.of(4F, 0F, 128 * (1 << i), 1).build()); | ||
| } | ||
| } | ||
| } | ||
| } |
164 changes: 164 additions & 0 deletions
164
src/main/java/gregtech/api/unification/material/properties/ExtraToolProperty.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,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 SimpleToolProperty { | ||
|
|
||
| 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 void setShouldIgnoreCraftingTools(boolean ignore) { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| public void setUnbreakable(boolean isUnbreakable) { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| public boolean isMagnetic() { | ||
| throw new UnsupportedOperationException(); | ||
| } | ||
|
|
||
| private SimpleToolProperty override(@NotNull SimpleToolProperty property) { | ||
| // copy to prevent the previous map is produced | ||
| SimpleToolProperty result = new SimpleToolProperty(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 getOverrideProperty(toolId) != null; | ||
|
||
| } | ||
|
|
||
| public SimpleToolProperty getOverriddenResult(String toolId, @Nullable ToolProperty toolProperty) { | ||
| if (toolProperty == null) toolProperty = new ToolProperty(); | ||
| return overrideMap.getOrDefault(toolId, new OverrideToolProperty()) | ||
| .override(toolProperty); | ||
| } | ||
|
|
||
| @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; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.There was a problem hiding this comment.
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.