Skip to content

Commit

Permalink
[Savestates] Fix entities being duplicated after loadstate
Browse files Browse the repository at this point in the history
  • Loading branch information
ScribbleTAS committed Dec 11, 2024
1 parent 5dc9725 commit 0803451
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.minecrafttas.tasmod.mixin.savestates;

import java.util.Set;

import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;

import com.minecrafttas.tasmod.util.Ducks.WorldClientDuck;

import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.entity.Entity;

@Mixin(WorldClient.class)
public class MixinWorldClient implements WorldClientDuck {

@Shadow
@Final
private Set<Entity> entityList;

@Override
public void clearEntityList() {
entityList.clear();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.minecrafttas.tasmod.savestates.gui.GuiSavestateSavingScreen;
import com.minecrafttas.tasmod.util.Ducks.ChunkProviderDuck;
import com.minecrafttas.tasmod.util.Ducks.SubtickDuck;
import com.minecrafttas.tasmod.util.Ducks.WorldClientDuck;
import com.minecrafttas.tasmod.util.LoggerMarkers;
import com.mojang.realmsclient.gui.ChatFormatting;

Expand Down Expand Up @@ -325,7 +326,8 @@ public static void unloadAllClientChunks() {
ChunkProviderClient chunkProvider = mc.world.getChunkProvider();

((ChunkProviderDuck) chunkProvider).unloadAllChunks();
Minecraft.getMinecraft().renderGlobal.loadRenderers();
mc.renderGlobal.loadRenderers();
((WorldClientDuck) mc.world).clearEntityList();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ private void addPlayerToChunkMap(WorldServer world, EntityPlayerMP player) {
}
world.getChunkProvider().provideChunk(playerChunkPosX, playerChunkPosY);

world.addWeatherEffect(player);
world.spawnEntity(player);
}

Expand Down
11 changes: 11 additions & 0 deletions src/main/java/com/minecrafttas/tasmod/util/Ducks.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,15 @@ public static interface ScoreboardDuck {
*/
public void clearScoreboard();
}

/**
* Quacks the world client
*/
public static interface WorldClientDuck {

/**
* Clear entitylist on the client
*/
public void clearEntityList();
}
}
1 change: 1 addition & 0 deletions src/main/resources/tasmod.mixin.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

// Savestates
"savestates.MixinChunkProviderClient",
"savestates.MixinWorldClient",

// Interpolation
"MixinFrustum",
Expand Down

0 comments on commit 0803451

Please sign in to comment.