Backport blockentitytagquery crash fix to 1.17.1 (#111)

* Backport blockentitytagquery crash fix to 1.17.1

* Test
This commit is contained in:
Luna 2023-06-30 14:43:00 -03:00 committed by GitHub
parent 76155af1ed
commit 671bf4bd18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -5,15 +5,19 @@ Subject: [PATCH] Validate block entity tag query positions
diff --git a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
index a102586b42ac408a3f655f7c0d069ab0990ec7fc..dbf982c85ff361184a34b462bec331ac5b1a472c 100644
index a102586b42ac408a3f655f7c0d069ab0990ec7fc..3e6160650a2e22f9d4232d4656a176007b5bea9e 100644
--- a/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
+++ b/src/main/java/net/minecraft/server/network/ServerGamePacketListenerImpl.java
@@ -1252,7 +1252,7 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@@ -1252,8 +1252,10 @@ public class ServerGamePacketListenerImpl implements ServerPlayerConnection, Ser
@Override
public void handleBlockEntityTagQuery(ServerboundBlockEntityTagQuery packet) {
PacketUtils.ensureRunningOnSameThread(packet, this, this.player.getLevel());
- if (this.player.hasPermissions(2)) {
+ if (this.player.hasPermissions(2) && Level.isInSpawnableBounds(packet.getPos())) { // Scissors - Validate block entity tag query positions
BlockEntity tileentity = this.player.getLevel().getBlockEntity(packet.getPos());
- BlockEntity tileentity = this.player.getLevel().getBlockEntity(packet.getPos());
+ // Scissors start - Validate block entity tag query positions
+ if (this.player.hasPermissions(2) && Level.isInSpawnableBounds(packet.getPos())) {
+ BlockEntity tileentity = this.player.getLevel().isLoaded(packet.getPos()) ? this.player.getLevel().getBlockEntity(packet.getPos()) : null;
+ // Scissors end
CompoundTag nbttagcompound = tileentity != null ? tileentity.save(new CompoundTag()) : null;
this.player.connection.send(new ClientboundTagQueryPacket(packet.getTransactionId(), nbttagcompound));