Added cooldown to sword use. Adjusted ally buff effects and cleaned up related logic.
This commit is contained in:
@@ -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,
|
||||||
@@ -61,16 +65,18 @@ public class StaliniumSwordItem extends SwordItem {
|
|||||||
for (Player ally : allies) {
|
for (Player ally : allies) {
|
||||||
Vec3 toAlly = ally.position().subtract(player.position()).normalize();
|
Vec3 toAlly = ally.position().subtract(player.position()).normalize();
|
||||||
if (toAlly.dot(look) >= COS_HALF_ANGLE) {
|
if (toAlly.dot(look) >= COS_HALF_ANGLE) {
|
||||||
ally.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, DURATION, SPEED_AMP, false, true));
|
ally.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SPEED, DURATION, SPEED_AMP, false, true));
|
||||||
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;
|
||||||
|
|||||||
Reference in New Issue
Block a user