Skip to content

Commit cac9b51

Browse files
committed
[Savestates] Started on fixing resourcepacks
1 parent b26a9b4 commit cac9b51

File tree

6 files changed

+65
-0
lines changed

6 files changed

+65
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.minecrafttas.tasmod.mixin.savestates;
2+
3+
import java.util.concurrent.locks.ReentrantLock;
4+
5+
import org.spongepowered.asm.mixin.Final;
6+
import org.spongepowered.asm.mixin.Mixin;
7+
import org.spongepowered.asm.mixin.Shadow;
8+
9+
import com.google.common.util.concurrent.ListenableFuture;
10+
import com.minecrafttas.tasmod.util.Ducks.ResourcePackRepositoryDuck;
11+
12+
import net.minecraft.client.Minecraft;
13+
import net.minecraft.client.resources.IResourcePack;
14+
import net.minecraft.client.resources.ResourcePackRepository;
15+
16+
@Mixin(ResourcePackRepository.class)
17+
public class MixinResourcePackRepository implements ResourcePackRepositoryDuck {
18+
19+
@Shadow
20+
@Final
21+
private ReentrantLock lock;
22+
@Shadow
23+
private ListenableFuture<Object> downloadingPacks;
24+
@Shadow
25+
private IResourcePack serverResourcePack;
26+
27+
@Override
28+
public void clearServerResourcePackBlocking() {
29+
this.lock.lock();
30+
31+
try {
32+
if (this.downloadingPacks != null) {
33+
this.downloadingPacks.cancel(true);
34+
}
35+
36+
this.downloadingPacks = null;
37+
if (this.serverResourcePack != null) {
38+
this.serverResourcePack = null;
39+
Minecraft.getMinecraft().refreshResources();
40+
}
41+
} finally {
42+
this.lock.unlock();
43+
}
44+
}
45+
46+
}

src/main/java/com/minecrafttas/tasmod/savestates/SavestateHandlerClient.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import com.minecrafttas.tasmod.savestates.exceptions.SavestateException;
2929
import com.minecrafttas.tasmod.savestates.gui.GuiSavestateSavingScreen;
3030
import com.minecrafttas.tasmod.util.Ducks.ChunkProviderDuck;
31+
import com.minecrafttas.tasmod.util.Ducks.ResourcePackRepositoryDuck;
3132
import com.minecrafttas.tasmod.util.Ducks.SubtickDuck;
3233
import com.minecrafttas.tasmod.util.Ducks.WorldClientDuck;
3334
import com.minecrafttas.tasmod.util.LoggerMarkers;
@@ -151,6 +152,8 @@ public static void loadstate(String nameOfSavestate) throws Exception {
151152
return;
152153
}
153154

155+
((ResourcePackRepositoryDuck) Minecraft.getMinecraft().getResourcePackRepository()).clearServerResourcePackBlocking();
156+
154157
PlaybackControllerClient controller = TASmodClient.controller;
155158

156159
TASstate state = controller.getState();

src/main/java/com/minecrafttas/tasmod/savestates/SavestateHandlerServer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ public void loadState(int savestateIndex, boolean tickrate0, boolean changeIndex
398398

399399
worldHandler.sendChunksToClient();
400400

401+
playerHandler.updateServerResourcePack();
402+
401403
try {
402404
TASmod.server.sendToAll(new TASmodBufferBuilder(CLEAR_SCREEN));
403405
} catch (Exception e) {

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,4 +225,13 @@ public void onClientPacket(PacketID id, ByteBuffer buf, String username) throws
225225
break;
226226
}
227227
}
228+
229+
public void updateServerResourcePack() {
230+
if (!this.server.getResourcePackUrl().isEmpty()) {
231+
List<EntityPlayerMP> players = server.getPlayerList().getPlayers();
232+
for (EntityPlayerMP player : players) {
233+
player.loadResourcePack(this.server.getResourcePackUrl(), this.server.getResourcePackHash());
234+
}
235+
}
236+
}
228237
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,8 @@ public static interface PlayerChunkMapDuck {
142142
*/
143143
public void forceTick();
144144
}
145+
146+
public static interface ResourcePackRepositoryDuck {
147+
public void clearServerResourcePackBlocking();
148+
}
145149
}

src/main/resources/tasmod.mixin.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
// Savestates
3333
"savestates.MixinChunkProviderClient",
3434
"savestates.MixinWorldClient",
35+
"savestates.MixinResourcePackRepository",
3536

3637
// Interpolation
3738
"MixinFrustum",

0 commit comments

Comments
 (0)