-
Notifications
You must be signed in to change notification settings - Fork 776
/
SmelteryRender.java
172 lines (158 loc) · 7.29 KB
/
SmelteryRender.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
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package tconstruct.client.block;
import mantle.blocks.BlockUtils;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import tconstruct.blocks.logic.SmelteryLogic;
import tconstruct.client.TProxyClient;
import tconstruct.library.crafting.Smeltery;
import cpw.mods.fml.client.registry.ISimpleBlockRenderingHandler;
import cpw.mods.fml.client.registry.RenderingRegistry;
public class SmelteryRender implements ISimpleBlockRenderingHandler
{
public static int smelteryModel = RenderingRegistry.getNextAvailableRenderId();
@Override
public void renderInventoryBlock (Block block, int metadata, int modelID, RenderBlocks renderer)
{
if (modelID == smelteryModel)
{
TProxyClient.renderStandardInvBlock(renderer, block, metadata);
}
}
@Override
public boolean renderWorldBlock (IBlockAccess world, int x, int y, int z, Block block, int modelID, RenderBlocks renderer)
{
if (modelID == smelteryModel)
{
if (world.getBlockMetadata(x, y, z) == 0)
return renderSmeltery(world, x, y, z, block, modelID, renderer);
else
renderer.renderStandardBlock(block, x, y, z);
}
return true;
}
public boolean renderSmeltery (IBlockAccess world, int x, int y, int z, Block block, int modelID, RenderBlocks renderer)
{
renderer.renderStandardBlock(block, x, y, z);
SmelteryLogic logic = (SmelteryLogic) world.getTileEntity(x, y, z);
if (logic.validStructure)
{
int posX = logic.centerPos.x - 1, posY = logic.centerPos.y, posZ = logic.centerPos.z - 1;
// Melting
if (logic.getSizeInventory() > 0)
{
for (int i = 0; i < logic.layers; i++)
{
renderLayer(logic, i * 9, posX, posY + i, posZ, renderer, world);
}
}
// Liquids
float base = 0F;
int yBase = 0;
int liquidBase = 0;
for (FluidStack liquid : logic.moltenMetal)
{
int liquidSize = liquid.amount;
while (liquidSize > 0)
{
int room = 20000 - liquidBase;
int countSize = liquidSize > room ? room : liquidSize;
liquidSize -= countSize;
float height = countSize > 20000 ? 1.0F : countSize / 20000F;
// renderer.setRenderBounds(0, base, 0, 1, height + base,
// 1);
float renderBase = base;
float renderHeight = height + base;
base += height;
liquidBase += countSize;
Fluid fluid = liquid.getFluid();
for (int i = 0; i < 9; i++)
{
float minX = i % 3 == 0 ? -0.001F : 0F;
float minZ = i / 3 == 0 ? -0.001F : 0F;
float maxX = i % 3 == 2 ? 1.001F : 1F;
float maxZ = i / 3 == 2 ? 1.001F : 1F;
renderer.setRenderBounds(minX, renderBase, minZ, maxX, renderHeight, maxZ);
if (fluid.canBePlacedInWorld())
BlockSkinRenderHelper.renderMetadataBlock(fluid.getBlock(), 0, posX + i % 3, posY + yBase, posZ + i / 3, renderer, world);
else
BlockSkinRenderHelper.renderLiquidBlock(fluid.getStillIcon(), fluid.getFlowingIcon(), posX + i % 3, posY + yBase, posZ + i / 3, renderer, world);
}
/*
* if (liquid.itemID < 4096) //Block { Block liquidBlock =
* Block.blocksList[liquid.itemID]; for (int i = 0; i < 9;
* i++) { float minX = i % 3 == 0 ? -0.001F : 0F; float minZ
* = i / 3 == 0 ? -0.001F : 0F; float maxX = i % 3 == 2 ?
* 1.001F : 1F; float maxZ = i / 3 == 2 ? 1.001F : 1F;
* renderer.setRenderBounds(minX, renderBase, minZ, maxX,
* renderHeight, maxZ);
* BlockSkinRenderHelper.renderMetadataBlock(liquidBlock,
* liquid.itemMeta, posX + i % 3, posY + yBase, posZ + i /
* 3, renderer, world); } } else //Item { Item liquidItem =
* Item.itemsList[liquid.itemID]; for (int i = 0; i < 9;
* i++) { float minX = i % 3 == 0 ? -0.001F : 0F; float minZ
* = i / 3 == 0 ? -0.001F : 0F; float maxX = i % 3 == 2 ?
* 1.001F : 1F; float maxZ = i / 3 == 2 ? 1.001F : 1F;
* renderer.setRenderBounds(minX, renderBase, minZ, maxX,
* renderHeight, maxZ);
* BlockSkinRenderHelper.renderFakeBlock
* (liquidItem.getIconFromDamage(liquid.itemMeta), posX,
* posY + yBase, posZ, renderer, world); } }
*/
if (countSize == room)
{
base = 0F;
yBase++;
liquidBase = 0;
}
}
}
}
return true;
}
void renderLayer (SmelteryLogic logic, int start, int posX, int posY, int posZ, RenderBlocks renderer, IBlockAccess world)
{
renderer.setRenderBounds(-0.001F, -0.001F, -0.001F, 1.001F, 1.001F, 1.001F);
for (int i = 0; i < 9; i++)
{
ItemStack input = logic.getStackInSlot(i + start);
if (input != null && logic.getTempForSlot(i + start) > 20)
{
ItemStack blockToRender = Smeltery.getRenderIndex(input);
if (blockToRender != null)
{
float blockHeight = input.stackSize / (float) blockToRender.stackSize;
renderer.setRenderBounds(0.0F, 0.0F, 0.0F, 1.0F, MathHelper.clamp_float(blockHeight, 0.01F, 1.0F), 1.0F);
// TODO is this needed???
// if (blockToRender.itemID < 4096) //Block
// {
Block liquidBlock = BlockUtils.getBlockFromItemStack(blockToRender);
BlockSkinRenderHelper.renderMetadataBlock(liquidBlock, blockToRender.getItemDamage(), posX + i % 3, posY, posZ + i / 3, renderer, world);
// }
/*
* else //No items, only blocks //Item { Item liquidItem =
* Item.itemsList[blockToRender.itemID]; int metadata =
* blockToRender.getItemDamage();
* BlockSkinRenderHelper.renderFakeBlock
* (liquidItem.getIconFromDamage(metadata), posX + i % 3,
* posY, posZ + i / 3, renderer, world); }
*/
}
}
}
}
@Override
public boolean shouldRender3DInInventory (int modelID)
{
return true;
}
@Override
public int getRenderId ()
{
return smelteryModel;
}
}