Skip to content

Commit

Permalink
Fix sky stone tank rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
nk2IsHere committed Jan 17, 2025
1 parent 3b10d15 commit 15b08cc
Showing 1 changed file with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;

import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.renderer.v1.Renderer;
import net.fabricmc.fabric.api.renderer.v1.RendererAccess;
import net.fabricmc.fabric.api.renderer.v1.mesh.MutableQuadView;
Expand All @@ -36,12 +38,12 @@
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.util.Mth;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;

import appeng.blockentity.storage.SkyStoneTankBlockEntity;

@Environment(EnvType.CLIENT)
public final class SkyStoneTankBlockEntityRenderer implements BlockEntityRenderer<SkyStoneTankBlockEntity> {

public SkyStoneTankBlockEntityRenderer(BlockEntityRendererProvider.Context context) {
Expand Down Expand Up @@ -80,37 +82,32 @@ public static void drawFluidInTank(Level level, BlockPos pos, PoseStack ps, Mult

int color = FluidVariantRendering.getColor(fluid, level, pos);

float a = ((color >> 24) & 255) / 256f;
float r = ((color >> 16) & 255) / 256f;
float g = ((color >> 8) & 255) / 256f;
float b = (color & 255) / 256f;
float a = ((color >> 24) & 255) / 256f;

var fillY = Mth.lerp(Mth.clamp(fill, 0, 1), TANK_W, 1 - TANK_W);
fill = TANK_W + (1 - 2 * TANK_W) * Math.min(1, Math.max(fill, 0));

// Top and bottom positions of the fluid inside the tank
float topHeight = fillY;
float topHeight = fill;
float bottomHeight = TANK_W;

// Render gas from top to bottom
if (FluidVariantAttributes.isLighterThanAir(fluid)) {
topHeight = 1 - TANK_W;
bottomHeight = 1 - fillY;
bottomHeight = 1 - fill;
}

Renderer renderer = RendererAccess.INSTANCE.getRenderer();
for (Direction direction : Direction.values()) {
QuadEmitter emitter = renderer.meshBuilder().getEmitter();

var x1 = TANK_W * 16;
var z1 = TANK_W * 16;
var x2 = (1 - TANK_W) * 16;
var z2 = (1 - TANK_W) * 16;
var y1 = bottomHeight * 16;
var y2 = topHeight * 16;
if (direction.getAxis().isVertical()) {
emitter.square(direction, x1, z1, x2, z2, direction == Direction.UP ? 1 - y2 : y1);
emitter.square(direction, TANK_W, TANK_W, 1 - TANK_W, 1 - TANK_W,
direction == Direction.UP ? 1 - topHeight : bottomHeight);
} else {
emitter.square(direction, x1, bottomHeight, x2, topHeight, z1);
emitter.square(direction, TANK_W, bottomHeight, 1 - TANK_W, topHeight, TANK_W);
}

emitter.spriteBake(sprite, MutableQuadView.BAKE_LOCK_UV);
Expand Down

0 comments on commit 15b08cc

Please sign in to comment.