Skip to content

Commit b55b27d

Browse files
ScribbleScribble
authored andcommitted
Working on #137
1 parent 9cb5f67 commit b55b27d

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed

src/main/java/de/scribble/lp/tasmod/events/LoadWorldEvents.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
public class LoadWorldEvents {
99

1010
public static boolean waszero = false;
11+
private static boolean isLoading =false;
1112

1213
/**
1314
* Delay after the loading screen is finished before firing "doneWithLoadingScreen"
@@ -24,6 +25,7 @@ public static void startLaunchServer() {
2425
if (TickrateChangerClient.ticksPerSecond == 0 || TickrateChangerClient.advanceTick) {
2526
waszero = true;
2627
}
28+
isLoading = true;
2729
}
2830

2931
/**
@@ -85,9 +87,13 @@ public static void doneWithLoadingScreen() {
8587
} else {
8688
waszero = false;
8789
}
90+
isLoading=false;
8891
}
8992
loadingScreenDelay--;
9093
}
9194
}
9295

96+
public static boolean isLoading() {
97+
return isLoading;
98+
}
9399
}

src/main/java/de/scribble/lp/tasmod/mixin/MixinMinecraftServer.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -96,28 +96,28 @@ public void redirectThreadSleep(long msToTick) {
9696
if (TickrateChangerServer.ticksPerSecond == 0) {
9797
currentTime = System.currentTimeMillis();
9898
faketick++;
99-
if (faketick >= 20) {
99+
if (faketick >= 50) {
100100
faketick = 0;
101101
networkSystem.networkTick();
102102
if (((MinecraftServer) (Object) this).isDedicatedServer()) {
103103
runPendingCommands();
104104
}
105+
synchronized (this.futureTaskQueue) {
106+
while (!this.futureTaskQueue.isEmpty()) {
107+
try {
108+
((FutureTask<?>) this.futureTaskQueue.poll()).run();
109+
} catch (Throwable var9) {
110+
var9.printStackTrace();
111+
}
112+
}
113+
}
105114
}
106115
}
107116
if (TickrateChangerServer.interrupt) {
108117
currentTime = System.currentTimeMillis();
109118
msToTick = 1L;
110119
TickrateChangerServer.interrupt = false;
111120
}
112-
synchronized (this.futureTaskQueue) {
113-
while (!this.futureTaskQueue.isEmpty()) {
114-
try {
115-
((FutureTask<?>) this.futureTaskQueue.poll()).run();
116-
} catch (Throwable var9) {
117-
var9.printStackTrace();
118-
}
119-
}
120-
}
121121

122122
try {
123123
Thread.sleep(1L);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package de.scribble.lp.tasmod.mixin.fixes;
2+
3+
import org.spongepowered.asm.mixin.Mixin;
4+
import org.spongepowered.asm.mixin.Shadow;
5+
import org.spongepowered.asm.mixin.injection.At;
6+
import org.spongepowered.asm.mixin.injection.Redirect;
7+
8+
import de.scribble.lp.tasmod.events.LoadWorldEvents;
9+
import de.scribble.lp.tasmod.tickratechanger.TickrateChangerServer;
10+
import net.minecraft.network.INetHandler;
11+
import net.minecraft.network.NetHandlerPlayServer;
12+
import net.minecraft.network.NetworkManager;
13+
import net.minecraft.util.ITickable;
14+
15+
@Mixin(NetworkManager.class)
16+
public class MixinNetworkManager {
17+
@Shadow
18+
private INetHandler packetListener;
19+
20+
/**
21+
* Fixes #137
22+
*
23+
* @param manager
24+
*/
25+
@Redirect(method = "processReceivedPackets", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/ITickable;update()V"))
26+
public void redirect_processReceivedPackets(ITickable manager) {
27+
if (TickrateChangerServer.ticksPerSecond == 0) {
28+
if (!(packetListener instanceof NetHandlerPlayServer) || LoadWorldEvents.isLoading()) {
29+
manager.update();
30+
}
31+
} else {
32+
manager.update();
33+
}
34+
}
35+
}

src/main/resources/mixins.tasmod.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
//Fixing forge and vanilla stuff
2222
"fixes.MixinDragonFightManager",
23+
"fixes.MixinNetworkManager",
2324

2425
//Accessors
2526
"accessors.AccessorEntity",

0 commit comments

Comments
 (0)