From 79a73f5e876c3d9e750393f9659f3cea810991c8 Mon Sep 17 00:00:00 2001
From: Bukkit/Spigot <noreply+git-bukkit@papermc.io>
Date: Tue, 29 Oct 2024 06:43:18 +1100
Subject: [PATCH] #1071: Make Fluid an interface and add missing entry

By: DerFrZocker <derrieple@gmail.com>
---
 paper-api/src/main/java/org/bukkit/Fluid.java | 51 ++++++++++++++-----
 .../src/main/java/org/bukkit/Registry.java    |  2 +-
 2 files changed, 38 insertions(+), 15 deletions(-)

diff --git a/paper-api/src/main/java/org/bukkit/Fluid.java b/paper-api/src/main/java/org/bukkit/Fluid.java
index 4cc974689a..dff295a4ca 100644
--- a/paper-api/src/main/java/org/bukkit/Fluid.java
+++ b/paper-api/src/main/java/org/bukkit/Fluid.java
@@ -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]);
     }
 }
diff --git a/paper-api/src/main/java/org/bukkit/Registry.java b/paper-api/src/main/java/org/bukkit/Registry.java
index eb03e39e9d..fbc1a540a2 100644
--- a/paper-api/src/main/java/org/bukkit/Registry.java
+++ b/paper-api/src/main/java/org/bukkit/Registry.java
@@ -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.
      *