-
Notifications
You must be signed in to change notification settings - Fork 755
/
BoonOfSssssModifier.java
55 lines (50 loc) · 2.59 KB
/
BoonOfSssssModifier.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
53
54
55
package slimeknights.tconstruct.tools.modifiers.traits.skull;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.MobEffectEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import slimeknights.tconstruct.library.modifiers.ModifierEntry;
import slimeknights.tconstruct.library.modifiers.ModifierHooks;
import slimeknights.tconstruct.library.modifiers.hook.armor.EquipmentChangeModifierHook;
import slimeknights.tconstruct.library.modifiers.impl.NoLevelsModifier;
import slimeknights.tconstruct.library.module.ModuleHookMap.Builder;
import slimeknights.tconstruct.library.tools.context.EquipmentChangeContext;
import slimeknights.tconstruct.library.tools.helper.ModifierUtil;
import slimeknights.tconstruct.library.tools.nbt.IToolStackView;
public class BoonOfSssssModifier extends NoLevelsModifier implements EquipmentChangeModifierHook {
public BoonOfSssssModifier() {
MinecraftForge.EVENT_BUS.addListener(EventPriority.NORMAL, false, MobEffectEvent.Added.class, this::onPotionStart);
}
@Override
protected void registerHooks(Builder hookBuilder) {
super.registerHooks(hookBuilder);
hookBuilder.addHook(this, ModifierHooks.EQUIPMENT_CHANGE);
}
@Override
public void onUnequip(IToolStackView tool, ModifierEntry modifier, EquipmentChangeContext context) {
if (context.getChangedSlot() == EquipmentSlot.HEAD) {
IToolStackView replacement = context.getReplacementTool();
if (replacement == null || replacement.getModifierLevel(this) == 0 || replacement.getItem() != tool.getItem()) {
// cure effects using the helmet
context.getEntity().curePotionEffects(new ItemStack(tool.getItem()));
}
}
}
/** Called when the potion effects start to apply this effect */
private void onPotionStart(MobEffectEvent.Added event) {
MobEffectInstance newEffect = event.getEffectInstance();
if (newEffect.getEffect().isBeneficial() && !newEffect.getCurativeItems().isEmpty()) {
LivingEntity living = event.getEntity();
// strong bones has to be the helmet as we use it for curing
// TODO 1.20: can use the new cure effects to make this work in any slot
ItemStack helmet = living.getItemBySlot(EquipmentSlot.HEAD);
if (ModifierUtil.getModifierLevel(helmet, this.getId()) > 0) {
newEffect.duration *= 1.25f;
newEffect.getCurativeItems().add(new ItemStack(helmet.getItem()));
}
}
}
}