2021-06-12 07:20:08 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Zach Brown <zach.brown@destroystokyo.com>
Date: Sun, 22 May 2016 20:20:55 -0500
Subject: [PATCH] Optional TNT doesn't move in water
diff --git a/src/main/java/net/minecraft/server/level/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
2022-06-07 21:55:39 +02:00
index 61efa24cb1b24216ae80dcd4e68abc39a9ced1bb..232341fa41b1962d329cc17f3146e41c51d22164 100644
2021-06-12 07:20:08 +02:00
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
2022-06-07 21:55:39 +02:00
@@ -65,7 +65,7 @@ public class ServerEntity {
2021-06-12 07:20:08 +02:00
private boolean wasRiding;
private boolean wasOnGround;
// CraftBukkit start
- private final Set<ServerPlayerConnection> trackedPlayers;
+ final Set<ServerPlayerConnection> trackedPlayers; // Paper - private -> package
public ServerEntity(ServerLevel worldserver, Entity entity, int i, boolean flag, Consumer<Packet<?>> consumer, Set<ServerPlayerConnection> trackedPlayers) {
this.trackedPlayers = trackedPlayers;
diff --git a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
2022-06-09 10:51:45 +02:00
index 10f8b5ff56e4c1d8300835e045abdce719a99343..8101f358975b35b5a2dafbade3d14a910e408fa2 100644
2021-06-12 07:20:08 +02:00
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
@@ -97,6 +97,27 @@ public class PrimedTnt extends Entity {
}
}
+ // Paper start - Optional prevent TNT from moving in water
2022-06-09 10:51:45 +02:00
+ if (!this.isRemoved() && this.wasTouchingWater && this.level.paperConfig().fixes.preventTntFromMovingInWater) {
2021-06-12 07:20:08 +02:00
+ /*
+ * Author: Jedediah Smith <jedediah@silencegreys.com>
+ */
+ // Send position and velocity updates to nearby players on every tick while the TNT is in water.
+ // This does pretty well at keeping their clients in sync with the server.
+ net.minecraft.server.level.ChunkMap.TrackedEntity ete = ((net.minecraft.server.level.ServerLevel)this.level).getChunkSource().chunkMap.entityMap.get(this.getId());
+ if (ete != null) {
+ net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket velocityPacket = new net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket(this);
+ net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket positionPacket = new net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket(this);
+
+ ete.seenBy.stream()
+ .filter(viewer -> (viewer.getPlayer().getX() - this.getX()) * (viewer.getPlayer().getY() - this.getY()) * (viewer.getPlayer().getZ() - this.getZ()) < 16 * 16)
+ .forEach(viewer -> {
+ viewer.send(velocityPacket);
+ viewer.send(positionPacket);
+ });
+ }
+ }
+ // Paper end
}
private void explode() {
@@ -152,4 +173,11 @@ public class PrimedTnt extends Entity {
public Packet<?> getAddEntityPacket() {
return new ClientboundAddEntityPacket(this);
}
+
+ // Paper start - Optional prevent TNT from moving in water
+ @Override
+ public boolean isPushedByFluid() {
2022-06-09 10:51:45 +02:00
+ return !level.paperConfig().fixes.preventTntFromMovingInWater && super.isPushedByFluid();
2021-06-12 07:20:08 +02:00
+ }
+ // Paper end
}