-
Notifications
You must be signed in to change notification settings - Fork 752
/
FieryModifier.java
52 lines (46 loc) · 2.19 KB
/
FieryModifier.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package slimeknights.tconstruct.tools.modifiers.upgrades.melee;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.projectile.AbstractArrow;
import slimeknights.tconstruct.library.modifiers.ModifierEntry;
import slimeknights.tconstruct.library.modifiers.TinkerHooks;
import slimeknights.tconstruct.library.modifiers.hook.ArrowLaunchModifierHook;
import slimeknights.tconstruct.library.modifiers.impl.IncrementalModifier;
import slimeknights.tconstruct.library.modifiers.util.ModifierHookMap.Builder;
import slimeknights.tconstruct.library.tools.context.ToolAttackContext;
import slimeknights.tconstruct.library.tools.nbt.IToolStackView;
import slimeknights.tconstruct.library.tools.nbt.NamespacedNBT;
public class FieryModifier extends IncrementalModifier implements ArrowLaunchModifierHook {
@Override
protected void registerHooks(Builder hookBuilder) {
hookBuilder.addHook(this, TinkerHooks.ARROW_LAUNCH);
}
@Override
public float beforeEntityHit(IToolStackView tool, int level, ToolAttackContext context, float damage, float baseKnockback, float knockback) {
// vanilla hack: apply fire so the entity drops the proper items on instant kill
LivingEntity target = context.getLivingTarget();
if (target != null && !target.isOnFire()) {
target.setRemainingFireTicks(1);
}
return knockback;
}
@Override
public void failedEntityHit(IToolStackView tool, int level, ToolAttackContext context) {
// conclusion of vanilla hack: we don't want the target on fire if we did not hit them
LivingEntity target = context.getLivingTarget();
if (target != null && target.isOnFire()) {
target.clearFire();
}
}
@Override
public int afterEntityHit(IToolStackView tool, int level, ToolAttackContext context, float damageDealt) {
LivingEntity target = context.getLivingTarget();
if (target != null) {
target.setSecondsOnFire(Math.round(getEffectiveLevel(tool, level) * 5));
}
return 0;
}
@Override
public void onArrowLaunch(IToolStackView tool, ModifierEntry modifier, LivingEntity shooter, AbstractArrow arrow, NamespacedNBT persistentData) {
arrow.setSecondsOnFire(Math.round(modifier.getEffectiveLevel(tool) * 20));
}
}