Added cooldown to sword use. Adjusted ally buff effects and cleaned up related logic.

This commit is contained in:
IM23a-spirgif
2025-05-26 12:20:50 +02:00
parent a92cc137e3
commit 35364bd4d5
@@ -33,13 +33,12 @@ public class StaliniumSwordItem extends SwordItem {
public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) { public boolean hurtEnemy(ItemStack stack, LivingEntity target, LivingEntity attacker) {
Level world = attacker.getCommandSenderWorld(); Level world = attacker.getCommandSenderWorld();
if (!world.isClientSide && attacker instanceof Player player) { if (!world.isClientSide && attacker instanceof Player player) {
player.addEffect(new MobEffectInstance(MobEffects.DAMAGE_BOOST, 100, 0, false, true));
AABB box = player.getBoundingBox().inflate(5.0); AABB box = player.getBoundingBox().inflate(5.0);
List<Player> allies = world.getEntitiesOfClass( List<Player> allies = world.getEntitiesOfClass(
Player.class, box, Player.class, box,
p -> p instanceof ServerPlayer && player.isAlliedTo(p) p -> p instanceof ServerPlayer && player.isAlliedTo(p)
); );
MobEffectInstance allyBuff = new MobEffectInstance(MobEffects.DAMAGE_BOOST, 100, 1, false, true); MobEffectInstance allyBuff = new MobEffectInstance(MobEffects.DAMAGE_BOOST, 100, 0, false, true);
for (Player ally : allies) { for (Player ally : allies) {
ally.addEffect(allyBuff); ally.addEffect(allyBuff);
} }
@@ -49,9 +48,14 @@ public class StaliniumSwordItem extends SwordItem {
@Override @Override
public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) { public InteractionResultHolder<ItemStack> use(Level world, Player player, InteractionHand hand) {
ItemStack stack = player.getItemInHand(hand);
if (player.getCooldowns().isOnCooldown(this)) {
return InteractionResultHolder.fail(stack);
}
if (!world.isClientSide) { if (!world.isClientSide) {
player.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, DURATION, SPEED_AMP, false, true)); player.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, DURATION, SPEED_AMP, false, true));
player.addEffect(new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, DURATION, RESIST_AMP, false, true)); player.addEffect(new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, DURATION, RESIST_AMP, false, true));
AABB area = player.getBoundingBox().inflate(RANGE); AABB area = player.getBoundingBox().inflate(RANGE);
List<Player> allies = world.getEntitiesOfClass( List<Player> allies = world.getEntitiesOfClass(
Player.class, area, Player.class, area,
@@ -65,12 +69,14 @@ public class StaliniumSwordItem extends SwordItem {
ally.addEffect(new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, DURATION, RESIST_AMP, false, true)); ally.addEffect(new MobEffectInstance(MobEffects.DAMAGE_RESISTANCE, DURATION, RESIST_AMP, false, true));
} }
} }
player.getCooldowns().addCooldown(this, 20 * 20);
} }
player.startUsingItem(hand); player.startUsingItem(hand);
player.swing(hand, true); player.swing(hand, true);
return InteractionResultHolder.sidedSuccess(player.getItemInHand(hand), world.isClientSide); return InteractionResultHolder.sidedSuccess(stack, world.isClientSide);
} }
@Override @Override
public UseAnim getUseAnimation(ItemStack stack) { public UseAnim getUseAnimation(ItemStack stack) {
return UseAnim.BOW; return UseAnim.BOW;