aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0101-Optional-TNT-doesn-t-move-in-water.patch
blob: 8f5d535c758a80bd4029a70c56bf8cb4c1aa4f6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
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/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
index eb04fdb172a50ec1f5b7fe78fa0e7655246abd60..6eca3f300020006f02dd36253b522db442e3cc33 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -2,7 +2,6 @@ package com.destroystokyo.paper;
 
 import java.util.List;
 
-import org.bukkit.Bukkit;
 import org.bukkit.configuration.file.YamlConfiguration;
 import org.spigotmc.SpigotWorldConfig;
 
@@ -291,4 +290,14 @@ public class PaperWorldConfig {
             );
         }
     }
+
+    public boolean preventTntFromMovingInWater;
+    private void preventTntFromMovingInWater() {
+        if (PaperConfig.version < 13) {
+            boolean oldVal = getBoolean("enable-old-tnt-cannon-behaviors", false);
+            set("prevent-tnt-from-moving-in-water", oldVal);
+        }
+        preventTntFromMovingInWater = getBoolean("prevent-tnt-from-moving-in-water", false);
+        log("Prevent TNT from moving in water: " + preventTntFromMovingInWater);
+    }
 }
diff --git a/src/main/java/net/minecraft/server/level/EntityTrackerEntry.java b/src/main/java/net/minecraft/server/level/EntityTrackerEntry.java
index beb0beb716869978be6bc5a78ce3b6cf785c5aee..e3cdea3c85d762af6984f3dbe544fdfe101f6ff6 100644
--- a/src/main/java/net/minecraft/server/level/EntityTrackerEntry.java
+++ b/src/main/java/net/minecraft/server/level/EntityTrackerEntry.java
@@ -67,7 +67,7 @@ public class EntityTrackerEntry {
     private boolean q;
     private boolean r;
     // CraftBukkit start
-    private final Set<EntityPlayer> trackedPlayers;
+    final Set<EntityPlayer> trackedPlayers; // Paper - private -> package
     // Paper start
     private java.util.Map<EntityPlayer, Boolean> trackedPlayerMap = null;
 
diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java
index 092ee75f9527af25a48ab052659e3304986b50e0..d314cdd9341e6aa5748a5b1afdd9569bec956c74 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -2771,6 +2771,11 @@ public abstract class Entity implements INamableTileEntity, ICommandListener, ne
     }
 
     public boolean bV() {
+        // Paper start
+        return this.pushedByWater();
+    }
+    public boolean pushedByWater() {
+        // Paper end
         return true;
     }
 
diff --git a/src/main/java/net/minecraft/world/entity/item/EntityTNTPrimed.java b/src/main/java/net/minecraft/world/entity/item/EntityTNTPrimed.java
index 535e7d7297d81026b8586d5049b72fa65519b464..63b35feac07f01b200dd68c4836ceb419e951660 100644
--- a/src/main/java/net/minecraft/world/entity/item/EntityTNTPrimed.java
+++ b/src/main/java/net/minecraft/world/entity/item/EntityTNTPrimed.java
@@ -4,10 +4,14 @@ import javax.annotation.Nullable;
 import net.minecraft.core.particles.Particles;
 import net.minecraft.nbt.NBTTagCompound;
 import net.minecraft.network.protocol.Packet;
+import net.minecraft.network.protocol.game.PacketPlayOutEntityTeleport;
+import net.minecraft.network.protocol.game.PacketPlayOutEntityVelocity;
 import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity;
 import net.minecraft.network.syncher.DataWatcher;
 import net.minecraft.network.syncher.DataWatcherObject;
 import net.minecraft.network.syncher.DataWatcherRegistry;
+import net.minecraft.server.level.PlayerChunkMap;
+import net.minecraft.server.level.WorldServer;
 import net.minecraft.world.entity.Entity;
 import net.minecraft.world.entity.EntityLiving;
 import net.minecraft.world.entity.EntityPose;
@@ -96,7 +100,27 @@ public class EntityTNTPrimed extends Entity {
                 this.world.addParticle(Particles.SMOKE, this.locX(), this.locY() + 0.5D, this.locZ(), 0.0D, 0.0D, 0.0D);
             }
         }
-
+        // Paper start - Optional prevent TNT from moving in water
+        if (!this.dead && this.inWater && this.world.paperConfig.preventTntFromMovingInWater) {
+            /*
+             * 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.
+            PlayerChunkMap.EntityTracker ete = ((WorldServer)this.world).getChunkProvider().playerChunkMap.trackedEntities.get(this.getId());
+            if (ete != null) {
+                PacketPlayOutEntityVelocity velocityPacket = new PacketPlayOutEntityVelocity(this);
+                PacketPlayOutEntityTeleport positionPacket = new PacketPlayOutEntityTeleport(this);
+
+                ete.trackedPlayers.stream()
+                    .filter(viewer -> (viewer.locX() - this.locX()) * (viewer.locY() - this.locY()) * (viewer.locZ() - this.locZ()) < 16 * 16)
+                    .forEach(viewer -> {
+                        viewer.playerConnection.sendPacket(velocityPacket);
+                        viewer.playerConnection.sendPacket(positionPacket);
+                    });
+            }
+        }
+        // Paper end
     }
 
     private void explode() {
@@ -165,4 +189,11 @@ public class EntityTNTPrimed extends Entity {
     public Packet<?> P() {
         return new PacketPlayOutSpawnEntity(this);
     }
+
+    // Paper start - Optional prevent TNT from moving in water
+    @Override
+    public boolean pushedByWater() {
+        return !world.paperConfig.preventTntFromMovingInWater && super.pushedByWater();
+    }
+    // Paper end
 }