Added logic to Player class to read elytra cooldowns
This commit is contained in:
parent
72e7e24693
commit
82f09e2bac
|
|
@ -21,11 +21,7 @@ public record SmackEffect(LevelBasedValue amount) implements EnchantmentEntityEf
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void apply(ServerLevel world, int level, EnchantedItemInUse context, Entity target, Vec3 pos) {
|
public void apply(ServerLevel world, int level, EnchantedItemInUse context, Entity target, Vec3 pos) {
|
||||||
/*boolean playerAndCharged;
|
if (target instanceof Player player && player.getInventory().getArmor(2).is(Items.ELYTRA)) {
|
||||||
if(context.owner()!=null && context.owner() instanceof Player player && player){
|
|
||||||
playerAndCharged=true;
|
|
||||||
}*/
|
|
||||||
if (context.owner() != null && target instanceof Player player && player.getInventory().getArmor(1).is(Items.ELYTRA)) {
|
|
||||||
player.getCooldowns().addCooldown(Items.ELYTRA, (int)(20 * this.amount.calculate(level)) ); // Tick conversion
|
player.getCooldowns().addCooldown(Items.ELYTRA, (int)(20 * this.amount.calculate(level)) ); // Tick conversion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ package xyz.nearmisses.patience.mc_rebalance.mixin;
|
||||||
|
|
||||||
import net.minecraft.world.entity.Entity;
|
import net.minecraft.world.entity.Entity;
|
||||||
import net.minecraft.world.entity.EntityType;
|
import net.minecraft.world.entity.EntityType;
|
||||||
|
import net.minecraft.world.entity.EquipmentSlot;
|
||||||
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.item.ItemCooldowns;
|
import net.minecraft.world.item.ItemCooldowns;
|
||||||
|
|
@ -12,16 +13,18 @@ import org.spongepowered.asm.mixin.Shadow;
|
||||||
import org.spongepowered.asm.mixin.injection.At;
|
import org.spongepowered.asm.mixin.injection.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
|
||||||
|
|
||||||
@Mixin(Player.class)
|
@Mixin(Player.class)
|
||||||
public abstract class CooldownAttacksTweak extends LivingEntity {
|
public abstract class PlayerTweaks extends LivingEntity {
|
||||||
@Shadow
|
@Shadow
|
||||||
public abstract ItemCooldowns getCooldowns();
|
public abstract ItemCooldowns getCooldowns();
|
||||||
|
|
||||||
protected CooldownAttacksTweak(EntityType<? extends LivingEntity> entityType, Level level) {
|
protected PlayerTweaks(EntityType<? extends LivingEntity> entityType, Level level) {
|
||||||
super(entityType, level);
|
super(entityType, level);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Disable attacks from tools on cooldown (item tier variants intentionally omitted out of curiosity)
|
||||||
@Inject(method="attack", at=@At(value = "INVOKE", target = "Lnet/minecraft/world/entity/player/Player;getWeaponItem()Lnet/minecraft/world/item/ItemStack;"), cancellable = true)
|
@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){
|
private void attack(Entity entity, CallbackInfo ci){
|
||||||
ItemStack itemStack = this.getWeaponItem();
|
ItemStack itemStack = this.getWeaponItem();
|
||||||
|
|
@ -29,4 +32,12 @@ public abstract class CooldownAttacksTweak extends LivingEntity {
|
||||||
ci.cancel();
|
ci.cancel();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Disable elytra flight (should work on modded variants)
|
||||||
|
@Inject(method="tryToStartFallFlying", at=@At("HEAD"), cancellable = true)
|
||||||
|
private void tryToStartFallFlying(CallbackInfoReturnable<Boolean> cir){
|
||||||
|
if(!this.getItemBySlot(EquipmentSlot.CHEST).isEmpty() && this.getCooldowns().isOnCooldown(this.getItemBySlot(EquipmentSlot.CHEST).getItem())){
|
||||||
|
cir.setReturnValue(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -5,9 +5,10 @@
|
||||||
"mixins": [
|
"mixins": [
|
||||||
"BlazeAIRework",
|
"BlazeAIRework",
|
||||||
"BlazeRework",
|
"BlazeRework",
|
||||||
"CooldownAttacksTweak",
|
"PlayerTweaks",
|
||||||
"CreakingRework",
|
"CreakingRework",
|
||||||
"ExperienceOrbRework",
|
"ExperienceOrbRework",
|
||||||
|
"GrowRateTweak",
|
||||||
"HappyGhastTweak",
|
"HappyGhastTweak",
|
||||||
"WardenRework",
|
"WardenRework",
|
||||||
"WitherSkeletonRework"
|
"WitherSkeletonRework"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue