#1071: Make Fluid an interface and add missing entry

By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
Bukkit/Spigot 2024-10-29 06:43:18 +11:00
parent 5b78d5d8a2
commit 79a73f5e87
2 changed files with 38 additions and 15 deletions

View file

@ -1,39 +1,62 @@
package org.bukkit;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import java.util.Locale;
import org.bukkit.util.OldEnum;
import org.jetbrains.annotations.NotNull;
/**
* Represents a fluid type.
*/
public enum Fluid implements Keyed {
public interface Fluid extends OldEnum<Fluid>, Keyed {
/**
* No fluid.
*/
Fluid EMPTY = getFluid("empty");
/**
* Stationary water.
*/
WATER,
Fluid WATER = getFluid("water");
/**
* Flowing water.
*/
FLOWING_WATER,
Fluid FLOWING_WATER = getFluid("flowing_water");
/**
* Stationary lava.
*/
LAVA,
Fluid LAVA = getFluid("lava");
/**
* Flowing lava.
*/
FLOWING_LAVA;
private final NamespacedKey key;
private Fluid() {
this.key = NamespacedKey.minecraft(this.name().toLowerCase(Locale.ROOT));
}
Fluid FLOWING_LAVA = getFluid("flowing_lava");
@NotNull
@Override
public NamespacedKey getKey() {
return key;
private static Fluid getFluid(@NotNull String key) {
return Registry.FLUID.getOrThrow(NamespacedKey.minecraft(key));
}
/**
* @param name of the fluid.
* @return the fluid with the given name.
* @deprecated only for backwards compatibility, use {@link Registry#get(NamespacedKey)} instead.
*/
@NotNull
@Deprecated(since = "1.21.3")
static Fluid valueOf(@NotNull String name) {
Fluid fluid = Bukkit.getUnsafe().get(Registry.FLUID, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
Preconditions.checkArgument(fluid != null, "No fluid found with the name %s", name);
return fluid;
}
/**
* @return an array of all known fluids.
* @deprecated use {@link Registry#iterator()}.
*/
@NotNull
@Deprecated(since = "1.21.3")
static Fluid[] values() {
return Lists.newArrayList(Registry.FLUID).toArray(new Fluid[0]);
}
}

View file

@ -323,7 +323,7 @@ public interface Registry<T extends Keyed> extends Iterable<T> {
*
* @see Fluid
*/
Registry<Fluid> FLUID = new SimpleRegistry<>(Fluid.class);
Registry<Fluid> FLUID = Objects.requireNonNull(Bukkit.getRegistry(Fluid.class), "No registry present for Fluid. This is a bug.");
/**
* Frog variants.
*