PaperMC/patches/server-remapped/0101-Optional-TNT-doesn-t-move-in-water.patch
2021-06-11 14:02:28 +02:00

121 lines
5.7 KiB
Diff

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/ServerEntity.java b/src/main/java/net/minecraft/server/level/ServerEntity.java
index fa6893055fa5617742bfb4b7eff60c8139395cb6..49c71b21b6b88bc41ca6ddf4c76186ce522ee456 100644
--- a/src/main/java/net/minecraft/server/level/ServerEntity.java
+++ b/src/main/java/net/minecraft/server/level/ServerEntity.java
@@ -66,7 +66,7 @@ public class ServerEntity {
private boolean wasRiding;
private boolean wasOnGround;
// CraftBukkit start
- private final Set<ServerPlayer> trackedPlayers;
+ final Set<ServerPlayer> trackedPlayers; // Paper - private -> package
// Paper start
private java.util.Map<ServerPlayer, 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 171697e88f5a4d8c0be2a47b67b865bbdc4dfe8c..c3aece8e5001828edea304b2a8377e9a28b34cfe 100644
--- a/src/main/java/net/minecraft/world/entity/Entity.java
+++ b/src/main/java/net/minecraft/world/entity/Entity.java
@@ -2770,6 +2770,11 @@ public abstract class Entity implements Nameable, CommandSource, net.minecraft.s
}
public boolean isPushedByFluid() {
+ // Paper start
+ return this.pushedByWater();
+ }
+ public boolean pushedByWater() {
+ // Paper end
return true;
}
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 661848084fd986321ef782317934dac19ed4dce3..347ac17643de8bcb0c8496c2ea5eb18c2e4d856b 100644
--- a/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
+++ b/src/main/java/net/minecraft/world/entity/item/PrimedTnt.java
@@ -5,9 +5,13 @@ import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
+import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket;
+import net.minecraft.network.protocol.game.ClientboundTeleportEntityPacket;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.network.syncher.SynchedEntityData;
+import net.minecraft.server.level.ChunkMap;
+import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityDimensions;
import net.minecraft.world.entity.EntityType;
@@ -95,7 +99,27 @@ public class PrimedTnt extends Entity {
this.level.addParticle(ParticleTypes.SMOKE, this.getX(), this.getY() + 0.5D, this.getZ(), 0.0D, 0.0D, 0.0D);
}
}
-
+ // Paper start - Optional prevent TNT from moving in water
+ if (!this.removed && this.wasTouchingWater && this.level.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.
+ ChunkMap.TrackedEntity ete = ((ServerLevel)this.level).getChunkSource().chunkMap.entityMap.get(this.getId());
+ if (ete != null) {
+ ClientboundSetEntityMotionPacket velocityPacket = new ClientboundSetEntityMotionPacket(this);
+ ClientboundTeleportEntityPacket positionPacket = new ClientboundTeleportEntityPacket(this);
+
+ ete.seenBy.stream()
+ .filter(viewer -> (viewer.getX() - this.getX()) * (viewer.getY() - this.getY()) * (viewer.getZ() - this.getZ()) < 16 * 16)
+ .forEach(viewer -> {
+ viewer.connection.send(velocityPacket);
+ viewer.connection.send(positionPacket);
+ });
+ }
+ }
+ // Paper end
}
private void explode() {
@@ -164,4 +188,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 pushedByWater() {
+ return !level.paperConfig.preventTntFromMovingInWater && super.pushedByWater();
+ }
+ // Paper end
}