Skip to content

Commit 41d0d82

Browse files
committed
[Savestates] Merged WorldServerDuck into PlayerChunkMapDuck
Merged both "sendingToClient" functionality and removed a mixin and duck in the process
1 parent 528dc00 commit 41d0d82

File tree

5 files changed

+24
-70
lines changed

5 files changed

+24
-70
lines changed

src/main/java/com/minecrafttas/tasmod/mixin/savestates/MixinPlayerChunkMap.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@
1818
import net.minecraft.server.management.PlayerChunkMapEntry;
1919
import net.minecraft.world.WorldProvider;
2020
import net.minecraft.world.WorldServer;
21+
import net.minecraft.world.chunk.Chunk;
2122

2223
@Mixin(PlayerChunkMap.class)
23-
public class MixinPlayerChunkMap implements PlayerChunkMapDuck {
24+
public abstract class MixinPlayerChunkMap implements PlayerChunkMapDuck {
2425

2526
@Shadow
2627
@Final
@@ -54,6 +55,20 @@ public List<EntityPlayerMP> getPlayers() {
5455
*/
5556
@Override
5657
public void forceTick() {
58+
59+
/*
60+
* Update the chunks to make them eligible to be sent to the client
61+
*
62+
* In the #sendToPlayers() method is a check where the chunk is not sent,
63+
* when Chunk#isPopulated() is false. This would normally happen during the WorldServer#updateBlocks() method,
64+
* but we want to send the chunks without updating the blocks, hence this is circumvented like this.
65+
*/
66+
for (Iterator<Chunk> iterator2 = this.getChunkIterator(); iterator2.hasNext();) {
67+
Chunk chunk = (Chunk) iterator2.next();
68+
chunk.enqueueRelightChecks();
69+
chunk.onTick(false);
70+
}
71+
5772
this.sortMissingChunks = false;
5873
Collections.sort(this.entriesWithoutChunks, new Comparator<PlayerChunkMapEntry>() {
5974
public int compare(PlayerChunkMapEntry playerChunkMapEntry, PlayerChunkMapEntry playerChunkMapEntry2) {
@@ -92,4 +107,7 @@ public int compare(PlayerChunkMapEntry playerChunkMapEntry, PlayerChunkMapEntry
92107
}
93108
}
94109
}
110+
111+
@Shadow
112+
protected abstract Iterator<Chunk> getChunkIterator();
95113
}

src/main/java/com/minecrafttas/tasmod/mixin/savestates/MixinWorldServer.java

Lines changed: 0 additions & 44 deletions
This file was deleted.

src/main/java/com/minecrafttas/tasmod/savestates/handlers/SavestateWorldHandler.java

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
import com.minecrafttas.tasmod.savestates.SavestateHandlerClient;
99
import com.minecrafttas.tasmod.util.Ducks.ChunkProviderDuck;
1010
import com.minecrafttas.tasmod.util.Ducks.PlayerChunkMapDuck;
11-
import com.minecrafttas.tasmod.util.Ducks.WorldServerDuck;
1211
import com.minecrafttas.tasmod.util.LoggerMarkers;
1312

1413
import net.minecraft.client.Minecraft;
@@ -147,11 +146,6 @@ public void addPlayersToChunkMap() {
147146
break;
148147
}
149148
}
150-
151-
// Tick the player chunk map to send the chunks to the clients
152-
for (WorldServer world : worlds) {
153-
((PlayerChunkMapDuck) world.getPlayerChunkMap()).forceTick();
154-
}
155149
}
156150

157151
/**
@@ -218,8 +212,8 @@ public void sendChunksToClient() {
218212
WorldServer[] worlds = server.worlds;
219213

220214
for (WorldServer world : worlds) {
221-
WorldServerDuck worldTick = (WorldServerDuck) world;
222-
worldTick.sendChunksToClient();
215+
PlayerChunkMapDuck chunkMap = (PlayerChunkMapDuck) world.getPlayerChunkMap();
216+
chunkMap.forceTick();
223217
}
224218
}
225219

src/main/java/com/minecrafttas/tasmod/util/Ducks.java

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,6 @@ public static interface ChunkProviderDuck {
3838
public void unloadAllChunks();
3939
}
4040

41-
/**
42-
* Quacks the worldserver to implement custom chunk ticking behavior
43-
*
44-
* @author Scribble
45-
*/
46-
public static interface WorldServerDuck {
47-
48-
/**
49-
* Sends the chunks to the client
50-
* @see com.minecrafttas.tasmod.mixin.savestates.MixinWorldServer#sendChunksToClient() MixinWorldServer#sendChunksToClient()
51-
*/
52-
public void sendChunksToClient();
53-
}
54-
5541
/**
5642
* Quacks the gui screen to spit out mouse positions independent of the display size
5743
*/
@@ -149,8 +135,9 @@ public static interface PlayerChunkMapDuck {
149135
* <p>Forces a tick in the chunk map without being dependent on the world time.
150136
* <p>The chunk map is responsible for sending the necessary chunks to the client.<br>
151137
* However, to properly do that, the chunks have to be sorted first, which happens every few world ticks.
152-
*
153-
* <p>This method sorts and sends the chunks to the clients, without waiting for the world time
138+
* <p>Under normal circumstances, WorldServer#tick() would update the world time to make this happen,
139+
* but our goal with savestates is to load the chunks without advancing the world time.
140+
* Hence why this method sorts and ticks the chunk map, without waiting for the world time
154141
* @see MixinPlayerChunkMap#forceTick()
155142
*/
156143
public void forceTick();

src/main/resources/tasmod.mixin.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
"savestates.MixinChunkProviderServer",
1717
"savestates.MixinNetHandlerPlayServer",
1818
"savestates.MixinScoreboard",
19-
"savestates.MixinWorldServer",
2019

2120
// Events
2221
"events.MixinEntityPlayerMP",

0 commit comments

Comments
 (0)