diff --git a/api/ctjs.api b/api/ctjs.api index 079d8d26..295bbf0e 100644 --- a/api/ctjs.api +++ b/api/ctjs.api @@ -2075,7 +2075,6 @@ public final class com/chattriggers/ctjs/api/triggers/TriggerType : java/lang/En public static final field GUI_RENDER Lcom/chattriggers/ctjs/api/triggers/TriggerType; public static final field ITEM_TOOLTIP Lcom/chattriggers/ctjs/api/triggers/TriggerType; public static final field MESSAGE_SENT Lcom/chattriggers/ctjs/api/triggers/TriggerType; - public static final field MIXIN Lcom/chattriggers/ctjs/api/triggers/TriggerType; public static final field OTHER Lcom/chattriggers/ctjs/api/triggers/TriggerType; public static final field PACKET_RECEIVED Lcom/chattriggers/ctjs/api/triggers/TriggerType; public static final field PACKET_SENT Lcom/chattriggers/ctjs/api/triggers/TriggerType; diff --git a/src/main/java/com/chattriggers/ctjs/internal/mixins/LivingEntityMixin.java b/src/main/java/com/chattriggers/ctjs/internal/mixins/LivingEntityMixin.java new file mode 100644 index 00000000..33a3a0f3 --- /dev/null +++ b/src/main/java/com/chattriggers/ctjs/internal/mixins/LivingEntityMixin.java @@ -0,0 +1,27 @@ +package com.chattriggers.ctjs.internal.mixins; + +import com.chattriggers.ctjs.api.triggers.TriggerType; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.damage.DamageSource; +import net.minecraft.world.World; +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(LivingEntity.class) +public abstract class LivingEntityMixin extends Entity { + public LivingEntityMixin(EntityType type, World world) { + super(type, world); + } + + @Inject(method = "onDeath", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;setPose(Lnet/minecraft/entity/EntityPose;)V")) + private void chattriggers$entityDeath(DamageSource damageSource, CallbackInfo ci) { + if (getWorld().isClient) { + TriggerType.ENTITY_DEATH.triggerAll(this); + } + } +} diff --git a/src/main/java/com/chattriggers/ctjs/internal/mixins/PlayerEntityMixin.java b/src/main/java/com/chattriggers/ctjs/internal/mixins/PlayerEntityMixin.java index f2a91b7b..8e2ac39c 100644 --- a/src/main/java/com/chattriggers/ctjs/internal/mixins/PlayerEntityMixin.java +++ b/src/main/java/com/chattriggers/ctjs/internal/mixins/PlayerEntityMixin.java @@ -1,20 +1,31 @@ package com.chattriggers.ctjs.internal.mixins; +import com.chattriggers.ctjs.api.triggers.TriggerType; import com.chattriggers.ctjs.internal.NameTagOverridable; import com.chattriggers.ctjs.api.message.TextComponent; +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.text.MutableText; +import net.minecraft.world.World; import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.ModifyVariable; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(PlayerEntity.class) -public class PlayerEntityMixin implements NameTagOverridable { +public abstract class PlayerEntityMixin extends LivingEntity implements NameTagOverridable { @Unique private TextComponent overriddenNametagName; + protected PlayerEntityMixin(EntityType entityType, World world) { + super(entityType, world); + } + @ModifyVariable(method = "getDisplayName", at = @At(value = "STORE", ordinal = 0)) private MutableText injectGetName(MutableText original) { if (overriddenNametagName != null) @@ -22,6 +33,32 @@ private MutableText injectGetName(MutableText original) { return original; } + @Inject( + method = "attack", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/entity/Entity;damage(Lnet/minecraft/entity/damage/DamageSource;F)Z" + ) + ) + private void chattriggers$entityDamage(Entity target, CallbackInfo ci) { + if (getWorld().isClient) { + TriggerType.ENTITY_DAMAGE.triggerAll(com.chattriggers.ctjs.api.entity.Entity.fromMC(target)); + } + } + + @Inject( + method = "attack", + at = @At( + value = "INVOKE", + target = "Lnet/minecraft/entity/LivingEntity;damage(Lnet/minecraft/entity/damage/DamageSource;F)Z" + ) + ) + private void chattriggers$entityDamageSweeping(Entity target, CallbackInfo ci) { + if (getWorld().isClient) { + TriggerType.ENTITY_DAMAGE.triggerAll(com.chattriggers.ctjs.api.entity.Entity.fromMC(target)); + } + } + @Override public void ctjs_setOverriddenNametagName(@Nullable TextComponent component) { overriddenNametagName = component; diff --git a/src/main/kotlin/com/chattriggers/ctjs/api/triggers/TriggerType.kt b/src/main/kotlin/com/chattriggers/ctjs/api/triggers/TriggerType.kt index d10f1132..3f9e9cd3 100644 --- a/src/main/kotlin/com/chattriggers/ctjs/api/triggers/TriggerType.kt +++ b/src/main/kotlin/com/chattriggers/ctjs/api/triggers/TriggerType.kt @@ -55,7 +55,6 @@ enum class TriggerType : ITriggerType { ENTITY_DAMAGE, // misc - MIXIN, COMMAND, OTHER } diff --git a/src/main/kotlin/com/chattriggers/ctjs/engine/Register.kt b/src/main/kotlin/com/chattriggers/ctjs/engine/Register.kt index b49482fb..85f1c517 100644 --- a/src/main/kotlin/com/chattriggers/ctjs/engine/Register.kt +++ b/src/main/kotlin/com/chattriggers/ctjs/engine/Register.kt @@ -496,11 +496,10 @@ object Register { } /** - * Registers a new trigger that runs before an entity is damaged + * Registers a new trigger that runs when an entity is damaged by the player * - * Passes through two arguments: + * Passes through one argument: * - The target Entity that is damaged - * - The PlayerMP attacker * * @param method The method to call when the event is fired * @return The trigger for additional modification @@ -511,7 +510,7 @@ object Register { } /** - * Registers a new trigger that runs before an entity dies + * Registers a new trigger that runs when an entity dies * * Passes through one argument: * - The Entity that died diff --git a/src/main/resources/chattriggers.mixins.json b/src/main/resources/chattriggers.mixins.json index 129b0f0d..ad44393f 100644 --- a/src/main/resources/chattriggers.mixins.json +++ b/src/main/resources/chattriggers.mixins.json @@ -29,6 +29,7 @@ "InGameHudMixin", "ItemStackMixin", "KeyBindingAccessor", + "LivingEntityMixin", "MinecraftClientMixin", "MouseMixin", "NbtCompoundAccessor",