From 8d68aa5777db2d348282c2d13daa8018e8061a8b Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 2 Mar 2023 14:40:57 +0100 Subject: [PATCH] soulstrider armor effects --- .../naturesaura/items/tools/ItemArmor.java | 18 +++++++++++++----- .../naturesaura/reg/ModArmorMaterial.java | 12 +++++++----- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/ellpeck/naturesaura/items/tools/ItemArmor.java b/src/main/java/de/ellpeck/naturesaura/items/tools/ItemArmor.java index 40f5913d..0b3da2d2 100644 --- a/src/main/java/de/ellpeck/naturesaura/items/tools/ItemArmor.java +++ b/src/main/java/de/ellpeck/naturesaura/items/tools/ItemArmor.java @@ -12,7 +12,10 @@ import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.ai.attributes.Attributes; +import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.*; +import net.minecraft.world.phys.AABB; +import net.minecraft.world.phys.Vec3; import net.minecraftforge.common.capabilities.ICapabilityProvider; import net.minecraftforge.event.TickEvent; import net.minecraftforge.event.entity.living.LivingAttackEvent; @@ -70,11 +73,16 @@ public class ItemArmor extends ArmorItem implements IModItem { public static void onAttack(LivingAttackEvent event) { var entity = event.getEntity(); if (!entity.level.isClientSide) { - if (!ItemArmor.isFullSetEquipped(entity, ModArmorMaterial.INFUSED)) - return; - var source = event.getSource().getEntity(); - if (source instanceof LivingEntity) - ((LivingEntity) source).addEffect(new MobEffectInstance(MobEffects.WITHER, 40)); + if (ItemArmor.isFullSetEquipped(entity, ModArmorMaterial.INFUSED)) { + var source = event.getSource().getEntity(); + if (source instanceof LivingEntity) + ((LivingEntity) source).addEffect(new MobEffectInstance(MobEffects.WITHER, 40)); + } else if (ItemArmor.isFullSetEquipped(entity, ModArmorMaterial.DEPTH)) { + for (var other : entity.level.getEntitiesOfClass(LivingEntity.class, new AABB(entity.position(), Vec3.ZERO).inflate(2))) { + if (other != entity && (!(other instanceof Player otherPlayer) || !otherPlayer.isAlliedTo(entity))) + other.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 60, 255)); + } + } } } diff --git a/src/main/java/de/ellpeck/naturesaura/reg/ModArmorMaterial.java b/src/main/java/de/ellpeck/naturesaura/reg/ModArmorMaterial.java index cd9140b2..e5a41654 100644 --- a/src/main/java/de/ellpeck/naturesaura/reg/ModArmorMaterial.java +++ b/src/main/java/de/ellpeck/naturesaura/reg/ModArmorMaterial.java @@ -15,9 +15,9 @@ import java.util.function.Supplier; public enum ModArmorMaterial implements ArmorMaterial { - INFUSED(NaturesAura.MOD_ID + ":infused_iron", 19, new int[]{2, 5, 6, 2}, 16, SoundEvents.ARMOR_EQUIP_IRON, 0, () -> Ingredient.of(ModItems.INFUSED_IRON)), - SKY(NaturesAura.MOD_ID + ":sky", 33, new int[]{3, 6, 8, 3}, 12, SoundEvents.ARMOR_EQUIP_DIAMOND, 2, () -> Ingredient.of(ModItems.SKY_INGOT)), - DEPTH(NaturesAura.MOD_ID + ":depth", 37, new int[]{3, 6, 8, 3}, 18, SoundEvents.ARMOR_EQUIP_NETHERITE, 3, () -> Ingredient.of(ModItems.DEPTH_INGOT)); + INFUSED(NaturesAura.MOD_ID + ":infused_iron", 19, new int[]{2, 5, 6, 2}, 16, SoundEvents.ARMOR_EQUIP_IRON, 0, 0, () -> Ingredient.of(ModItems.INFUSED_IRON)), + SKY(NaturesAura.MOD_ID + ":sky", 33, new int[]{3, 6, 8, 3}, 12, SoundEvents.ARMOR_EQUIP_DIAMOND, 2, 0, () -> Ingredient.of(ModItems.SKY_INGOT)), + DEPTH(NaturesAura.MOD_ID + ":depth", 37, new int[]{3, 6, 8, 3}, 18, SoundEvents.ARMOR_EQUIP_NETHERITE, 3, 1, () -> Ingredient.of(ModItems.DEPTH_INGOT)); private static final int[] MAX_DAMAGE_ARRAY = {13, 15, 16, 11}; private final String name; @@ -26,15 +26,17 @@ public enum ModArmorMaterial implements ArmorMaterial { private final int enchantability; private final SoundEvent soundEvent; private final float toughness; + private final float knockbackResistance; private final Lazy repairMaterial; - ModArmorMaterial(String nameIn, int maxDamageFactorIn, int[] damageReductionAmountsIn, int enchantabilityIn, SoundEvent equipSoundIn, float toughness, Supplier repairMaterialSupplier) { + ModArmorMaterial(String nameIn, int maxDamageFactorIn, int[] damageReductionAmountsIn, int enchantabilityIn, SoundEvent equipSoundIn, float toughness, float knockbackResistance, Supplier repairMaterialSupplier) { this.name = nameIn; this.maxDamageFactor = maxDamageFactorIn; this.damageReductionAmountArray = damageReductionAmountsIn; this.enchantability = enchantabilityIn; this.soundEvent = equipSoundIn; this.toughness = toughness; + this.knockbackResistance = knockbackResistance; this.repairMaterial = Lazy.of(repairMaterialSupplier); } @@ -76,6 +78,6 @@ public enum ModArmorMaterial implements ArmorMaterial { @Override public float getKnockbackResistance() { - return 0; + return this.knockbackResistance; } }