Skip to content

Commit

Permalink
it shall not tick compat fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tasgon committed Dec 18, 2022
1 parent 3b99c62 commit e089b58
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 30 deletions.
30 changes: 0 additions & 30 deletions common/src/main/java/observable/mixin/LevelMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,6 @@

@Mixin(Level.class)
public class LevelMixin {
/**
* @reason This is an overwrite to insert the monitoring code.
* @author .
*/
@Overwrite
public <T extends Entity> void guardEntityTick(Consumer<T> 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) {
Expand Down
28 changes: 28 additions & 0 deletions common/src/main/java/observable/mixin/ServerLevelMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 {
Expand Down Expand Up @@ -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<Entity> 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);
}
}

0 comments on commit e089b58

Please sign in to comment.