Skip to content

Commit

Permalink
DRY some damage related code in manaweave helm
Browse files Browse the repository at this point in the history
Why is the cost differnt anyways?
  • Loading branch information
williewillus committed Nov 22, 2023
1 parent 1244bd1 commit 453282b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@

public class ManasteelArmorItem extends ArmorItem implements CustomDamageItem, PhantomInkable {

private static final int MANA_PER_DAMAGE = 70;

private static final String TAG_PHANTOM_INK = "phantomInk";

public final Type type;
Expand All @@ -61,15 +59,19 @@ public ManasteelArmorItem(Type type, ArmorMaterial mat, Properties props) {
@Override
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
if (entity instanceof Player player) {
if (!world.isClientSide && stack.getDamageValue() > 0 && ManaItemHandler.instance().requestManaExact(stack, player, MANA_PER_DAMAGE * 2, true)) {
if (!world.isClientSide && stack.getDamageValue() > 0 && ManaItemHandler.instance().requestManaExact(stack, player, getManaPerDamage() * 2, true)) {
stack.setDamageValue(stack.getDamageValue() - 1);
}
}
}

@Override
public <T extends LivingEntity> int damageItem(ItemStack stack, int amount, T entity, Consumer<T> onBroken) {
return ToolCommons.damageItemIfPossible(stack, amount, entity, MANA_PER_DAMAGE);
return ToolCommons.damageItemIfPossible(stack, amount, entity, getManaPerDamage());
}

protected int getManaPerDamage() {
return 70;
}

@SoftImplement("IForgeItem")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,17 @@
*/
package vazkii.botania.common.item.equipment.armor.manaweave;

import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;

import org.jetbrains.annotations.Nullable;

import vazkii.botania.api.item.ManaProficiencyArmor;
import vazkii.botania.api.mana.ManaDiscountArmor;
import vazkii.botania.api.mana.ManaItemHandler;
import vazkii.botania.common.item.equipment.tool.ToolCommons;

import java.util.function.Consumer;

public class ManaweaveHelmItem extends ManaweaveArmorItem implements ManaDiscountArmor, ManaProficiencyArmor {

private static final int MANA_PER_DAMAGE = 30;

public ManaweaveHelmItem(Properties props) {
super(Type.HELMET, props);
}
Expand All @@ -43,16 +34,7 @@ public boolean shouldGiveProficiency(ItemStack stack, EquipmentSlot slot, Player
}

@Override
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
if (entity instanceof Player player) {
if (!world.isClientSide && stack.getDamageValue() > 0 && ManaItemHandler.instance().requestManaExact(stack, player, MANA_PER_DAMAGE * 2, true)) {
stack.setDamageValue(stack.getDamageValue() - 1);
}
}
}

@Override
public <T extends LivingEntity> int damageItem(ItemStack stack, int amount, T entity, Consumer<T> onBroken) {
return ToolCommons.damageItemIfPossible(stack, amount, entity, MANA_PER_DAMAGE);
protected int getManaPerDamage() {
return 30;
}
}

0 comments on commit 453282b

Please sign in to comment.