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:
@@ -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) {
|
Level world = attacker.getCommandSenderWorld();
|
||||||
MobEffectInstance strength = new MobEffectInstance(MobEffects.DAMAGE_BOOST, 100, 0, false, true);
|
if (!world.isClientSide && attacker instanceof Player player) {
|
||||||
attacker.addEffect(strength);
|
player.addEffect(new MobEffectInstance(MobEffects.DAMAGE_BOOST, 100, 1, false, true));
|
||||||
Level world = attacker.getCommandSenderWorld();
|
AABB box = player.getBoundingBox().inflate(5.0);
|
||||||
var box = attacker.getBoundingBox().inflate(5.0);
|
List<Player> allies = world.getEntitiesOfClass(
|
||||||
List<Player> nearby = world.getEntitiesOfClass(Player.class, box, p -> p instanceof ServerPlayer && attacker.isAlliedTo(p));
|
Player.class, box,
|
||||||
for (Player p : nearby) {
|
p -> p instanceof ServerPlayer && player.isAlliedTo(p)
|
||||||
p.addEffect(strength);
|
);
|
||||||
|
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) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user