Skip to content

Commit b1a3704

Browse files
committed
chore: update to 1.21.6
1 parent e9d6366 commit b1a3704

File tree

11 files changed

+57
-37
lines changed

11 files changed

+57
-37
lines changed

build.gradle.kts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ allprojects {
6060
includeGroup("com.github.retrooper")
6161
}
6262
}
63+
maven("https://repo.codemc.io/repository/maven-snapshots/") {
64+
mavenContent {
65+
includeGroup("com.github.retrooper")
66+
}
67+
}
6368
}
6469
}
6570

bukkit/src/main/java/com/github/juliarn/npclib/bukkit/protocol/PacketEventsPacketAdapter.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ final class PacketEventsPacketAdapter implements PlatformPacketAdapter<World, Pl
104104

105105
static final PacketEventsPacketAdapter INSTANCE = new PacketEventsPacketAdapter();
106106

107+
@SuppressWarnings("UnstableApiUsage") // fine for now
107108
private static final PacketEventsSettings PACKET_EVENTS_SETTINGS = new PacketEventsSettings()
108109
.debug(false)
109110
.checkForUpdates(false)
@@ -128,7 +129,7 @@ final class PacketEventsPacketAdapter implements PlatformPacketAdapter<World, Pl
128129
return new Location(pos.x(), pos.y(), pos.z(), yaw, pitch);
129130
}
130131

131-
private static @NotNull EntityData createEntityData(
132+
private static @NotNull EntityData<Object> createEntityData(
132133
int index,
133134
@NotNull Type type,
134135
@NotNull Object value,
@@ -144,7 +145,9 @@ final class PacketEventsPacketAdapter implements PlatformPacketAdapter<World, Pl
144145
value = converted.getValue();
145146
}
146147

147-
return new EntityData(index, Lazy.ENTITY_DATA_TYPE_LOOKUP.get(type), value);
148+
@SuppressWarnings("unchecked") // safe to cast here
149+
EntityDataType<Object> entityDataType = (EntityDataType<Object>) Lazy.ENTITY_DATA_TYPE_LOOKUP.get(type);
150+
return new EntityData<>(index, entityDataType, value);
148151
}
149152

150153
@Override
@@ -323,7 +326,7 @@ final class PacketEventsPacketAdapter implements PlatformPacketAdapter<World, Pl
323326
}
324327

