added inhabited_time and player events revolving around damage, death and respawns.

This commit is contained in:
gnembon committed 2020-04-12 19:42:04 -03:00
1 parent 0133ceb507
commit d6d6b69fcb
12 files changed
+154 -4

No files matched your search

@@ -5,6 +5,7 @@ import carpet.script.EntityEventsGroup;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.damage.DamageTracker;
import net.minecraft.server.network.ServerPlayerEntity;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
@@ -12,8 +13,11 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import static carpet.script.CarpetEventServer.Event.PLAYER_DEALS_DAMAGE;
import static carpet.script.CarpetEventServer.Event.PLAYER_TAKES_DAMAGE;
@Mixin(DamageTracker.class)
public class DamageTracker_scarpetEventMixin
public abstract class DamageTracker_scarpetEventMixin
{
@Shadow @Final private LivingEntity entity;
@@ -21,5 +25,13 @@ public class DamageTracker_scarpetEventMixin
private void onDamageTaken(DamageSource damageSource_1, float float_1, float float_2, CallbackInfo ci)
{
((EntityInterface)entity).getEventContainer().onEvent(EntityEventsGroup.EntityEventType.ON_DAMAGE, entity, float_2, damageSource_1);
if (entity instanceof ServerPlayerEntity && PLAYER_TAKES_DAMAGE.isNeeded())
{
PLAYER_TAKES_DAMAGE.onDamage(entity, float_2, damageSource_1);
}
if (damageSource_1.getAttacker() instanceof ServerPlayerEntity && PLAYER_DEALS_DAMAGE.isNeeded())
{
PLAYER_DEALS_DAMAGE.onDamage(entity, float_2, damageSource_1);
}
}
}