From facd3e29006dc806d5b7ca71a08b8674e7cc196d Mon Sep 17 00:00:00 2001 From: Encode42 Date: Sat, 11 Jan 2025 18:41:14 -0800 Subject: [PATCH] Configurable mob blindness Ported from https://github.com/raltsmc/mobblindness --- .../0155-Configurable-mob-blindness.patch | 49 ------------------- .../world/entity/LivingEntity.java.patch | 18 +++++++ .../purpurmc/purpur/PurpurWorldConfig.java | 2 + 3 files changed, 20 insertions(+), 49 deletions(-) delete mode 100644 patches/server/0155-Configurable-mob-blindness.patch diff --git a/patches/server/0155-Configurable-mob-blindness.patch b/patches/server/0155-Configurable-mob-blindness.patch deleted file mode 100644 index 919f594e2..000000000 --- a/patches/server/0155-Configurable-mob-blindness.patch +++ /dev/null @@ -1,49 +0,0 @@ -From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001 -From: Encode42 -Date: Tue, 11 May 2021 21:00:53 -0400 -Subject: [PATCH] Configurable mob blindness - -Ported from https://github.com/raltsmc/mobblindness - -diff --git a/net/minecraft/world/entity/LivingEntity.java b/net/minecraft/world/entity/LivingEntity.java -index dc0656378d81a77e1d49895a90f92f27e3e247f3..28d3b200ab0c3e8993dfb89a3e48146898c6b85e 100644 ---- a/net/minecraft/world/entity/LivingEntity.java -+++ b/net/minecraft/world/entity/LivingEntity.java -@@ -1065,6 +1065,17 @@ public abstract class LivingEntity extends Entity implements Attackable { - if (entitytypes == EntityType.SKELETON && itemstack.is(Items.SKELETON_SKULL) || entitytypes == EntityType.ZOMBIE && itemstack.is(Items.ZOMBIE_HEAD) || entitytypes == EntityType.PIGLIN && itemstack.is(Items.PIGLIN_HEAD) || entitytypes == EntityType.PIGLIN_BRUTE && itemstack.is(Items.PIGLIN_HEAD) || entitytypes == EntityType.CREEPER && itemstack.is(Items.CREEPER_HEAD)) { - d0 *= 0.5D; - } -+ -+ // Purpur start -+ if (entity instanceof LivingEntity entityliving) { -+ if (entityliving.hasEffect(MobEffects.BLINDNESS)) { -+ int amplifier = entityliving.getEffect(MobEffects.BLINDNESS).getAmplifier(); -+ for (int i = 0; i < amplifier; i++) { -+ d0 *= this.level().purpurConfig.mobsBlindnessMultiplier; -+ } -+ } -+ } -+ // Purpur end - } - - return d0; -diff --git a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java -index 19e77eadb5ece2da43eb82f7b7d196e1616348af..1ae95a30b6e4cf69028dc61c398651bde526418f 100644 ---- a/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java -+++ b/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java -@@ -138,6 +138,7 @@ public class PurpurWorldConfig { - public boolean imposeTeleportRestrictionsOnNetherPortals = false; - public boolean imposeTeleportRestrictionsOnEndPortals = false; - public boolean tickFluids = true; -+ public double mobsBlindnessMultiplier = 1; - private void miscGameplayMechanicsSettings() { - useBetterMending = getBoolean("gameplay-mechanics.use-better-mending", useBetterMending); - alwaysTameInCreative = getBoolean("gameplay-mechanics.always-tame-in-creative", alwaysTameInCreative); -@@ -158,6 +159,7 @@ public class PurpurWorldConfig { - imposeTeleportRestrictionsOnNetherPortals = getBoolean("gameplay-mechanics.impose-teleport-restrictions-on-nether-portals", imposeTeleportRestrictionsOnNetherPortals); - imposeTeleportRestrictionsOnEndPortals = getBoolean("gameplay-mechanics.impose-teleport-restrictions-on-end-portals", imposeTeleportRestrictionsOnEndPortals); - tickFluids = getBoolean("gameplay-mechanics.tick-fluids", tickFluids); -+ mobsBlindnessMultiplier = getDouble("gameplay-mechanics.entity-blindness-multiplier", mobsBlindnessMultiplier); - } - - public int daytimeTicks = 12000; diff --git a/purpur-server/minecraft-patches/sources/net/minecraft/world/entity/LivingEntity.java.patch b/purpur-server/minecraft-patches/sources/net/minecraft/world/entity/LivingEntity.java.patch index 67eafd57a..b1933fade 100644 --- a/purpur-server/minecraft-patches/sources/net/minecraft/world/entity/LivingEntity.java.patch +++ b/purpur-server/minecraft-patches/sources/net/minecraft/world/entity/LivingEntity.java.patch @@ -31,6 +31,24 @@ } } else if (this.getAirSupply() < this.getMaxAirSupply()) { this.setAirSupply(this.increaseAirSupply(this.getAirSupply())); +@@ -1018,6 +_,17 @@ + } + } + ++ // Purpur start - Configurable mob blindness ++ if (lookingEntity instanceof LivingEntity entityliving) { ++ if (entityliving.hasEffect(MobEffects.BLINDNESS)) { ++ int amplifier = entityliving.getEffect(MobEffects.BLINDNESS).getAmplifier(); ++ for (int i = 0; i < amplifier; i++) { ++ d *= this.level().purpurConfig.mobsBlindnessMultiplier; ++ } ++ } ++ } ++ // Purpur end - Configurable mob blindness ++ + return d; + } + @@ -1372,6 +_,24 @@ this.stopSleeping(); } 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 bde207359..226f9eb94 100644 --- a/purpur-server/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java +++ b/purpur-server/src/main/java/org/purpurmc/purpur/PurpurWorldConfig.java @@ -130,6 +130,7 @@ public class PurpurWorldConfig { public boolean imposeTeleportRestrictionsOnNetherPortals = false; public boolean imposeTeleportRestrictionsOnEndPortals = false; public boolean tickFluids = true; + public double mobsBlindnessMultiplier = 1; private void miscGameplayMechanicsSettings() { useBetterMending = getBoolean("gameplay-mechanics.use-better-mending", useBetterMending); alwaysTameInCreative = getBoolean("gameplay-mechanics.always-tame-in-creative", alwaysTameInCreative); @@ -150,6 +151,7 @@ public class PurpurWorldConfig { imposeTeleportRestrictionsOnNetherPortals = getBoolean("gameplay-mechanics.impose-teleport-restrictions-on-nether-portals", imposeTeleportRestrictionsOnNetherPortals); imposeTeleportRestrictionsOnEndPortals = getBoolean("gameplay-mechanics.impose-teleport-restrictions-on-end-portals", imposeTeleportRestrictionsOnEndPortals); tickFluids = getBoolean("gameplay-mechanics.tick-fluids", tickFluids); + mobsBlindnessMultiplier = getDouble("gameplay-mechanics.entity-blindness-multiplier", mobsBlindnessMultiplier); } public int daytimeTicks = 12000;