-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from GrowthcraftCE/73-brew-kettle-recipe-missing
Fixed Misc Mixing Vat third person fluid renderering
- Loading branch information
Showing
3 changed files
with
127 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 124 additions & 2 deletions
126
src/main/java/growthcraft/milk/block/entity/renderer/MixingVatBlockEntityRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters