From ad879a803ca0c2fd879b0dcff20510bf67d8c02c Mon Sep 17 00:00:00 2001 From: shedaniel Date: Mon, 2 May 2022 01:41:19 +0800 Subject: [PATCH] [ci cancel] Add more fluid attributes (#247) --- build.gradle | 2 +- .../hooks/fluid/FluidStackHooks.java | 83 +++++++++++++++++++ .../fluid/fabric/FluidStackHooksImpl.java | 41 ++++++--- .../fluid/forge/FluidStackHooksImpl.java | 37 +++++++++ 4 files changed, 149 insertions(+), 14 deletions(-) diff --git a/build.gradle b/build.gradle index 0d53b23b..3e8abac5 100644 --- a/build.gradle +++ b/build.gradle @@ -5,7 +5,7 @@ buildscript { } plugins { - id "architectury-plugin" version "3.4.130" + id "architectury-plugin" version "3.4-SNAPSHOT" id "dev.architectury.loom" version "0.11.0-SNAPSHOT" apply false id "org.cadixdev.licenser" version "0.6.1" id "com.matthewprenger.cursegradle" version "1.4.0" apply false diff --git a/common/src/main/java/dev/architectury/hooks/fluid/FluidStackHooks.java b/common/src/main/java/dev/architectury/hooks/fluid/FluidStackHooks.java index 0cf4c911..0ed010f0 100644 --- a/common/src/main/java/dev/architectury/hooks/fluid/FluidStackHooks.java +++ b/common/src/main/java/dev/architectury/hooks/fluid/FluidStackHooks.java @@ -29,6 +29,7 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.Level; import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.FluidState; import org.jetbrains.annotations.Nullable; @@ -148,4 +149,86 @@ public class FluidStackHooks { public static int getColor(Fluid fluid) { throw new AssertionError(); } + + /** + * Returns the luminosity of the fluid. + * + * @param fluid the fluid + * @param level the level, can be {@code null} + * @param pos the block position, can be {@code null} + * @return the luminosity of the fluid, this ranges from 0 to 15 + */ + @ExpectPlatform + public static int getLuminosity(FluidStack fluid, @Nullable Level level, @Nullable BlockPos pos) { + throw new AssertionError(); + } + + /** + * Returns the luminosity of the fluid. + * + * @param fluid the fluid + * @param level the level, can be {@code null} + * @param pos the block position, can be {@code null} + * @return the luminosity of the fluid, this ranges from 0 to 15 + */ + @ExpectPlatform + public static int getLuminosity(Fluid fluid, @Nullable Level level, @Nullable BlockPos pos) { + throw new AssertionError(); + } + + /** + * Returns the temperature of the fluid. + * The temperature is in kelvin, for example, 300 kelvin is equal to room temperature. + * + * @param fluid the fluid + * @param level the level, can be {@code null} + * @param pos the block position, can be {@code null} + * @return the temperature of the fluid + */ + @ExpectPlatform + public static int getTemperature(FluidStack fluid, @Nullable Level level, @Nullable BlockPos pos) { + throw new AssertionError(); + } + + /** + * Returns the temperature of the fluid. + * The temperature is in kelvin, for example, 300 kelvin is equal to room temperature. + * + * @param fluid the fluid + * @param level the level, can be {@code null} + * @param pos the block position, can be {@code null} + * @return the temperature of the fluid + */ + @ExpectPlatform + public static int getTemperature(Fluid fluid, @Nullable Level level, @Nullable BlockPos pos) { + throw new AssertionError(); + } + + /** + * Returns the viscosity of the fluid. A lower viscosity means that the fluid will flow faster. + * The default value is 1000 for water. + * + * @param fluid the fluid + * @param level the level, can be {@code null} + * @param pos the block position, can be {@code null} + * @return the viscosity of the fluid + */ + @ExpectPlatform + public static int getViscosity(FluidStack fluid, @Nullable Level level, @Nullable BlockPos pos) { + throw new AssertionError(); + } + + /** + * Returns the viscosity of the fluid. A lower viscosity means that the fluid will flow faster. + * The default value is 1000 for water. + * + * @param fluid the fluid + * @param level the level, can be {@code null} + * @param pos the block position, can be {@code null} + * @return the viscosity of the fluid + */ + @ExpectPlatform + public static int getViscosity(Fluid fluid, @Nullable Level level, @Nullable BlockPos pos) { + throw new AssertionError(); + } } diff --git a/fabric/src/main/java/dev/architectury/hooks/fluid/fabric/FluidStackHooksImpl.java b/fabric/src/main/java/dev/architectury/hooks/fluid/fabric/FluidStackHooksImpl.java index 2d4d598f..53aded69 100644 --- a/fabric/src/main/java/dev/architectury/hooks/fluid/fabric/FluidStackHooksImpl.java +++ b/fabric/src/main/java/dev/architectury/hooks/fluid/fabric/FluidStackHooksImpl.java @@ -20,11 +20,11 @@ package dev.architectury.hooks.fluid.fabric; import dev.architectury.fluid.FluidStack; -import dev.architectury.platform.Platform; -import dev.architectury.utils.Env; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.fabricmc.fabric.api.client.render.fluid.v1.FluidRenderHandlerRegistry; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariant; +import net.fabricmc.fabric.api.transfer.v1.fluid.FluidVariantAttributes; import net.minecraft.client.renderer.texture.TextureAtlasSprite; import net.minecraft.core.BlockPos; import net.minecraft.core.Registry; @@ -32,9 +32,9 @@ import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.Tag; import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; -import net.minecraft.network.chat.TranslatableComponent; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.Level; import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.material.Fluids; @@ -44,16 +44,7 @@ import java.util.Objects; public class FluidStackHooksImpl { public static Component getName(FluidStack stack) { - if (Platform.getEnvironment() == Env.CLIENT) { - return getNameClient(stack); - } - - return new TranslatableComponent(getTranslationKey(stack)); - } - - @Environment(EnvType.CLIENT) - private static Component getNameClient(FluidStack stack) { - return stack.getFluid().defaultFluidState().createLegacyBlock().getBlock().getName(); + return FluidVariantAttributes.getName(FluidVariant.of(stack.getFluid(), stack.getTag())); } public static String getTranslationKey(FluidStack stack) { @@ -195,4 +186,28 @@ public class FluidStackHooksImpl { if (handler == null) return -1; return handler.getFluidColor(null, null, fluid.defaultFluidState()); } + + public static int getLuminosity(FluidStack fluid, @Nullable Level level, @Nullable BlockPos pos) { + return FluidVariantAttributes.getLuminance(FluidVariant.of(fluid.getFluid(), fluid.getTag())); + } + + public static int getLuminosity(Fluid fluid, @Nullable Level level, @Nullable BlockPos pos) { + return FluidVariantAttributes.getLuminance(FluidVariant.of(fluid)); + } + + public static int getTemperature(FluidStack fluid, @Nullable Level level, @Nullable BlockPos pos) { + return FluidVariantAttributes.getTemperature(FluidVariant.of(fluid.getFluid(), fluid.getTag())); + } + + public static int getTemperature(Fluid fluid, @Nullable Level level, @Nullable BlockPos pos) { + return FluidVariantAttributes.getTemperature(FluidVariant.of(fluid)); + } + + public static int getViscosity(FluidStack fluid, @Nullable Level level, @Nullable BlockPos pos) { + return FluidVariantAttributes.getViscosity(FluidVariant.of(fluid.getFluid(), fluid.getTag()), level); + } + + public static int getViscosity(Fluid fluid, @Nullable Level level, @Nullable BlockPos pos) { + return FluidVariantAttributes.getViscosity(FluidVariant.of(fluid), level); + } } diff --git a/forge/src/main/java/dev/architectury/hooks/fluid/forge/FluidStackHooksImpl.java b/forge/src/main/java/dev/architectury/hooks/fluid/forge/FluidStackHooksImpl.java index d862ed57..5020b06d 100644 --- a/forge/src/main/java/dev/architectury/hooks/fluid/forge/FluidStackHooksImpl.java +++ b/forge/src/main/java/dev/architectury/hooks/fluid/forge/FluidStackHooksImpl.java @@ -29,6 +29,7 @@ import net.minecraft.network.FriendlyByteBuf; import net.minecraft.network.chat.Component; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.BlockAndTintGetter; +import net.minecraft.world.level.Level; import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.FluidState; import net.minecraft.world.level.material.Fluids; @@ -130,4 +131,40 @@ public class FluidStackHooksImpl { if (fluid == Fluids.EMPTY) return -1; return fluid.getAttributes().getColor(); } + + public static int getLuminosity(FluidStack fluid, @Nullable Level level, @Nullable BlockPos pos) { + return fluid.getFluid().getAttributes().getLuminosity(FluidStackHooksForge.toForge(fluid)); + } + + public static int getLuminosity(Fluid fluid, @Nullable Level level, @Nullable BlockPos pos) { + if (level != null && pos != null) { + return fluid.getAttributes().getLuminosity(level, pos); + } + + return fluid.getAttributes().getLuminosity(); + } + + public static int getTemperature(FluidStack fluid, @Nullable Level level, @Nullable BlockPos pos) { + return fluid.getFluid().getAttributes().getTemperature(FluidStackHooksForge.toForge(fluid)); + } + + public static int getTemperature(Fluid fluid, @Nullable Level level, @Nullable BlockPos pos) { + if (level != null && pos != null) { + return fluid.getAttributes().getTemperature(level, pos); + } + + return fluid.getAttributes().getTemperature(); + } + + public static int getViscosity(FluidStack fluid, @Nullable Level level, @Nullable BlockPos pos) { + return fluid.getFluid().getAttributes().getViscosity(FluidStackHooksForge.toForge(fluid)); + } + + public static int getViscosity(Fluid fluid, @Nullable Level level, @Nullable BlockPos pos) { + if (level != null && pos != null) { + return fluid.getAttributes().getViscosity(level, pos); + } + + return fluid.getAttributes().getViscosity(); + } }