325328
// construct the meta we want to send out
326-
List<EntityData> entityData = new ArrayList<>();
329+
List<EntityData<?>> entityData = new ArrayList<>();
327330
entityData.add(createEntityData(
328331
entityMetadata.index(),
329332
entityMetadata.type(),
@@ -543,10 +546,11 @@ private static final class Lazy {
543546
OPTIONAL_CHAT_COMPONENT_TYPE,
544547
optionalComponent.map(component -> {
545548
// build the component based on the given input
549+
AdventureSerializer serializer = AdventureSerializer.serializer();
546550
if (component.rawMessage() != null) {
547-
return AdventureSerializer.fromLegacyFormat(component.rawMessage());
551+
return serializer.fromLegacy(component.rawMessage());
548552
} else {
549-
return AdventureSerializer.parseComponent(component.encodedJsonMessage());
553+
return serializer.fromJson(component.encodedJsonMessage());
550554
}
551555
}));
552556
} else {

bukkit/src/main/java/com/github/juliarn/npclib/bukkit/protocol/ProtocolLibPacketAdapter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,14 +235,14 @@ final class ProtocolLibPacketAdapter implements PlatformPacketAdapter<World, Pla
235235
boolean optional = parameterized.getRawType() == Optional.class;
236236
if (optional) {
237237
Type serializerType = parameterized.getActualTypeArguments()[0];
238-
Class<?> rawSerializerType = GenericTypeReflector.erase(serializerType);
238+
Type rawSerializerType = GenericTypeReflector.erase(serializerType);
239239

240240
WrappedDataWatcher.Serializer serializer = WrappedDataWatcher.Registry.get(rawSerializerType, true);
241241
return new WrappedWatchableObject(new WrappedDataWatcher.WrappedDataWatcherObject(index, serializer), value);
242242
}
243243
}
244244

245-
Class<?> raw = GenericTypeReflector.erase(type);
245+
Type raw = GenericTypeReflector.erase(type);
246246
WrappedDataWatcher.Serializer serializer = WrappedDataWatcher.Registry.get(raw, false);
247247
return new WrappedWatchableObject(new WrappedDataWatcher.WrappedDataWatcherObject(index, serializer), value);
248248
} else {

fabric/src/main/java/com/github/juliarn/npclib/fabric/FabricVersionAccessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
public final class FabricVersionAccessor {
3232

3333
private static int[] extractServerVersionParts() {
34-
String[] parts = SharedConstants.getCurrentVersion().getName().split("\\.");
34+
String[] parts = SharedConstants.getCurrentVersion().name().split("\\.");
3535
if (parts.length == 2 || parts.length == 3) {
3636
// should be in the correct format, just to make sure
3737
try {

fabric/src/main/java/com/github/juliarn/npclib/fabric/controller/FabricActionController.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public FabricActionController(
7777
ServerPlayer player = event.player();
7878
var pos = player.position();
7979
var rot = player.getRotationVector();
80-
var level = player.serverLevel();
80+
var level = player.level();
8181

8282
double distance = FabricUtil.distance(event.npc(), pos);
8383
if (distance <= this.imitateDistance && event.npc().flagValueOrDefault(Npc.LOOK_AT_PLAYER)) {
@@ -109,7 +109,7 @@ private void handleMove(@NotNull ServerPlayer player, @Nullable Vec3 pos, @Nulla
109109
for (var npc : this.npcTracker.trackedNpcs()) {
110110
// check if the player is still in the same world as the npc
111111
var npcPos = npc.position();
112-
var level = player.serverLevel();
112+
var level = player.level();
113113
if (!npc.world().equals(level) || !npc.world().hasChunk(npcPos.chunkX(), npcPos.chunkZ())) {
114114
// if the player is tracked by the npc, stop that
115115
npc.stopTrackingPlayer(player);
@@ -146,7 +146,7 @@ private void handleLevelChange(
146146
) {
147147
// ensure that we stop tracking the player on NPCs which are not in the same world as the player
148148
for (var npc : this.npcTracker.trackedNpcs()) {
149-
if (!npc.world().equals(player.serverLevel())) {
149+
if (!npc.world().equals(player.level())) {
150150
// the player is no longer in the same world, stop tracking
151151
npc.stopTrackingPlayer(player);
152152
continue;
@@ -164,7 +164,7 @@ private void handleToggleSneak(@NotNull ServerPlayer player, boolean sneaking) {
164164
for (var npc : this.npcTracker.trackedNpcs()) {
165165
// check if we should imitate the action
166166
var distance = FabricUtil.distance(npc, player.position());
167-
if (npc.world().equals(player.serverLevel())
167+
if (npc.world().equals(player.level())
168168
&& npc.tracksPlayer(player)
169169
&& distance <= this.imitateDistance
170170
&& npc.flagValueOrDefault(Npc.SNEAK_WHEN_PLAYER_SNEAKS)) {
@@ -180,7 +180,7 @@ private void handlePlayerHandSwing(@NotNull ServerPlayer player) {
180180
for (var npc : this.npcTracker.trackedNpcs()) {
181181
// check if we should imitate the action
182182
var distance = FabricUtil.distance(npc, player.position());
183-
if (npc.world().equals(player.serverLevel())
183+
if (npc.world().equals(player.level())
184184
&& npc.tracksPlayer(player)
185185
&& distance <= this.imitateDistance
186186
&& npc.flagValueOrDefault(Npc.HIT_WHEN_PLAYER_HITS)) {

fabric/src/main/java/com/github/juliarn/npclib/fabric/mixins/PlayerListMixin.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public abstract class PlayerListMixin {
5050
CommonListenerCookie commonListenerCookie,
5151
CallbackInfo ci
5252
) {
53-
var newLevel = serverPlayer.serverLevel();
53+
var newLevel = serverPlayer.level();
5454
var invoker = FabricActionControllerEvents.SERVER_PLAYER_LEVEL_CHANGE.invoker();
5555
invoker.levelChange(serverPlayer, null, newLevel);
5656
}

fabric/src/main/java/com/github/juliarn/npclib/fabric/mixins/ServerGamePacketListenerImplMixin.java

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import net.minecraft.network.protocol.game.ServerboundInteractPacket;
2929
import net.minecraft.network.protocol.game.ServerboundMovePlayerPacket;
3030
import net.minecraft.network.protocol.game.ServerboundMoveVehiclePacket;
31-
import net.minecraft.network.protocol.game.ServerboundPlayerCommandPacket;
31+
import net.minecraft.network.protocol.game.ServerboundPlayerInputPacket;
3232
import net.minecraft.network.protocol.game.ServerboundSwingPacket;
3333
import net.minecraft.server.level.ServerPlayer;
3434
import net.minecraft.server.network.ServerGamePacketListenerImpl;
@@ -45,21 +45,24 @@
4545
@Mixin(ServerGamePacketListenerImpl.class)
4646
public abstract class ServerGamePacketListenerImplMixin {
4747

48-
@Shadow
49-
public ServerPlayer player;
50-
5148
@Shadow
5249
public abstract ServerPlayer getPlayer();
5350

54-
@Inject(method = "handlePlayerCommand", at = @At("TAIL"))
55-
public void npc_lib$handlePlayerCommand(ServerboundPlayerCommandPacket packet, CallbackInfo ci) {
51+
@Inject(
52+
method = "handlePlayerInput",
53+
at = @At(
54+
value = "INVOKE",
55+
shift = At.Shift.AFTER,
56+
target = "Lnet/minecraft/network/protocol/PacketUtils;ensureRunningOnSameThread(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketListener;Lnet/minecraft/server/level/ServerLevel;)V"
57+
)
58+
)
59+
public void npc_lib$handlePlayerInput(ServerboundPlayerInputPacket packet, CallbackInfo ci) {
5660
var player = this.getPlayer();
57-
var command = packet.getAction();
58-
if (command == ServerboundPlayerCommandPacket.Action.PRESS_SHIFT_KEY
59-
|| command == ServerboundPlayerCommandPacket.Action.RELEASE_SHIFT_KEY) {
61+
var sentInput = packet.input();
62+
var lastInput = player.getLastClientInput();
63+
if (lastInput.shift() != sentInput.shift()) {
6064
var invoker = FabricActionControllerEvents.SERVER_PLAYER_TOGGLE_SNEAK.invoker();
61-
var sprintStarted = command == ServerboundPlayerCommandPacket.Action.PRESS_SHIFT_KEY;
62-
invoker.toggleSneak(player, sprintStarted);
65+
invoker.toggleSneak(player, sentInput.shift());
6366
}
6467
}
6568

fabric/src/main/java/com/github/juliarn/npclib/fabric/mixins/ServerPlayerMixin.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@
3737
public abstract class ServerPlayerMixin {
3838

3939
@Shadow
40-
public abstract ServerLevel serverLevel();
40+
public abstract ServerLevel level();
4141

4242
@Inject(method = "setServerLevel", at = @At("HEAD"))
4343
public void npc_lib$setServerLevel(ServerLevel level, CallbackInfo ci) {
44-
var currentLevel = this.serverLevel();
44+
var currentLevel = this.level();
4545
var player = (ServerPlayer) (Object) this;
4646
if (currentLevel != null && player.connection != null) {
4747
var eventInvoker = FabricActionControllerEvents.SERVER_PLAYER_LEVEL_CHANGE.invoker();

fabric/src/main/java/com/github/juliarn/npclib/fabric/protocol/FabricProtocolAdapter.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,11 @@
3737
import com.github.juliarn.npclib.common.event.DefaultInteractNpcEvent;
3838
import com.github.juliarn.npclib.fabric.controller.FabricActionControllerEvents;
3939
import com.github.juliarn.npclib.fabric.util.FabricUtil;
40+
import com.google.gson.JsonParser;
4041
import com.mojang.authlib.GameProfile;
4142
import com.mojang.authlib.properties.Property;
4243
import com.mojang.datafixers.util.Pair;
44+
import com.mojang.serialization.JsonOps;
4345
import io.leangen.geantyref.TypeFactory;
4446
import java.lang.reflect.Type;
4547
import java.util.ArrayList;
@@ -54,6 +56,7 @@
5456
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
5557
import net.fabricmc.fabric.impl.networking.PayloadTypeRegistryImpl;
5658
import net.minecraft.network.chat.Component;
59+
import net.minecraft.network.chat.ComponentSerialization;
5760
import net.minecraft.network.protocol.common.custom.CustomPacketPayload;
5861
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
5962
import net.minecraft.network.protocol.game.ClientboundAnimatePacket;
@@ -152,8 +155,13 @@ public final class FabricProtocolAdapter
152155
if (rawMessage != null) {
153156
return Component.literal(rawMessage);
154157
} else {
155-
var registries = FabricUtil.getServer().registryAccess();
156-
return Component.Serializer.fromJson(Objects.requireNonNull(component.encodedJsonMessage()), registries);
158+
var encodedJson = Objects.requireNonNull(component.encodedJsonMessage());
159+
var encodedJsonTree = JsonParser.parseString(encodedJson);
160+
var context = FabricUtil.getServer().registryAccess().createSerializationContext(JsonOps.INSTANCE);
161+
return ComponentSerialization.CODEC
162+
.decode(context, encodedJsonTree)
163+
.getOrThrow(IllegalArgumentException::new)
164+
.getFirst();
157165
}
158166
});
159167
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
],
2424
"accessWidener": "npc_lib.accesswidener",
2525
"depends": {
26-
"fabricloader": ">=0.16.10",
27-
"minecraft": "~1.21.5",
26+
"fabricloader": ">=0.16.14",
27+
"minecraft": "~1.21.6",
2828
"java": ">=21",
2929
"fabric-networking-api-v1": "*"
3030
}

0 commit comments

Comments
 (0)