-
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.
Mingrate block breaking modifier methods to hooks
- Loading branch information
1 parent
c52d82c
commit 0ab41df
Showing
11 changed files
with
198 additions
and
58 deletions.
There are no files selected for viewing
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
34 changes: 34 additions & 0 deletions
34
...in/java/slimeknights/tconstruct/library/modifiers/hook/mining/BlockBreakModifierHook.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,34 @@ | ||
package slimeknights.tconstruct.library.modifiers.hook.mining; | ||
|
||
import slimeknights.tconstruct.library.modifiers.ModifierEntry; | ||
import slimeknights.tconstruct.library.tools.context.ToolHarvestContext; | ||
import slimeknights.tconstruct.library.tools.nbt.IToolStackView; | ||
|
||
import java.util.Collection; | ||
|
||
/** Hook called after a block is broken by a modifier. Called for every block broken by an AOE tool. */ | ||
public interface BlockBreakModifierHook { | ||
/** | ||
* Called after a block is broken to apply special effects | ||
* <br> | ||
* Alternatives: | ||
* <ul> | ||
* <li>{@link RemoveBlockModifierHook}: Called before the block is set to air.</li> | ||
* <li>{@link FinishHarvestModifierHook}: Called after all blocks are broken instead of per block.</li> | ||
* </ul> | ||
* @param tool Tool used | ||
* @param modifier Modifier level | ||
* @param context Harvest context | ||
*/ | ||
void afterBlockBreak(IToolStackView tool, ModifierEntry modifier, ToolHarvestContext context); | ||
|
||
/** Merger that runs all nested hooks */ | ||
record AllMerger(Collection<BlockBreakModifierHook> modules) implements BlockBreakModifierHook { | ||
@Override | ||
public void afterBlockBreak(IToolStackView tool, ModifierEntry modifier, ToolHarvestContext context) { | ||
for (BlockBreakModifierHook module : modules) { | ||
module.afterBlockBreak(tool, modifier, context); | ||
} | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...in/java/slimeknights/tconstruct/library/modifiers/hook/mining/BreakSpeedModifierHook.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,38 @@ | ||
package slimeknights.tconstruct.library.modifiers.hook.mining; | ||
|
||
import net.minecraft.core.Direction; | ||
import net.minecraftforge.event.entity.player.PlayerEvent.BreakSpeed; | ||
import slimeknights.tconstruct.library.modifiers.ModifierEntry; | ||
import slimeknights.tconstruct.library.tools.nbt.IToolStackView; | ||
|
||
import java.util.Collection; | ||
|
||
/** Hook used to increase mining speed of a block conditioned on the environment or the player */ | ||
public interface BreakSpeedModifierHook { | ||
/** | ||
* Called when break speed is being calculated to affect mining speed conditionally. | ||
* <br> | ||
* Alternatives: | ||
* <ul> | ||
* <li>{@link slimeknights.tconstruct.library.modifiers.hook.build.ToolStatsModifierHook}: Limited context, but effect shows in the tooltip automatically.</li> | ||
* <li>{@link slimeknights.tconstruct.library.modifiers.hook.TooltipModifierHook}: Allows adding bonus effects to the tooltip.</li> | ||
* </ul> | ||
* @param tool Current tool instance | ||
* @param modifier Modifier level | ||
* @param event Event instance | ||
* @param sideHit Side of the block that was hit | ||
* @param isEffective If true, the tool is effective against this block type | ||
* @param miningSpeedModifier Calculated modifier from potion effects such as haste and environment such as water, use for additive bonuses to ensure consistency with the mining speed stat | ||
*/ | ||
void onBreakSpeed(IToolStackView tool, ModifierEntry modifier, BreakSpeed event, Direction sideHit, boolean isEffective, float miningSpeedModifier); | ||
|
||
/** Merger that runs each hook in succession */ | ||
record AllMerger(Collection<BreakSpeedModifierHook> modules) implements BreakSpeedModifierHook { | ||
@Override | ||
public void onBreakSpeed(IToolStackView tool, ModifierEntry modifier, BreakSpeed event, Direction sideHit, boolean isEffective, float miningSpeedModifier) { | ||
for (BreakSpeedModifierHook module : modules) { | ||
module.onBreakSpeed(tool, modifier, event, sideHit, isEffective, miningSpeedModifier); | ||
} | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...java/slimeknights/tconstruct/library/modifiers/hook/mining/FinishHarvestModifierHook.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,33 @@ | ||
package slimeknights.tconstruct.library.modifiers.hook.mining; | ||
|
||
import slimeknights.tconstruct.library.modifiers.ModifierEntry; | ||
import slimeknights.tconstruct.library.tools.context.ToolHarvestContext; | ||
import slimeknights.tconstruct.library.tools.nbt.IToolStackView; | ||
|
||
import java.util.Collection; | ||
|
||
/** Hook called after a tool completes breaking all blocks in its AOE */ | ||
public interface FinishHarvestModifierHook { | ||
/** | ||
* Called after all blocks are broken on the target block | ||
* <br> | ||
* Alternatives: | ||
* <ul> | ||
* <li>{@link BlockBreakModifierHook}: Called after each individual block is broken.</li> | ||
* </ul> | ||
* @param tool Tool used | ||
* @param modifier Modifier level | ||
* @param context Harvest context | ||
*/ | ||
void finishHarvest(IToolStackView tool, ModifierEntry modifier, ToolHarvestContext context); | ||
|
||
/** Merger that runs all submodules */ | ||
record AllMerger(Collection<FinishHarvestModifierHook> modules) implements FinishHarvestModifierHook { | ||
@Override | ||
public void finishHarvest(IToolStackView tool, ModifierEntry modifier, ToolHarvestContext context) { | ||
for (FinishHarvestModifierHook module : modules) { | ||
module.finishHarvest(tool, modifier, context); | ||
} | ||
} | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
...n/java/slimeknights/tconstruct/library/modifiers/hook/mining/RemoveBlockModifierHook.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,41 @@ | ||
package slimeknights.tconstruct.library.modifiers.hook.mining; | ||
|
||
import slimeknights.tconstruct.library.modifiers.ModifierEntry; | ||
import slimeknights.tconstruct.library.tools.context.ToolHarvestContext; | ||
import slimeknights.tconstruct.library.tools.nbt.IToolStackView; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.Collection; | ||
|
||
/** Hook called when a block is removed to allow the modifier to control the details of the block's removal. */ | ||
public interface RemoveBlockModifierHook { | ||
/** | ||
* Removes the block from the world | ||
* <br> | ||
* Alternatives: | ||
* <ul> | ||
* <li>{@link BlockBreakModifierHook}: Called after the block is successfully removed.</li> | ||
* </ul> | ||
* @param tool Tool used | ||
* @param modifier Modifier level | ||
* @param context Harvest context | ||
* @return True to override the default block removing logic and stop all later modifiers from running. False to override default without breaking the block. Null to let default logic run | ||
*/ | ||
@Nullable | ||
Boolean removeBlock(IToolStackView tool, ModifierEntry modifier, ToolHarvestContext context); | ||
|
||
/** Merger that returns when the first hook finishes the action */ | ||
record FirstMerger(Collection<RemoveBlockModifierHook> modules) implements RemoveBlockModifierHook { | ||
@Nullable | ||
@Override | ||
public Boolean removeBlock(IToolStackView tool, ModifierEntry modifier, ToolHarvestContext context) { | ||
for (RemoveBlockModifierHook module : modules) { | ||
Boolean handled = module.removeBlock(tool, modifier, context); | ||
if (handled != null) { | ||
return handled; | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/slimeknights/tconstruct/library/modifiers/hook/mining/package-info.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,7 @@ | ||
@ParametersAreNonnullByDefault | ||
@MethodsReturnNonnullByDefault | ||
package slimeknights.tconstruct.library.modifiers.hook.mining; | ||
|
||
import net.minecraft.MethodsReturnNonnullByDefault; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; |
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