-
Notifications
You must be signed in to change notification settings - Fork 755
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Generalize arrow launch into projectile launch
Will help for launching fireworks eventually
- Loading branch information
1 parent
a6bedfb
commit f93fa5d
Showing
11 changed files
with
99 additions
and
79 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
40 changes: 0 additions & 40 deletions
40
src/main/java/slimeknights/tconstruct/library/modifiers/hook/ArrowLaunchModifierHook.java
This file was deleted.
Oops, something went wrong.
43 changes: 43 additions & 0 deletions
43
...ain/java/slimeknights/tconstruct/library/modifiers/hook/ProjectileLaunchModifierHook.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,43 @@ | ||
package slimeknights.tconstruct.library.modifiers.hook; | ||
|
||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.projectile.AbstractArrow; | ||
import net.minecraft.world.entity.projectile.Projectile; | ||
import slimeknights.tconstruct.library.modifiers.ModifierEntry; | ||
import slimeknights.tconstruct.library.tools.nbt.IToolStackView; | ||
import slimeknights.tconstruct.library.tools.nbt.NamespacedNBT; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.Collection; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* Hook for modifiers which wish to modify an arrow before its fired | ||
*/ | ||
public interface ProjectileLaunchModifierHook { | ||
/** Default instance */ | ||
ProjectileLaunchModifierHook EMPTY = (tool, modifier, shooter, projectile, arrow, persistentData) -> {}; | ||
/** Merger instance */ | ||
Function<Collection<ProjectileLaunchModifierHook>,ProjectileLaunchModifierHook> ALL_MERGER = AllMerger::new; | ||
|
||
/** | ||
* Hook to modify arrow properties after an arrow is fired. Called serverside only, so randomness is safe. | ||
* @param tool Bow instance | ||
* @param modifier Modifier being used | ||
* @param shooter Entity firing the arrow | ||
* @param projectile Projectile to modify | ||
* @param arrow Arrow to modify as most modifiers wish to change that, will be null for non-arrow projectiles | ||
* @param persistentData Persistent data instance stored on the arrow to write arbitrary data. Note the modifier list was already written | ||
*/ | ||
void onProjectileLaunch(IToolStackView tool, ModifierEntry modifier, LivingEntity shooter, Projectile projectile, @Nullable AbstractArrow arrow, NamespacedNBT persistentData); | ||
|
||
/** Logic to merge multiple hooks into one */ | ||
record AllMerger(Collection<ProjectileLaunchModifierHook> modules) implements ProjectileLaunchModifierHook { | ||
@Override | ||
public void onProjectileLaunch(IToolStackView tool, ModifierEntry modifier, LivingEntity shooter, Projectile projectile, @Nullable AbstractArrow arrow, NamespacedNBT persistentData) { | ||
for (ProjectileLaunchModifierHook module : modules) { | ||
module.onProjectileLaunch(tool, modifier, shooter, projectile, arrow, persistentData); | ||
} | ||
} | ||
} | ||
} |
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
Oops, something went wrong.