-
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.
Implement reflecting modifier for shields
Grants a 2 second window after starting to block in which any projectile is redirected in the direction you look Recipe is the same as bouncy, as its basic
- Loading branch information
1 parent
458ed8f
commit 00d73db
Showing
30 changed files
with
257 additions
and
13 deletions.
There are no files selected for viewing
4 changes: 4 additions & 0 deletions
4
src/generated/resources/data/forge/tags/entity_types/reflecting/blacklist.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,4 @@ | ||
{ | ||
"replace": false, | ||
"values": [] | ||
} |
6 changes: 6 additions & 0 deletions
6
src/generated/resources/data/forge/tags/entity_types/reflecting/preserve_owner.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,6 @@ | ||
{ | ||
"replace": false, | ||
"values": [ | ||
"minecraft:fishing_bobber" | ||
] | ||
} |
6 changes: 6 additions & 0 deletions
6
src/generated/resources/data/parry/tags/items/excluded_shields.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,6 @@ | ||
{ | ||
"replace": false, | ||
"values": [ | ||
"#tconstruct:modifiable/held" | ||
] | ||
} |
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
36 changes: 36 additions & 0 deletions
36
src/generated/resources/data/tconstruct/recipes/tools/modifiers/ability/reflecting.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,36 @@ | ||
{ | ||
"type": "tconstruct:modifier", | ||
"inputs": [ | ||
{ | ||
"item": "tconstruct:sky_congealed_slime", | ||
"amount_needed": 4 | ||
}, | ||
{ | ||
"item": "tconstruct:ichor_congealed_slime", | ||
"amount_needed": 4 | ||
}, | ||
{ | ||
"item": "tconstruct:sky_congealed_slime", | ||
"amount_needed": 4 | ||
}, | ||
{ | ||
"item": "tconstruct:earth_congealed_slime", | ||
"amount_needed": 4 | ||
}, | ||
{ | ||
"item": "tconstruct:earth_congealed_slime", | ||
"amount_needed": 4 | ||
} | ||
], | ||
"tools": { | ||
"tag": "tconstruct:modifiable/shields" | ||
}, | ||
"slots": { | ||
"abilities": 1 | ||
}, | ||
"allow_crystal": true, | ||
"result": { | ||
"name": "tconstruct:reflecting", | ||
"level": 1 | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...nerated/resources/data/tconstruct/recipes/tools/modifiers/salvage/ability/reflecting.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:modifier_salvage", | ||
"tools": { | ||
"tag": "tconstruct:modifiable/shields" | ||
}, | ||
"slots": { | ||
"abilities": 1 | ||
}, | ||
"modifier": "tconstruct:reflecting", | ||
"min_level": 1 | ||
} |
9 changes: 9 additions & 0 deletions
9
src/generated/resources/data/tconstruct/tags/enchantment/modifier_like/reflecting.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,9 @@ | ||
{ | ||
"replace": false, | ||
"values": [ | ||
{ | ||
"id": "parry:rebound", | ||
"required": false | ||
} | ||
] | ||
} |
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
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
83 changes: 83 additions & 0 deletions
83
src/main/java/slimeknights/tconstruct/tools/modifiers/ability/armor/ReflectingModifier.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,83 @@ | ||
package slimeknights.tconstruct.tools.modifiers.ability.armor; | ||
|
||
import net.minecraft.sounds.SoundEvents; | ||
import net.minecraft.sounds.SoundSource; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.entity.projectile.AbstractHurtingProjectile; | ||
import net.minecraft.world.entity.projectile.Projectile; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.UseAnim; | ||
import net.minecraft.world.phys.EntityHitResult; | ||
import net.minecraft.world.phys.HitResult; | ||
import net.minecraft.world.phys.HitResult.Type; | ||
import net.minecraft.world.phys.Vec3; | ||
import net.minecraftforge.common.MinecraftForge; | ||
import net.minecraftforge.event.entity.ProjectileImpactEvent; | ||
import slimeknights.mantle.util.RegistryHelper; | ||
import slimeknights.tconstruct.common.TinkerTags; | ||
import slimeknights.tconstruct.library.modifiers.Modifier; | ||
import slimeknights.tconstruct.library.modifiers.ModifierEntry; | ||
import slimeknights.tconstruct.library.modifiers.TinkerHooks; | ||
import slimeknights.tconstruct.library.modifiers.hook.ConditionalStatModifierHook; | ||
import slimeknights.tconstruct.library.modifiers.hook.interaction.GeneralInteractionModifierHook; | ||
import slimeknights.tconstruct.library.tools.helper.ModifierUtil; | ||
import slimeknights.tconstruct.library.tools.nbt.ToolStack; | ||
import slimeknights.tconstruct.library.tools.stat.ToolStats; | ||
import slimeknights.tconstruct.tools.logic.InteractionHandler; | ||
|
||
public class ReflectingModifier extends Modifier { | ||
public ReflectingModifier() { | ||
MinecraftForge.EVENT_BUS.addListener(this::projectileImpact); | ||
} | ||
|
||
private void projectileImpact(ProjectileImpactEvent event) { | ||
Entity entity = event.getEntity(); | ||
// first, need a projectile that is hitting a living entity | ||
if (!entity.level.isClientSide) { | ||
Projectile projectile = event.getProjectile(); | ||
|
||
// handle blacklist for projectiles | ||
// living entity must be using one of our shields | ||
HitResult hit = event.getRayTraceResult(); | ||
if (!RegistryHelper.contains(TinkerTags.EntityTypes.REFLECTING_BLACKLIST, projectile.getType()) | ||
&& hit.getType() == Type.ENTITY && ((EntityHitResult) hit).getEntity() instanceof LivingEntity living && living.isUsingItem()) { | ||
ItemStack stack = living.getUseItem(); | ||
if (stack.is(TinkerTags.Items.SHIELDS)) { | ||
ToolStack tool = ToolStack.from(stack); | ||
|
||
// only support the new hook for blocking, the old hook is a pain | ||
ModifierEntry activeModifier = ModifierUtil.getActiveModifier(tool); | ||
if (activeModifier != null) { | ||
GeneralInteractionModifierHook hook = activeModifier.getHook(TinkerHooks.CHARGEABLE_INTERACT); | ||
int time = hook.getUseDuration(tool, activeModifier) - living.getUseItemRemainingTicks(); | ||
// must be blocking, started blocking within the last 2*level seconds, and be within the block angle | ||
if (hook.getUseAction(tool, activeModifier) == UseAnim.BLOCK | ||
&& (time >= 5 && time < 40 * activeModifier.getLevel()) | ||
&& InteractionHandler.canBlock(living, projectile.position(), tool)) { | ||
|
||
// time to actually reflect, this code is strongly based on code from the Parry mod | ||
// take ownership of the projectile so it counts as a player kill, except in the case of fishing bobbers | ||
if (!RegistryHelper.contains(TinkerTags.EntityTypes.REFLECTING_PRESERVE_OWNER, projectile.getType())) { | ||
projectile.setOwner(living); | ||
projectile.leftOwner = true; | ||
} | ||
|
||
Vec3 reboundAngle = living.getLookAngle(); | ||
// use the shield accuracy and velocity stats when reflecting | ||
float velocity = ConditionalStatModifierHook.getModifiedStat(tool, living, ToolStats.VELOCITY) * 1.1f; | ||
projectile.shoot(reboundAngle.x, reboundAngle.y, reboundAngle.z, velocity, ModifierUtil.getInaccuracy(tool, living, (float)(velocity * projectile.getDeltaMovement().length()))); | ||
if (projectile instanceof AbstractHurtingProjectile hurting) { | ||
hurting.xPower = reboundAngle.x * 0.1; | ||
hurting.yPower = reboundAngle.y * 0.1; | ||
hurting.zPower = reboundAngle.z * 0.1; | ||
} | ||
living.level.playSound(null, living.blockPosition(), SoundEvents.SHIELD_BLOCK, SoundSource.PLAYERS, 1.0F, 1.5F + living.level.random.nextFloat() * 0.4F); | ||
event.setCanceled(true); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.