SPIGOT-5753: Back PotionType by a minecraft registry

By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
CraftBukkit/Spigot
2023-10-09 20:22:53 +11:00
parent a2e3f213cf
commit 691d43eb42
8 changed files with 220 additions and 99 deletions

View File

@@ -3,8 +3,6 @@ package org.bukkit.craftbukkit.entity;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.util.List;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.MinecraftKey;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectList;
import net.minecraft.world.entity.EntityAreaEffectCloud;
@@ -14,13 +12,16 @@ import org.bukkit.Particle;
import org.bukkit.craftbukkit.CraftParticle;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.potion.CraftPotionEffectType;
import org.bukkit.craftbukkit.potion.CraftPotionType;
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
import org.bukkit.entity.AreaEffectCloud;
import org.bukkit.entity.LivingEntity;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import org.bukkit.projectiles.ProjectileSource;
import org.jetbrains.annotations.NotNull;
public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud {
@@ -203,12 +204,27 @@ public class CraftAreaEffectCloud extends CraftEntity implements AreaEffectCloud
@Override
public void setBasePotionData(PotionData data) {
Preconditions.checkArgument(data != null, "PotionData cannot be null");
getHandle().setPotion(BuiltInRegistries.POTION.get(new MinecraftKey(CraftPotionUtil.fromBukkit(data))));
getHandle().setPotion(CraftPotionType.bukkitToMinecraft(CraftPotionUtil.fromBukkit(data)));
}
@Override
public PotionData getBasePotionData() {
return CraftPotionUtil.toBukkit((BuiltInRegistries.POTION.getKey(getHandle().potion)).toString());
return CraftPotionUtil.toBukkit(CraftPotionType.minecraftToBukkit(getHandle().getPotion()));
}
@Override
public void setBasePotionType(@NotNull PotionType potionType) {
// TODO: 10/6/23 Change PotionType.UNCRAFTABLE to PotionType.EMPTY in error message
Preconditions.checkArgument(potionType != null, "PotionType cannot be null use PotionType.UNCRAFTABLE to represent no effect instead.");
getHandle().setPotion(CraftPotionType.bukkitToMinecraft(potionType));
}
@NotNull
@Override
public PotionType getBasePotionType() {
return CraftPotionType.minecraftToBukkit(getHandle().getPotion());
}
@Override

View File

@@ -3,19 +3,20 @@ package org.bukkit.craftbukkit.entity;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import java.util.List;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.MinecraftKey;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectList;
import net.minecraft.world.entity.projectile.EntityTippedArrow;
import org.bukkit.Color;
import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.potion.CraftPotionEffectType;
import org.bukkit.craftbukkit.potion.CraftPotionType;
import org.bukkit.craftbukkit.potion.CraftPotionUtil;
import org.bukkit.entity.Arrow;
import org.bukkit.potion.PotionData;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import org.bukkit.potion.PotionType;
import org.jetbrains.annotations.NotNull;
public class CraftTippedArrow extends CraftArrow implements Arrow {
@@ -103,12 +104,26 @@ public class CraftTippedArrow extends CraftArrow implements Arrow {
@Override
public void setBasePotionData(PotionData data) {
Preconditions.checkArgument(data != null, "PotionData cannot be null");
this.getHandle().potion = BuiltInRegistries.POTION.get(new MinecraftKey(CraftPotionUtil.fromBukkit(data)));
this.getHandle().potion = CraftPotionType.bukkitToMinecraft(CraftPotionUtil.fromBukkit(data));
}
@Override
public PotionData getBasePotionData() {
return CraftPotionUtil.toBukkit(BuiltInRegistries.POTION.getKey(this.getHandle().potion).toString());
return CraftPotionUtil.toBukkit(CraftPotionType.minecraftToBukkit(getHandle().potion));
}
@Override
public void setBasePotionType(@NotNull PotionType potionType) {
// TODO: 10/6/23 Change PotionType.UNCRAFTABLE to PotionType.EMPTY in error message
Preconditions.checkArgument(potionType != null, "PotionType cannot be null use PotionType.UNCRAFTABLE to represent no effect instead.");
getHandle().potion = CraftPotionType.bukkitToMinecraft(potionType);
}
@NotNull
@Override
public PotionType getBasePotionType() {
return CraftPotionType.minecraftToBukkit(getHandle().potion);
}
@Override