package com.simibubi.create; import java.util.function.Consumer; import javax.annotation.Nullable; import com.simibubi.create.AllTags.AllFluidTags; import com.simibubi.create.content.contraptions.fluids.VirtualFluid; import com.simibubi.create.content.contraptions.fluids.potion.PotionFluid; import com.simibubi.create.content.contraptions.fluids.potion.PotionFluid.PotionFluidType; import com.simibubi.create.content.palettes.AllPaletteStoneTypes; import com.simibubi.create.foundation.data.CreateRegistrate; import com.tterrag.registrate.util.entry.FluidEntry; import net.minecraft.client.renderer.ItemBlockRenderTypes; import net.minecraft.client.renderer.RenderType; import net.minecraft.core.BlockPos; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.level.BlockAndTintGetter; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.material.Fluid; import net.minecraft.world.level.material.FluidState; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions; import net.minecraftforge.fluids.FluidStack; import net.minecraftforge.fluids.FluidType; import net.minecraftforge.fluids.ForgeFlowingFluid; public class AllFluids { private static final CreateRegistrate REGISTRATE = Create.registrate(); public static final FluidEntry POTION = REGISTRATE.virtualFluid("potion", PotionFluidType::new, PotionFluid::new) .lang(f -> "fluid.create.potion", "Potion") .register(); public static final FluidEntry TEA = REGISTRATE.virtualFluid("tea") .lang(f -> "fluid.create.tea", "Builder's Tea") .tag(AllTags.forgeFluidTag("tea")) .register(); public static final FluidEntry HONEY = REGISTRATE.standardFluid("honey", NoColorFluidAttributes::new) .lang(f -> "fluid.create.honey", "Honey") .properties(b -> b.viscosity(2000) .density(1400)) .fluidProperties(p -> p.levelDecreasePerBlock(2) .tickRate(25) .slopeFindDistance(3) .explosionResistance(100f)) .tag(AllFluidTags.HONEY.tag) .source(ForgeFlowingFluid.Source::new) // TODO: remove when Registrate fixes FluidBuilder .bucket() .tag(AllTags.forgeItemTag("buckets/honey")) .build() .register(); public static final FluidEntry CHOCOLATE = REGISTRATE.standardFluid("chocolate", NoColorFluidAttributes::new) .lang(f -> "fluid.create.chocolate", "Chocolate") .tag(AllTags.forgeFluidTag("chocolate")) .properties(b -> b.viscosity(1500) .density(1400)) .fluidProperties(p -> p.levelDecreasePerBlock(2) .tickRate(25) .slopeFindDistance(3) .explosionResistance(100f)) .register(); // Load this class public static void register() {} @OnlyIn(Dist.CLIENT) public static void assignRenderLayers() {} @OnlyIn(Dist.CLIENT) private static void makeTranslucent(FluidEntry entry) { ForgeFlowingFluid fluid = entry.get(); ItemBlockRenderTypes.setRenderLayer(fluid, RenderType.translucent()); ItemBlockRenderTypes.setRenderLayer(fluid.getSource(), RenderType.translucent()); } @Nullable public static BlockState getLavaInteraction(FluidState fluidState) { Fluid fluid = fluidState.getType(); if (fluid.isSame(HONEY.get())) return AllPaletteStoneTypes.LIMESTONE.getBaseBlock() .get() .defaultBlockState(); if (fluid.isSame(CHOCOLATE.get())) return AllPaletteStoneTypes.SCORIA.getBaseBlock() .get() .defaultBlockState(); return null; } public static abstract class TintedFluidType extends FluidType { protected static final int NO_TINT = 0xffffffff; private ResourceLocation stillTexture; private ResourceLocation flowingTexture; public TintedFluidType(Properties properties, ResourceLocation stillTexture, ResourceLocation flowingTexture) { super(properties); } @Override public void initializeClient(Consumer consumer) { consumer.accept(new IClientFluidTypeExtensions() { @Override public ResourceLocation getFlowingTexture() { return flowingTexture; } @Override public ResourceLocation getStillTexture() { return stillTexture; } @Override public int getTintColor(FluidStack stack) { return getTintColor(stack); } @Override public int getTintColor(FluidState state, BlockAndTintGetter getter, BlockPos pos) { return getTintColor(state, getter, pos); } }); } protected abstract int getTintColor(FluidStack stack); protected abstract int getTintColor(FluidState state, BlockAndTintGetter getter, BlockPos pos); } /** * Removing alpha from tint prevents optifine from forcibly applying biome * colors to modded fluids (Makes translucent fluids disappear) */ private static class NoColorFluidAttributes extends TintedFluidType { public NoColorFluidAttributes(Properties properties, ResourceLocation stillTexture, ResourceLocation flowingTexture) { super(properties, stillTexture, flowingTexture); } @Override public int getTintColor(FluidState state, BlockAndTintGetter world, BlockPos pos) { return 0x00ffffff; } @Override protected int getTintColor(FluidStack stack) { return NO_TINT; } } }