TZR-Redstonemaniac

BaseFluidType

Mar 23rd, 2023
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.34 KB | None | 0 0
  1. package net.khalid.learning.fluid;
  2.  
  3. import com.mojang.blaze3d.shaders.FogShape;
  4. import com.mojang.blaze3d.systems.RenderSystem;
  5. import net.minecraft.client.Camera;
  6. import net.minecraft.client.multiplayer.ClientLevel;
  7. import net.minecraft.client.renderer.FogRenderer;
  8. import net.minecraft.resources.ResourceLocation;
  9. import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions;
  10. import net.minecraftforge.fluids.FluidStack;
  11. import net.minecraftforge.fluids.FluidType;
  12. import org.jetbrains.annotations.NotNull;
  13. import org.jetbrains.annotations.Nullable;
  14. import org.joml.Vector3f;
  15.  
  16. import java.util.function.Consumer;
  17.  
  18. public class BaseFluidType extends FluidType {
  19.     //Textures
  20.     private final ResourceLocation stillTexture;
  21.     private final ResourceLocation flowingTexture;
  22.     private final ResourceLocation overlayTexture;
  23.  
  24.     //Colors
  25.     private final int tintColor;
  26.     private final Vector3f fogColor;
  27.  
  28.     //Constructor
  29.     public BaseFluidType(final ResourceLocation stillTexture, final ResourceLocation flowingTexture, final ResourceLocation overlayTexture, final int tintColor,
  30.             final Vector3f fogColor, final Properties properties) {
  31.         super(properties);
  32.  
  33.         this.stillTexture = stillTexture;
  34.         this.flowingTexture = flowingTexture;
  35.         this.overlayTexture = overlayTexture;
  36.  
  37.         this.tintColor = tintColor;
  38.  
  39.         this.fogColor = fogColor;
  40.     }
  41.  
  42.     //Initializer
  43.     @Override
  44.     public void initializeClient(Consumer<IClientFluidTypeExtensions> consumer) {
  45.         consumer.accept(new IClientFluidTypeExtensions() {
  46.             //Texture return methods
  47.             @Override
  48.             public ResourceLocation getStillTexture() {
  49.                 return stillTexture;
  50.             }
  51.             @Override
  52.             public ResourceLocation getFlowingTexture(FluidStack stack) {
  53.                 return flowingTexture;
  54.             }
  55.             @Override
  56.             public @Nullable ResourceLocation getOverlayTexture() {
  57.                 return overlayTexture;
  58.             }
  59.  
  60.             //Tint color return method
  61.             @Override
  62.             public int getTintColor() {
  63.                 return tintColor;
  64.             }
  65.  
  66.             //Fog color and distance modifiers
  67.             @Override
  68.             public @NotNull Vector3f modifyFogColor(Camera camera, float partialTick, ClientLevel level, int renderDistance, float darkenWorldAmount,
  69.                                                     Vector3f fluidFogColor) {
  70.                 return fogColor;
  71.             }
  72.             @Override
  73.             public void modifyFogRender(Camera camera, FogRenderer.FogMode mode, float renderDistance, float partialTick, float nearDistance, float farDistance,
  74.                                         FogShape shape) {
  75.                 RenderSystem.setShaderFogStart(1f);
  76.                 RenderSystem.setShaderFogEnd(6f);
  77.             }
  78.         });
  79.     }
  80.  
  81.     //Getters
  82.     public ResourceLocation getStillTexture() {
  83.         return stillTexture;
  84.     }
  85.     public ResourceLocation getFlowingTexture() {
  86.         return flowingTexture;
  87.     }
  88.     public ResourceLocation getOverlayTexture() {
  89.         return overlayTexture;
  90.     }
  91.     public int getTintColor() {
  92.         return tintColor;
  93.     }
  94.     public Vector3f getFogColor() {
  95.         return fogColor;
  96.     }
  97. }
  98.  
Add Comment
Please, Sign In to add comment