mirror of
https://github.com/PaperMC/Paper.git
synced 2024-11-22 15:17:17 +01:00
fixup sus effect entry patches
This commit is contained in:
parent
3062eb208d
commit
e85e1ec4a6
1 changed files with 63 additions and 32 deletions
|
@ -14,69 +14,76 @@ in which it replaces PotionEffect.
|
|||
Co-authored-by: Yannick Lamprecht <yannicklamprecht@live.de>
|
||||
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java
|
||||
index 9cc81bcccbf1141f66fedada1359b7c0dfa8e22a..7491c7cf38d888b31a509613d237b55f9732400a 100644
|
||||
index 9cc81bcccbf1141f66fedada1359b7c0dfa8e22a..5c5b64bd058684520fa175bfd10622ff57856b7c 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java
|
||||
@@ -34,11 +34,19 @@ public class CraftMushroomCow extends CraftCow implements MushroomCow, io.paperm
|
||||
return ImmutableList.of();
|
||||
}
|
||||
|
||||
+ // Paper start - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
|
||||
@@ -37,16 +37,24 @@ public class CraftMushroomCow extends CraftCow implements MushroomCow, io.paperm
|
||||
@Override
|
||||
public boolean addEffectToNextStew(PotionEffect potionEffect, boolean overwrite) {
|
||||
Preconditions.checkArgument(potionEffect != null, "PotionEffect cannot be null");
|
||||
- MobEffectInstance minecraftPotionEffect = CraftPotionUtil.fromBukkit(potionEffect);
|
||||
- if (!overwrite && this.hasEffectForNextStew(potionEffect.getType())) {
|
||||
+ return addEffectToNextStew(io.papermc.paper.potion.SuspiciousEffectEntry.create(potionEffect.getType(), potionEffect.getDuration()), overwrite);
|
||||
+ // Paper start - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
|
||||
+ return this.addEffectToNextStew(io.papermc.paper.potion.SuspiciousEffectEntry.create(potionEffect.getType(), potionEffect.getDuration()), overwrite);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public boolean addEffectToNextStew(io.papermc.paper.potion.SuspiciousEffectEntry suspiciousEffectEntry, boolean overwrite) {
|
||||
+ Preconditions.checkArgument(suspiciousEffectEntry != null, "SuspiciousEffectEntry cannot be null");
|
||||
+ MobEffect minecraftPotionEffect = CraftPotionEffectType.bukkitToMinecraft(suspiciousEffectEntry.effect());
|
||||
+ Holder<MobEffect> minecraftPotionEffect = CraftPotionEffectType.bukkitToMinecraftHolder(suspiciousEffectEntry.effect());
|
||||
+ // Paper end - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
|
||||
+ if (!overwrite && this.hasEffectForNextStew(suspiciousEffectEntry.effect())) {
|
||||
return false;
|
||||
}
|
||||
SuspiciousStewEffects stewEffects = this.getHandle().stewEffects;
|
||||
if (stewEffects == null) {
|
||||
stewEffects = SuspiciousStewEffects.EMPTY;
|
||||
}
|
||||
- SuspiciousStewEffects.Entry recordSuspiciousEffect = new SuspiciousStewEffects.Entry(minecraftPotionEffect.getEffect(), minecraftPotionEffect.getDuration());
|
||||
- this.removeEffectFromNextStew(potionEffect.getType()); // Avoid duplicates of effects
|
||||
+ SuspiciousStewEffects.Entry recordSuspiciousEffect = new SuspiciousStewEffects.Entry(minecraftPotionEffect, suspiciousEffectEntry.duration()); // Paper - sus effect entry API
|
||||
+ this.removeEffectFromNextStew(suspiciousEffectEntry.effect()); // Avoid duplicates of effects // Paper - sus effect entry API
|
||||
this.getHandle().stewEffects = stewEffects.withEffectAdded(recordSuspiciousEffect);
|
||||
return true;
|
||||
}
|
||||
@@ -101,6 +109,43 @@ public class CraftMushroomCow extends CraftCow implements MushroomCow, io.paperm
|
||||
this.getHandle().setVariant(net.minecraft.world.entity.animal.MushroomCow.MushroomType.values()[variant.ordinal()]);
|
||||
}
|
||||
|
||||
+ // Paper start
|
||||
+ @Override
|
||||
+ public java.util.List<io.papermc.paper.potion.SuspiciousEffectEntry> getStewEffects() {
|
||||
+ public List<io.papermc.paper.potion.SuspiciousEffectEntry> getStewEffects() {
|
||||
+ if (this.getHandle().stewEffects == null) {
|
||||
+ return java.util.List.of();
|
||||
+ return List.of();
|
||||
+ }
|
||||
+
|
||||
+ java.util.List<io.papermc.paper.potion.SuspiciousEffectEntry> nmsPairs = new java.util.ArrayList<>(this.getHandle().stewEffects.size());
|
||||
+ for (final net.minecraft.world.level.block.SuspiciousEffectHolder.EffectEntry effect : this.getHandle().stewEffects) {
|
||||
+ nmsPairs.add(io.papermc.paper.potion.SuspiciousEffectEntry.create(
|
||||
+ org.bukkit.craftbukkit.potion.CraftPotionEffectType.minecraftToBukkit(effect.effect()),
|
||||
+ final List<io.papermc.paper.potion.SuspiciousEffectEntry> effectEntries = new java.util.ArrayList<>(this.getHandle().stewEffects.effects().size());
|
||||
+ for (final SuspiciousStewEffects.Entry effect : this.getHandle().stewEffects.effects()) {
|
||||
+ effectEntries.add(io.papermc.paper.potion.SuspiciousEffectEntry.create(
|
||||
+ org.bukkit.craftbukkit.potion.CraftPotionEffectType.minecraftHolderToBukkit(effect.effect()),
|
||||
+ effect.duration()
|
||||
+ ));
|
||||
+ }
|
||||
+
|
||||
+ return java.util.Collections.unmodifiableList(nmsPairs);
|
||||
+ return java.util.Collections.unmodifiableList(effectEntries);
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public void setStewEffects(final java.util.List<io.papermc.paper.potion.SuspiciousEffectEntry> effects) {
|
||||
+ public void setStewEffects(final List<io.papermc.paper.potion.SuspiciousEffectEntry> effects) {
|
||||
+ if (effects.isEmpty()) {
|
||||
+ this.getHandle().stewEffects = null;
|
||||
+ return;
|
||||
+ }
|
||||
+
|
||||
+ java.util.List<net.minecraft.world.level.block.SuspiciousEffectHolder.EffectEntry> nmsPairs = new java.util.ArrayList<>(effects.size());
|
||||
+ List<SuspiciousStewEffects.Entry> nmsPairs = new java.util.ArrayList<>(effects.size());
|
||||
+ for (final io.papermc.paper.potion.SuspiciousEffectEntry effect : effects) {
|
||||
+ nmsPairs.add(new net.minecraft.world.level.block.SuspiciousEffectHolder.EffectEntry(
|
||||
+ org.bukkit.craftbukkit.potion.CraftPotionEffectType.bukkitToMinecraft(effect.effect()),
|
||||
+ nmsPairs.add(new SuspiciousStewEffects.Entry(
|
||||
+ org.bukkit.craftbukkit.potion.CraftPotionEffectType.bukkitToMinecraftHolder(effect.effect()),
|
||||
+ effect.duration()
|
||||
+ ));
|
||||
+ }
|
||||
+
|
||||
+ this.getHandle().stewEffects = nmsPairs;
|
||||
+ this.getHandle().stewEffects = new SuspiciousStewEffects(nmsPairs);
|
||||
+ }
|
||||
+ // Paper end
|
||||
+
|
||||
|
@ -84,7 +91,7 @@ index 9cc81bcccbf1141f66fedada1359b7c0dfa8e22a..7491c7cf38d888b31a509613d237b55f
|
|||
public String toString() {
|
||||
return "CraftMushroomCow";
|
||||
diff --git a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSuspiciousStew.java b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSuspiciousStew.java
|
||||
index 8fc3cd507d333d2bdea759d7c102a56e88ad5f5a..6b229ec0d4110fd0e758610bfacd9e8ec71ad2c5 100644
|
||||
index 8fc3cd507d333d2bdea759d7c102a56e88ad5f5a..4825edab85c7969e96018eb9ff47ef0fb3703c69 100644
|
||||
--- a/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSuspiciousStew.java
|
||||
+++ b/src/main/java/org/bukkit/craftbukkit/inventory/CraftMetaSuspiciousStew.java
|
||||
@@ -22,7 +22,7 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
|
||||
|
@ -96,6 +103,15 @@ index 8fc3cd507d333d2bdea759d7c102a56e88ad5f5a..6b229ec0d4110fd0e758610bfacd9e8e
|
|||
|
||||
CraftMetaSuspiciousStew(CraftMetaItem meta) {
|
||||
super(meta);
|
||||
@@ -48,7 +48,7 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
|
||||
continue;
|
||||
}
|
||||
int duration = effect.duration();
|
||||
- this.customEffects.add(new PotionEffect(type, duration, 0));
|
||||
+ this.customEffects.add(io.papermc.paper.potion.SuspiciousEffectEntry.create(type, duration)); // Paper - use suspicious effect entry for suspicious stew meta
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -74,8 +74,8 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
|
||||
if (this.customEffects != null) {
|
||||
List<SuspiciousStewEffects.Entry> effectList = new ArrayList<>();
|
||||
|
@ -116,7 +132,7 @@ index 8fc3cd507d333d2bdea759d7c102a56e88ad5f5a..6b229ec0d4110fd0e758610bfacd9e8e
|
|||
}
|
||||
return ImmutableList.of();
|
||||
}
|
||||
@@ -120,15 +120,21 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
|
||||
@@ -120,27 +120,46 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
|
||||
@Override
|
||||
public boolean addCustomEffect(PotionEffect effect, boolean overwrite) {
|
||||
Preconditions.checkArgument(effect != null, "Potion effect cannot be null");
|
||||
|
@ -124,25 +140,40 @@ index 8fc3cd507d333d2bdea759d7c102a56e88ad5f5a..6b229ec0d4110fd0e758610bfacd9e8e
|
|||
+ }
|
||||
|
||||
- int index = this.indexOfEffect(effect.getType());
|
||||
- if (index != -1) {
|
||||
+ // Paper start - add overloads to use suspicious effect entry to mushroom cow and suspicious stew meta
|
||||
+ @Override
|
||||
+ public boolean addCustomEffect(final io.papermc.paper.potion.SuspiciousEffectEntry suspiciousEffectEntry, final boolean overwrite) {
|
||||
+ Preconditions.checkArgument(suspiciousEffectEntry != null, "Suspicious effect entry cannot be null");
|
||||
+ int index = this.indexOfEffect(suspiciousEffectEntry.effect());
|
||||
if (index != -1) {
|
||||
+ final List<io.papermc.paper.potion.SuspiciousEffectEntry> matchingEffects = this.customEffects.stream().filter(
|
||||
+ entry -> entry.effect() == suspiciousEffectEntry.effect()
|
||||
+ ).toList();
|
||||
+ if (!matchingEffects.isEmpty()) {
|
||||
if (overwrite) {
|
||||
- PotionEffect old = this.customEffects.get(index);
|
||||
- if (old.getDuration() == effect.getDuration()) {
|
||||
+ io.papermc.paper.potion.SuspiciousEffectEntry old = this.customEffects.get(index);
|
||||
+ if (old.duration() == suspiciousEffectEntry.duration()) {
|
||||
+ boolean foundMatchingDuration = false;
|
||||
+ boolean mutated = false;
|
||||
+ for (final io.papermc.paper.potion.SuspiciousEffectEntry matchingEffect : matchingEffects) {
|
||||
+ if (matchingEffect.duration() != suspiciousEffectEntry.duration()) {
|
||||
+ this.customEffects.remove(suspiciousEffectEntry);
|
||||
+ mutated = true;
|
||||
+ } else {
|
||||
+ foundMatchingDuration = true;
|
||||
+ }
|
||||
+ }
|
||||
+ if (foundMatchingDuration && !mutated) {
|
||||
return false;
|
||||
+ } else if (!foundMatchingDuration) {
|
||||
+ this.customEffects.add(suspiciousEffectEntry);
|
||||
}
|
||||
- this.customEffects.set(index, effect);
|
||||
+ this.customEffects.set(index, suspiciousEffectEntry);
|
||||
return true;
|
||||
} else {
|
||||
- } else {
|
||||
+ } else {
|
||||
return false;
|
||||
@@ -137,10 +143,11 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
|
||||
}
|
||||
} else {
|
||||
if (this.customEffects == null) {
|
||||
this.customEffects = new ArrayList<>();
|
||||
}
|
||||
|
@ -155,7 +186,7 @@ index 8fc3cd507d333d2bdea759d7c102a56e88ad5f5a..6b229ec0d4110fd0e758610bfacd9e8e
|
|||
|
||||
@Override
|
||||
public boolean removeCustomEffect(PotionEffectType type) {
|
||||
@@ -151,10 +158,12 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
|
||||
@@ -151,10 +170,12 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
|
||||
}
|
||||
|
||||
boolean changed = false;
|
||||
|
@ -171,7 +202,7 @@ index 8fc3cd507d333d2bdea759d7c102a56e88ad5f5a..6b229ec0d4110fd0e758610bfacd9e8e
|
|||
iterator.remove();
|
||||
changed = true;
|
||||
}
|
||||
@@ -177,7 +186,7 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
|
||||
@@ -177,7 +198,7 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
|
||||
}
|
||||
|
||||
for (int i = 0; i < this.customEffects.size(); i++) {
|
||||
|
@ -180,7 +211,7 @@ index 8fc3cd507d333d2bdea759d7c102a56e88ad5f5a..6b229ec0d4110fd0e758610bfacd9e8e
|
|||
return i;
|
||||
}
|
||||
}
|
||||
@@ -222,7 +231,7 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
|
||||
@@ -222,7 +243,7 @@ public class CraftMetaSuspiciousStew extends CraftMetaItem implements Suspicious
|
||||
super.serialize(builder);
|
||||
|
||||
if (this.hasCustomEffects()) {
|
||||
|
|
Loading…
Reference in a new issue