From c47b9c52fe410ba5ecd5886187346f73260832ef Mon Sep 17 00:00:00 2001 From: DBotThePony Date: Thu, 15 Sep 2022 15:44:04 +0700 Subject: [PATCH] Use PlayerTickEvent --- .../ru/dbotthepony/mc/otm/OverdriveThatMatters.java | 2 +- .../mc/otm/capability/MatteryPlayerCapability.kt | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java index f291d52a6..be8672397 100644 --- a/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java +++ b/src/main/java/ru/dbotthepony/mc/otm/OverdriveThatMatters.java @@ -101,7 +101,7 @@ public final class OverdriveThatMatters { EVENT_BUS.addListener(EventPriority.LOWEST, GlobalEventHandlerKt::onWorldTick); EVENT_BUS.addListener(EventPriority.LOWEST, GlobalEventHandlerKt::onServerTick); - EVENT_BUS.addListener(EventPriority.NORMAL, MatteryPlayerCapability.Companion::onLivingTick); + EVENT_BUS.addListener(EventPriority.NORMAL, MatteryPlayerCapability.Companion::onPlayerTick); EVENT_BUS.addListener(EventPriority.NORMAL, MatteryPlayerCapability.Companion::onHurtEvent); EVENT_BUS.addGenericListener(Entity.class, EventPriority.NORMAL, MatteryPlayerCapability.Companion::onAttachCapabilityEvent); EVENT_BUS.addListener(EventPriority.NORMAL, MatteryPlayerCapability.Companion::onPlayerChangeDimensionEvent); diff --git a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayerCapability.kt b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayerCapability.kt index a84ffd254..7960f1be1 100644 --- a/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayerCapability.kt +++ b/src/main/kotlin/ru/dbotthepony/mc/otm/capability/MatteryPlayerCapability.kt @@ -24,9 +24,10 @@ import net.minecraftforge.common.capabilities.ICapabilityProvider import net.minecraftforge.common.util.INBTSerializable import net.minecraftforge.common.util.LazyOptional import net.minecraftforge.event.AttachCapabilitiesEvent +import net.minecraftforge.event.TickEvent +import net.minecraftforge.event.TickEvent.PlayerTickEvent import net.minecraftforge.event.entity.living.LivingDeathEvent import net.minecraftforge.event.entity.living.LivingDropsEvent -import net.minecraftforge.event.entity.living.LivingEvent.LivingTickEvent import net.minecraftforge.event.entity.living.LivingHurtEvent import net.minecraftforge.event.entity.player.EntityItemPickupEvent import net.minecraftforge.event.entity.player.PlayerEvent @@ -664,8 +665,11 @@ class MatteryPlayerCapability(val ply: Player) : ICapabilityProvider, INBTSerial UNAFFECTED_EFFECTS.add(MobEffects.DOLPHINS_GRACE) } - fun onLivingTick(event: LivingTickEvent) { - val ent = event.entity + fun onPlayerTick(event: PlayerTickEvent) { + if (event.phase == TickEvent.Phase.START) + return + + val ent = event.player if (ent.level.isClientSide) { ent.getCapability(MatteryCapability.MATTERY_PLAYER).ifPresentK {