Skip to content

Commit

Permalink
Disallow boon of sssss and strong bones from working on non-helmets
Browse files Browse the repository at this point in the history
While cleaning this up in the breaking changes branch, noticed a couple of bugs that would happen if used on other slots so figured switching to the simplier logic with the limited slot is the best play here

* Boon of Sssss and Strong Bones both are restricted to helmets in implementation now, as they had some functionality that required hemets anyways
  • Loading branch information
KnightMiner committed Mar 11, 2024
1 parent eda8b43 commit 7e5cf12
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,40 +7,39 @@
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.PotionEvent;
import net.minecraftforge.eventbus.api.EventPriority;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.library.modifiers.impl.TotalArmorLevelModifier;
import slimeknights.tconstruct.library.tools.capability.TinkerDataCapability.TinkerDataKey;
import slimeknights.tconstruct.library.modifiers.impl.NoLevelsModifier;
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 TotalArmorLevelModifier {
private static final TinkerDataKey<Integer> POTENT_POTIONS = TConstruct.createKey("boon_of_sssss");
public class BoonOfSssssModifier extends NoLevelsModifier {
public BoonOfSssssModifier() {
super(POTENT_POTIONS, true);
MinecraftForge.EVENT_BUS.addListener(EventPriority.NORMAL, false, PotionEvent.PotionAddedEvent.class, BoonOfSssssModifier::onPotionStart);
MinecraftForge.EVENT_BUS.addListener(EventPriority.NORMAL, false, PotionEvent.PotionAddedEvent.class, this::onPotionStart);
}

@Override
public void onUnequip(IToolStackView tool, int level, EquipmentChangeContext context) {
super.onUnequip(tool, level, context);
if (context.getChangedSlot() == EquipmentSlot.HEAD) {
IToolStackView replacement = context.getReplacementTool();
if (replacement == null || replacement.getModifierLevel(this) == 0) {
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 static void onPotionStart(PotionEvent.PotionAddedEvent event) {
private void onPotionStart(PotionEvent.PotionAddedEvent event) {
MobEffectInstance newEffect = event.getPotionEffect();
if (newEffect.getEffect().isBeneficial() && !newEffect.getCurativeItems().isEmpty()) {
LivingEntity living = event.getEntityLiving();
if (ModifierUtil.getTotalModifierLevel(living, POTENT_POTIONS) > 0) {
// 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(living.getItemBySlot(EquipmentSlot.HEAD).getItem()));
newEffect.getCurativeItems().add(new ItemStack(helmet.getItem()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.fluids.FluidStack;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.library.modifiers.impl.TotalArmorLevelModifier;
import slimeknights.tconstruct.library.modifiers.impl.NoLevelsModifier;
import slimeknights.tconstruct.library.modifiers.spilling.ISpillingEffect;
import slimeknights.tconstruct.library.tools.capability.TinkerDataCapability.TinkerDataKey;
import slimeknights.tconstruct.library.tools.context.EquipmentChangeContext;
Expand All @@ -25,12 +25,10 @@
import slimeknights.tconstruct.library.utils.JsonUtils;
import slimeknights.tconstruct.tools.TinkerModifiers;

public class StrongBonesModifier extends TotalArmorLevelModifier {
private static final TinkerDataKey<Integer> STRONG_BONES = TConstruct.createKey("strong_bones");
public class StrongBonesModifier extends NoLevelsModifier {
/** Key for modifiers that are boosted by drinking milk */
public static final TinkerDataKey<Integer> CALCIFIABLE = TConstruct.createKey("calcifable");
public StrongBonesModifier() {
super(STRONG_BONES, true);
MinecraftForge.EVENT_BUS.addListener(EventPriority.NORMAL, false, LivingEntityUseItemEvent.Finish.class, StrongBonesModifier::onItemFinishUse);
}

Expand All @@ -39,18 +37,21 @@ public void onUnequip(IToolStackView tool, int level, EquipmentChangeContext con
super.onUnequip(tool, level, context);
if (context.getChangedSlot() == EquipmentSlot.HEAD) {
IToolStackView replacement = context.getReplacementTool();
if (replacement == null || replacement.getModifierLevel(this) == 0) {
if (replacement == null || replacement.getModifierLevel(this) == 0 || replacement.getItem() != tool.getItem()) {
// cure effects using the helmet
context.getEntity().curePotionEffects(new ItemStack(tool.getItem()));
}
}
}

private static void drinkMilk(LivingEntity living, int duration) {
if (ModifierUtil.getTotalModifierLevel(living, STRONG_BONES) > 0) {
// 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, TinkerModifiers.strongBones.getId()) > 0) {
MobEffectInstance effect = new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, duration);
effect.getCurativeItems().clear();
effect.getCurativeItems().add(new ItemStack(living.getItemBySlot(EquipmentSlot.HEAD).getItem()));
effect.getCurativeItems().add(new ItemStack(helmet.getItem()));
living.addEffect(effect);
}
if (ModifierUtil.getTotalModifierLevel(living, CALCIFIABLE) > 0) {
Expand Down

0 comments on commit 7e5cf12

Please sign in to comment.