diff --git a/src/main/java/com/github/zly2006/reden/access/PlayerData.kt b/src/main/java/com/github/zly2006/reden/access/PlayerData.kt index 5b6b9e2c..4bb78d83 100644 --- a/src/main/java/com/github/zly2006/reden/access/PlayerData.kt +++ b/src/main/java/com/github/zly2006/reden/access/PlayerData.kt @@ -73,6 +73,11 @@ class PlayerData( .expand(0.1), ) { x -> x !is PlayerEntity && x !is TntEntity } list.forEach { entity -> + if (lastThread == null) lastThread = Thread.currentThread() + else if (lastThread!!.id != Thread.currentThread().id) { + println("aaaaaaaaaaa") + throw IllegalStateException("Not thread safe") + } entities.computeIfAbsent(entity.uuid) { EntityEntry(entity.type, NbtCompound().apply(entity::writeNbt), entity.blockPos) } @@ -106,3 +111,5 @@ class PlayerData( val pos: BlockPos ) } + +var lastThread: Thread? = null \ No newline at end of file diff --git a/src/main/java/com/github/zly2006/reden/mixin/undo/MixinMovingPiston.java b/src/main/java/com/github/zly2006/reden/mixin/undo/MixinMovingPiston.java index 9e04cc6b..92745126 100644 --- a/src/main/java/com/github/zly2006/reden/mixin/undo/MixinMovingPiston.java +++ b/src/main/java/com/github/zly2006/reden/mixin/undo/MixinMovingPiston.java @@ -2,9 +2,9 @@ import com.github.zly2006.reden.access.UndoableAccess; import com.github.zly2006.reden.mixinhelper.UpdateMonitorHelper; +import com.github.zly2006.reden.utils.DebugKt; import net.minecraft.block.BlockState; import net.minecraft.block.PistonExtensionBlock; -import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntityTicker; import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.PistonBlockEntity; @@ -21,13 +21,22 @@ public class MixinMovingPiston { */ @Overwrite @Nullable - public BlockEntityTicker getTicker(World world, BlockState state, BlockEntityType type) { + public BlockEntityTicker getTicker(World world, BlockState state, BlockEntityType type) { return (type == BlockEntityType.PISTON) ? (world1, pos, state1, be) -> { - if (be instanceof UndoableAccess access) { - UpdateMonitorHelper.INSTANCE.setRecording(UpdateMonitorHelper.INSTANCE.getUndoRecordsMap().get(access.getUndoId())); + boolean shouldTick = be.progress >= 1.0f; + if (shouldTick) { + if (be instanceof UndoableAccess access) { + DebugKt.debugLogger.invoke("Before piston block entity tick: " + pos.toShortString() + ", id" + access.getUndoId()); + UpdateMonitorHelper.INSTANCE.setRecording(UpdateMonitorHelper.INSTANCE.getUndoRecordsMap().get(access.getUndoId())); + } + } + PistonBlockEntity.tick(world1, pos, state1, be); + if (shouldTick) { + if (be instanceof UndoableAccess access) { + DebugKt.debugLogger.invoke("After piston block entity tick: " + pos.toShortString() + ", id" + access.getUndoId()); + UpdateMonitorHelper.INSTANCE.setRecording(null); + } } - PistonBlockEntity.tick(world1, pos, state1, (PistonBlockEntity) be); - UpdateMonitorHelper.INSTANCE.setRecording(null); } : null; } } diff --git a/src/main/java/com/github/zly2006/reden/mixin/undo/MixinSchedule.java b/src/main/java/com/github/zly2006/reden/mixin/undo/MixinSchedule.java index 14702341..c4bace3a 100644 --- a/src/main/java/com/github/zly2006/reden/mixin/undo/MixinSchedule.java +++ b/src/main/java/com/github/zly2006/reden/mixin/undo/MixinSchedule.java @@ -50,6 +50,9 @@ private void afterRunSchedule(CallbackInfo ci) { ) ) private void onAddSchedule(OrderedTick orderedTick, CallbackInfo ci) { + if (orderedTick.pos().equals(new BlockPos(5, -57, -4))) { + System.out.println("bbbbb"); + } UndoableAccess access = (UndoableAccess) orderedTick; PlayerData.UndoRecord recording = UpdateMonitorHelper.INSTANCE.getRecording(); if (recording != null) { diff --git a/src/main/java/com/github/zly2006/reden/mixinhelper/UpdateMonitorHelper.kt b/src/main/java/com/github/zly2006/reden/mixinhelper/UpdateMonitorHelper.kt index 5bc0e3f8..589f719a 100644 --- a/src/main/java/com/github/zly2006/reden/mixinhelper/UpdateMonitorHelper.kt +++ b/src/main/java/com/github/zly2006/reden/mixinhelper/UpdateMonitorHelper.kt @@ -47,7 +47,7 @@ object UpdateMonitorHelper { @JvmStatic fun onUpdate(world: World, entry: ChainRestrictedNeighborUpdater.Entry) { - debugLogger("UpdateMonitorHelper.onUpdate") + //debugLogger("UpdateMonitorHelper.onUpdate") listeners.forEach { (k, v) -> k.invoke(world, entry) if (v == LifeTime.ONCE) { @@ -58,7 +58,7 @@ object UpdateMonitorHelper { @JvmStatic fun onChainFinish(world: World) { - debugLogger("UpdateMonitorHelper.finish") + //debugLogger("UpdateMonitorHelper.finish") listeners.forEach { (k, v) -> if (v == LifeTime.CHAIN) { listeners.remove(k) diff --git a/src/main/resources/reden.accesswidener b/src/main/resources/reden.accesswidener index f3da54cb..a488f19a 100644 --- a/src/main/resources/reden.accesswidener +++ b/src/main/resources/reden.accesswidener @@ -32,3 +32,9 @@ accessible field net/minecraft/world/chunk/Chunk heightmaps Ljava/util/Map; accessible field net/minecraft/command/EntitySelector PASSTHROUGH_FILTER Lnet/minecraft/util/TypeFilter; accessible field net/minecraft/server/integrated/IntegratedServer localPlayerUuid Ljava/util/UUID; accessible field net/minecraft/server/world/ServerWorld syncedBlockEventQueue Lit/unimi/dsi/fastutil/objects/ObjectLinkedOpenHashSet; +accessible field net/minecraft/world/tick/WorldTickScheduler tickableTicks Ljava/util/Queue; +accessible field net/minecraft/world/tick/WorldTickScheduler tickedTicks Ljava/util/List; +accessible field net/minecraft/world/tick/WorldTickScheduler copiedTickableTicksList Ljava/util/Set; +accessible field net/minecraft/world/tick/ChunkTickScheduler queuedTicks Ljava/util/Set; +accessible field net/minecraft/block/entity/PistonBlockEntity progress F +accessible field net/minecraft/block/entity/PistonBlockEntity lastProgress F