~williewillus/botania

453282b6d039ab6d9a77efd005c2976b5fbcd287 — Vincent Lee 4 months ago 1244bd1
DRY some damage related code in manaweave helm

Why is the cost differnt anyways?
M Xplat/src/main/java/vazkii/botania/common/item/equipment/armor/manasteel/ManasteelArmorItem.java => Xplat/src/main/java/vazkii/botania/common/item/equipment/armor/manasteel/ManasteelArmorItem.java +6 -4
@@ 43,8 43,6 @@ import java.util.function.Supplier;

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;


@@ 61,7 59,7 @@ public class ManasteelArmorItem extends ArmorItem implements CustomDamageItem, P
	@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);
			}
		}


@@ 69,7 67,11 @@ public class ManasteelArmorItem extends ArmorItem implements CustomDamageItem, P

	@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")

M Xplat/src/main/java/vazkii/botania/common/item/equipment/armor/manaweave/ManaweaveHelmItem.java => Xplat/src/main/java/vazkii/botania/common/item/equipment/armor/manaweave/ManaweaveHelmItem.java +2 -20
@@ 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);
	}


@@ 43,16 34,7 @@ public class ManaweaveHelmItem extends ManaweaveArmorItem implements ManaDiscoun
	}

	@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;
	}
}