11package com .zixiken .dimdoors .client ;
22
33import java .nio .FloatBuffer ;
4+ import java .util .HashMap ;
5+ import java .util .Map ;
46import java .util .Random ;
57
68import com .zixiken .dimdoors .DimDoors ;
7- import com .zixiken .dimdoors .shared .blocks .BlockDimDoorBase ;
8- import com .zixiken .dimdoors .shared .tileentities .TileEntityVerticalEntranceRift ;
9+ import com .zixiken .dimdoors .shared .tileentities .TileEntityEntranceRift ;
910import com .zixiken .dimdoors .shared .util .RGBA ;
10- import net .minecraft .block .BlockDoor ;
11- import net .minecraft .block .state .IBlockState ;
1211import net .minecraft .client .renderer .*;
1312import net .minecraft .client .renderer .vertex .*;
1413import net .minecraft .util .EnumFacing ;
15- import net .minecraft .util .math .BlockPos ;
16- import net .minecraft .world .World ;
1714import org .lwjgl .opengl .GL11 ;
1815
1916import net .minecraft .client .Minecraft ;
2219
2320import static org .lwjgl .opengl .GL11 .*;
2421
25- public class TileEntityVerticalEntranceRiftRenderer extends TileEntitySpecialRenderer <TileEntityVerticalEntranceRift > {
22+ public class TileEntityEntranceRiftRenderer extends TileEntitySpecialRenderer <TileEntityEntranceRift > { // TODO: see TileEntityEndGatewayRenderer
2623
2724 private FloatBuffer buffer = GLAllocation .createDirectFloatBuffer (16 );
2825 private ResourceLocation warpPath = new ResourceLocation (DimDoors .MODID + ":textures/other/warp.png" );
2926 private ResourceLocation keyPath = new ResourceLocation (DimDoors .MODID + ":textures/other/keyhole.png" );
3027 private ResourceLocation keyholeLight = new ResourceLocation (DimDoors .MODID + ":textures/other/keyhole_light.png" );
28+ Map <TileEntityEntranceRift , RGBA []> colorMap = new HashMap <>();
3129
32- /**
33- * Renders the dimdoor.
34- */
35- public void renderDimDoorTileEntity (TileEntityVerticalEntranceRift tile , double x , double y , double z ) {
30+ // TODO: allow any angle, make static and in a separate class
31+ public void renderDimensionalWall (double x , double y , double z , RGBA [] colors , EnumFacing orientation , double extendUp , double extendDown , double extendLeft , double extendRight , double pushIn ) {
3632 GL11 .glDisable (GL11 .GL_LIGHTING );
37- Random rand = new Random (31100L );
38-
39- EnumFacing orientation = tile .orientation ;
40- IBlockState state = tile .getWorld ().getBlockState (tile .getPos ());
41- if (state .getBlock () instanceof BlockDoor && state .getValue (BlockDoor .HALF ) == BlockDoor .EnumDoorHalf .LOWER ) y += 1 ;
42- // TODO: option for non-doors in the TileEntityEntranceRift
4333
44- for (int count = 0 ; count < 16 ; ++ count ) {
34+ for (int pass = 0 ; pass < 16 ; pass ++ ) {
4535 GlStateManager .pushMatrix ();
4636
47- float var15 = 16 - count ;
37+ float var15 = 16 - pass ;
4838 float var16 = 0.2625F ;
4939 float var17 = 1.0F / (var15 + .80F );
5040
5141 bindTexture (warpPath );
5242 GlStateManager .enableBlend ();
5343
54- if (count == 0 ) {
44+ if (pass == 0 ) {
5545 var17 = 0.1F ;
5646 var15 = 25.0F ;
5747 var16 = 0.125F ;
5848
5949 GlStateManager .blendFunc (GL11 .GL_SRC_ALPHA , GL11 .GL_ONE_MINUS_SRC_ALPHA );
6050 }
6151
62- if (count == 1 ) {
63- var16 = .5F ;
64-
52+ if (pass == 1 ) {
53+ var16 = 0.5F ;
6554 GlStateManager .blendFunc (GL11 .GL_ONE , GL11 .GL_ONE );
6655 }
6756
@@ -74,6 +63,7 @@ public void renderDimDoorTileEntity(TileEntityVerticalEntranceRift tile, double
7463 GlStateManager .texGen (GlStateManager .TexGen .R , GL11 .GL_OBJECT_LINEAR );
7564 GlStateManager .texGen (GlStateManager .TexGen .Q , GL11 .GL_OBJECT_LINEAR );
7665
66+
7767 switch (orientation ) {
7868 case SOUTH :
7969 GlStateManager .texGen (GlStateManager .TexGen .S , GL11 .GL_OBJECT_PLANE , getFloatBuffer (0.0F , 1.0F , 0.0F , 0.0F ));
@@ -99,6 +89,14 @@ public void renderDimDoorTileEntity(TileEntityVerticalEntranceRift tile, double
9989 GlStateManager .texGen (GlStateManager .TexGen .R , GL11 .GL_OBJECT_PLANE , getFloatBuffer (0.0F , 0.0F , 0.0F , 1.0F ));
10090 GlStateManager .texGen (GlStateManager .TexGen .Q , GL11 .GL_OBJECT_PLANE , getFloatBuffer (1.0F , 0.0F , 0.0F , -0.15F ));
10191 break ;
92+ case DOWN :
93+ GlStateManager .texGen (GlStateManager .TexGen .S , GL11 .GL_OBJECT_PLANE , getFloatBuffer (1.0F , 0.0F , 0.0F , 0.0F ));
94+ GlStateManager .texGen (GlStateManager .TexGen .T , GL11 .GL_OBJECT_PLANE , getFloatBuffer (0.0F , 0.0F , 1.0F , 0.0F ));
95+ GlStateManager .texGen (GlStateManager .TexGen .R , GL11 .GL_OBJECT_PLANE , getFloatBuffer (0.0F , 0.0F , 0.0F , 1.0F ));
96+ GlStateManager .texGen (GlStateManager .TexGen .Q , GL11 .GL_EYE_PLANE , getFloatBuffer (0.0F , 1.0F , 0.0F , 0.0F ));
97+ break ;
98+ case UP :
99+ // TODO: logic for UP
102100 }
103101
104102 GlStateManager .enableTexGenCoord (GlStateManager .TexGen .S );
@@ -114,40 +112,44 @@ public void renderDimDoorTileEntity(TileEntityVerticalEntranceRift tile, double
114112 GlStateManager .translate (0.0F , Minecraft .getSystemTime () % 200000L / 200000.0F * var15 , 0.0F );
115113 GlStateManager .scale (var16 , var16 , var16 );
116114 GlStateManager .translate (0.5F , 0.5F , 0.5F );
117- GlStateManager .rotate ((count * count * 4321 + count * 9 ) * 2.0F , 0.0F , 0.0F , 1.0F );
115+ GlStateManager .rotate ((pass * pass * 4321 + pass * 9 ) * 2.0F , 0.0F , 0.0F , 1.0F );
118116 GlStateManager .translate (0.5F , 0.5F , 0.5F );
119117
120118 Tessellator tessellator = Tessellator .getInstance ();
121119 BufferBuilder worldRenderer = tessellator .getBuffer ();
122120 worldRenderer .begin (GL11 .GL_QUADS , DefaultVertexFormats .POSITION );
123121
124- RGBA color = tile . getEntranceRenderColor ( rand ); // TODO: cache this since it's constant
122+ RGBA color = colors [ pass ];
125123 GlStateManager .color (color .getRed () * var17 , color .getGreen () * var17 , color .getBlue () * var17 , color .getAlpha ());
126124
125+ // Offsets in horizontal vertical and depth directions
126+ double ohs = 0.5 - extendLeft ;
127+ double ohe = 0.5 + extendRight ;
128+ double ovs = 0.5 - extendDown ;
129+ double ove = 0.5 + extendUp ;
130+ // Render the rectangle based on the orientation
131+ double od = orientation == EnumFacing .NORTH || orientation == EnumFacing .WEST || orientation == EnumFacing .DOWN ? pushIn : 1 - pushIn ;
127132 switch (orientation ) {
133+ case NORTH :
128134 case SOUTH :
129- worldRenderer .pos (x , y - 1 , z + .99 ).endVertex ();
130- worldRenderer .pos (x + 1 , y - 1 , z + .99 ).endVertex ();
131- worldRenderer .pos (x + 1 , y + 1 , z + .99 ).endVertex ();
132- worldRenderer .pos (x , y + 1 , z + .99 ).endVertex ();
135+ worldRenderer .pos (x + ohs , y + ovs , z + od ).endVertex ();
136+ worldRenderer .pos (x + ohe , y + ovs , z + od ).endVertex ();
137+ worldRenderer .pos (x + ohe , y + ove , z + od ).endVertex ();
138+ worldRenderer .pos (x + ohs , y + ove , z + od ).endVertex ();
133139 break ;
134140 case WEST :
135- worldRenderer .pos (x + .01 , y - 1 , z ).endVertex ();
136- worldRenderer .pos (x + .01 , y - 1 , z + 1.0D ).endVertex ();
137- worldRenderer .pos (x + .01 , y + 1 , z + 1.0D ).endVertex ();
138- worldRenderer .pos (x + .01 , y + 1 , z ).endVertex ();
139- break ;
140- case NORTH :
141- worldRenderer .pos (x , y + 1 , z + .01 ).endVertex ();
142- worldRenderer .pos (x + 1 , y + 1 , z + .01 ).endVertex ();
143- worldRenderer .pos (x + 1 , y - 1 , z + .01 ).endVertex ();
144- worldRenderer .pos (x , y - 1 , z + .01 ).endVertex ();
145- break ;
146141 case EAST :
147- worldRenderer .pos (x + .99 , y + 1 , z ).endVertex ();
148- worldRenderer .pos (x + .99 , y + 1 , z + 1.0D ).endVertex ();
149- worldRenderer .pos (x + .99 , y - 1 , z + 1.0D ).endVertex ();
150- worldRenderer .pos (x + .99 , y - 1 , z ).endVertex ();
142+ worldRenderer .pos (x + od , y + ovs , z + ohs ).endVertex ();
143+ worldRenderer .pos (x + od , y + ove , z + ohs ).endVertex ();
144+ worldRenderer .pos (x + od , y + ove , z + ohe ).endVertex ();
145+ worldRenderer .pos (x + od , y + ovs , z + ohe ).endVertex ();
146+ break ;
147+ case UP :
148+ case DOWN :
149+ worldRenderer .pos (x + ovs , y + od , z + ohs ).endVertex ();
150+ worldRenderer .pos (x + ohe , y + od , z + ohs ).endVertex ();
151+ worldRenderer .pos (x + ohe , y + od , z + ohe ).endVertex ();
152+ worldRenderer .pos (x + ohs , y + od , z + ohe ).endVertex ();
151153 break ;
152154 }
153155
@@ -165,14 +167,23 @@ public void renderDimDoorTileEntity(TileEntityVerticalEntranceRift tile, double
165167 GlStateManager .enableLighting ();
166168 }
167169
170+ private RGBA [] getColors (TileEntityEntranceRift entrance ) {
171+ if (colorMap .containsKey (entrance )) return colorMap .get (entrance );
172+ Random rand = new Random (31100L );
173+ RGBA [] colors = new RGBA [16 ];
174+ for (int i = 0 ; i < 16 ; i ++) colors [i ] = entrance .getEntranceRenderColor (rand );
175+ colorMap .put (entrance , colors );
176+ return colors ;
177+ }
178+
168179 private FloatBuffer getFloatBuffer (float par1 , float par2 , float par3 , float par4 ) {
169180 buffer .clear ();
170181 buffer .put (par1 ).put (par2 ).put (par3 ).put (par4 );
171182 buffer .flip ();
172183 return buffer ;
173184 }
174185
175- private void renderKeyHole (TileEntityVerticalEntranceRift tile , double x , double y , double z , int i ) {
186+ private void renderKeyHole (TileEntityEntranceRift tile , double x , double y , double z , int i ) {
176187 EnumFacing rotation = EnumFacing .getHorizontal ((tile .orientation .getHorizontalIndex () + 3 ) % 4 );
177188
178189 GlStateManager .pushMatrix ();
@@ -238,17 +249,14 @@ private void renderKeyHole(TileEntityVerticalEntranceRift tile, double x, double
238249 }
239250
240251 @ Override
241- public void render (TileEntityVerticalEntranceRift te , double x , double y , double z , float partialTicks , int destroyStage , float alpha ) {
242- World world = te .getWorld ();
243- BlockPos pos = te .getPos ();
244- if (te .doorShouldRender ) {
245- renderDimDoorTileEntity (te , x , y , z );
246- if (te .lockStatus >= 1 ) {
247- for (int i = 0 ; i < 1 + te .lockStatus ; i ++) {
248- renderKeyHole (te , x , y , z , i );
252+ public void render (TileEntityEntranceRift entrance , double x , double y , double z , float partialTicks , int destroyStage , float alpha ) {
253+ if (entrance .shouldRender ) {
254+ renderDimensionalWall (x , y , z , getColors (entrance ), entrance .orientation , entrance .extendUp , entrance .extendDown , entrance .extendLeft , entrance .extendRight , entrance .pushIn );
255+ if (entrance .lockStatus >= 1 ) {
256+ for (int i = 0 ; i < 1 + entrance .lockStatus ; i ++) {
257+ renderKeyHole (entrance , x , y , z , i );
249258 }
250259 }
251-
252260 }
253261 }
254262}
0 commit comments