From b410fe86974adfe47eaf361fee92d8a189afed9f Mon Sep 17 00:00:00 2001 From: Axionize <154778082+Axionize@users.noreply.github.com> Date: Sun, 29 Sep 2024 18:06:13 -0400 Subject: [PATCH] Configurable per-world void damage offset/damage(#11436) --- .../0494-Void-damage-configuration-API.patch | 65 +++++++++++++ patches/server/0005-Paper-config-files.patch | 7 +- ...-Add-and-fix-missing-BlockFadeEvents.patch | 2 +- .../1064-Void-damage-configuration-API.patch | 94 +++++++++++++++++++ 4 files changed, 165 insertions(+), 3 deletions(-) create mode 100644 patches/api/0494-Void-damage-configuration-API.patch create mode 100644 patches/server/1064-Void-damage-configuration-API.patch diff --git a/patches/api/0494-Void-damage-configuration-API.patch b/patches/api/0494-Void-damage-configuration-API.patch new file mode 100644 index 0000000000..26cbd83b18 --- /dev/null +++ b/patches/api/0494-Void-damage-configuration-API.patch @@ -0,0 +1,65 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Axionize <154778082+Axionize@users.noreply.github.com> +Date: Wed, 25 Sep 2024 04:43:26 -0400 +Subject: [PATCH] Void damage configuration API + + +diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java +index adcd8161846b06fd1a7895750f98b629204a8406..ef32a937e6faf1e8a5d6b1207986715bae5a246c 100644 +--- a/src/main/java/org/bukkit/World.java ++++ b/src/main/java/org/bukkit/World.java +@@ -52,6 +52,54 @@ import org.jetbrains.annotations.Nullable; + */ + public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient, Metadatable, PersistentDataHolder, Keyed, net.kyori.adventure.audience.ForwardingAudience { // Paper + ++ // Paper start - void damage configuration ++ /** ++ * Checks if void damage is enabled on this world. ++ * ++ * @return true if enabled ++ */ ++ boolean isVoidDamageEnabled(); ++ ++ /** ++ * Sets whether void damage is enabled on this world. ++ * ++ * @param enabled true to enable void damage ++ */ ++ void setVoidDamageEnabled(boolean enabled); ++ ++ /** ++ * Gets the damage applied to the player when they are in the void in this world. ++ * Check {@link #isVoidDamageEnabled()} to see if void damage is enabled. ++ * ++ * @return amount of damage to apply ++ * @see #isVoidDamageEnabled() ++ */ ++ float getVoidDamageAmount(); ++ ++ /** ++ * Sets the damage applied to the player when they are in the void in this world. ++ * Check {@link #isVoidDamageEnabled()} to see if void damage is enabled. ++ * ++ * @param voidDamageAmount amount of damage to apply ++ */ ++ void setVoidDamageAmount(float voidDamageAmount); ++ ++ /** ++ * Gets the offset applied to {@link #getMinHeight()} to determine the height at which void damage starts to apply. ++ * ++ * @return offset from min build height ++ * @see #isVoidDamageEnabled() ++ */ ++ double getVoidDamageMinBuildHeightOffset(); ++ ++ /** ++ * Sets the offset applied to {@link #getMinHeight()} to determine the height at which void damage starts to apply. ++ * ++ * @param minBuildHeightOffset offset from min build height ++ */ ++ void setVoidDamageMinBuildHeightOffset(double minBuildHeightOffset); ++ // Paper end - void damage configuration ++ + // Paper start + /** + * @return The amount of Entities in this world diff --git a/patches/server/0005-Paper-config-files.patch b/patches/server/0005-Paper-config-files.patch index f6155d2ac0..4f4f48cb51 100644 --- a/patches/server/0005-Paper-config-files.patch +++ b/patches/server/0005-Paper-config-files.patch @@ -1423,10 +1423,10 @@ index 0000000000000000000000000000000000000000..990d1bb46e0f9719f4e9af928d80ac6f +} diff --git a/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java b/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java new file mode 100644 -index 0000000000000000000000000000000000000000..790e3167cfa2511ef2fc707d9b9aa681a78d8ba0 +index 0000000000000000000000000000000000000000..fd3b1c10695634f65c7291016bf671c084bc4d57 --- /dev/null +++ b/src/main/java/io/papermc/paper/configuration/WorldConfiguration.java -@@ -0,0 +1,578 @@ +@@ -0,0 +1,581 @@ +package io.papermc.paper.configuration; + +import com.google.common.collect.HashBasedTable; @@ -1455,6 +1455,7 @@ index 0000000000000000000000000000000000000000..790e3167cfa2511ef2fc707d9b9aa681 +import java.util.IdentityHashMap; +import java.util.List; +import java.util.Map; ++import java.util.OptionalDouble; +import java.util.function.Function; +import java.util.stream.Collectors; +import net.minecraft.Util; @@ -1838,6 +1839,8 @@ index 0000000000000000000000000000000000000000..790e3167cfa2511ef2fc707d9b9aa681 + public boolean disableExplosionKnockback = false; + public boolean generateFlatBedrock = false; + public FrostedIce frostedIce; ++ public DoubleOr.Disabled voidDamageAmount = new DoubleOr.Disabled(OptionalDouble.of(4)); ++ public double voidDamageMinBuildHeightOffset = -64.0; + + public class FrostedIce extends ConfigurationPart { + public boolean enabled = true; diff --git a/patches/server/0727-Add-and-fix-missing-BlockFadeEvents.patch b/patches/server/0727-Add-and-fix-missing-BlockFadeEvents.patch index 062bad35bb..a889bba447 100644 --- a/patches/server/0727-Add-and-fix-missing-BlockFadeEvents.patch +++ b/patches/server/0727-Add-and-fix-missing-BlockFadeEvents.patch @@ -7,7 +7,7 @@ Beyond calling the BlockFadeEvent in more places, this patch also aims to pass the proper replacement state to the event, specifically for potentially waterlogged block states fading. -Co-authored-by: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com +Co-authored-by: Lulu13022002 <41980282+Lulu13022002@users.noreply.github.com> diff --git a/src/main/java/net/minecraft/world/level/block/FrogspawnBlock.java b/src/main/java/net/minecraft/world/level/block/FrogspawnBlock.java index 669234bca9fa50548447f77dc5f314df8d9dd7c9..f2d4264743b6070f36adb66d00a3de0a72b86846 100644 diff --git a/patches/server/1064-Void-damage-configuration-API.patch b/patches/server/1064-Void-damage-configuration-API.patch new file mode 100644 index 0000000000..73205dffa3 --- /dev/null +++ b/patches/server/1064-Void-damage-configuration-API.patch @@ -0,0 +1,94 @@ +From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 +From: Axionize <154778082+Axionize@users.noreply.github.com> +Date: Sun, 29 Sep 2024 14:20:42 -0700 +Subject: [PATCH] Void damage configuration API + + +diff --git a/src/main/java/net/minecraft/world/entity/Entity.java b/src/main/java/net/minecraft/world/entity/Entity.java +index bc45c74987974b4828201e06fc8b1f3fbc0af8b4..4b54d0ea31062972e68ee8fafe3cfaf68f65a5cd 100644 +--- a/src/main/java/net/minecraft/world/entity/Entity.java ++++ b/src/main/java/net/minecraft/world/entity/Entity.java +@@ -931,8 +931,10 @@ public abstract class Entity implements SyncedDataHolder, Nameable, EntityAccess + } + + public void checkBelowWorld() { ++ if (!this.level.getWorld().isVoidDamageEnabled()) return; // Paper - check if void damage is enabled on the world ++ + // Paper start - Configurable nether ceiling damage +- if (this.getY() < (double) (this.level.getMinBuildHeight() - 64) || (this.level.getWorld().getEnvironment() == org.bukkit.World.Environment.NETHER ++ if (this.getY() < (double) (this.level.getMinBuildHeight() + this.level.getWorld().getVoidDamageMinBuildHeightOffset()) || (this.level.getWorld().getEnvironment() == org.bukkit.World.Environment.NETHER // Paper - use configured min build height offset + && this.level.paperConfig().environment.netherCeilingVoidDamageHeight.test(v -> this.getY() >= v) + && (!(this instanceof Player player) || !player.getAbilities().invulnerable))) { + // Paper end - Configurable nether ceiling damage +diff --git a/src/main/java/net/minecraft/world/entity/LivingEntity.java b/src/main/java/net/minecraft/world/entity/LivingEntity.java +index 30f4f1254fc295442d72d50479e8af635f2fe983..2aa6374cd4a96efd85899be8cd3172a8257bfe6b 100644 +--- a/src/main/java/net/minecraft/world/entity/LivingEntity.java ++++ b/src/main/java/net/minecraft/world/entity/LivingEntity.java +@@ -2625,7 +2625,7 @@ public abstract class LivingEntity extends Entity implements Attackable { + + @Override + protected void onBelowWorld() { +- this.hurt(this.damageSources().fellOutOfWorld(), 4.0F); ++ this.hurt(this.damageSources().fellOutOfWorld(), this.level().getWorld().getVoidDamageAmount()); // Paper - use configured void damage amount + } + + protected void updateSwingTime() { +diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +index 38b046da5acac8633db8618a2957187d291f5e73..33e4818ba5a90d78d69baad9f6b1be1b1382e9f3 100644 +--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java ++++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java +@@ -163,6 +163,41 @@ public class CraftWorld extends CraftRegionAccessor implements World { + private final Object2IntOpenHashMap spawnCategoryLimit = new Object2IntOpenHashMap<>(); + private final CraftPersistentDataContainer persistentDataContainer = new CraftPersistentDataContainer(CraftWorld.DATA_TYPE_REGISTRY); + private net.kyori.adventure.pointer.Pointers adventure$pointers; // Paper - implement pointers ++ // Paper start - void damage configuration ++ private boolean voidDamageEnabled; ++ private float voidDamageAmount; ++ private double voidDamageMinBuildHeightOffset; ++ ++ @Override ++ public boolean isVoidDamageEnabled() { ++ return this.voidDamageEnabled; ++ } ++ ++ @Override ++ public void setVoidDamageEnabled(final boolean enabled) { ++ this.voidDamageEnabled = enabled; ++ } ++ ++ @Override ++ public float getVoidDamageAmount() { ++ return this.voidDamageAmount; ++ } ++ ++ @Override ++ public void setVoidDamageAmount(float voidDamageAmount) { ++ this.voidDamageAmount = voidDamageAmount; ++ } ++ ++ @Override ++ public double getVoidDamageMinBuildHeightOffset() { ++ return this.voidDamageMinBuildHeightOffset; ++ } ++ ++ @Override ++ public void setVoidDamageMinBuildHeightOffset(double minBuildHeightOffset) { ++ this.voidDamageMinBuildHeightOffset = minBuildHeightOffset; ++ } ++ // Paper end - void damage configuration + + // Paper start - Provide fast information methods + @Override +@@ -271,6 +306,12 @@ public class CraftWorld extends CraftRegionAccessor implements World { + } + } + // Paper end - per world spawn limits ++ ++ // Paper start - per world void damage height ++ this.voidDamageEnabled = this.world.paperConfig().environment.voidDamageAmount.enabled(); ++ this.voidDamageMinBuildHeightOffset = this.world.paperConfig().environment.voidDamageMinBuildHeightOffset; ++ this.voidDamageAmount = (float) this.world.paperConfig().environment.voidDamageAmount.or(0); ++ // Paper end - per world void damage height + } + + @Override