move damage events before damage effects are applied

This commit is contained in:
gnembon committed 2020-07-14 23:36:11 -03:00
1 parent ce19dbe505
commit f871a5d473
4 files changed
+72 -38

No files matched your search

@@ -1,5 +1,6 @@
package carpet.mixins;
import carpet.CarpetSettings;
import carpet.fakes.EntityInterface;
import carpet.fakes.LivingEntityInterface;
import carpet.script.EntityEventsGroup;
@@ -7,12 +8,17 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.server.network.ServerPlayerEntity;
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;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
import static carpet.script.CarpetEventServer.Event.PLAYER_DEALS_DAMAGE;
import static carpet.script.CarpetEventServer.Event.PLAYER_TAKES_DAMAGE;
@Mixin(LivingEntity.class)
public abstract class LivingEntity_scarpetEventsMixin extends Entity implements LivingEntityInterface
@@ -33,6 +39,25 @@ public abstract class LivingEntity_scarpetEventsMixin extends Entity implements
((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.EntityEventType.ON_DEATH, damageSource_1.name);
}
@Inject(method = "applyDamage", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(
value = "INVOKE",
target = "Lnet/minecraft/entity/LivingEntity;getHealth()F",
shift = At.Shift.BEFORE
))
private void entityTakingDamage(DamageSource source, float amount, CallbackInfo ci)
{
((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.EntityEventType.ON_DAMAGE, amount, source);
// this is not applicable since its not a playr for sure
//if (entity instanceof ServerPlayerEntity && PLAYER_TAKES_DAMAGE.isNeeded())
//{
// PLAYER_TAKES_DAMAGE.onDamage(entity, float_2, damageSource_1);
//}
if (source.getAttacker() instanceof ServerPlayerEntity && PLAYER_DEALS_DAMAGE.isNeeded())
{
PLAYER_DEALS_DAMAGE.onDamage(this, amount, source);
}
}
@Override
public void doJumpCM()
{