diff options
Diffstat (limited to 'src/main/java/dev/mayaqq/ygasi/mixin')
-rw-r--r-- | src/main/java/dev/mayaqq/ygasi/mixin/PlayerEntityMixin.java | 34 | ||||
-rw-r--r-- | src/main/java/dev/mayaqq/ygasi/mixin/StatusEffectMixin.java | 42 |
2 files changed, 76 insertions, 0 deletions
diff --git a/src/main/java/dev/mayaqq/ygasi/mixin/PlayerEntityMixin.java b/src/main/java/dev/mayaqq/ygasi/mixin/PlayerEntityMixin.java new file mode 100644 index 0000000..5eeea63 --- /dev/null +++ b/src/main/java/dev/mayaqq/ygasi/mixin/PlayerEntityMixin.java @@ -0,0 +1,34 @@ +package dev.mayaqq.ygasi.mixin; + +import dev.mayaqq.ygasi.util.AdvUtils; +import net.minecraft.entity.Entity; +import net.minecraft.entity.effect.StatusEffectInstance; +import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.server.network.ServerPlayerEntity; +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; + +import static dev.mayaqq.ygasi.abilities.mercenary.Offence1.attackList; + +@Mixin(PlayerEntity.class) +public abstract class PlayerEntityMixin { + @Shadow public abstract boolean isPlayer(); + + @Inject(method = "attack", at = @At("HEAD")) + public void onAttack(Entity target, CallbackInfo ci) { + if (this.isPlayer()) { + ServerPlayerEntity player = (ServerPlayerEntity) (Object) this; + if (!attackList.containsKey(player.getUuidAsString() + target.getUuidAsString()) && AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/offence1")) { + attackList.put(player.getUuidAsString() + target.getUuidAsString(), true); + StatusEffectInstance currentEffect = player.getStatusEffect(StatusEffects.STRENGTH); + int currentLevel = currentEffect != null ? currentEffect.getAmplifier() : 0; + int currentTime = currentEffect != null ? currentEffect.getDuration() : 0; + player.addStatusEffect(new StatusEffectInstance(StatusEffects.STRENGTH, currentTime + 2 * 20, currentLevel, false, false, true)); + } + } + } +}
\ No newline at end of file diff --git a/src/main/java/dev/mayaqq/ygasi/mixin/StatusEffectMixin.java b/src/main/java/dev/mayaqq/ygasi/mixin/StatusEffectMixin.java new file mode 100644 index 0000000..e2df799 --- /dev/null +++ b/src/main/java/dev/mayaqq/ygasi/mixin/StatusEffectMixin.java @@ -0,0 +1,42 @@ +package dev.mayaqq.ygasi.mixin; + +import dev.mayaqq.ygasi.util.AdvUtils; +import dev.mayaqq.ygasi.util.Multithreading; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.attribute.AttributeContainer; +import net.minecraft.entity.effect.StatusEffect; +import net.minecraft.entity.effect.StatusEffects; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.sound.SoundCategory; +import net.minecraft.sound.SoundEvent; +import net.minecraft.sound.SoundEvents; +import net.minecraft.text.Text; +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; + +import java.util.concurrent.TimeUnit; + +import static dev.mayaqq.ygasi.Ygasi.LOGGER; +import static dev.mayaqq.ygasi.abilities.mercenary.Offence1.attackList; + +@Mixin(StatusEffect.class) +public abstract class StatusEffectMixin { + + @Shadow public abstract Text getName(); + + @Inject(method = "onRemoved", at = @At("HEAD")) + public void onUpdateStatusEffect(LivingEntity entity, AttributeContainer attributes, int amplifier, CallbackInfo ci) { + LOGGER.info("onRemovedTick"); + if (entity.isPlayer()) { + ServerPlayerEntity player = (ServerPlayerEntity) entity; + if (this.getName() != null && this.getName().equals(StatusEffects.STRENGTH.getName()) && AdvUtils.getAdvancementProgress(player, "minecraft", "ygasi/offence1")) { + Multithreading.schedule(() -> { + attackList.entrySet().removeIf(entry -> entry.getKey().startsWith(player.getUuidAsString())); + },4, TimeUnit.SECONDS); + } + } + } +} |