aboutsummaryrefslogtreecommitdiffhomepage
path: root/Spigot-Server-Patches/0136-Optional-old-TNT-cannon-behaviors.patch
blob: a3d99a89fb997c04ea37cc414847c60832cc332b (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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
From 05fa0e17dc7ea46a6a78ddf70e0f29d49edf114a 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 old TNT cannon behaviors


diff --git a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
index fbe769eb3..c4acb7597 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -327,4 +327,12 @@ public class PaperWorldConfig {
             );
         }
     }
+
+    public boolean oldCannonBehaviors;
+    private void oldCannonBehaviors() {
+        oldCannonBehaviors = getBoolean("enable-old-tnt-cannon-behaviors", false);
+        if (oldCannonBehaviors) {
+            log("Old Cannon Behaviors: This feature may not be working entirely properly at the moment");
+        }
+    }
 }
diff --git a/src/main/java/net/minecraft/server/BlockDiodeAbstract.java b/src/main/java/net/minecraft/server/BlockDiodeAbstract.java
index 59ee13de8..40c9f18bf 100644
--- a/src/main/java/net/minecraft/server/BlockDiodeAbstract.java
+++ b/src/main/java/net/minecraft/server/BlockDiodeAbstract.java
@@ -76,6 +76,17 @@ public abstract class BlockDiodeAbstract extends BlockFacingHorizontal {
         } else {
             this.b(world, blockposition, iblockdata, 0);
             world.setAir(blockposition);
+            // Paper start - Old TNT cannon behaviors
+            if (world.paperConfig.oldCannonBehaviors) {
+                world.applyPhysics(blockposition.shift(EnumDirection.EAST), this, false);
+                world.applyPhysics(blockposition.shift(EnumDirection.WEST), this, false);
+                world.applyPhysics(blockposition.shift(EnumDirection.SOUTH), this, false);
+                world.applyPhysics(blockposition.shift(EnumDirection.NORTH), this, false);
+                world.applyPhysics(blockposition.shift(EnumDirection.DOWN), this, false);
+                world.applyPhysics(blockposition.shift(EnumDirection.UP), this, false);
+                return;
+            }
+            // Paper end
             EnumDirection[] aenumdirection = EnumDirection.values();
             int i = aenumdirection.length;
 
@@ -173,6 +184,17 @@ public abstract class BlockDiodeAbstract extends BlockFacingHorizontal {
 
     public void postBreak(World world, BlockPosition blockposition, IBlockData iblockdata) {
         if (this.d) {
+            // Paper start - Old TNT cannon behaviors
+            if (world.paperConfig.oldCannonBehaviors) {
+                world.applyPhysics(blockposition.shift(EnumDirection.EAST), this, false);
+                world.applyPhysics(blockposition.shift(EnumDirection.WEST), this, false);
+                world.applyPhysics(blockposition.shift(EnumDirection.NORTH), this, false);
+                world.applyPhysics(blockposition.shift(EnumDirection.SOUTH), this, false);
+                world.applyPhysics(blockposition.shift(EnumDirection.DOWN), this, false);
+                world.applyPhysics(blockposition.shift(EnumDirection.UP), this, false);
+                return;
+            }
+            // Paper end
             EnumDirection[] aenumdirection = EnumDirection.values();
             int i = aenumdirection.length;
 
diff --git a/src/main/java/net/minecraft/server/BlockRedstoneTorch.java b/src/main/java/net/minecraft/server/BlockRedstoneTorch.java
index c7e095a11..741236289 100644
--- a/src/main/java/net/minecraft/server/BlockRedstoneTorch.java
+++ b/src/main/java/net/minecraft/server/BlockRedstoneTorch.java
@@ -52,6 +52,12 @@ public class BlockRedstoneTorch extends BlockTorch {
 
     public void onPlace(World world, BlockPosition blockposition, IBlockData iblockdata) {
         if (this.isOn) {
+            // Paper start - Old TNT cannon behaviors
+            if (world.paperConfig.oldCannonBehaviors) {
+                this.shiftPositions(world, blockposition);
+                return;
+            }
+            // Paper end
             EnumDirection[] aenumdirection = EnumDirection.values();
             int i = aenumdirection.length;
 
@@ -66,6 +72,12 @@ public class BlockRedstoneTorch extends BlockTorch {
 
     public void remove(World world, BlockPosition blockposition, IBlockData iblockdata) {
         if (this.isOn) {
+            // Paper start - Old TNT cannon behaviors
+            if (world.paperConfig.oldCannonBehaviors) {
+                this.shiftPositions(world, blockposition);
+                return;
+            }
+            // Paper end
             EnumDirection[] aenumdirection = EnumDirection.values();
             int i = aenumdirection.length;
 
@@ -78,6 +90,17 @@ public class BlockRedstoneTorch extends BlockTorch {
 
     }
 
+    // Paper start - Old TNT cannon behaviors
+    private void shiftPositions(World world, BlockPosition blockposition) {
+        world.applyPhysics(blockposition.shift(EnumDirection.DOWN), this, false);
+        world.applyPhysics(blockposition.shift(EnumDirection.UP), this, false);
+        world.applyPhysics(blockposition.shift(EnumDirection.WEST), this, false);
+        world.applyPhysics(blockposition.shift(EnumDirection.EAST), this, false);
+        world.applyPhysics(blockposition.shift(EnumDirection.SOUTH), this, false);
+        world.applyPhysics(blockposition.shift(EnumDirection.NORTH), this, false);
+    }
+    // Paper end
+
     public int b(IBlockData iblockdata, IBlockAccess iblockaccess, BlockPosition blockposition, EnumDirection enumdirection) {
         return this.isOn && iblockdata.get(BlockRedstoneTorch.FACING) != enumdirection ? 15 : 0;
     }
diff --git a/src/main/java/net/minecraft/server/BlockRedstoneWire.java b/src/main/java/net/minecraft/server/BlockRedstoneWire.java
index 5a0f026b1..20b9465e7 100644
--- a/src/main/java/net/minecraft/server/BlockRedstoneWire.java
+++ b/src/main/java/net/minecraft/server/BlockRedstoneWire.java
@@ -20,7 +20,7 @@ public class BlockRedstoneWire extends Block {
     public static final BlockStateInteger POWER = BlockStateInteger.of("power", 0, 15);
     protected static final AxisAlignedBB[] f = new AxisAlignedBB[] { new AxisAlignedBB(0.1875D, 0.0D, 0.1875D, 0.8125D, 0.0625D, 0.8125D), new AxisAlignedBB(0.1875D, 0.0D, 0.1875D, 0.8125D, 0.0625D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.1875D, 0.8125D, 0.0625D, 0.8125D), new AxisAlignedBB(0.0D, 0.0D, 0.1875D, 0.8125D, 0.0625D, 1.0D), new AxisAlignedBB(0.1875D, 0.0D, 0.0D, 0.8125D, 0.0625D, 0.8125D), new AxisAlignedBB(0.1875D, 0.0D, 0.0D, 0.8125D, 0.0625D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.8125D, 0.0625D, 0.8125D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 0.8125D, 0.0625D, 1.0D), new AxisAlignedBB(0.1875D, 0.0D, 0.1875D, 1.0D, 0.0625D, 0.8125D), new AxisAlignedBB(0.1875D, 0.0D, 0.1875D, 1.0D, 0.0625D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.1875D, 1.0D, 0.0625D, 0.8125D), new AxisAlignedBB(0.0D, 0.0D, 0.1875D, 1.0D, 0.0625D, 1.0D), new AxisAlignedBB(0.1875D, 0.0D, 0.0D, 1.0D, 0.0625D, 0.8125D), new AxisAlignedBB(0.1875D, 0.0D, 0.0D, 1.0D, 0.0625D, 1.0D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.0625D, 0.8125D), new AxisAlignedBB(0.0D, 0.0D, 0.0D, 1.0D, 0.0625D, 1.0D)};
     private boolean g = true;
-    private final Set<BlockPosition> B = Sets.newHashSet();
+    private final Set<BlockPosition> B = Sets.newHashSet(); private final Set<BlockPosition> blocksToUpdate = B; // Paper - OBFHELPER
 
     public BlockRedstoneWire() {
         super(Material.ORIENTABLE);
@@ -186,6 +186,19 @@ public class BlockRedstoneWire extends Block {
             }
 
             this.B.add(blockposition);
+            // Paper start - Old TNT cannon behaviors
+            if (world.paperConfig.oldCannonBehaviors) {
+                this.blocksToUpdate.add(blockposition.shift(EnumDirection.WEST));
+                this.blocksToUpdate.add(blockposition.shift(EnumDirection.EAST));
+                this.blocksToUpdate.add(blockposition.shift(EnumDirection.DOWN));
+                this.blocksToUpdate.add(blockposition.shift(EnumDirection.UP));
+                this.blocksToUpdate.add(blockposition.shift(EnumDirection.NORTH));
+                this.blocksToUpdate.add(blockposition.shift(EnumDirection.SOUTH));
+                return iblockdata;
+            }
+            // Paper end
+
+
             EnumDirection[] aenumdirection = EnumDirection.values();
             int i1 = aenumdirection.length;
 
@@ -202,6 +215,16 @@ public class BlockRedstoneWire extends Block {
     private void b(World world, BlockPosition blockposition) {
         if (world.getType(blockposition).getBlock() == this) {
             world.applyPhysics(blockposition, this, false);
+            if (world.paperConfig.oldCannonBehaviors) {
+                world.applyPhysics(blockposition.shift(EnumDirection.WEST), this, false);
+                world.applyPhysics(blockposition.shift(EnumDirection.EAST), this, false);
+                world.applyPhysics(blockposition.shift(EnumDirection.NORTH), this, false);
+                world.applyPhysics(blockposition.shift(EnumDirection.SOUTH), this, false);
+                world.applyPhysics(blockposition.shift(EnumDirection.DOWN), this, false);
+                world.applyPhysics(blockposition.shift(EnumDirection.UP), this, false);
+                return;
+            }
+            // Paper end
             EnumDirection[] aenumdirection = EnumDirection.values();
             int i = aenumdirection.length;
 
diff --git a/src/main/java/net/minecraft/server/BlockTNT.java b/src/main/java/net/minecraft/server/BlockTNT.java
index 6b6aa892a..5cec4160c 100644
--- a/src/main/java/net/minecraft/server/BlockTNT.java
+++ b/src/main/java/net/minecraft/server/BlockTNT.java
@@ -29,7 +29,11 @@ public class BlockTNT extends Block {
 
     public void wasExploded(World world, BlockPosition blockposition, Explosion explosion) {
         if (!world.isClientSide) {
-            EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(world, (double) ((float) blockposition.getX() + 0.5F), (double) blockposition.getY(), (double) ((float) blockposition.getZ() + 0.5F), explosion.getSource());
+            // Paper start - Old TNT cannon behaviors
+            double y = blockposition.getY();
+            if (!world.paperConfig.oldCannonBehaviors) y += 0.5;
+            EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(world, (double) ((float) blockposition.getX() + 0.5F), y, (double) ((float) blockposition.getZ() + 0.5F), explosion.getSource());
+            // Paper end
 
             entitytntprimed.setFuseTicks((short) (world.random.nextInt(entitytntprimed.getFuseTicks() / 4) + entitytntprimed.getFuseTicks() / 8));
             world.addEntity(entitytntprimed);
@@ -43,7 +47,11 @@ public class BlockTNT extends Block {
     public void a(World world, BlockPosition blockposition, IBlockData iblockdata, EntityLiving entityliving) {
         if (!world.isClientSide) {
             if (((Boolean) iblockdata.get(BlockTNT.EXPLODE)).booleanValue()) {
-                EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(world, (double) ((float) blockposition.getX() + 0.5F), (double) blockposition.getY(), (double) ((float) blockposition.getZ() + 0.5F), entityliving);
+                // Paper start - Old TNT cannon behaviors
+                double y = blockposition.getY();
+                if (!world.paperConfig.oldCannonBehaviors) y += 0.5;
+                EntityTNTPrimed entitytntprimed = new EntityTNTPrimed(world, (double) ((float) blockposition.getX() + 0.5F), y, (double) ((float) blockposition.getZ() + 0.5F), entityliving);
+                // Paper end
 
                 world.addEntity(entitytntprimed);
                 world.a((EntityHuman) null, entitytntprimed.locX, entitytntprimed.locY, entitytntprimed.locZ, SoundEffects.gV, SoundCategory.BLOCKS, 1.0F, 1.0F);
diff --git a/src/main/java/net/minecraft/server/DispenserRegistry.java b/src/main/java/net/minecraft/server/DispenserRegistry.java
index 6af9f206b..bec623c4d 100644
--- a/src/main/java/net/minecraft/server/DispenserRegistry.java
+++ b/src/main/java/net/minecraft/server/DispenserRegistry.java
@@ -507,7 +507,11 @@ public class DispenserRegistry {
                 org.bukkit.block.Block block = world.getWorld().getBlockAt(isourceblock.getBlockPosition().getX(), isourceblock.getBlockPosition().getY(), isourceblock.getBlockPosition().getZ());
                 CraftItemStack craftItem = CraftItemStack.asCraftMirror(itemstack1);
 
-                BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector((double) blockposition.getX() + 0.5D, (double) blockposition.getY(), (double) blockposition.getZ() + 0.5D));
+                // Paper start - Old TNT cannon behaviors
+                double y = blockposition.getY();
+                if (!world.paperConfig.oldCannonBehaviors) y += 0.5;
+                BlockDispenseEvent event = new BlockDispenseEvent(block, craftItem.clone(), new org.bukkit.util.Vector((double) blockposition.getX() + 0.5D, y, (double) blockposition.getZ() + 0.5D));
+                // Paper end
                 if (!BlockDispenser.eventFired) {
                    world.getServer().getPluginManager().callEvent(event);
                 }
diff --git a/src/main/java/net/minecraft/server/Entity.java b/src/main/java/net/minecraft/server/Entity.java
index 96b1e9a78..0d1fdd3ee 100644
--- a/src/main/java/net/minecraft/server/Entity.java
+++ b/src/main/java/net/minecraft/server/Entity.java
@@ -1089,6 +1089,12 @@ public abstract class Entity implements ICommandListener {
     }
 
     public boolean ak() {
+        // Paper start - OBFHELPER
+        return this.doWaterMovement();
+    }
+
+    public boolean doWaterMovement() {
+        // Paper end
         if (this.bB() instanceof EntityBoat) {
             this.inWater = false;
         } else if (this.world.a(this.getBoundingBox().grow(0.0D, -0.4000000059604645D, 0.0D).shrink(0.001D), Material.WATER, this)) {
@@ -1292,6 +1298,12 @@ public abstract class Entity implements ICommandListener {
     }
 
     public double e(double d0, double d1, double d2) {
+        // Paper start - OBFHELPER
+        return this.getDistance(d0, d1, d2);
+    }
+
+    public double getDistance(double d0, double d1, double d2) {
+        // Paper end
         double d3 = this.locX - d0;
         double d4 = this.locY - d1;
         double d5 = this.locZ - d2;
@@ -1346,6 +1358,11 @@ public abstract class Entity implements ICommandListener {
     }
 
     public void f(double d0, double d1, double d2) {
+        // Paper start - OBFHELPER
+        this.addVelocity(d0, d1, d2);
+    }
+
+    public void addVelocity(double d0, double d1, double d2) {
         this.motX += d0;
         this.motY += d1;
         this.motZ += d2;
@@ -2505,6 +2522,12 @@ public abstract class Entity implements ICommandListener {
     }
 
     public boolean bg() {
+        // Paper start - OBFHELPER
+        return this.pushedByWater();
+    }
+
+    public boolean pushedByWater() {
+        // Paper end
         return true;
     }
 
diff --git a/src/main/java/net/minecraft/server/EntityFallingBlock.java b/src/main/java/net/minecraft/server/EntityFallingBlock.java
index 307a44c85..bb01929e8 100644
--- a/src/main/java/net/minecraft/server/EntityFallingBlock.java
+++ b/src/main/java/net/minecraft/server/EntityFallingBlock.java
@@ -280,4 +280,19 @@ public class EntityFallingBlock extends Entity {
     public boolean bu() {
         return true;
     }
+
+    // Paper start - Old TNT cannon behaviors
+    @Override
+    public double getDistance(double d0, double d1, double d2) {
+        if (!world.paperConfig.oldCannonBehaviors) return super.getDistance(d0, d1, d2);
+
+        double newX = this.locX - d0;
+        double newY = this.locY + this.getHeadHeight() - d1;
+        double newZ = this.locZ - d2;
+
+        return (double) MathHelper.sqrt(newX * newX + newY * newY + newZ * newZ);
+    }
+
+
+    // Paper end
 }
diff --git a/src/main/java/net/minecraft/server/EntityTNTPrimed.java b/src/main/java/net/minecraft/server/EntityTNTPrimed.java
index 25e471d37..e796ade87 100644
--- a/src/main/java/net/minecraft/server/EntityTNTPrimed.java
+++ b/src/main/java/net/minecraft/server/EntityTNTPrimed.java
@@ -32,6 +32,7 @@ public class EntityTNTPrimed extends Entity {
         this.lastY = d1;
         this.lastZ = d2;
         this.source = entityliving;
+        if (world.paperConfig.oldCannonBehaviors) this.motX = this.motZ = 0.0F; // Paper - Old TNT cannon behaviors
     }
 
     protected void i() {
@@ -124,7 +125,7 @@ public class EntityTNTPrimed extends Entity {
     }
 
     public float getHeadHeight() {
-        return 0.0F;
+        return world.paperConfig.oldCannonBehaviors ? this.length / 16F : 0.0F; // Paper - Old TNT cannon behaviors
     }
 
     public void setFuseTicks(int i) {
@@ -146,4 +147,58 @@ public class EntityTNTPrimed extends Entity {
     public int getFuseTicks() {
         return this.c;
     }
+
+    // Paper start - Old TNT cannon behaviors
+    @Override
+    public double getDistance(double d0, double d1, double d2) {
+        if (!world.paperConfig.oldCannonBehaviors) return super.getDistance(d0, d1, d2);
+
+        double newX = this.locX - d0;
+        double newY = this.locY + this.getHeadHeight() - d1;
+        double newZ = this.locZ - d2;
+
+        return (double) MathHelper.sqrt(newX * newX + newY * newY + newZ * newZ);
+    }
+
+    @Override
+    public boolean pushedByWater() {
+        return !world.paperConfig.oldCannonBehaviors && super.pushedByWater();
+    }
+
+    /**
+     * Author: Jedediah Smith <jedediah@silencegreys.com>
+     */
+    @Override
+    public boolean doWaterMovement() {
+        if (!world.paperConfig.oldCannonBehaviors) return super.doWaterMovement();
+
+        // Preserve velocity while calling the super method
+        double oldMotX = this.motX;
+        double oldMotY = this.motY;
+        double oldMotZ = this.motZ;
+
+        super.doWaterMovement();
+
+        this.motX = oldMotX;
+        this.motY = oldMotY;
+        this.motZ = oldMotZ;
+
+        if (this.inWater) {
+            // 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.
+            EntityTrackerEntry ete = ((WorldServer) this.getWorld()).getTracker().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);
+                });
+            }
+        }
+
+        return this.inWater;
+    }
+    // Paper end
 }
diff --git a/src/main/java/net/minecraft/server/Explosion.java b/src/main/java/net/minecraft/server/Explosion.java
index d7bc6a0ed..f2785d86c 100644
--- a/src/main/java/net/minecraft/server/Explosion.java
+++ b/src/main/java/net/minecraft/server/Explosion.java
@@ -149,9 +149,15 @@ public class Explosion {
                             d14 = entity instanceof EntityHuman && world.paperConfig.disableExplosionKnockback ? 0 : EnchantmentProtection.a((EntityLiving) entity, d13); // Paper - Disable explosion knockback
                         }
 
-                        entity.motX += d8 * d14;
-                        entity.motY += d9 * d14;
-                        entity.motZ += d10 * d14;
+                        // Paper start - Fix cannons
+                        /*
+                         entity.motX += d8 * d14;
+                         entity.motY += d9 * d14;
+                         entity.motZ += d10 * d14;
+                          */
+                        // This impulse method sets the dirty flag, so clients will get an immediate velocity update
+                        entity.addVelocity(d8 * d14, d9 * d14, d10 * d14);
+                        // Paper end
                         if (entity instanceof EntityHuman) {
                             EntityHuman entityhuman = (EntityHuman) entity;
 
-- 
2.12.2