#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; package org.bukkit;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import java.util.Locale; import java.util.Locale;
import org.bukkit.util.OldEnum;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
/** /**
* Represents a fluid type. * Represents a fluid type.
*/ */
public enum Fluid implements Keyed { public interface Fluid extends OldEnum<Fluid>, Keyed {
/**
* No fluid.
*/
Fluid EMPTY = getFluid("empty");
/** /**
* Stationary water. * Stationary water.
*/ */
WATER, Fluid WATER = getFluid("water");
/** /**
* Flowing water. * Flowing water.
*/ */
FLOWING_WATER, Fluid FLOWING_WATER = getFluid("flowing_water");
/** /**
* Stationary lava. * Stationary lava.
*/ */
LAVA, Fluid LAVA = getFluid("lava");
/** /**
* Flowing lava. * Flowing lava.
*/ */
FLOWING_LAVA; Fluid FLOWING_LAVA = getFluid("flowing_lava");
private final NamespacedKey key;
private Fluid() {
this.key = NamespacedKey.minecraft(this.name().toLowerCase(Locale.ROOT));
}
@NotNull @NotNull
@Override private static Fluid getFluid(@NotNull String key) {
public NamespacedKey getKey() { return Registry.FLUID.getOrThrow(NamespacedKey.minecraft(key));
return 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 * @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. * Frog variants.
* *