forked from MCTown/DimensionalThreading
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix WearBlackAllDay#72. Time ticking is not thread-safe and cause pis…
…ton problems on worlds that does not tick the time
- Loading branch information
1 parent
66a519c
commit ff3c9a9
Showing
5 changed files
with
63 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/wearblackallday/dimthread/mixin/ServerWorldMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package wearblackallday.dimthread.mixin; | ||
|
||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.util.profiler.Profiler; | ||
import net.minecraft.util.registry.RegistryEntry; | ||
import net.minecraft.util.registry.RegistryKey; | ||
import net.minecraft.world.MutableWorldProperties; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.dimension.DimensionType; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
import wearblackallday.dimthread.DimThread; | ||
import wearblackallday.dimthread.util.ServerWorldAccessor; | ||
|
||
import java.util.function.Supplier; | ||
|
||
@Mixin(ServerWorld.class) | ||
public abstract class ServerWorldMixin extends World implements ServerWorldAccessor { | ||
protected ServerWorldMixin(MutableWorldProperties properties, RegistryKey<World> registryRef, RegistryEntry<DimensionType> registryEntry, Supplier<Profiler> profiler, boolean isClient, boolean debugWorld, long seed) { | ||
super(properties, registryRef, registryEntry, profiler, isClient, debugWorld, seed); | ||
} | ||
|
||
@Shadow protected abstract void tickTime(); | ||
|
||
boolean onMainThread = false; | ||
boolean timeTickedOnWorldThread = false; | ||
|
||
/** | ||
* Time ticking is not thread-safe. We cancel time ticking from the world thread. However, DimThread will tick time on the main thread | ||
*/ | ||
@Inject(method = "tickTime", at = @At("HEAD"), cancellable = true) | ||
private void preventTimeTicking(CallbackInfo ci) { | ||
if (DimThread.MANAGER.isActive(getServer()) && !onMainThread) { | ||
timeTickedOnWorldThread = true; | ||
ci.cancel(); | ||
} | ||
} | ||
|
||
@Override | ||
public void dimthread_tickTime() { | ||
if (timeTickedOnWorldThread) { | ||
onMainThread = true; | ||
tickTime(); | ||
onMainThread = false; | ||
timeTickedOnWorldThread = false; | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/wearblackallday/dimthread/util/ServerWorldAccessor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package wearblackallday.dimthread.util; | ||
|
||
/** | ||
* Create this calass wo that we can call tickTime from ServerWorldMixin | ||
*/ | ||
public interface ServerWorldAccessor { | ||
void dimthread_tickTime(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters