Skip to content

Commit 836d6ce

Browse files
committed
Player damage event update
1 parent fe199ba commit 836d6ce

File tree

4 files changed

+13
-25
lines changed

4 files changed

+13
-25
lines changed

common/src/main/java/com/lambda/mixin/entity/ClientPlayerEntityMixin.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import net.minecraft.client.network.ClientPlayerEntity;
2929
import net.minecraft.entity.MovementType;
3030
import net.minecraft.entity.damage.DamageSource;
31+
import net.minecraft.network.packet.s2c.play.EntityDamageS2CPacket;
3132
import net.minecraft.util.Hand;
3233
import net.minecraft.util.math.Vec3d;
3334
import org.spongepowered.asm.mixin.Mixin;
@@ -124,10 +125,8 @@ void onSwingHandPre(Hand hand, CallbackInfo ci) {
124125
if (EventFlow.post(new PlayerEvent.SwingHand(hand)).isCanceled()) ci.cancel();
125126
}
126127

127-
@Inject(method = "damage", at = @At("HEAD"), cancellable = true)
128-
public void damage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
129-
if (EventFlow.post(new PlayerEvent.Damage(source, amount)).isCanceled()) {
130-
cir.setReturnValue(false);
131-
}
128+
@Inject(method = "updateHealth", at = @At("HEAD"))
129+
public void damage(float health, CallbackInfo ci) {
130+
EventFlow.post(new PlayerEvent.Damage(health));
132131
}
133132
}

common/src/main/java/com/lambda/mixin/entity/EntityMixin.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,4 @@ public void onTrackedDataSet(TrackedData<?> data, CallbackInfo ci) {
9898

9999
EventFlow.post(new EntityEvent.EntityUpdate(entity, data));
100100
}
101-
102-
// ToDo: Does not trigger for some reason.
103-
@Inject(method = "damage", at = @At("HEAD"), cancellable = true)
104-
public void damage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> cir) {
105-
Entity entity = (Entity) (Object) this;
106-
107-
if (EventFlow.post(new EntityEvent.Damage(entity, source, amount)).isCanceled()) {
108-
cir.setReturnValue(false);
109-
}
110-
}
111101
}

common/src/main/kotlin/com/lambda/event/events/PlayerEvent.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
package com.lambda.event.events
1919

20+
import com.lambda.event.Event
2021
import com.lambda.event.callback.Cancellable
2122
import com.lambda.event.callback.ICancellable
2223
import net.minecraft.entity.damage.DamageSource
@@ -52,15 +53,11 @@ sealed class PlayerEvent {
5253
) : ICancellable by Cancellable()
5354

5455
/**
55-
* Represents a damage event for entities.
56+
* Represents a damage event for the player.
5657
*
57-
* @property source The source of the damage, which identifies what caused the damage.
5858
* @property amount The amount of damage dealt.
5959
*/
60-
data class Damage(
61-
val source: DamageSource,
62-
val amount: Float,
63-
) : ICancellable by Cancellable()
60+
data class Damage(val amount: Float) : Event
6461

6562
sealed class Interact {
6663
/**

common/src/main/kotlin/com/lambda/module/modules/combat/AutoDisconnect.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,12 @@ object AutoDisconnect : Module(
103103
trident to DamageTypes.TRIDENT
104104
)
105105

106-
damageHandlers.firstOrNull { (enabled, damageSource) ->
107-
enabled && event.source.isOf(damageSource)
108-
}?.let {
109-
damageDisconnect(event.source, event.amount)
106+
player.recentDamageSource?.let { source ->
107+
damageHandlers.firstOrNull { (enabled, damageSource) ->
108+
enabled && source.isOf(damageSource)
109+
}?.let {
110+
damageDisconnect(source, event.amount)
111+
}
110112
}
111113
}
112114
}

0 commit comments

Comments
 (0)