From d12a88e1de61ae60dff3fd62a5f280537611b83c Mon Sep 17 00:00:00 2001 From: William Blake Galbreath Date: Sun, 6 Nov 2022 08:38:29 -0600 Subject: [PATCH] Fix #1181 (#1182) --- .../server/0240-Potion-NamespacedKey.patch | 60 +++++++++++-------- 1 file changed, 35 insertions(+), 25 deletions(-) diff --git a/patches/server/0240-Potion-NamespacedKey.patch b/patches/server/0240-Potion-NamespacedKey.patch index d6cdc39f1..af62899da 100644 --- a/patches/server/0240-Potion-NamespacedKey.patch +++ b/patches/server/0240-Potion-NamespacedKey.patch @@ -5,7 +5,7 @@ Subject: [PATCH] Potion NamespacedKey diff --git a/src/main/java/net/minecraft/world/effect/MobEffectInstance.java b/src/main/java/net/minecraft/world/effect/MobEffectInstance.java -index f5c9be3fde2654bd5a6b3ee737afe96a9393e836..64571396652d4447ce3665cd8cef668c0d27a862 100644 +index f5c9be3fde2654bd5a6b3ee737afe96a9393e836..3aecf016ce182391e20c8d31b9399a9855ceb3e6 100644 --- a/src/main/java/net/minecraft/world/effect/MobEffectInstance.java +++ b/src/main/java/net/minecraft/world/effect/MobEffectInstance.java @@ -13,6 +13,7 @@ import net.minecraft.util.ExtraCodecs; @@ -24,23 +24,33 @@ index f5c9be3fde2654bd5a6b3ee737afe96a9393e836..64571396652d4447ce3665cd8cef668c private MobEffectInstance hiddenEffect; private Optional factorData; -@@ -48,12 +50,27 @@ public class MobEffectInstance implements Comparable { +@@ -43,17 +45,36 @@ public class MobEffectInstance implements Comparable { + this(type, duration, amplifier, ambient, visible, visible); + } + ++ // Purpur start ++ public MobEffectInstance(MobEffect type, int duration, int amplifier, boolean ambient, boolean visible, @Nullable NamespacedKey key) { ++ this(type, duration, amplifier, ambient, visible, visible, key); ++ } ++ // Purpur end ++ + public MobEffectInstance(MobEffect type, int duration, int amplifier, boolean ambient, boolean showParticles, boolean showIcon) { +- this(type, duration, amplifier, ambient, showParticles, showIcon, (MobEffectInstance)null, type.createFactorData()); ++ // Purpur start ++ this(type, duration, amplifier, ambient, showParticles, showIcon, (MobEffectInstance)null, type.createFactorData(), (NamespacedKey)null); ++ } ++ ++ public MobEffectInstance(MobEffect type, int duration, int amplifier, boolean ambient, boolean showParticles, boolean showIcon, @Nullable NamespacedKey key) { ++ this(type, duration, amplifier, ambient, showParticles, showIcon, (MobEffectInstance)null, type.createFactorData(), key); ++ // Purpur end } public MobEffectInstance(MobEffect type, int duration, int amplifier, boolean ambient, boolean showParticles, boolean showIcon, @Nullable MobEffectInstance hiddenEffect, Optional factorCalculationData) { + // Purpur start -+ this(type, duration, amplifier, ambient, showParticles, showIcon, (NamespacedKey)null, hiddenEffect, factorCalculationData); ++ this(type, duration, amplifier, ambient, showParticles, showIcon, hiddenEffect, factorCalculationData, (NamespacedKey) null); + } + -+ public MobEffectInstance(MobEffect type, int duration, int amplifier, boolean ambient, boolean showParticles, @Nullable NamespacedKey key, Optional factorCalculationData) { -+ this(type, duration, amplifier, ambient, showParticles, showParticles, key, (MobEffectInstance)null, factorCalculationData); -+ } -+ -+ public MobEffectInstance(MobEffect type, int duration, int amplifier, boolean ambient, boolean showParticles, boolean showIcon, @Nullable NamespacedKey key, Optional factorCalculationData) { -+ this(type, duration, amplifier, ambient, showParticles, showIcon, key, (MobEffectInstance)null, factorCalculationData); -+ } -+ -+ public MobEffectInstance(MobEffect type, int duration, int amplifier, boolean ambient, boolean showParticles, boolean showIcon, @Nullable NamespacedKey key, @Nullable MobEffectInstance hiddenEffect, Optional factorCalculationData) { // Purpur - add key ++ public MobEffectInstance(MobEffect type, int duration, int amplifier, boolean ambient, boolean showParticles, boolean showIcon, @Nullable MobEffectInstance hiddenEffect, Optional factorCalculationData, @Nullable NamespacedKey key) { + // Purpur end this.effect = type; this.duration = duration; @@ -52,7 +62,7 @@ index f5c9be3fde2654bd5a6b3ee737afe96a9393e836..64571396652d4447ce3665cd8cef668c this.hiddenEffect = hiddenEffect; this.factorData = factorCalculationData; } -@@ -74,6 +91,7 @@ public class MobEffectInstance implements Comparable { +@@ -74,6 +95,7 @@ public class MobEffectInstance implements Comparable { this.ambient = that.ambient; this.visible = that.visible; this.showIcon = that.showIcon; @@ -60,7 +70,7 @@ index f5c9be3fde2654bd5a6b3ee737afe96a9393e836..64571396652d4447ce3665cd8cef668c } public boolean update(MobEffectInstance that) { -@@ -126,6 +144,13 @@ public class MobEffectInstance implements Comparable { +@@ -126,6 +148,13 @@ public class MobEffectInstance implements Comparable { bl = true; } @@ -74,7 +84,7 @@ index f5c9be3fde2654bd5a6b3ee737afe96a9393e836..64571396652d4447ce3665cd8cef668c return bl; } -@@ -153,6 +178,17 @@ public class MobEffectInstance implements Comparable { +@@ -153,6 +182,17 @@ public class MobEffectInstance implements Comparable { return this.showIcon; } @@ -92,7 +102,7 @@ index f5c9be3fde2654bd5a6b3ee737afe96a9393e836..64571396652d4447ce3665cd8cef668c public boolean tick(LivingEntity entity, Runnable overwriteCallback) { if (this.duration > 0) { if (this.effect.isDurationEffectTick(this.duration, this.amplifier)) { -@@ -209,6 +245,12 @@ public class MobEffectInstance implements Comparable { +@@ -209,6 +249,12 @@ public class MobEffectInstance implements Comparable { string = string + ", Show Icon: false"; } @@ -105,7 +115,7 @@ index f5c9be3fde2654bd5a6b3ee737afe96a9393e836..64571396652d4447ce3665cd8cef668c return string; } -@@ -220,7 +262,7 @@ public class MobEffectInstance implements Comparable { +@@ -220,7 +266,7 @@ public class MobEffectInstance implements Comparable { return false; } else { MobEffectInstance mobEffectInstance = (MobEffectInstance)object; @@ -114,7 +124,7 @@ index f5c9be3fde2654bd5a6b3ee737afe96a9393e836..64571396652d4447ce3665cd8cef668c } } -@@ -244,6 +286,11 @@ public class MobEffectInstance implements Comparable { +@@ -244,6 +290,11 @@ public class MobEffectInstance implements Comparable { nbt.putBoolean("Ambient", this.isAmbient()); nbt.putBoolean("ShowParticles", this.isVisible()); nbt.putBoolean("ShowIcon", this.showIcon()); @@ -126,7 +136,7 @@ index f5c9be3fde2654bd5a6b3ee737afe96a9393e836..64571396652d4447ce3665cd8cef668c if (this.hiddenEffect != null) { CompoundTag compoundTag = new CompoundTag(); this.hiddenEffect.save(compoundTag); -@@ -278,6 +325,13 @@ public class MobEffectInstance implements Comparable { +@@ -278,6 +329,13 @@ public class MobEffectInstance implements Comparable { bl3 = nbt.getBoolean("ShowIcon"); } @@ -140,17 +150,17 @@ index f5c9be3fde2654bd5a6b3ee737afe96a9393e836..64571396652d4447ce3665cd8cef668c MobEffectInstance mobEffectInstance = null; if (nbt.contains("HiddenEffect", 10)) { mobEffectInstance = loadSpecifiedEffect(type, nbt.getCompound("HiddenEffect")); -@@ -290,7 +344,7 @@ public class MobEffectInstance implements Comparable { +@@ -290,7 +348,7 @@ public class MobEffectInstance implements Comparable { optional = Optional.empty(); } - return new MobEffectInstance(type, j, Math.max(i, 0), bl, bl2, bl3, mobEffectInstance, optional); -+ return new MobEffectInstance(type, j, Math.max(i, 0), bl, bl2, bl3, key, mobEffectInstance, optional); // Purpur - add key ++ return new MobEffectInstance(type, j, Math.max(i, 0), bl, bl2, bl3, mobEffectInstance, optional, key); // Purpur - add key } public void setNoCounter(boolean permanent) { diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java -index f2d17cb06fbcd7370ab8465c5c4830f8ba31169a..d726575f8df0176f2ee0b19d224d49d9ee3f248f 100644 +index f2d17cb06fbcd7370ab8465c5c4830f8ba31169a..3a3476000ee8c13e1c1a565b0ef38a5ac69bdfb3 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftLivingEntity.java @@ -438,7 +438,7 @@ public class CraftLivingEntity extends CraftEntity implements LivingEntity { @@ -158,7 +168,7 @@ index f2d17cb06fbcd7370ab8465c5c4830f8ba31169a..d726575f8df0176f2ee0b19d224d49d9 @Override public boolean addPotionEffect(PotionEffect effect, boolean force) { - this.getHandle().addEffect(new MobEffectInstance(MobEffect.byId(effect.getType().getId()), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles(), effect.hasIcon()), EntityPotionEffectEvent.Cause.PLUGIN); // Paper - Don't ignore icon -+ this.getHandle().addEffect(new MobEffectInstance(MobEffect.byId(effect.getType().getId()), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles(), effect.hasIcon(), effect.getKey(), java.util.Optional.empty()), EntityPotionEffectEvent.Cause.PLUGIN); // Purpur - add key // Paper - Don't ignore icon ++ this.getHandle().addEffect(new MobEffectInstance(MobEffect.byId(effect.getType().getId()), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles(), effect.hasIcon(), effect.getKey()), EntityPotionEffectEvent.Cause.PLUGIN); // Purpur - add key // Paper - Don't ignore icon return true; } @@ -237,7 +247,7 @@ index 298326115f048bb79e3c949861c187134eb5efb8..9b060070ddbbade4c1b6830b9b861f46 } this.customEffects.set(index, effect); diff --git a/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionUtil.java b/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionUtil.java -index acb69821a99aa69bce6d127e10976089c85be223..a44fc6122f6e653b149fff52e553d60a049e7432 100644 +index acb69821a99aa69bce6d127e10976089c85be223..c5abd73981c5f4b41605eba0d44e6573dfd2a77a 100644 --- a/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionUtil.java +++ b/src/main/java/org/bukkit/craftbukkit/potion/CraftPotionUtil.java @@ -101,7 +101,7 @@ public class CraftPotionUtil { @@ -245,7 +255,7 @@ index acb69821a99aa69bce6d127e10976089c85be223..a44fc6122f6e653b149fff52e553d60a public static MobEffectInstance fromBukkit(PotionEffect effect) { MobEffect type = MobEffect.byId(effect.getType().getId()); - return new MobEffectInstance(type, effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles()); -+ return new MobEffectInstance(type, effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles(), effect.getKey(), java.util.Optional.empty()); // Purpur - add key ++ return new MobEffectInstance(type, effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles(), effect.getKey()); // Purpur - add key } public static PotionEffect toBukkit(MobEffectInstance effect) {