13
0
geforkt von Mirrors/Paper

SPIGOT-7576, #1347: Add methods in MushroomCow to change stew effects

By: Doc <nachito94@msn.com>
Dieser Commit ist enthalten in:
CraftBukkit/Spigot 2024-02-08 22:54:51 +11:00
Ursprung b5ff47182d
Commit 684554a642
2 geänderte Dateien mit 73 neuen und 3 gelöschten Zeilen

Datei anzeigen

@ -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<EntityMushroomCow.Type> {
private static final DataWatcherObject<String> 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<SuspiciousEffectHolder.a> stewEffects;
+ public List<SuspiciousEffectHolder.a> stewEffects;
@Nullable
private UUID lastLightningBoltUUID;
@@ -114,6 +121,11 @@
this.playSound(soundeffect, 1.0F, 1.0F);
return EnumInteractionResult.sidedSuccess(this.level().isClientSide);

Datei anzeigen

@ -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<PotionEffect> 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()]);
}