-
Notifications
You must be signed in to change notification settings - Fork 754
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Migrate repair factor to a modifier hook
Added repair modifier module to increase/decrease repair amount] Migrate cultivated to dynamic modifiers Added 50% repair efficiency bonus to the emerald modifier
- Loading branch information
1 parent
99af4c5
commit 09626c7
Showing
16 changed files
with
145 additions
and
29 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/generated/resources/data/tconstruct/tinkering/modifiers/cultivated.json
This file contains 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,11 @@ | ||
{ | ||
"type": "tconstruct:composable", | ||
"level_display": "tconstruct:default", | ||
"tooltip_display": "always", | ||
"modules": [ | ||
{ | ||
"type": "tconstruct:repair", | ||
"leveling": 0.5 | ||
} | ||
] | ||
} |
This file contains 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 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 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
29 changes: 29 additions & 0 deletions
29
src/main/java/slimeknights/tconstruct/library/modifiers/hook/RepairFactorModifierHook.java
This file contains 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,29 @@ | ||
package slimeknights.tconstruct.library.modifiers.hook; | ||
|
||
import slimeknights.tconstruct.library.modifiers.ModifierEntry; | ||
import slimeknights.tconstruct.library.tools.nbt.IToolStackView; | ||
|
||
import java.util.Collection; | ||
|
||
/** Hook called when repairing a tool to allow modifiers to adjust repair amount */ | ||
public interface RepairFactorModifierHook { | ||
/** | ||
* Called when the tool is repair. Can be used to decrease, increase, or cancel the repair. | ||
* @param tool Tool stack | ||
* @param entry Modifier and level | ||
* @param factor Original factor | ||
* @return Replacement factor. Returning 0 prevents repair | ||
*/ | ||
float getRepairFactor(IToolStackView tool, ModifierEntry entry, float factor); | ||
|
||
/** Merger that composes all submodules */ | ||
record ComposeMerger(Collection<RepairFactorModifierHook> modules) implements RepairFactorModifierHook { | ||
@Override | ||
public float getRepairFactor(IToolStackView tool, ModifierEntry entry, float factor) { | ||
for (RepairFactorModifierHook module : modules) { | ||
factor = module.getRepairFactor(tool, entry, factor); | ||
} | ||
return factor; | ||
} | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/slimeknights/tconstruct/library/modifiers/modules/RepairModule.java
This file contains 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,77 @@ | ||
package slimeknights.tconstruct.library.modifiers.modules; | ||
|
||
import com.google.gson.JsonObject; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.util.GsonHelper; | ||
import slimeknights.mantle.data.GenericLoaderRegistry.IGenericLoader; | ||
import slimeknights.tconstruct.library.modifiers.ModifierEntry; | ||
import slimeknights.tconstruct.library.modifiers.ModifierHook; | ||
import slimeknights.tconstruct.library.modifiers.TinkerHooks; | ||
import slimeknights.tconstruct.library.modifiers.hook.RepairFactorModifierHook; | ||
import slimeknights.tconstruct.library.tools.nbt.IToolStackView; | ||
|
||
import java.util.List; | ||
|
||
/** Module for multiplying tool repair */ | ||
public record RepairModule(float flat, float leveling) implements RepairFactorModifierHook, ModifierModule { | ||
private static final List<ModifierHook<?>> DEFAULT_HOOKS = List.of(TinkerHooks.REPAIR_FACTOR); | ||
|
||
@Override | ||
public float getRepairFactor(IToolStackView tool, ModifierEntry entry, float factor) { | ||
factor *= (1 + (entry.getEffectiveLevel(tool) * leveling) + flat); | ||
return factor; | ||
} | ||
|
||
@Override | ||
public List<ModifierHook<?>> getDefaultHooks() { | ||
return DEFAULT_HOOKS; | ||
} | ||
|
||
@Override | ||
public IGenericLoader<? extends ModifierModule> getLoader() { | ||
return LOADER; | ||
} | ||
|
||
public static final IGenericLoader<RepairModule> LOADER = new IGenericLoader<>() { | ||
@Override | ||
public RepairModule deserialize(JsonObject json) { | ||
float flat = GsonHelper.getAsFloat(json, "flat", 0); | ||
float leveling = GsonHelper.getAsFloat(json, "leveling", 0); | ||
return new RepairModule(flat, leveling); | ||
} | ||
|
||
@Override | ||
public void serialize(RepairModule object, JsonObject json) { | ||
if (object.flat != 0) { | ||
json.addProperty("flat", object.flat); | ||
} | ||
if (object.leveling != 0) { | ||
json.addProperty("leveling", object.leveling); | ||
} | ||
} | ||
|
||
@Override | ||
public RepairModule fromNetwork(FriendlyByteBuf buffer) { | ||
float flat = buffer.readFloat(); | ||
float leveling = buffer.readFloat(); | ||
return new RepairModule(flat, leveling); | ||
} | ||
|
||
@Override | ||
public void toNetwork(RepairModule object, FriendlyByteBuf buffer) { | ||
buffer.writeFloat(object.flat); | ||
buffer.writeFloat(object.leveling); | ||
} | ||
}; | ||
|
||
|
||
/* Helpers */ | ||
|
||
public static RepairModule flat(float value) { | ||
return new RepairModule(value, 0); | ||
} | ||
|
||
public static RepairModule leveling(float leveling) { | ||
return new RepairModule(0, leveling); | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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 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 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
12 changes: 0 additions & 12 deletions
12
src/main/java/slimeknights/tconstruct/tools/modifiers/traits/general/CultivatedModifier.java
This file was deleted.
Oops, something went wrong.