From e089b58c9a582a456c0e6a4bfd16e4084272d712 Mon Sep 17 00:00:00 2001 From: tasgon Date: Sun, 18 Dec 2022 04:08:34 -0500 Subject: [PATCH] it shall not tick compat fix --- .../java/observable/mixin/LevelMixin.java | 30 ------------------- .../observable/mixin/ServerLevelMixin.java | 28 +++++++++++++++++ 2 files changed, 28 insertions(+), 30 deletions(-) diff --git a/common/src/main/java/observable/mixin/LevelMixin.java b/common/src/main/java/observable/mixin/LevelMixin.java index 7ecb9f2..c68a635 100644 --- a/common/src/main/java/observable/mixin/LevelMixin.java +++ b/common/src/main/java/observable/mixin/LevelMixin.java @@ -22,36 +22,6 @@ @Mixin(Level.class) public class LevelMixin { - /** - * @reason This is an overwrite to insert the monitoring code. - * @author . - */ - @Overwrite - public void guardEntityTick(Consumer consumer, T entity) { - try { - if (Props.notProcessing) consumer.accept(entity); - else { - if (Props.entityDepth < 0) Props.entityDepth = Thread.currentThread().getStackTrace().length - 1; - if ((Object)this instanceof ServerLevel) { - Profiler.TimingData data = Observable.INSTANCE.getPROFILER().process(entity); - Props.currentTarget.set(data); - long start = System.nanoTime(); - consumer.accept(entity); - data.setTime(System.nanoTime() - start + data.getTime()); - Props.currentTarget.set(null); - data.setTicks(data.getTicks() + 1); - } else { - consumer.accept(entity); - } - } - } catch (Throwable throwable) { - CrashReport crashReport = CrashReport.forThrowable(throwable, "Ticking entity"); - CrashReportCategory crashReportCategory = crashReport.addCategory("Entity being ticked"); - entity.fillCrashReportCategory(crashReportCategory); - throw new ReportedException(crashReport); - } - } - @Redirect(method = "tickBlockEntities", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/block/entity/TickingBlockEntity;tick()V")) public final void redirectTick(TickingBlockEntity blockEntity) { diff --git a/common/src/main/java/observable/mixin/ServerLevelMixin.java b/common/src/main/java/observable/mixin/ServerLevelMixin.java index 66c768d..e5052f6 100644 --- a/common/src/main/java/observable/mixin/ServerLevelMixin.java +++ b/common/src/main/java/observable/mixin/ServerLevelMixin.java @@ -3,6 +3,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.server.level.ServerLevel; import net.minecraft.util.RandomSource; +import net.minecraft.world.entity.Entity; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.FluidState; @@ -14,6 +15,7 @@ import org.spongepowered.asm.mixin.injection.Redirect; import java.util.Random; +import java.util.function.Consumer; @Mixin(ServerLevel.class) public class ServerLevelMixin { @@ -48,4 +50,30 @@ public final void onTickBlock(BlockState state, ServerLevel level, BlockPos pos, data.setTicks(data.getTicks() + 1); } } + + public final void track(Entity entity, Consumer consumer) { + if (Props.notProcessing) consumer.accept(entity); + else { + if (Props.entityDepth < 0) Props.entityDepth = Thread.currentThread().getStackTrace().length - 1; + Profiler.TimingData data = Observable.INSTANCE.getPROFILER().process(entity); + Props.currentTarget.set(data); + long start = System.nanoTime(); + consumer.accept(entity); + data.setTime(System.nanoTime() - start + data.getTime()); + Props.currentTarget.set(null); + data.setTicks(data.getTicks() + 1); + } + } + + @Redirect(method = "tickNonPassenger", at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/entity/Entity;tick()V")) + public final void onTickNonPassenger(Entity entity) { + track(entity, Entity::tick); + } + + @Redirect(method = "tickPassenger", at = @At(value = "INVOKE", + target = "Lnet/minecraft/world/entity/Entity;rideTick()V")) + public final void onTickPassenger(Entity entity) { + track(entity, Entity::rideTick); + } }