diff --git a/src/main/java/growthcraft/milk/block/entity/MixingVatBlockEntity.java b/src/main/java/growthcraft/milk/block/entity/MixingVatBlockEntity.java index 45c2ed7..f08d136 100644 --- a/src/main/java/growthcraft/milk/block/entity/MixingVatBlockEntity.java +++ b/src/main/java/growthcraft/milk/block/entity/MixingVatBlockEntity.java @@ -50,7 +50,6 @@ import static growthcraft.cellar.block.CultureJarBlock.LIT; public class MixingVatBlockEntity extends BlockEntity implements BlockEntityTicker, MenuProvider { - //TODO[5]: Implement MixingVatBlockEntity private int tickClock = 0; private int tickMax = -1; private boolean activated = false; @@ -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; } diff --git a/src/main/java/growthcraft/milk/block/entity/renderer/MixingVatBlockEntityRenderer.java b/src/main/java/growthcraft/milk/block/entity/renderer/MixingVatBlockEntityRenderer.java index d3e6252..930fe5c 100644 --- a/src/main/java/growthcraft/milk/block/entity/renderer/MixingVatBlockEntityRenderer.java +++ b/src/main/java/growthcraft/milk/block/entity/renderer/MixingVatBlockEntityRenderer.java @@ -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 { + @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(); + + } } diff --git a/src/main/java/growthcraft/milk/init/client/GrowthcraftMilkBlockEntityRenderers.java b/src/main/java/growthcraft/milk/init/client/GrowthcraftMilkBlockEntityRenderers.java index 36da039..5ab76a6 100644 --- a/src/main/java/growthcraft/milk/init/client/GrowthcraftMilkBlockEntityRenderers.java +++ b/src/main/java/growthcraft/milk/init/client/GrowthcraftMilkBlockEntityRenderers.java @@ -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; @@ -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() {