Enhanced StaliniumSwordItem mechanics. Buffed player and nearby allies on hit. Added passive resistance effect when health is low. Removed unused postHurtEnemy method.

This commit is contained in:
IM23a-spirgif
2025-05-26 11:23:09 +02:00
parent b5dcdabcc1
commit 8f888887a1
@@ -1,14 +1,16 @@
package net.krituximon.stalinium.item; package net.krituximon.stalinium.item;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.world.entity.Entity;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player; import net.minecraft.world.entity.player.Player;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.item.SwordItem; import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier; import net.minecraft.world.item.Tier;
import net.minecraft.world.level.Level; import net.minecraft.world.level.Level;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.phys.AABB;
import java.util.List; import java.util.List;
@@ -19,18 +21,41 @@ public class StaliniumSwordItem extends SwordItem {
@Override @Override
public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) { public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
if (!attacker.getCommandSenderWorld().isClientSide) {
MobEffectInstance strength = new MobEffectInstance(MobEffects.DAMAGE_BOOST, 100, 0, false, true);
attacker.addEffect(strength);
Level world = attacker.getCommandSenderWorld(); Level world = attacker.getCommandSenderWorld();
var box = attacker.getBoundingBox().inflate(5.0); if (!world.isClientSide && attacker instanceof Player player) {
List<Player> nearby = world.getEntitiesOfClass(Player.class, box, p -> p instanceof ServerPlayer && attacker.isAlliedTo(p)); player.addEffect(new MobEffectInstance(MobEffects.DAMAGE_BOOST, 100, 1, false, true));
for (Player p : nearby) { AABB box = player.getBoundingBox().inflate(5.0);
p.addEffect(strength); List<Player> allies = world.getEntitiesOfClass(
Player.class, box,
p -> p instanceof ServerPlayer && player.isAlliedTo(p)
);
MobEffectInstance allyBuff = new MobEffectInstance(MobEffects.DAMAGE_BOOST, 100, 0, false, true);
for (Player ally : allies) {
ally.addEffect(allyBuff);
} }
} }
return true; return super.hurtEnemy(stack, target, attacker);
} }
@Override
public void inventoryTick(ItemStack stack, Level world, Entity entity, int slot, boolean selected) {
super.inventoryTick(stack, world, entity, slot, selected);
if (world.isClientSide || !selected || !(entity instanceof Player player)) return;
if (player.getHealth() < 10.0f) {
MobEffectInstance res = new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, 20, 0, false, false);
player.addEffect(res);
AABB area = player.getBoundingBox().inflate(3.0);
List<Player> allies = world.getEntitiesOfClass(
Player.class, area,
p -> p != player && player.isAlliedTo(p)
);
for (Player ally : allies) {
ally.addEffect(res);
}
}
}
@Override @Override
public boolean isDamageable(ItemStack stack) { public boolean isDamageable(ItemStack stack) {
return false; return false;
@@ -45,9 +70,4 @@ public class StaliniumSwordItem extends SwordItem {
public int getMaxDamage(ItemStack stack) { public int getMaxDamage(ItemStack stack) {
return 2; return 2;
} }
@Override
public void postHurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
}
} }