Paper/patches/server/Optional-TNT-doesn-t-move-in-water.patch

83 lines
4.3 KiB
Diff
Raw Normal View History

2021-06-11 14:02:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Zach Brown <1254957+zachbr@users.noreply.github.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 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
+++ b/src/main/java/com/destroystokyo/paper/PaperWorldConfig.java
@@ -0,0 +0,0 @@ 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/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
@@ -0,0 +0,0 @@ public class ServerEntity {
private boolean wasRiding;
private boolean wasOnGround;
// CraftBukkit start
2021-06-12 07:20:08 +02:00
- private final Set<ServerPlayerConnection> trackedPlayers;
+ final Set<ServerPlayerConnection> trackedPlayers; // Paper - private -> package
2021-06-11 14:02:28 +02:00
2021-06-12 07:20:08 +02:00
public ServerEntity(ServerLevel worldserver, Entity entity, int i, boolean flag, Consumer<Packet<?>> consumer, Set<ServerPlayerConnection> trackedPlayers) {
this.trackedPlayers = trackedPlayers;
2021-06-11 14:02:28 +02:00
diff --git a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 100644
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
@@ -0,0 +0,0 @@ public class PrimedTnt extends Entity {
}
}
2021-06-12 07:20:08 +02:00
2021-06-11 14:02:28 +02:00
+ // Paper start - Optional prevent TNT from moving in water
2021-06-12 07:20:08 +02:00
+ if (!this.isRemoved() && this.wasTouchingWater && this.level.paperConfig.preventTntFromMovingInWater) {
2021-06-11 14:02:28 +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.
2021-06-12 07:20:08 +02:00
+ net.minecraft.server.level.ChunkMap.TrackedEntity ete = ((net.minecraft.server.level.ServerLevel)this.level).getChunkSource().chunkMap.entityMap.get(this.getId());
2021-06-11 14:02:28 +02:00
+ if (ete != null) {
2021-06-12 07:20:08 +02:00
+ 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);
2021-06-11 14:02:28 +02:00
+
+ ete.seenBy.stream()
2021-06-12 07:20:08 +02:00
+ .filter(viewer -> (viewer.getPlayer().getX() - this.getX()) * (viewer.getPlayer().getY() - this.getY()) * (viewer.getPlayer().getZ() - this.getZ()) < 16 * 16)
2021-06-11 14:02:28 +02:00
+ .forEach(viewer -> {
2021-06-12 07:20:08 +02:00
+ viewer.send(velocityPacket);
+ viewer.send(positionPacket);
2021-06-11 14:02:28 +02:00
+ });
+ }
+ }
+ // Paper end
}
private void explode() {
@@ -0,0 +0,0 @@ public class PrimedTnt extends Entity {
public Packet<?> getAddEntityPacket() {
return new ClientboundAddEntityPacket(this);
}
+
+ // Paper start - Optional prevent TNT from moving in water
+ @Override
2021-06-12 07:20:08 +02:00
+ public boolean isPushedByFluid() {
+ return !level.paperConfig.preventTntFromMovingInWater && super.isPushedByFluid();
2021-06-11 14:02:28 +02:00
+ }
+ // Paper end
}