Skip to content

Commit

Permalink
流体注册机添加fogColor属性
Browse files Browse the repository at this point in the history
  • Loading branch information
zlw380 committed Nov 20, 2024
1 parent 49335c2 commit 0ed075a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/main/java/kasuga/lib/example_env/AllExampleElements.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package kasuga.lib.example_env;

import com.mojang.math.Vector3f;
import kasuga.lib.KasugaLib;
import kasuga.lib.core.base.BucketItem;
import kasuga.lib.core.menu.base.GuiBinding;
Expand Down Expand Up @@ -135,6 +136,8 @@ public class AllExampleElements {
.bucketItem(BucketItem::new)
.basicFluidProperties(5, 15, 5, true)
.defaultSounds()
.tintColor(0xFFD2691E)
.fogColor(210, 105, 30)
.blockType(ExampleFluidBlock::new)
.noLootAndOcclusion()
.setRenderType(RenderType.translucent())
Expand Down
28 changes: 28 additions & 0 deletions src/main/java/kasuga/lib/registrations/common/FluidReg.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package kasuga.lib.registrations.common;

import com.mojang.blaze3d.shaders.FogShape;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.math.Vector3f;
import kasuga.lib.core.annos.Inner;
import kasuga.lib.core.annos.Mandatory;
Expand All @@ -11,6 +13,7 @@
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.MenuAccess;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.renderer.FogRenderer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
Expand Down Expand Up @@ -61,6 +64,7 @@ public class FluidReg<E extends ForgeFlowingFluid> extends Reg {
boolean registerItem = false, registerBlock = false, registerMenu = false;
private final FluidTagReg tag;
private RenderType renderType = null;
private Vector3f fogColor = null;

/**
* Create a fluid registration.
Expand Down Expand Up @@ -448,6 +452,18 @@ public FluidReg<E> setTranslucentRenderType() {
return this;
}

@Optional
public FluidReg<E> fogColor(Vector3f fogColor) {
this.fogColor = fogColor;
return this;
}

@Optional
public FluidReg<E> fogColor(float r, float g, float b) {
this.fogColor = new Vector3f(r / 255f, g / 255f, b / 255f);
return this;
}

/**
* Customize your fluid's property.
* @param builder your fluid's property customizer lambda.
Expand Down Expand Up @@ -544,6 +560,7 @@ private FluidType initDefaultType(SimpleRegistry registry) {
ResourceLocation overlayLoc = overlayTexturePath == null ? null : new ResourceLocation(registry.namespace, overlayTexturePath);

FluidType type = new FluidType(properties) {

@Override
public void initializeClient(Consumer<IClientFluidTypeExtensions> consumer) {
consumer.accept(
Expand Down Expand Up @@ -573,6 +590,17 @@ public ResourceLocation getFlowingTexture() {
return overlayLoc;
return IClientFluidTypeExtensions.super.getOverlayTexture();
}

@Override
public @NotNull Vector3f modifyFogColor(Camera camera, float partialTick, ClientLevel level, int renderDistance, float darkenWorldAmount, Vector3f fluidFogColor) {
return fogColor;
}

@Override
public void modifyFogRender(Camera camera, FogRenderer.FogMode mode, float renderDistance, float partialTick, float nearDistance, float farDistance, FogShape shape) {
RenderSystem.setShaderFogStart(1f);
RenderSystem.setShaderFogEnd(6f);
}
}
);
}
Expand Down

0 comments on commit 0ed075a

Please sign in to comment.