Skip to content

Commit 1f3c580

Browse files
committed
chore(minecraft): update implementations for 25w32a
Noticeable changes are in PlayerList management for server player loads. See: https://minecraft.wiki/w/Java_Edition_25w32a
1 parent e7696bb commit 1f3c580

14 files changed

Lines changed: 184 additions & 129 deletions

File tree

gradle/verification-metadata.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3751,6 +3751,11 @@
37513751
<sha256 value="8776a213deaa1cbbadb77820225211e1b9adead2341b55cc35bc92c9076620a3" origin="Generated by Gradle"/>
37523752
</artifact>
37533753
</component>
3754+
<component group="net.ltgt.errorprone" name="net.ltgt.errorprone.gradle.plugin" version="4.3.0">
3755+
<artifact name="net.ltgt.errorprone.gradle.plugin-4.3.0.pom">
3756+
<sha256 value="3370e20ef3213ffce47f7fda31266c33e9cca3b1b7f4d54169b482277042654b" origin="Generated by Gradle"/>
3757+
</artifact>
3758+
</component>
37543759
<component group="net.ltgt.gradle" name="gradle-errorprone-plugin" version="3.1.0">
37553760
<artifact name="gradle-errorprone-plugin-3.1.0.jar">
37563761
<sha256 value="10fb66b55747ced1db9c89c8c3d0adb5dbd3f8f12f2a183bee2b5ff818d1fd6c" origin="Generated by Gradle"/>
@@ -3759,6 +3764,14 @@
37593764
<sha256 value="d393a0d3337193cb21b64a98714a1da8a966349be214cbb16171a9925a7985ee" origin="Generated by Gradle"/>
37603765
</artifact>
37613766
</component>
3767+
<component group="net.ltgt.gradle" name="gradle-errorprone-plugin" version="4.3.0">
3768+
<artifact name="gradle-errorprone-plugin-4.3.0.jar">
3769+
<sha256 value="42f89c1f582ecd09459586d3d19c0fa92a332035e4a70b5699a8ec6a81aec32c" origin="Generated by Gradle"/>
3770+
</artifact>
3771+
<artifact name="gradle-errorprone-plugin-4.3.0.module">
3772+
<sha256 value="6d2b0a7809ffde227ec15a4cf28e68929be22a1a12a0f56ad5e795d5058f2f6e" origin="Generated by Gradle"/>
3773+
</artifact>
3774+
</component>
37623775
<component group="net.md-5" name="SpecialSource" version="1.8.5">
37633776
<artifact name="SpecialSource-1.8.5.jar">
37643777
<sha256 value="0ac4b7acac8d927e75cf47061b0c067130dd3bd713c493205ea7607241df2813" origin="Generated by Gradle"/>

src/accessors/java/org/spongepowered/common/accessor/network/chat/StyleAccessor.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
import net.minecraft.network.chat.HoverEvent;
3030
import net.minecraft.network.chat.Style;
3131
import net.minecraft.network.chat.TextColor;
32-
import net.minecraft.resources.ResourceLocation;
3332
import org.spongepowered.asm.mixin.Mixin;
3433
import org.spongepowered.asm.mixin.gen.Accessor;
3534
import org.spongepowered.asm.mixin.gen.Invoker;

src/main/java/org/spongepowered/common/data/provider/item/stack/SpawnEggItemStackData.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@
3030
import net.minecraft.world.item.Item;
3131
import net.minecraft.world.item.ItemStack;
3232
import net.minecraft.world.item.SpawnEggItem;
33-
import net.minecraft.world.item.component.CustomData;
3433
import net.minecraft.world.item.component.TypedEntityData;
3534
import org.checkerframework.checker.nullness.qual.Nullable;
3635
import org.spongepowered.api.data.Keys;
3736
import org.spongepowered.api.entity.EntityArchetype;
38-
import org.spongepowered.common.SpongeCommon;
3937
import org.spongepowered.common.data.provider.DataProviderRegistrator;
4038
import org.spongepowered.common.entity.SpongeEntityArchetypeBuilder;
4139

src/main/java/org/spongepowered/common/item/SpongeItemStack.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import com.google.common.collect.ImmutableList;
2929
import com.mojang.datafixers.util.Pair;
3030
import com.mojang.serialization.Dynamic;
31-
import net.minecraft.core.Registry;
3231
import net.minecraft.core.component.DataComponentPatch;
3332
import net.minecraft.core.component.DataComponentType;
3433
import net.minecraft.core.component.DataComponents;

src/mixins/java/org/spongepowered/common/mixin/core/client/server/IntegratedPlayerListMixin.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
*/
2525
package org.spongepowered.common.mixin.core.client.server;
2626

27-
import com.mojang.authlib.GameProfile;
2827
import net.minecraft.client.server.IntegratedPlayerList;
2928
import net.minecraft.network.chat.Component;
3029
import net.minecraft.server.players.NameAndId;
@@ -48,9 +47,10 @@ public abstract class IntegratedPlayerListMixin extends PlayerListMixin implemen
4847

