/
FiredCrucibleRender.java
113 lines (96 loc) · 4.92 KB
/
FiredCrucibleRender.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package com.novamachina.exnihilosequentia.client.render;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import com.novamachina.exnihilosequentia.common.setup.ModTiles;
import com.novamachina.exnihilosequentia.common.tileentity.crucible.FiredCrucibleTile;
import com.novamachina.exnihilosequentia.common.utility.Color;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher;
import net.minecraft.fluid.Fluid;
import net.minecraft.inventory.container.PlayerContainer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.client.registry.ClientRegistry;
public class FiredCrucibleRender extends TileEntityRenderer<FiredCrucibleTile> {
public FiredCrucibleRender(TileEntityRendererDispatcher rendererDispatcher) {
super(rendererDispatcher);
}
public static void register() {
ClientRegistry
.bindTileEntityRenderer(ModTiles.CRUCIBLE_FIRED.get(), FiredCrucibleRender::new);
}
private void add(IVertexBuilder renderer, MatrixStack stack, float x, float y, float z, float u,
float v, Color color) {
renderer.pos(stack.getLast().getMatrix(), x, y, z)
.color(color.r, color.g, color.b, color.a)
.tex(u, v)
.lightmap(0, 240)
.normal(1, 0, 0)
.endVertex();
}
@Override
public void render(FiredCrucibleTile tileEntity, float partialTicks, MatrixStack matrixStack,
IRenderTypeBuffer buffer, int combinedLightIn, int combinedOverlayIn) {
ResourceLocation solidTexture = tileEntity.getSolidTexture();
Fluid fluid = tileEntity.getFluid();
ResourceLocation fluidTexture =
fluid != null ? fluid.getAttributes().getStillTexture() : null;
Color fluidColor =
fluid != null ? new Color(fluid.getAttributes().getColor()) : Color.INVALID_COLOR;
Color blockColor = getBlockColor(solidTexture, tileEntity);
if (fluidTexture != null) {
IVertexBuilder builder = buffer.getBuffer(RenderType.getTranslucent());
TextureAtlasSprite sprite = Minecraft.getInstance()
.getAtlasSpriteGetter(PlayerContainer.LOCATION_BLOCKS_TEXTURE).apply(
fluidTexture);
// Subtract 0.005 to prevent texture fighting
float fillAmount = (0.75f * tileEntity.getFluidProportion()) - 0.005f;
matrixStack.push();
matrixStack.translate(.5, .5, .5);
matrixStack.translate(-.5, -.5, -.5);
add(builder, matrixStack, 0, 0.25f + fillAmount, 1, sprite.getMinU(), sprite.getMaxV(),
fluidColor);
add(builder, matrixStack, 1, 0.25f + fillAmount, 1, sprite.getMaxU(), sprite.getMaxV(),
fluidColor);
add(builder, matrixStack, 1, 0.25f + fillAmount, 0, sprite.getMaxU(), sprite.getMinV(),
fluidColor);
add(builder, matrixStack, 0, 0.25f + fillAmount, 0, sprite.getMinU(), sprite.getMinV(),
fluidColor);
matrixStack.pop();
}
if (solidTexture != null) {
IVertexBuilder builder = buffer.getBuffer(RenderType.getSolid());
TextureAtlasSprite sprite = Minecraft.getInstance()
.getAtlasSpriteGetter(PlayerContainer.LOCATION_BLOCKS_TEXTURE).apply(
new ResourceLocation(solidTexture.getNamespace(),
"block/" + solidTexture.getPath()));
// Subtract 0.005 to prevent texture fighting
float fillAmount = (0.75f * tileEntity.getSolidProportion()) - 0.005f;
matrixStack.push();
matrixStack.translate(.5, .5, .5);
matrixStack.translate(-.5, -.5, -.5);
add(builder, matrixStack, 0, 0.25f + fillAmount, 1, sprite.getMinU(), sprite.getMaxV(),
blockColor);
add(builder, matrixStack, 1, 0.25f + fillAmount, 1, sprite.getMaxU(), sprite.getMaxV(),
blockColor);
add(builder, matrixStack, 1, 0.25f + fillAmount, 0, sprite.getMaxU(), sprite.getMinV(),
blockColor);
add(builder, matrixStack, 0, 0.25f + fillAmount, 0, sprite.getMinU(), sprite.getMinV(),
blockColor);
matrixStack.pop();
}
}
private Color getBlockColor(ResourceLocation solidTexture,
FiredCrucibleTile tileEntity) {
if (solidTexture != null) {
if (solidTexture.toString().contains("leaves")) {
return new Color(
tileEntity.getWorld().getBiome(tileEntity.getPos()).getFoliageColor());
}
}
return Color.WHITE;
}
}