Skip to content

Commit 895f3e5

Browse files
committed
fix crash on windows platform & fix fabric dep version range
1 parent 92417d8 commit 895f3e5

6 files changed

Lines changed: 74 additions & 12 deletions

File tree

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.github.litermc.vschunkloader.mixin;
2+
3+
import com.github.litermc.vschunkloader.platform.PlatformHelper;
4+
5+
import net.minecraft.server.MinecraftServer;
6+
import net.minecraft.server.level.ServerPlayer;
7+
import net.minecraft.server.players.PlayerList;
8+
import net.minecraft.stats.ServerStatsCounter;
9+
import net.minecraft.world.entity.player.Player;
10+
import net.minecraft.world.level.storage.LevelResource;
11+
12+
import org.spongepowered.asm.mixin.Final;
13+
import org.spongepowered.asm.mixin.Mixin;
14+
import org.spongepowered.asm.mixin.Shadow;
15+
import org.spongepowered.asm.mixin.injection.At;
16+
import org.spongepowered.asm.mixin.injection.Inject;
17+
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
18+
19+
import java.io.File;
20+
21+
@Mixin(PlayerList.class)
22+
public class MixinPlayerList {
23+
@Shadow
24+
@Final
25+
private MinecraftServer server;
26+
27+
@Inject(method = "getPlayerStats", at = @At("HEAD"), cancellable = true)
28+
public void getPlayerStats(final Player player, final CallbackInfoReturnable<ServerStatsCounter> cir) {
29+
if (!(player instanceof final ServerPlayer serverPlayer)) {
30+
return;
31+
}
32+
if (!PlatformHelper.get().isSpecialFakePlayer(serverPlayer)) {
33+
return;
34+
}
35+
cir.setReturnValue(new ServerStatsCounter(
36+
this.server,
37+
new File(
38+
this.server.getWorldPath(LevelResource.PLAYER_STATS_DIR).toFile(),
39+
player.getUUID() + ".json"
40+
)
41+
));
42+
}
43+
}

common/src/main/java/com/github/litermc/vschunkloader/platform/PlatformHelper.java

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -176,25 +176,33 @@ public static PlatformHelper get() {
176176
CreativeModeTab.Builder newCreativeModeTab();
177177

178178
/**
179-
* Create a new fake player.
180-
*
181-
* @param level The level the player should be created in.
182-
* @param profile The user this player should mimic.
183-
* @return The newly constructed fake player.
184-
*/
179+
* Create a new fake player.
180+
*
181+
* @param level The level the player should be created in.
182+
* @param profile The user this player should mimic.
183+
* @return The newly constructed fake player.
184+
*/
185185
ServerPlayer createFakePlayer(ServerLevel level, GameProfile profile);
186186

187187
/**
188-
* Determine if a player is not a real player.
189-
*
190-
* @param player The player to check.
191-
* @return Whether this player is fake.
192-
*/
188+
* Determine if a player is not a real player.
189+
*
190+
* @param player The player to check.
191+
* @return Whether this player is fake.
192+
*/
193193
default boolean isFakePlayer(ServerPlayer player) {
194194
// Any subclass of ServerPlayer (i.e. Forge's FakePlayer) is assumed to be a fake.
195195
return player.connection == null || player.getClass() != ServerPlayer.class;
196196
}
197197

198+
/**
199+
* Determine if a player the mod's fake player
200+
*
201+
* @param player The player to check.
202+
* @return Whether this player is this mod's fake player.
203+
*/
204+
boolean isSpecialFakePlayer(ServerPlayer player);
205+
198206
final class Instance {
199207
static final @Nullable PlatformHelper INSTANCE;
200208
static final @Nullable Throwable ERROR;

common/src/main/resources/vschunkloader.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"mixins": [
88
"MixinChunkMap",
99
"MixinMinecraftPlayer",
10+
"MixinPlayerList",
1011
"MixinServerLevel",
1112
"MixinShipObjectServerWorld",
1213
"MixinSleepStatus"

fabric/src/main/java/com/github/litermc/vschunkloader/platform/PlatformHelperImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ public ServerPlayer createFakePlayer(ServerLevel world, GameProfile name) {
182182
return FakePlayer.create(world, name);
183183
}
184184

185+
@Override
186+
public boolean isSpecialFakePlayer(ServerPlayer player) {
187+
return player instanceof FakePlayer;
188+
}
189+
185190
private record RegistryWrapperImpl<T>(
186191
ResourceLocation name, Registry<T> registry
187192
) implements RegistryWrappers.RegistryWrapper<T> {

fabric/src/main/resources/fabric.mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
"fabricloader": ">=0.16",
3333
"java": ">=17",
3434
"minecraft": "${minecraft_version}",
35-
"valkyrienskies": "[2.4,2.5)"
35+
"valkyrienskies": "2.4.*"
3636
}
3737
}
3838

forge/src/main/java/com/github/litermc/vschunkloader/platform/PlatformHelperImpl.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ public ServerPlayer createFakePlayer(ServerLevel world, GameProfile profile) {
171171
return FakePlayer.create(world, profile);
172172
}
173173

174+
@Override
175+
public boolean isSpecialFakePlayer(ServerPlayer player) {
176+
return player instanceof FakePlayer;
177+
}
178+
174179
private record RegistryWrapperImpl<T>(
175180
ResourceLocation name, ForgeRegistry<T> registry
176181
) implements RegistryWrappers.RegistryWrapper<T> {

0 commit comments

Comments
 (0)