Applied-Energistics-2-tiler.../src/main/java/appeng/client/render/blocks/RenderQuartzGlass.java

237 lines
8.3 KiB
Java
Raw Normal View History

2014-11-14 12:02:52 +01:00
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
2014-09-24 02:26:27 +02:00
package appeng.client.render.blocks;
2014-09-24 02:26:27 +02:00
import java.util.Random;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.item.ItemStack;
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.client.IItemRenderer.ItemRenderType;
import net.minecraftforge.common.util.ForgeDirection;
2014-12-29 21:59:05 +01:00
2014-09-24 02:26:27 +02:00
import appeng.api.AEApi;
import appeng.block.solids.BlockQuartzGlass;
2014-09-24 02:26:27 +02:00
import appeng.client.render.BaseBlockRender;
import appeng.client.texture.ExtraBlockTextures;
import appeng.client.texture.OffsetIcon;
import appeng.tile.AEBaseTile;
2014-09-24 02:26:27 +02:00
public class RenderQuartzGlass extends BaseBlockRender<BlockQuartzGlass, AEBaseTile>
2014-09-24 02:26:27 +02:00
{
static byte[][][] offsets;
2014-09-24 02:26:27 +02:00
public RenderQuartzGlass()
{
2014-09-24 02:26:27 +02:00
super( false, 0 );
if( offsets == null )
2014-09-24 02:26:27 +02:00
{
Random r = new Random( 924 );
offsets = new byte[10][10][10];
for( int x = 0; x < 10; x++ )
2015-04-29 02:30:53 +02:00
{
for( int y = 0; y < 10; y++ )
2015-04-29 02:30:53 +02:00
{
2014-09-24 02:26:27 +02:00
r.nextBytes( offsets[x][y] );
2015-04-29 02:30:53 +02:00
}
}
2014-09-24 02:26:27 +02:00
}
}
@Override
public void renderInventory( BlockQuartzGlass block, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj )
2014-09-24 02:26:27 +02:00
{
renderer.overrideBlockTexture = ExtraBlockTextures.GlassFrame.getIcon();
super.renderInventory( block, is, renderer, type, obj );
renderer.overrideBlockTexture = null;
super.renderInventory( block, is, renderer, type, obj );
}
@Override
public boolean renderInWorld( BlockQuartzGlass imb, IBlockAccess world, int x, int y, int z, RenderBlocks renderer )
2014-09-24 02:26:27 +02:00
{
renderer.setRenderBounds( 0, 0, 0, 1, 1, 1 );
int cx = Math.abs( x % 10 );
int cy = Math.abs( y % 10 );
int cz = Math.abs( z % 10 );
int u = offsets[cx][cy][cz] % 4;
int v = offsets[9 - cx][9 - cy][9 - cz] % 4;
switch( Math.abs( ( offsets[cx][cy][cz] + ( x + y + z ) ) % 4 ) )
2014-09-24 02:26:27 +02:00
{
case 0:
renderer.overrideBlockTexture = new OffsetIcon( imb.getIcon( 0, 0 ), u / 2, v / 2 );
break;
case 1:
renderer.overrideBlockTexture = new OffsetIcon( ExtraBlockTextures.BlockQuartzGlassB.getIcon(), u / 2, v / 2 );
break;
case 2:
renderer.overrideBlockTexture = new OffsetIcon( ExtraBlockTextures.BlockQuartzGlassC.getIcon(), u, v );
break;
case 3:
renderer.overrideBlockTexture = new OffsetIcon( ExtraBlockTextures.BlockQuartzGlassD.getIcon(), u, v );
break;
2014-09-24 02:26:27 +02:00
}
boolean result = renderer.renderStandardBlock( imb, x, y, z );
renderer.overrideBlockTexture = null;
2014-12-29 15:13:47 +01:00
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.UP, ForgeDirection.EAST );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.UP, ForgeDirection.WEST );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.UP, ForgeDirection.NORTH );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.UP, ForgeDirection.SOUTH );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.DOWN, ForgeDirection.EAST );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.DOWN, ForgeDirection.WEST );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.DOWN, ForgeDirection.NORTH );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.DOWN, ForgeDirection.SOUTH );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.EAST, ForgeDirection.UP );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.EAST, ForgeDirection.DOWN );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.EAST, ForgeDirection.NORTH );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.EAST, ForgeDirection.SOUTH );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.WEST, ForgeDirection.UP );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.WEST, ForgeDirection.DOWN );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.WEST, ForgeDirection.NORTH );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.WEST, ForgeDirection.SOUTH );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.NORTH, ForgeDirection.EAST );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.NORTH, ForgeDirection.WEST );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.NORTH, ForgeDirection.UP );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.NORTH, ForgeDirection.DOWN );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.SOUTH, ForgeDirection.EAST );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.SOUTH, ForgeDirection.WEST );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.SOUTH, ForgeDirection.UP );
this.renderEdge( imb, world, x, y, z, renderer, ForgeDirection.SOUTH, ForgeDirection.DOWN );
2014-09-24 02:26:27 +02:00
return result;
}
private void renderEdge( BlockQuartzGlass imb, IBlockAccess world, int x, int y, int z, RenderBlocks renderer, ForgeDirection side, ForgeDirection direction )
{
if( !this.isFlush( imb, world, x + side.offsetX, y + side.offsetY, z + side.offsetZ ) )
{
if( !this.isFlush( imb, world, x + direction.offsetX, y + direction.offsetY, z + direction.offsetZ ) )
{
float minX = 0.5f + ( side.offsetX + direction.offsetX ) / 2.0f;
float minY = 0.5f + ( side.offsetY + direction.offsetY ) / 2.0f;
float minZ = 0.5f + ( side.offsetZ + direction.offsetZ ) / 2.0f;
float maxX = 0.5f + ( side.offsetX + direction.offsetX ) / 2.0f;
float maxY = 0.5f + ( side.offsetY + direction.offsetY ) / 2.0f;
float maxZ = 0.5f + ( side.offsetZ + direction.offsetZ ) / 2.0f;
if( 0 == side.offsetX && 0 == direction.offsetX )
{
minX = 0.0f;
maxX = 1.0f;
}
if( 0 == side.offsetY && 0 == direction.offsetY )
{
minY = 0.0f;
maxY = 1.0f;
}
if( 0 == side.offsetZ && 0 == direction.offsetZ )
{
minZ = 0.0f;
maxZ = 1.0f;
}
if( maxX <= 0.001f )
2015-04-29 02:30:53 +02:00
{
maxX += 0.9f / 16.0f;
2015-04-29 02:30:53 +02:00
}
if( maxY <= 0.001f )
2015-04-29 02:30:53 +02:00
{
maxY += 0.9f / 16.0f;
2015-04-29 02:30:53 +02:00
}
if( maxZ <= 0.001f )
2015-04-29 02:30:53 +02:00
{
maxZ += 0.9f / 16.0f;
2015-04-29 02:30:53 +02:00
}
if( minX >= 0.999f )
2015-04-29 02:30:53 +02:00
{
minX -= 0.9f / 16.0f;
2015-04-29 02:30:53 +02:00
}
if( minY >= 0.999f )
2015-04-29 02:30:53 +02:00
{
minY -= 0.9f / 16.0f;
2015-04-29 02:30:53 +02:00
}
if( minZ >= 0.999f )
2015-04-29 02:30:53 +02:00
{
minZ -= 0.9f / 16.0f;
2015-04-29 02:30:53 +02:00
}
renderer.setRenderBounds( minX, minY, minZ, maxX, maxY, maxZ );
switch( side )
{
case WEST:
renderer.renderFaceXNeg( imb, x, y, z, ExtraBlockTextures.GlassFrame.getIcon() );
break;
case EAST:
renderer.renderFaceXPos( imb, x, y, z, ExtraBlockTextures.GlassFrame.getIcon() );
break;
case NORTH:
renderer.renderFaceZNeg( imb, x, y, z, ExtraBlockTextures.GlassFrame.getIcon() );
break;
case SOUTH:
renderer.renderFaceZPos( imb, x, y, z, ExtraBlockTextures.GlassFrame.getIcon() );
break;
case DOWN:
renderer.renderFaceYNeg( imb, x, y, z, ExtraBlockTextures.GlassFrame.getIcon() );
break;
case UP:
renderer.renderFaceYPos( imb, x, y, z, ExtraBlockTextures.GlassFrame.getIcon() );
break;
default:
break;
}
}
}
}
private boolean isFlush( BlockQuartzGlass imb, IBlockAccess world, int x, int y, int z )
{
return this.isGlass( imb, world, x, y, z );
}
private boolean isGlass( BlockQuartzGlass imb, IBlockAccess world, int x, int y, int z )
{
return this.isQuartzGlass( world, x, y, z ) || this.isVibrantQuartzGlass( world, x, y, z );
}
private boolean isQuartzGlass( IBlockAccess world, int x, int y, int z )
{
return AEApi.instance().definitions().blocks().quartzGlass().isSameAs( world, x, y, z );
}
private boolean isVibrantQuartzGlass( IBlockAccess world, int x, int y, int z )
{
return AEApi.instance().definitions().blocks().quartzVibrantGlass().isSameAs( world, x, y, z );
}
2014-09-24 02:26:27 +02:00
}