|
28 | 28 | import java.util.Objects; |
29 | 29 | import java.util.concurrent.ConcurrentHashMap; |
30 | 30 | import net.minecraft.core.component.DataComponentPatch; |
31 | | -import net.minecraft.core.registries.BuiltInRegistries; |
32 | | -import net.minecraft.resources.ResourceLocation; |
33 | | -import net.minecraft.world.level.material.FlowingFluid; |
34 | 31 | import net.minecraft.world.level.material.Fluid; |
35 | | -import net.minecraft.world.level.material.Fluids; |
36 | 32 | import net.neoforged.neoforge.fluids.FluidStack; |
37 | 33 | import org.slf4j.Logger; |
38 | 34 | import org.slf4j.LoggerFactory; |
39 | 35 |
|
40 | 36 | public class FluidVariantImpl implements FluidVariant { |
41 | 37 | private static final Map<Fluid, FluidVariant> noTagCache = new ConcurrentHashMap<>(); |
42 | 38 |
|
43 | | - private static Fluid normalizeFluid(Fluid fluid) { |
44 | | - if (!fluid.isSource(fluid.defaultFluidState()) && fluid != Fluids.EMPTY) { |
45 | | - // Note: the empty fluid is not still, that's why we check for it specifically. |
46 | | - |
47 | | - if (fluid instanceof FlowingFluid flowable) { |
48 | | - // Normalize FlowableFluids to their still variants. |
49 | | - return flowable.getSource(); |
50 | | - } else { |
51 | | - // If not a FlowableFluid, we don't know how to convert -> crash. |
52 | | - ResourceLocation id = BuiltInRegistries.FLUID.getKey(fluid); |
53 | | - throw new IllegalArgumentException("Cannot convert flowing fluid %s (%s) into a still fluid.".formatted(id, fluid)); |
54 | | - } |
55 | | - } |
56 | | - return fluid; |
57 | | - } |
58 | | - |
59 | 39 | public static FluidVariant of(Fluid fluid) { |
60 | 40 | Objects.requireNonNull(fluid, "Fluid may not be null."); |
61 | 41 |
|
62 | | - return noTagCache.computeIfAbsent(normalizeFluid(fluid), f -> new FluidVariantImpl(new FluidStack(f, 1))); |
| 42 | + return noTagCache.computeIfAbsent(fluid, f -> new FluidVariantImpl(new FluidStack(f, 1))); |
63 | 43 | } |
64 | 44 |
|
65 | 45 | public static FluidVariant of(FluidStack stack) { |
|
0 commit comments