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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
|
package ihl.model;
/* This code with minimal changes was
* taken by me (Foghrye4) from
* RailCraft GitHub.
*/
/*
* Copyright (c) CovertJaguar, 2014 http://railcraft.info
*
* This code is the property of CovertJaguar
* and may only be used with explicit written
* permission unless otherwise specified on the
* license page at http://railcraft.info/wiki/info:license.
*/
import java.util.HashMap;
import java.util.Map;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.GLAllocation;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.init.Blocks;
import net.minecraft.util.IIcon;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
/**
*
* @author CovertJaguar <http://www.railcraft.info>
*/
@SideOnly(value=Side.CLIENT)
public class FluidRenderer {
private static RenderBlocks renderBlocks = new RenderBlocks();
private static final ResourceLocation BLOCK_TEXTURE = TextureMap.locationBlocksTexture;
private static final Map<Fluid, int[]> flowingRenderCache = new HashMap<Fluid, int[]>();
private static final Map<Fluid, int[]> stillRenderCache = new HashMap<Fluid, int[]>();
public static final int DISPLAY_STAGES = 100;
private static final RenderInfo liquidBlock = new RenderInfo();
static {
liquidBlock.texture = new IIcon[1];
}
public static IIcon getFluidTexture(FluidStack fluidStack, boolean flowing) {
if (fluidStack == null)
return ((TextureMap) Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture)).getAtlasSprite("missingno");
Fluid fluid = fluidStack.getFluid();
if (fluid == null)
return ((TextureMap) Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture)).getAtlasSprite("missingno");
IIcon icon = flowing ? fluid.getFlowingIcon() : fluid.getStillIcon();
if(icon==null)
{
icon = ((TextureMap) Minecraft.getMinecraft().getTextureManager().getTexture(TextureMap.locationBlocksTexture)).getAtlasSprite("missingno");
}
return icon;
}
public static ResourceLocation getFluidSheet(FluidStack liquid) {
return BLOCK_TEXTURE;
}
public static ResourceLocation setupFlowingLiquidTexture(FluidStack liquid, IIcon[] texArray) {
if (liquid == null || liquid.amount <= 0)
return null;
Fluid fluid = liquid.getFluid();
if (fluid == null)
return null;
IIcon top = fluid.getStillIcon();
IIcon side = fluid.getFlowingIcon();
texArray[0] = top;
texArray[1] = top;
texArray[2] = side;
texArray[3] = side;
texArray[4] = side;
texArray[5] = side;
return getFluidSheet(liquid);
}
public static int[] getLiquidDisplayLists(FluidStack fluidStack) {
return getLiquidDisplayLists(fluidStack, false);
}
public static int[] getLiquidDisplayLists(FluidStack fluidStack, boolean flowing) {
if (fluidStack == null)
return null;
Fluid fluid = fluidStack.getFluid();
if (fluid == null)
return null;
Map<Fluid, int[]> cache = flowing ? flowingRenderCache : stillRenderCache;
int[] diplayLists = cache.get(fluid);
if (diplayLists != null)
return diplayLists;
diplayLists = new int[DISPLAY_STAGES];
liquidBlock.texture[0] = null;
if (fluid.getBlock() != null) {
liquidBlock.template = fluid.getBlock();
liquidBlock.texture[0] = getFluidTexture(fluidStack, flowing);
} else {
liquidBlock.template = Blocks.water;
liquidBlock.texture[0] = getFluidTexture(fluidStack, flowing);
}
GL11.glDisable(GL11.GL_LIGHTING);
GL11.glDisable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_CULL_FACE);
for (int s = 0; s < DISPLAY_STAGES; ++s) {
diplayLists[s] = GLAllocation.generateDisplayLists(1);
GL11.glNewList(diplayLists[s], 4864 /*GL_COMPILE*/);
liquidBlock.minX = 0.01f;
liquidBlock.minY = 0;
liquidBlock.minZ = 0.01f;
liquidBlock.maxX = 0.99f;
liquidBlock.maxY = (float) s / (float) DISPLAY_STAGES;
liquidBlock.maxZ = 0.99f;
Tessellator tessellator = Tessellator.instance;
tessellator.startDrawingQuads();
RenderInfo info = liquidBlock;
renderBlocks.setRenderBounds(info.minX, info.minY, info.minZ, info.maxX, info.maxY, info.maxZ);
if (info.renderSide[0])
renderBlocks.renderFaceYNeg(info.template, 0D, 0D, 0D, info.getBlockTextureFromSide(0));
if (info.renderSide[1])
renderBlocks.renderFaceYPos(info.template, 0D, 0D, 0D, info.getBlockTextureFromSide(1));
if (info.renderSide[2])
renderBlocks.renderFaceZNeg(info.template, 0D, 0D, 0D, info.getBlockTextureFromSide(2));
if (info.renderSide[3])
renderBlocks.renderFaceZPos(info.template, 0D, 0D, 0D, info.getBlockTextureFromSide(3));
if (info.renderSide[4])
renderBlocks.renderFaceXNeg(info.template, 0D, 0D, 0D, info.getBlockTextureFromSide(4));
if (info.renderSide[5])
renderBlocks.renderFaceXPos(info.template, 0D, 0D, 0D, info.getBlockTextureFromSide(5));
tessellator.draw();
GL11.glEndList();
}
GL11.glColor4f(1, 1, 1, 1);
GL11.glEnable(GL11.GL_CULL_FACE);
GL11.glEnable(GL11.GL_BLEND);
cache.put(fluid, diplayLists);
return diplayLists;
}
}
|