Skip to content

Commit

Permalink
Improve compatibility with worldthreader
Browse files Browse the repository at this point in the history
  • Loading branch information
2No2Name committed Feb 1, 2025
1 parent 9376fca commit 016512f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.caffeinemc.mods.lithium.common.world.chunk;

import net.caffeinemc.mods.lithium.common.tracking.block.ChunkSectionChangeCallback;
import net.caffeinemc.mods.lithium.mixin.util.accessors.LevelAccessor;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.LevelChunk;
Expand Down Expand Up @@ -45,7 +46,7 @@ public static void registerUnloadCallback(BiConsumer<ServerLevel, ChunkPos> call
}

public static void onChunkAccessible(ServerLevel serverLevel, LevelChunk levelChunk) {
if (!serverLevel.getServer().isSameThread()) {
if (((LevelAccessor) serverLevel).getThread() != Thread.currentThread()) {
throw new IllegalStateException("ChunkStatusTracker.onChunkAccessible called on wrong thread!");
}

Expand All @@ -55,7 +56,7 @@ public static void onChunkAccessible(ServerLevel serverLevel, LevelChunk levelCh
}

public static void onChunkInaccessible(ServerLevel serverLevel, ChunkPos pos) {
if (!serverLevel.getServer().isSameThread()) {
if (((LevelAccessor) serverLevel).getThread() != Thread.currentThread()) {
throw new IllegalStateException("ChunkStatusTracker.onChunkInaccessible called on wrong thread!");
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package net.caffeinemc.mods.lithium.mixin.util.accessors;

import net.minecraft.world.level.Level;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(Level.class)
public interface LevelAccessor {

@Accessor
Thread getThread();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
@MixinConfigOption(
description = "Allows reacting to changes of the load status of chunks."
description = "Allows reacting to changes of the load status of chunks.",
depends = @MixinConfigDependency(dependencyPath = "mixin.util.accessors")

)
package net.caffeinemc.mods.lithium.mixin.util.chunk_status_tracking;

import net.caffeinemc.gradle.MixinConfigDependency;
import net.caffeinemc.gradle.MixinConfigOption;
1 change: 1 addition & 0 deletions common/src/main/resources/lithium.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
"util.accessors.EntitySectionAccessor",
"util.accessors.ItemEntityAccessor",
"util.accessors.ItemStackAccessor",
"util.accessors.LevelAccessor",
"util.accessors.PersistentEntitySectionManagerAccessor",
"util.accessors.ServerLevelAccessor",
"util.block_entity_retrieval.LevelMixin",
Expand Down

0 comments on commit 016512f

Please sign in to comment.