diff --git a/nms-patches/net/minecraft/world/entity/animal/EntityMushroomCow.patch b/nms-patches/net/minecraft/world/entity/animal/EntityMushroomCow.patch index 9e8f91384..7cd469808 100644 --- a/nms-patches/net/minecraft/world/entity/animal/EntityMushroomCow.patch +++ b/nms-patches/net/minecraft/world/entity/animal/EntityMushroomCow.patch @@ -1,6 +1,6 @@ --- a/net/minecraft/world/entity/animal/EntityMushroomCow.java +++ b/net/minecraft/world/entity/animal/EntityMushroomCow.java -@@ -42,6 +42,13 @@ +@@ -42,13 +42,20 @@ import net.minecraft.world.level.block.state.IBlockData; import net.minecraft.world.level.gameevent.GameEvent; @@ -14,6 +14,14 @@ public class EntityMushroomCow extends EntityCow implements IShearable, VariantHolder { private static final DataWatcherObject DATA_TYPE = DataWatcher.defineId(EntityMushroomCow.class, DataWatcherRegistry.STRING); + private static final int MUTATE_CHANCE = 1024; + private static final String TAG_STEW_EFFECTS = "stew_effects"; + @Nullable +- private List stewEffects; ++ public List stewEffects; + @Nullable + private UUID lastLightningBoltUUID; + @@ -114,6 +121,11 @@ this.playSound(soundeffect, 1.0F, 1.0F); return EnumInteractionResult.sidedSuccess(this.level().isClientSide); diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java index 37bb10ff8..3bb6affab 100644 --- a/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java +++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftMushroomCow.java @@ -1,16 +1,78 @@ package org.bukkit.craftbukkit.entity; import com.google.common.base.Preconditions; +import com.google.common.collect.ImmutableList; +import java.util.ArrayList; +import java.util.List; +import net.minecraft.world.effect.MobEffect; +import net.minecraft.world.effect.MobEffectList; import net.minecraft.world.entity.animal.EntityMushroomCow; +import net.minecraft.world.level.block.SuspiciousEffectHolder; import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.potion.CraftPotionEffectType; +import org.bukkit.craftbukkit.potion.CraftPotionUtil; import org.bukkit.entity.MushroomCow; -import org.bukkit.entity.MushroomCow.Variant; +import org.bukkit.potion.PotionEffect; +import org.bukkit.potion.PotionEffectType; public class CraftMushroomCow extends CraftCow implements MushroomCow { public CraftMushroomCow(CraftServer server, EntityMushroomCow entity) { super(server, entity); } + @Override + public boolean hasEffectsForNextStew() { + return this.getHandle().stewEffects != null && !this.getHandle().stewEffects.isEmpty(); + } + + @Override + public List getEffectsForNextStew() { + if (this.hasEffectsForNextStew()) { + return this.getHandle().stewEffects.stream().map(recordSuspiciousEffect -> CraftPotionUtil.toBukkit(recordSuspiciousEffect.createEffectInstance())).toList(); + } + return ImmutableList.of(); + } + + @Override + public boolean addEffectToNextStew(PotionEffect potionEffect, boolean overwrite) { + Preconditions.checkArgument(potionEffect != null, "PotionEffect cannot be null"); + MobEffect minecraftPotionEffect = CraftPotionUtil.fromBukkit(potionEffect); + if (!overwrite && this.hasEffectForNextStew(potionEffect.getType())) { + return false; + } + if (this.getHandle().stewEffects == null) { + this.getHandle().stewEffects = new ArrayList<>(); + } + SuspiciousEffectHolder.a recordSuspiciousEffect = new SuspiciousEffectHolder.a(minecraftPotionEffect.getEffect(), minecraftPotionEffect.getDuration()); + this.removeEffectFromNextStew(potionEffect.getType()); // Avoid duplicates of effects + return this.getHandle().stewEffects.add(recordSuspiciousEffect); + } + + @Override + public boolean removeEffectFromNextStew(PotionEffectType potionEffectType) { + Preconditions.checkArgument(potionEffectType != null, "potionEffectType cannot be null"); + if (!this.hasEffectsForNextStew()) { + return false; + } + MobEffectList minecraftPotionEffectType = CraftPotionEffectType.bukkitToMinecraft(potionEffectType); + return this.getHandle().stewEffects.removeIf(recordSuspiciousEffect -> recordSuspiciousEffect.effect().equals(minecraftPotionEffectType)); + } + + @Override + public boolean hasEffectForNextStew(PotionEffectType potionEffectType) { + Preconditions.checkArgument(potionEffectType != null, "potionEffectType cannot be null"); + if (!this.hasEffectsForNextStew()) { + return false; + } + MobEffectList minecraftPotionEffectType = CraftPotionEffectType.bukkitToMinecraft(potionEffectType); + return this.getHandle().stewEffects.stream().anyMatch(recordSuspiciousEffect -> recordSuspiciousEffect.effect().equals(minecraftPotionEffectType)); + } + + @Override + public void clearEffectsForNextStew() { + this.getHandle().stewEffects = null; + } + @Override public EntityMushroomCow getHandle() { return (EntityMushroomCow) entity; @@ -23,7 +85,7 @@ public class CraftMushroomCow extends CraftCow implements MushroomCow { @Override public void setVariant(Variant variant) { - Preconditions.checkArgument(variant != null, "variant"); + Preconditions.checkArgument(variant != null, "Variant cannot be null"); getHandle().setVariant(EntityMushroomCow.Type.values()[variant.ordinal()]); }