use of slimeknights.mantle.client.model.fluid.FluidCuboid in project Ceramics by KnightMiner.
the class CisternTileEntityRenderer method render.
@Override
public void render(CisternTileEntity tileEntity, float partialTicks, MatrixStack matrices, IRenderTypeBuffer buffer, int light, int combinedOverlay) {
FluidStack fluid = tileEntity.getPublicHandler().orElse(EmptyFluidHandler.INSTANCE).getFluidInTank(0);
if (!fluid.isEmpty()) {
int renderIndex = tileEntity.getRenderIndex();
// capacity for gives us the minimum amount to start rendering in this segement
// render nothing beyond the base capacity
int amount = fluid.getAmount() - tileEntity.capacityFor(renderIndex);
if (amount > 0) {
// get the model pair, if the capacity is above the capacity per cistern, use the overfull model (no top face)
BlockState state = tileEntity.getBlockState();
CisternModel.BakedModel model = ModelHelper.getBakedModel(state, CisternModel.BakedModel.class);
if (model != null) {
// fetch textures and attributes
FluidAttributes attributes = fluid.getFluid().getAttributes();
TextureAtlasSprite still = FluidRenderer.getBlockSprite(attributes.getStillTexture(fluid));
TextureAtlasSprite flowing = FluidRenderer.getBlockSprite(attributes.getFlowingTexture(fluid));
IVertexBuilder builder = buffer.getBuffer(FluidRenderer.RENDER_TYPE);
int color = attributes.getColor(fluid);
light = FluidRenderer.withBlockLight(light, attributes.getLuminosity(fluid));
// if full, just render all full sides
int capacityPerLayer = tileEntity.capacityPerLayer();
if (amount > capacityPerLayer) {
for (Direction direction : Plane.HORIZONTAL) {
// state and model must contain that direction
FluidCuboid cuboid = model.getFluid(direction);
if (cuboid != null && state.get(CisternBlock.CONNECTIONS.get(direction))) {
FluidRenderer.renderCuboid(matrices, builder, cuboid, still, flowing, cuboid.getFromScaled(), cuboid.getToScaled(), color, light, false);
}
}
} else {
// determine the relevant height of the center
FluidCuboid center = model.getCenterFluid(state.get(CisternBlock.EXTENSION));
Vector3f from = center.getFromScaled();
Vector3f to = center.getToScaled().copy();
float minY = from.getY();
to.setY(minY + amount * (to.getY() - minY) / (float) capacityPerLayer);
// render the center using Mantle's logic
FluidRenderer.renderCuboid(matrices, builder, center, still, still, from, to, color, light, false);
// scale the sides based on the center
for (Direction direction : Plane.HORIZONTAL) {
// state and model must contain that direction
FluidCuboid cuboid = model.getFluid(direction);
if (cuboid != null && state.get(CisternBlock.CONNECTIONS.get(direction))) {
// bottom of the side must be smaller than the height to consider
Vector3f sFrom = cuboid.getFromScaled();
if (sFrom.getY() < to.getY()) {
// if the side end is larger than the center, clamp it down
Vector3f sTo = cuboid.getToScaled();
if (sTo.getY() > to.getY()) {
sTo = sTo.copy();
sTo.setY(to.getY());
}
FluidRenderer.renderCuboid(matrices, builder, cuboid, still, still, sFrom, sTo, color, light, false);
}
}
}
}
}
}
}
}
use of slimeknights.mantle.client.model.fluid.FluidCuboid in project Ceramics by KnightMiner.
the class ChannelTileEntityRenderer method render.
@Override
public void render(ChannelTileEntity te, float partialTicks, MatrixStack matrices, IRenderTypeBuffer buffer, int light, int combinedOverlayIn) {
FluidStack fluid = te.getFluid();
if (fluid.isEmpty()) {
return;
}
// fetch model properties
World world = te.getWorld();
if (world == null) {
return;
}
BlockPos pos = te.getPos();
BlockState state = te.getBlockState();
ChannelModel.BakedModel model = ModelHelper.getBakedModel(state, ChannelModel.BakedModel.class);
if (model == null) {
return;
}
// fluid attributes
FluidAttributes attributes = fluid.getFluid().getAttributes();
TextureAtlasSprite still = FluidRenderer.getBlockSprite(attributes.getStillTexture(fluid));
TextureAtlasSprite flowing = FluidRenderer.getBlockSprite(attributes.getFlowingTexture(fluid));
IVertexBuilder builder = buffer.getBuffer(FluidRenderer.RENDER_TYPE);
int color = attributes.getColor(fluid);
light = FluidRenderer.withBlockLight(light, attributes.getLuminosity(fluid));
// render sides first, while doing so we will determine center "flow"
FluidCuboid cube;
boolean isRotated;
Direction centerFlow = Direction.UP;
for (Direction direction : Plane.HORIZONTAL) {
// check if we have that side on the block
ChannelConnection connection = state.get(ChannelBlock.DIRECTION_MAP.get(direction));
if (connection.canFlow()) {
// apply rotation for the side
isRotated = RenderingHelper.applyRotation(matrices, direction);
// get the relevant fluid model, render it
if (te.isFlowing(direction)) {
cube = model.getSideFlow(connection == ChannelConnection.OUT);
// add to center direction
if (connection == ChannelConnection.OUT) {
// if unset (up), use this direction
if (centerFlow == Direction.UP) {
centerFlow = direction;
// if set and it disagrees, set the fail state (down)
} else if (centerFlow != direction) {
centerFlow = Direction.DOWN;
}
}
// render the extra edge against other blocks
if (!world.getBlockState(pos.offset(direction)).isIn(state.getBlock())) {
FluidRenderer.renderCuboid(matrices, builder, model.getSideEdge(), 0, still, flowing, color, light, false);
}
} else {
cube = model.getSideStill();
}
FluidRenderer.renderCuboid(matrices, builder, cube, 0, still, flowing, color, light, false);
// undo rotation
if (isRotated) {
matrices.pop();
}
}
}
// render center
isRotated = false;
if (centerFlow.getAxis().isVertical()) {
cube = model.getCenterFluid(false);
} else {
cube = model.getCenterFluid(true);
isRotated = RenderingHelper.applyRotation(matrices, centerFlow);
}
// render the cube and pop back
FluidRenderer.renderCuboid(matrices, builder, cube, 0, still, flowing, color, light, false);
if (isRotated) {
matrices.pop();
}
// render flow downwards
if (state.get(ChannelBlock.DOWN) && te.isFlowing(Direction.DOWN)) {
cube = model.getDownFluid();
FluidRenderer.renderCuboid(matrices, builder, cube, 0, still, flowing, color, light, false);
// render into the block(s) below
FaucetFluidLoader.renderFaucetFluids(world, pos, Direction.DOWN, matrices, builder, still, flowing, color, light);
}
}
use of slimeknights.mantle.client.model.fluid.FluidCuboid in project Ceramics by KnightMiner.
the class FaucetTileEntityRenderer method render.
@Override
public void render(FaucetTileEntity tileEntity, float partialTicks, MatrixStack matrices, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) {
FluidStack renderFluid = tileEntity.getRenderFluid();
if (!tileEntity.isPouring() || renderFluid.isEmpty()) {
return;
}
// safety
World world = tileEntity.getWorld();
if (world == null) {
return;
}
// fetch faucet model to determine where to render fluids
BlockState state = tileEntity.getBlockState();
FluidsModel.BakedModel model = ModelHelper.getBakedModel(state, FluidsModel.BakedModel.class);
if (model != null) {
// if side, rotate fluid model
Direction direction = state.get(FaucetBlock.FACING);
boolean isRotated = RenderingHelper.applyRotation(matrices, direction);
// fluid props
FluidAttributes attributes = renderFluid.getFluid().getAttributes();
int color = attributes.getColor(renderFluid);
Function<ResourceLocation, TextureAtlasSprite> spriteGetter = Minecraft.getInstance().getAtlasSpriteGetter(PlayerContainer.LOCATION_BLOCKS_TEXTURE);
TextureAtlasSprite still = spriteGetter.apply(attributes.getStillTexture(renderFluid));
TextureAtlasSprite flowing = spriteGetter.apply(attributes.getFlowingTexture(renderFluid));
boolean isGas = attributes.isGaseous(renderFluid);
combinedLightIn = FluidRenderer.withBlockLight(combinedLightIn, attributes.getLuminosity(renderFluid));
// render all cubes in the model
IVertexBuilder buffer = bufferIn.getBuffer(FluidRenderer.RENDER_TYPE);
for (FluidCuboid cube : model.getFluids()) {
FluidRenderer.renderCuboid(matrices, buffer, cube, 0, still, flowing, color, combinedLightIn, isGas);
}
// render into the block(s) below
FaucetFluidLoader.renderFaucetFluids(world, tileEntity.getPos(), direction, matrices, buffer, still, flowing, color, combinedLightIn);
// if rotated, pop back rotation
if (isRotated) {
matrices.pop();
}
}
}
Aggregations