4948
@Override
5049
public CompletableFuture<Component> bridge$canPlayerLoginClient(final SocketAddress param0, final com.mojang.authlib.GameProfile param1) {
51-
final Component component = this.shadow$canPlayerLogin(param0, new NameAndId(param1));
50+
final var name = new NameAndId(param1);
51+
final Component component = this.shadow$canPlayerLogin(param0, name);
5252
if (component == null) {
53-
return this.impl$canPlayerLoginServer(param0, param1);
53+
return this.impl$canPlayerLoginServer(param0, name);
5454
}
5555
return CompletableFuture.completedFuture(component);
5656
}

src/mixins/java/org/spongepowered/common/mixin/core/server/ServerFunctionLibraryMixin.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
2929
import net.minecraft.server.ServerFunctionLibrary;
3030
import net.minecraft.server.packs.resources.PreparableReloadListener;
31-
import net.minecraft.server.packs.resources.ResourceManager;
3231
import org.spongepowered.api.Sponge;
3332
import org.spongepowered.asm.mixin.Mixin;
3433

@@ -39,10 +38,11 @@
3938
public abstract class ServerFunctionLibraryMixin {
4039

4140
@WrapMethod(method = "reload")
42-
private CompletableFuture<Void> impl$onReload(final PreparableReloadListener.PreparationBarrier barrier, final ResourceManager manager,
43-
final Executor executor1, final Executor executor2, final Operation<CompletableFuture<Void>> original) {
41+
private CompletableFuture<Void> impl$onReload(
42+
final PreparableReloadListener.SharedState state, final Executor executor1,
43+
final PreparableReloadListener.PreparationBarrier barrier, Executor executor2, Operation<CompletableFuture<Void>> original) {
4444
if (Sponge.isServerAvailable()) {
45-
return original.call(barrier, manager, executor1, executor2);
45+
return original.call(state, executor1, barrier, executor2);
4646
}
4747
return barrier.wait(null);
4848
}

src/mixins/java/org/spongepowered/common/mixin/core/server/dedicated/DedicatedPlayerListMixin.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@
2424
*/
2525
package org.spongepowered.common.mixin.core.server.dedicated;
2626

27-
import com.mojang.authlib.GameProfile;
2827
import net.minecraft.core.LayeredRegistryAccess;
2928
import net.minecraft.server.MinecraftServer;
3029
import net.minecraft.server.RegistryLayer;

src/mixins/java/org/spongepowered/common/mixin/core/server/network/ServerConfigurationPacketListenerImplMixin.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import net.minecraft.network.protocol.configuration.ServerboundFinishConfigurationPacket;
3333
import net.minecraft.server.network.ConfigurationTask;
3434
import net.minecraft.server.network.ServerConfigurationPacketListenerImpl;
35+
import net.minecraft.server.players.NameAndId;
3536
import net.minecraft.server.players.PlayerList;
3637
import org.checkerframework.checker.nullness.qual.Nullable;
3738
import org.spongepowered.api.event.SpongeEventFactory;
@@ -137,8 +138,8 @@ public abstract class ServerConfigurationPacketListenerImplMixin extends ServerC
137138
}
138139

139140
@Redirect(method = "handleConfigurationFinished",
140-
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;canPlayerLogin(Ljava/net/SocketAddress;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/network/chat/Component;"))
141-
private Component impl$onCanPlayerLogin(final PlayerList instance, final SocketAddress $$0, final GameProfile $$1) {
141+
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;canPlayerLogin(Ljava/net/SocketAddress;Lnet/minecraft/server/players/NameAndId;)Lnet/minecraft/network/chat/Component;"))
142+
private Component impl$onCanPlayerLogin(final PlayerList instance, final SocketAddress $$0, final NameAndId $$1) {
142143
//Skip as we check it at the start.
143144
return null;
144145
}

src/mixins/java/org/spongepowered/common/mixin/core/server/network/ServerLoginPacketListenerImplMixin.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import net.minecraft.network.protocol.login.custom.CustomQueryAnswerPayload;
3838
import net.minecraft.server.MinecraftServer;
3939
import net.minecraft.server.network.ServerLoginPacketListenerImpl;
40+
import net.minecraft.server.players.NameAndId;
4041
import net.minecraft.server.players.PlayerList;
4142
import net.minecraft.util.Crypt;
4243
import net.minecraft.util.CryptException;
@@ -138,8 +139,8 @@ public abstract class ServerLoginPacketListenerImplMixin implements ServerLoginP
138139
}
139140

140141
@Redirect(method = "verifyLoginAndFinishConnectionSetup",
141-
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;canPlayerLogin(Ljava/net/SocketAddress;Lcom/mojang/authlib/GameProfile;)Lnet/minecraft/network/chat/Component;"))
142-
private Component impl$onCanPlayerLogin(final PlayerList instance, final SocketAddress $$0, final GameProfile $$1) {
142+
at = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;canPlayerLogin(Ljava/net/SocketAddress;Lnet/minecraft/server/players/NameAndId;)Lnet/minecraft/network/chat/Component;"))
143+
private Component impl$onCanPlayerLogin(final PlayerList instance, final SocketAddress $$0, final NameAndId $$1) {
143144
//We check this as part of auth event.
144145
return null;
145146
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* This file is part of Sponge, licensed under the MIT License (MIT).
3+
*
4+
* Copyright (c) SpongePowered <https://www.spongepowered.org>
5+
* Copyright (c) contributors
6+
*
7+
* Permission is hereby granted, free of charge, to any person obtaining a copy
8+
* of this software and associated documentation files (the "Software"), to deal
9+
* in the Software without restriction, including without limitation the rights
10+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11+
* copies of the Software, and to permit persons to whom the Software is
12+
* furnished to do so, subject to the following conditions:
13+
*
14+
* The above copyright notice and this permission notice shall be included in
15+
* all copies or substantial portions of the Software.
16+
*
17+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23+
* THE SOFTWARE.
24+
*/
25+
package org.spongepowered.common.mixin.core.server.network.config;
26+
27+
import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
28+
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
29+
import com.llamalad7.mixinextras.sugar.Local;
30+
import net.minecraft.world.level.storage.ValueInput;
31+
import org.spongepowered.api.data.Keys;
32+
import org.spongepowered.api.entity.living.player.server.ServerPlayer;
33+
import org.spongepowered.asm.mixin.Mixin;
34+
import org.spongepowered.asm.mixin.injection.At;
35+
import org.spongepowered.asm.mixin.injection.Slice;
36+
37+
import java.io.IOException;
38+
import java.time.Instant;
39+
import java.util.Optional;
40+
import java.util.function.Consumer;
41+
42+
@Mixin(targets = "net.minecraft.server.network.config.PrepareSpawnTask$Ready")
43+
public class PrepareSpawnTask_ReadyMixin {
44+
45+
@WrapOperation(
46+
method = "spawn", // or the mapped method containing the Player.load call
47+
at = @At(
48+
value = "INVOKE",
49+
target = "Ljava/util/Optional;ifPresent(Ljava/util/function/Consumer;)V"
50+
// If your version uses CompoundTag instead, use the proper descriptor
51+
)
52+
)
53+
private void impl$afterPlayerLoad(
54+
final Optional<ValueInput> instance, final Consumer<? super ValueInput> action,
55+
final Operation<Void> original,
56+
@Local net.minecraft.server.level.ServerPlayer player
57+
) throws IOException {
58+
// Call vanilla first
59+
original.call(instance, action);
60+
61+
final ServerPlayer sPlayer = (ServerPlayer) player;
62+
if (sPlayer.get(Keys.FIRST_DATE_JOINED).isEmpty()) {
63+
// TODO - 25w32a changed where we have access to the Player and moved access to the data files elsewhere.
64+
// final Path file = new File(this.playerDir, player.getStringUUID() + ".dat").toPath();
65+
// final Instant creationTime = java.nio.file.Files.exists(file)
66+
// ? java.nio.file.Files.readAttributes(file, java.nio.file.attribute.BasicFileAttributes.class)
67+
// .creationTime().toInstant()
68+
// : null;
69+
//
70+
// ((SpongeServer) SpongeCommon.server())
71+
// .getPlayerDataManager()
72+
// .readLegacyPlayerData(sPlayer, nbtOrValueInput, creationTime);
73+
}
74+
75+
sPlayer.offer(Keys.LAST_DATE_JOINED, java.time.Instant.now());
76+
}
77+
78+
79+
@WrapOperation(method = "spawn",
80+
at = @At(value = "INVOKE", target = "Ljava/util/Optional;ifPresent(Ljava/util/function/Consumer;)V"),
81+
slice = @Slice(
82+
from = @At(value = "INVOKE", target = "Lnet/minecraft/server/players/PlayerList;loadPlayerData(Lnet/minecraft/server/players/NameAndId;)Ljava/util/Optional;"),
83+
to = @At(value = "INVOKE", target = "Lnet/minecraft/server/level/ServerPlayer;snapTo(Lnet/minecraft/world/phys/Vec3;FF)V")
84+
)
85+
)
86+
private void impl$setPlayerDataForNewPlayers(
87+
final Optional<ValueInput> instance, final Consumer<? super ValueInput> action,
88+
final Operation<Void> original,
89+
@Local final net.minecraft.server.level.ServerPlayer playerIn
90+
) {
91+
original.call(instance, action);
92+
if (instance.isEmpty()) {
93+
final Instant now = Instant.now();
94+
((ServerPlayer) playerIn).offer(Keys.FIRST_DATE_JOINED, now);
95+
((ServerPlayer) playerIn).offer(Keys.LAST_DATE_JOINED, now);
96+
}
97+
}
98+
}

0 commit comments

Comments
 (0)