Redesigned stopping attacks on cooldown

This commit is contained in:
patience 2026-02-17 22:59:39 +00:00
parent 891011ad39
commit 55cb1b1615
No known key found for this signature in database
3 changed files with 33 additions and 22 deletions

View file

@ -0,0 +1,32 @@
package xyz.nearmisses.patience.mc_rebalance.mixin;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemCooldowns;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(Player.class)
public abstract class CooldownAttacksTweak extends LivingEntity {
@Shadow
public abstract ItemCooldowns getCooldowns();
protected CooldownAttacksTweak(EntityType<? extends LivingEntity> entityType, Level level) {
super(entityType, level);
}
@Inject(method="attack", at=@At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;getWeaponItem()Lnet/minecraft/world/item/ItemStack;"), cancellable = true)
private void attack(Entity entity, CallbackInfo ci){
ItemStack itemStack = this.getWeaponItem();
if(this.getCooldowns().isOnCooldown(itemStack.getItem())){
ci.cancel();
}
}
}

View file

@ -1,21 +0,0 @@
package xyz.nearmisses.patience.mc_rebalance.mixin;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.DiggerItem;
import net.minecraft.world.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
// Required for the Windup enchantment effect to work correctly. Why would this not happen by default?
@Mixin(DiggerItem.class)
public class DiggerItemHitCooldownsTweak {
@Inject(method = "hurtEnemy", at = @At("HEAD"), cancellable = true)
private static void hurtEnemy(ItemStack itemStack, LivingEntity owner, LivingEntity target, CallbackInfoReturnable<Boolean> cir){
if(owner instanceof Player && ((Player)owner).getCooldowns().isOnCooldown(itemStack.getItem())){
cir.setReturnValue(false);
}
}
}

View file

@ -5,8 +5,8 @@
"mixins": [
"BlazeAIRework",
"BlazeRework",
"CooldownAttacksTweak",
"CreakingRework",
"DiggerItemHitCooldownsTweak",
"ExperienceOrbRework",
"HappyGhastTweak",
"WardenRework",