Skip to content

Commit

Permalink
Merge pull request #78 from GrowthcraftCE/73-brew-kettle-recipe-missing
Browse files Browse the repository at this point in the history
Fixed Misc Mixing Vat third person fluid renderering
  • Loading branch information
Alatyami authored Jun 10, 2023
2 parents 0697b17 + 418150a commit b177814
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
import static growthcraft.cellar.block.CultureJarBlock.LIT;

public class MixingVatBlockEntity extends BlockEntity implements BlockEntityTicker<MixingVatBlockEntity>, MenuProvider {
//TODO[5]: Implement MixingVatBlockEntity
private int tickClock = 0;
private int tickMax = -1;
private boolean activated = false;
Expand Down Expand Up @@ -447,7 +446,7 @@ public FluidTank getFluidTank(String tankName) {
};
}

private FluidTank getFluidTank(int tankID) {
public FluidTank getFluidTank(int tankID) {
return tankID == 0 ? this.FLUID_TANK_INPUT : this.FLUID_TANK_OUTPUT;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,127 @@
package growthcraft.milk.block.entity.renderer;

public class MixingVatBlockEntityRenderer {
//TODO[5]: Implement MixingVatBlockEntityRenderer
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.mojang.math.Axis;
import growthcraft.milk.block.entity.MixingVatBlockEntity;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.client.extensions.common.IClientFluidTypeExtensions;
import net.minecraftforge.fluids.FluidStack;
import org.joml.Matrix3f;
import org.joml.Matrix4f;
import org.joml.Quaternionf;

import java.awt.*;

public class MixingVatBlockEntityRenderer implements BlockEntityRenderer<MixingVatBlockEntity> {
@Override
public boolean shouldRender(MixingVatBlockEntity blockEntity, Vec3 p_173569_) {
return true;
}

@Override
public boolean shouldRenderOffScreen(MixingVatBlockEntity blockEntity) {
return true;
}

@Override
public void render(MixingVatBlockEntity blockEntity, float partialTick, PoseStack poseStack, MultiBufferSource multiBufferSource, int light, int overlay) {

float baseOffset = 4.0F / 16F;
float maxFluidHeight = 14.0F / 16F;

if(!blockEntity.getFluidStackInTank(0).isEmpty()) {

FluidStack inputFluidStack = blockEntity.getFluidStackInTank(0);

float inputCapacity = blockEntity.getFluidTank(0).getCapacity();
float inputAmount = inputFluidStack.getAmount();
float inputFluidHeight = baseOffset + (maxFluidHeight - baseOffset) * inputAmount / inputCapacity;

renderFluidSingle(poseStack, multiBufferSource, inputFluidStack, 0.0F, inputFluidHeight, 0.0F, Axis.XP.rotationDegrees(90.0F), light, overlay);
}

if(!blockEntity.getFluidStackInTank(1).isEmpty()) {
FluidStack outputFluidStack = blockEntity.getFluidStackInTank(1);

float outputCapacity = blockEntity.getFluidTank(1).getCapacity();
float outputAmount = outputFluidStack.getAmount();
float outputFluidHeight = baseOffset + (maxFluidHeight - baseOffset) * outputAmount / outputCapacity;

renderFluidSingle(poseStack, multiBufferSource, outputFluidStack, 0.0F, outputFluidHeight, 0.0F, Axis.XP.rotationDegrees(90.0F), light, overlay);
}
}

public void renderFluidSingle(PoseStack poseStack, MultiBufferSource buffer, FluidStack fluidStack, float xOffset, float height, float zOffset, Quaternionf rotation, int lightLevel, int overlay) {
poseStack.pushPose();
poseStack.translate(0.5F, height, 0.5F);

float s = 15.0F / 256.0F;
float v = 1.55F / 8F;
float w = -(v) * 2.5F;

int alpha = 2 * 255;

poseStack.translate(w + xOffset, 0.0F, w + zOffset);
poseStack.mulPose(rotation);

poseStack.scale(s, s, s);

IClientFluidTypeExtensions fluidTypeExtensions = IClientFluidTypeExtensions.of(fluidStack.getFluid());
Color color = new Color(fluidTypeExtensions.getTintColor());

TextureAtlasSprite sprite = Minecraft.getInstance().getTextureAtlas(TextureAtlas.LOCATION_BLOCKS).apply(fluidTypeExtensions.getStillTexture(fluidStack));

VertexConsumer vertexBuilder = buffer.getBuffer(RenderType.translucent());

renderIcon(poseStack, vertexBuilder, sprite, color, alpha, overlay, lightLevel);

poseStack.popPose();
}

private static void renderIcon(PoseStack poseStack, VertexConsumer vertexBuilder, TextureAtlasSprite sprite, Color color, int alpha, int overlay, int light) {

int red = color.getRed();
int green = color.getGreen();
int blue = color.getBlue();

Matrix3f matrix3f = poseStack.last().normal();
Matrix4f matrix4f = poseStack.last().pose();

vertexBuilder.vertex(matrix4f, 1.0F, 15.0F, 0)
.color(red, green, blue, alpha)
.uv(sprite.getU0(), sprite.getV1())
.overlayCoords(overlay)
.uv2(light)
.normal(matrix3f, 0, 0, 1)
.endVertex();
vertexBuilder.vertex(matrix4f, 15.0F, 15.0F, 0)
.color(red, green, blue, alpha)
.uv(sprite.getU1(), sprite.getV1())
.overlayCoords(overlay)
.uv2(light)
.normal(matrix3f, 0, 0, 1)
.endVertex();
vertexBuilder.vertex(matrix4f, 15.0F, 1.0F, 0)
.color(red, green, blue, alpha)
.uv(sprite.getU1(), sprite.getV0())
.overlayCoords(overlay)
.uv2(light)
.normal(matrix3f, 0, 0, 1)
.endVertex();
vertexBuilder.vertex(matrix4f, 1.0F, 1.0F, 0)
.color(red, green, blue, alpha)
.uv(sprite.getU0(), sprite.getV0())
.overlayCoords(overlay)
.uv2(light)
.normal(matrix3f, 0, 0, 1)
.endVertex();

}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package growthcraft.milk.init.client;

import growthcraft.milk.block.entity.renderer.MixingVatBlockEntityRenderer;
import growthcraft.milk.block.entity.renderer.PancheonBlockEntityRenderer;
import growthcraft.milk.init.GrowthcraftMilkBlockEntities;
import net.minecraftforge.api.distmarker.Dist;
Expand All @@ -12,6 +13,7 @@ public class GrowthcraftMilkBlockEntityRenderers {
@SubscribeEvent
public static void register(EntityRenderersEvent.RegisterRenderers event) {
event.registerBlockEntityRenderer(GrowthcraftMilkBlockEntities.PANCHEON_BLOCK_ENTITY.get(), context -> new PancheonBlockEntityRenderer());
event.registerBlockEntityRenderer(GrowthcraftMilkBlockEntities.MIXING_VAT_BLOCK_ENTITY.get(), context -> new MixingVatBlockEntityRenderer());
}

private GrowthcraftMilkBlockEntityRenderers() {
Expand Down

0 comments on commit b177814

Please sign in to comment.