From d2410edc754f7e7a92b1ca53dd58f6b7d025ff9c Mon Sep 17 00:00:00 2001 From: JustDoom Date: Fri, 10 Jan 2025 14:48:42 -0800 Subject: [PATCH] Dont run with scissors! inspired by https://modrinth.com/mod/dont-run-with-scissors --- .../server/0126-Dont-run-with-scissors.patch | 181 ------------------ .../features/0001-Ridables.patch | 14 +- .../ServerGamePacketListenerImpl.java.patch | 32 ++++ .../damagesource/CombatTracker.java.patch | 14 ++ .../damagesource/DamageSource.java.patch | 42 +++- .../damagesource/DamageSources.java.patch | 29 +++ .../org/purpurmc/purpur/PurpurConfig.java | 7 + .../purpurmc/purpur/PurpurWorldConfig.java | 10 + 8 files changed, 137 insertions(+), 192 deletions(-) delete mode 100644 patches/server/0126-Dont-run-with-scissors.patch create mode 100644 purpur-server/minecraft-patches/sources/net/minecraft/world/damagesource/CombatTracker.java.patch create mode 100644 purpur-server/minecraft-patches/sources/net/minecraft/world/damagesource/DamageSources.java.patch diff --git a/patches/server/0126-Dont-run-with-scissors.patch b/patches/server/0126-Dont-run-with-scissors.patch deleted file mode 100644 index 08267bf5a..000000000 --- a/patches/server/0126-Dont-run-with-scissors.patch +++ /dev/null @@ -1,181 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: JustDoom -Date: Fri, 5 Mar 2021 14:23:16 -0500 -Subject: [PATCH] Dont run with scissors! - -inspired by https://modrinth.com/mod/dont-run-with-scissors - -diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java -index 2e714a4faf07e7ca18fa073ff6660c5d4f377507..ea6713bd5a2807cf00d664296c13e076b2fca3a0 100644 ---- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java -+++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java -@@ -1720,6 +1720,13 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl - this.player.tryResetCurrentImpulseContext(); - } - -+ // Purpur start - Dont run with scissors! -+ if (this.player.serverLevel().purpurConfig.dontRunWithScissors && this.player.isSprinting() && !(this.player.serverLevel().purpurConfig.ignoreScissorsInWater && this.player.isInWater()) && !(this.player.serverLevel().purpurConfig.ignoreScissorsInLava && this.player.isInLava()) && (isScissors(this.player.getItemInHand(InteractionHand.MAIN_HAND)) || isScissors(this.player.getItemInHand(InteractionHand.OFF_HAND))) && (int) (Math.random() * 10) == 0) { -+ this.player.hurtServer(this.player.serverLevel(), this.player.damageSources().scissors(), (float) this.player.serverLevel().purpurConfig.scissorsRunningDamage); -+ if (!org.purpurmc.purpur.PurpurConfig.dontRunWithScissors.isBlank()) this.player.sendActionBarMessage(org.purpurmc.purpur.PurpurConfig.dontRunWithScissors); -+ } -+ // Purpur end - Dont run with scissors! -+ - this.player.checkMovementStatistics(this.player.getX() - d3, this.player.getY() - d4, this.player.getZ() - d5); - this.lastGoodX = this.player.getX(); - this.lastGoodY = this.player.getY(); -@@ -1759,6 +1766,17 @@ public class ServerGamePacketListenerImpl extends ServerCommonPacketListenerImpl - } - } - -+ // Purpur start - Dont run with scissors! -+ public boolean isScissors(ItemStack stack) { -+ if (!stack.is(Items.SHEARS)) return false; -+ -+ ResourceLocation itemModelReference = stack.get(net.minecraft.core.component.DataComponents.ITEM_MODEL); -+ if (itemModelReference != null && itemModelReference.equals(this.player.serverLevel().purpurConfig.dontRunWithScissorsItemModelReference)) return true; -+ -+ return stack.getOrDefault(DataComponents.CUSTOM_MODEL_DATA, net.minecraft.world.item.component.CustomModelData.EMPTY).equals(net.minecraft.world.item.component.CustomModelData.EMPTY); -+ } -+ // Purpur end - Dont run with scissors! -+ - // Paper start - optimise out extra getCubes - private boolean hasNewCollision(final ServerLevel world, final Entity entity, final AABB oldBox, final AABB newBox) { - final List collisionsBB = new java.util.ArrayList<>(); -diff --git a/net/minecraft/world/damagesource/CombatTracker.java b/net/minecraft/world/damagesource/CombatTracker.java -index 99a7e9eb75231c15bd8bb24fbb4e296bc9fdedff..254aea4138afa1009a3c949a24c1a0fb8edbbd1d 100644 ---- a/net/minecraft/world/damagesource/CombatTracker.java -+++ b/net/minecraft/world/damagesource/CombatTracker.java -@@ -98,6 +98,11 @@ public class CombatTracker { - Component component = ComponentUtils.wrapInSquareBrackets(Component.translatable(string + ".link")).withStyle(INTENTIONAL_GAME_DESIGN_STYLE); - return Component.translatable(string + ".message", this.mob.getDisplayName(), component); - } else { -+ // Purpur start - Dont run with scissors! -+ if (damageSource.isScissors()) { -+ return damageSource.getLocalizedDeathMessage(org.purpurmc.purpur.PurpurConfig.deathMsgRunWithScissors, this.mob); -+ } -+ // Purpur end - Dont run with scissors! - return damageSource.getLocalizedDeathMessage(this.mob); - } - } -diff --git a/net/minecraft/world/damagesource/DamageSource.java b/net/minecraft/world/damagesource/DamageSource.java -index ab0ba4406dcaa915435c3f53ac9ca06fb21c673b..43985b4442145728c28bbeb9d18444a7c8f3a41f 100644 ---- a/net/minecraft/world/damagesource/DamageSource.java -+++ b/net/minecraft/world/damagesource/DamageSource.java -@@ -29,6 +29,7 @@ public class DamageSource { - private boolean sweep = false; - private boolean melting = false; - private boolean poison = false; -+ private boolean scissors = false; // Purpur - Dont run with scissors! - @Nullable - private Entity customEventDamager = null; // This field is a helper for when causing entity damage is not set by vanilla // Paper - fix DamageSource API - -@@ -59,6 +60,17 @@ public class DamageSource { - return this.poison; - } - -+ // Purpur start - Dont run with scissors! -+ public DamageSource scissors() { -+ this.scissors = true; -+ return this; -+ } -+ -+ public boolean isScissors() { -+ return this.scissors; -+ } -+ // Purpur end - Dont run with scissors! -+ - // Paper start - fix DamageSource API - @Nullable - public Entity getCustomEventDamager() { -@@ -117,6 +129,7 @@ public class DamageSource { - damageSource.sweep = this.isSweep(); - damageSource.poison = this.isPoison(); - damageSource.melting = this.isMelting(); -+ damageSource.scissors = this.isScissors(); // Purpur - Dont run with scissors! - return damageSource; - } - // CraftBukkit end -diff --git a/net/minecraft/world/damagesource/DamageSources.java b/net/minecraft/world/damagesource/DamageSources.java -index be87cb3cfa15a7d889118cdc4b87232e30749023..a4f710ad1aecd8265cde8d71d55eea952cd3c03b 100644 ---- a/net/minecraft/world/damagesource/DamageSources.java -+++ b/net/minecraft/world/damagesource/DamageSources.java -@@ -46,11 +46,13 @@ public class DamageSources { - // CraftBukkit start - private final DamageSource melting; - private final DamageSource poison; -+ private final DamageSource scissors; // Purpur - Dont run with scissors! - - public DamageSources(RegistryAccess registryManager) { - this.damageTypes = registryManager.lookupOrThrow(Registries.DAMAGE_TYPE); - this.melting = this.source(DamageTypes.ON_FIRE).melting(); - this.poison = this.source(DamageTypes.MAGIC).poison(); -+ this.scissors = this.source(DamageTypes.MAGIC).scissors(); // Purpur - Dont run with scissors! - // CraftBukkit end - this.inFire = this.source(DamageTypes.IN_FIRE); - this.campfire = this.source(DamageTypes.CAMPFIRE); -@@ -101,6 +103,12 @@ public class DamageSources { - } - // CraftBukkit end - -+ // Purpur start - Dont run with scissors! -+ public DamageSource scissors() { -+ return this.scissors; -+ } -+ // Purpur end - Dont run with scissors! -+ - public DamageSource inFire() { - return this.inFire; - } -diff --git a/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/src/main/java/org/purpurmc/purpur/PurpurConfig.java -index 6c7b7d6c6aff3dfd4bcc307c004513cf23f44a4d..693b9f04a35f055ea21a1b6be5ac27a04f1d80ad 100644 ---- a/src/main/java/org/purpurmc/purpur/PurpurConfig.java -+++ b/src/main/java/org/purpurmc/purpur/PurpurConfig.java -@@ -186,6 +186,7 @@ public class PurpurConfig { - public static String demoCommandOutput = "%s has been shown the demo screen"; - public static String pingCommandOutput = "%s's ping is %sms"; - public static String tpsbarCommandOutput = "Tpsbar toggled for "; -+ public static String dontRunWithScissors = "Don't run with scissors!"; - private static void messages() { - cannotRideMob = getString("settings.messages.cannot-ride-mob", cannotRideMob); - afkBroadcastAway = getString("settings.messages.afk-broadcast-away", afkBroadcastAway); -@@ -197,6 +198,12 @@ public class PurpurConfig { - demoCommandOutput = getString("settings.messages.demo-command-output", demoCommandOutput); - pingCommandOutput = getString("settings.messages.ping-command-output", pingCommandOutput); - tpsbarCommandOutput = getString("settings.messages.tpsbar-command-output", tpsbarCommandOutput); -+ dontRunWithScissors = getString("settings.messages.dont-run-with-scissors", dontRunWithScissors); -+ } -+ -+ public static String deathMsgRunWithScissors = " slipped and fell on their shears"; -+ private static void deathMessages() { -+ deathMsgRunWithScissors = getString("settings.messages.death-message.run-with-scissors", deathMsgRunWithScissors); - } - - public static String serverModName = io.papermc.paper.ServerBuildInfo.buildInfo().brandName(); -diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java -index 066a6407ed76a3a2b77541f24d4c3429d3a1a189..2fd0df56e94dca5ce91d0db29b56fa4bd5a2d1f2 100644 ---- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java -+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java -@@ -191,6 +191,11 @@ public class PurpurWorldConfig { - public List itemImmuneToExplosion = new ArrayList<>(); - public List itemImmuneToFire = new ArrayList<>(); - public List itemImmuneToLightning = new ArrayList<>(); -+ public boolean dontRunWithScissors = false; -+ public ResourceLocation dontRunWithScissorsItemModelReference = ResourceLocation.parse("purpurmc:scissors"); -+ public boolean ignoreScissorsInWater = false; -+ public boolean ignoreScissorsInLava = false; -+ public double scissorsRunningDamage = 1D; - private void itemSettings() { - itemImmuneToCactus.clear(); - getList("gameplay-mechanics.item.immune.cactus", new ArrayList<>()).forEach(key -> { -@@ -228,6 +233,11 @@ public class PurpurWorldConfig { - Item item = BuiltInRegistries.ITEM.getValue(ResourceLocation.parse(key.toString())); - if (item != Items.AIR) itemImmuneToLightning.add(item); - }); -+ dontRunWithScissors = getBoolean("gameplay-mechanics.item.shears.damage-if-sprinting", dontRunWithScissors); -+ dontRunWithScissorsItemModelReference = ResourceLocation.parse(getString("gameplay-mechanics.item.shears.damage-if-sprinting-item-model", "purpurmc:scissors")); -+ ignoreScissorsInWater = getBoolean("gameplay-mechanics.item.shears.ignore-in-water", ignoreScissorsInWater); -+ ignoreScissorsInLava = getBoolean("gameplay-mechanics.item.shears.ignore-in-lava", ignoreScissorsInLava); -+ scissorsRunningDamage = getDouble("gameplay-mechanics.item.shears.sprinting-damage", scissorsRunningDamage); - } - - public double minecartMaxSpeed = 0.4D; diff --git a/purpur-server/minecraft-patches/features/0001-Ridables.patch b/purpur-server/minecraft-patches/features/0001-Ridables.patch index 847c7b0b3..c892c2b03 100644 --- a/purpur-server/minecraft-patches/features/0001-Ridables.patch +++ b/purpur-server/minecraft-patches/features/0001-Ridables.patch @@ -62,10 +62,10 @@ index 78daeb23bb520774697c8d3d68aa4abe28a40cac..03d0df75dedd414aa54d88ed204cf82c private void updatePlayerAttributes() { diff --git a/net/minecraft/server/network/ServerGamePacketListenerImpl.java b/net/minecraft/server/network/ServerGamePacketListenerImpl.java -index 0c184da09628c0f2fd21e4cacd3ab6ae74f11e64..e569a1e0c282e43410ad321790114acc05bb2ad0 100644 +index a2832445eab54cc6d93f929ac061949002f1bd4b..6d19faa36b4f824533e1b76e7cda1f324d1c179f 100644 --- a/net/minecraft/server/network/ServerGamePacketListenerImpl.java +++ b/net/minecraft/server/network/ServerGamePacketListenerImpl.java -@@ -2800,6 +2800,8 @@ public class ServerGamePacketListenerImpl +@@ -2818,6 +2818,8 @@ public class ServerGamePacketListenerImpl ServerGamePacketListenerImpl.this.cserver.getPluginManager().callEvent(event); @@ -681,7 +681,7 @@ index 94244b148533ef026bf5c56abbc2bb5cfa83c938..474240c0fd68dbfe18b8fce7ae6e7634 } diff --git a/net/minecraft/world/entity/animal/Cat.java b/net/minecraft/world/entity/animal/Cat.java -index 6acb20424597933658b6f99e8e50681a200d84a8..06be2b391bad13165e1e0332053ae4e3e4198dc9 100644 +index 618f184ce9fed4d9b01f2df4d9a4476d20a55546..f066b0acfa0e954f6d71e62962c76afa1f05a4a5 100644 --- a/net/minecraft/world/entity/animal/Cat.java +++ b/net/minecraft/world/entity/animal/Cat.java @@ -93,10 +93,36 @@ public class Cat extends TamableAnimal implements VariantHolder collisionsBB = new java.util.ArrayList<>(); @@ -2734,6 +_,7 @@ AABB boundingBox = target.getBoundingBox(); diff --git a/purpur-server/minecraft-patches/sources/net/minecraft/world/damagesource/CombatTracker.java.patch b/purpur-server/minecraft-patches/sources/net/minecraft/world/damagesource/CombatTracker.java.patch new file mode 100644 index 000000000..c402b30c0 --- /dev/null +++ b/purpur-server/minecraft-patches/sources/net/minecraft/world/damagesource/CombatTracker.java.patch @@ -0,0 +1,14 @@ +--- a/net/minecraft/world/damagesource/CombatTracker.java ++++ b/net/minecraft/world/damagesource/CombatTracker.java +@@ -98,6 +_,11 @@ + Component component = ComponentUtils.wrapInSquareBrackets(Component.translatable(string + ".link")).withStyle(INTENTIONAL_GAME_DESIGN_STYLE); + return Component.translatable(string + ".message", this.mob.getDisplayName(), component); + } else { ++ // Purpur start - Dont run with scissors! ++ if (damageSource.isScissors()) { ++ return damageSource.getLocalizedDeathMessage(org.purpurmc.purpur.PurpurConfig.deathMsgRunWithScissors, this.mob); ++ } ++ // Purpur end - Dont run with scissors! + return damageSource.getLocalizedDeathMessage(this.mob); + } + } diff --git a/purpur-server/minecraft-patches/sources/net/minecraft/world/damagesource/DamageSource.java.patch b/purpur-server/minecraft-patches/sources/net/minecraft/world/damagesource/DamageSource.java.patch index 1dcb86c45..db0748b8d 100644 --- a/purpur-server/minecraft-patches/sources/net/minecraft/world/damagesource/DamageSource.java.patch +++ b/purpur-server/minecraft-patches/sources/net/minecraft/world/damagesource/DamageSource.java.patch @@ -1,9 +1,44 @@ --- a/net/minecraft/world/damagesource/DamageSource.java +++ b/net/minecraft/world/damagesource/DamageSource.java -@@ -188,6 +_,15 @@ - } +@@ -28,6 +_,7 @@ + private boolean sweep = false; + private boolean melting = false; + private boolean poison = false; ++ private boolean scissors = false; // Purpur - Dont run with scissors! + @Nullable + private Entity customEventDamager = null; // This field is a helper for when causing entity damage is not set by vanilla // Paper - fix DamageSource API + +@@ -58,6 +_,17 @@ + return this.poison; } ++ // Purpur start - Dont run with scissors! ++ public DamageSource scissors() { ++ this.scissors = true; ++ return this; ++ } ++ ++ public boolean isScissors() { ++ return this.scissors; ++ } ++ // Purpur end - Dont run with scissors! ++ + // Paper start - fix DamageSource API + @Nullable + public Entity getCustomEventDamager() { +@@ -116,6 +_,7 @@ + damageSource.sweep = this.isSweep(); + damageSource.poison = this.isPoison(); + damageSource.melting = this.isMelting(); ++ damageSource.scissors = this.isScissors(); // Purpur - Dont run with scissors! + return damageSource; + } + // CraftBukkit end +@@ -187,6 +_,15 @@ + : Component.translatable(string, livingEntity.getDisplayName(), component); + } + } ++ + // Purpur start - Component related conveniences + public Component getLocalizedDeathMessage(String str, LivingEntity entity) { + net.kyori.adventure.text.Component name = io.papermc.paper.adventure.PaperAdventure.asAdventure(entity.getDisplayName()); @@ -12,7 +47,6 @@ + return io.papermc.paper.adventure.PaperAdventure.asVanilla(component); + } + // Purpur end - Component related conveniences -+ + public String getMsgId() { return this.type().msgId(); - } diff --git a/purpur-server/minecraft-patches/sources/net/minecraft/world/damagesource/DamageSources.java.patch b/purpur-server/minecraft-patches/sources/net/minecraft/world/damagesource/DamageSources.java.patch new file mode 100644 index 000000000..2bcfc8f5c --- /dev/null +++ b/purpur-server/minecraft-patches/sources/net/minecraft/world/damagesource/DamageSources.java.patch @@ -0,0 +1,29 @@ +--- a/net/minecraft/world/damagesource/DamageSources.java ++++ b/net/minecraft/world/damagesource/DamageSources.java +@@ -45,11 +_,13 @@ + // CraftBukkit start + private final DamageSource melting; + private final DamageSource poison; ++ private final DamageSource scissors; // Purpur - Dont run with scissors! + + public DamageSources(RegistryAccess registry) { + this.damageTypes = registry.lookupOrThrow(Registries.DAMAGE_TYPE); + this.melting = this.source(DamageTypes.ON_FIRE).melting(); + this.poison = this.source(DamageTypes.MAGIC).poison(); ++ this.scissors = this.source(DamageTypes.MAGIC).scissors(); // Purpur - Dont run with scissors! + // CraftBukkit end + this.inFire = this.source(DamageTypes.IN_FIRE); + this.campfire = this.source(DamageTypes.CAMPFIRE); +@@ -99,6 +_,12 @@ + return this.poison; + } + // CraftBukkit end ++ ++ // Purpur start - Dont run with scissors! ++ public DamageSource scissors() { ++ return this.scissors; ++ } ++ // Purpur end - Dont run with scissors! + + public DamageSource inFire() { + return this.inFire; diff --git a/purpur-server/src/main/java/org/purpurmc/purpur/PurpurConfig.java b/purpur-server/src/main/java/org/purpurmc/purpur/PurpurConfig.java index ed681125c..3b0875ed8 100644 --- a/purpur-server/src/main/java/org/purpurmc/purpur/PurpurConfig.java +++ b/purpur-server/src/main/java/org/purpurmc/purpur/PurpurConfig.java @@ -171,6 +171,7 @@ public class PurpurConfig { public static String demoCommandOutput = "%s has been shown the demo screen"; public static String pingCommandOutput = "%s's ping is %sms"; public static String tpsbarCommandOutput = "Tpsbar toggled for "; + public static String dontRunWithScissors = "Don't run with scissors!"; private static void messages() { cannotRideMob = getString("settings.messages.cannot-ride-mob", cannotRideMob); afkBroadcastAway = getString("settings.messages.afk-broadcast-away", afkBroadcastAway); @@ -182,6 +183,12 @@ public class PurpurConfig { demoCommandOutput = getString("settings.messages.demo-command-output", demoCommandOutput); pingCommandOutput = getString("settings.messages.ping-command-output", pingCommandOutput); tpsbarCommandOutput = getString("settings.messages.tpsbar-command-output", tpsbarCommandOutput); + dontRunWithScissors = getString("settings.messages.dont-run-with-scissors", dontRunWithScissors); + } + + public static String deathMsgRunWithScissors = " slipped and fell on their shears"; + private static void deathMessages() { + deathMsgRunWithScissors = getString("settings.messages.death-message.run-with-scissors", deathMsgRunWithScissors); } public static String serverModName = io.papermc.paper.ServerBuildInfo.buildInfo().brandName(); diff --git a/purpur-server/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/purpur-server/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java index f9aa2f0ca..7dba6a334 100644 --- a/purpur-server/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java +++ b/purpur-server/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java @@ -183,6 +183,11 @@ public class PurpurWorldConfig { public List itemImmuneToExplosion = new ArrayList<>(); public List itemImmuneToFire = new ArrayList<>(); public List itemImmuneToLightning = new ArrayList<>(); + public boolean dontRunWithScissors = false; + public ResourceLocation dontRunWithScissorsItemModelReference = ResourceLocation.parse("purpurmc:scissors"); + public boolean ignoreScissorsInWater = false; + public boolean ignoreScissorsInLava = false; + public double scissorsRunningDamage = 1D; private void itemSettings() { itemImmuneToCactus.clear(); getList("gameplay-mechanics.item.immune.cactus", new ArrayList<>()).forEach(key -> { @@ -220,6 +225,11 @@ public class PurpurWorldConfig { Item item = BuiltInRegistries.ITEM.getValue(ResourceLocation.parse(key.toString())); if (item != Items.AIR) itemImmuneToLightning.add(item); }); + dontRunWithScissors = getBoolean("gameplay-mechanics.item.shears.damage-if-sprinting", dontRunWithScissors); + dontRunWithScissorsItemModelReference = ResourceLocation.parse(getString("gameplay-mechanics.item.shears.damage-if-sprinting-item-model", "purpurmc:scissors")); + ignoreScissorsInWater = getBoolean("gameplay-mechanics.item.shears.ignore-in-water", ignoreScissorsInWater); + ignoreScissorsInLava = getBoolean("gameplay-mechanics.item.shears.ignore-in-lava", ignoreScissorsInLava); + scissorsRunningDamage = getDouble("gameplay-mechanics.item.shears.sprinting-damage", scissorsRunningDamage); } public double minecartMaxSpeed = 0.4D;