2014-05-14 04:42:14 +02:00
|
|
|
package appeng.client.render.blocks;
|
|
|
|
|
2014-05-15 16:34:38 +02:00
|
|
|
import java.util.EnumSet;
|
|
|
|
|
2014-05-14 04:42:14 +02:00
|
|
|
import net.minecraft.client.renderer.RenderBlocks;
|
2014-05-18 05:19:23 +02:00
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
2014-05-14 04:42:14 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2014-05-15 16:34:38 +02:00
|
|
|
import net.minecraft.util.IIcon;
|
2014-05-14 04:42:14 +02:00
|
|
|
import net.minecraft.world.IBlockAccess;
|
|
|
|
import net.minecraftforge.client.IItemRenderer.ItemRenderType;
|
2014-05-15 16:34:38 +02:00
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-07-10 07:44:01 +02:00
|
|
|
import appeng.api.AEApi;
|
2014-07-17 06:44:02 +02:00
|
|
|
import appeng.api.util.AEColor;
|
2014-05-14 04:42:14 +02:00
|
|
|
import appeng.block.AEBaseBlock;
|
2014-05-18 05:19:23 +02:00
|
|
|
import appeng.block.crafting.BlockCraftingMonitor;
|
2014-05-15 16:34:38 +02:00
|
|
|
import appeng.block.crafting.BlockCraftingUnit;
|
2014-05-14 04:42:14 +02:00
|
|
|
import appeng.client.render.BaseBlockRender;
|
2014-05-15 16:34:38 +02:00
|
|
|
import appeng.client.render.BusRenderHelper;
|
|
|
|
import appeng.client.render.BusRenderer;
|
2014-05-26 03:58:44 +02:00
|
|
|
import appeng.client.texture.ExtraBlockTextures;
|
2014-07-17 06:44:02 +02:00
|
|
|
import appeng.tile.crafting.TileCraftingMonitorTile;
|
2014-05-14 04:42:14 +02:00
|
|
|
import appeng.tile.crafting.TileCraftingTile;
|
|
|
|
|
2014-07-11 06:46:51 +02:00
|
|
|
public class RenderBlockCraftingCPU extends BaseBlockRender
|
2014-05-14 04:42:14 +02:00
|
|
|
{
|
|
|
|
|
2014-07-11 06:46:51 +02:00
|
|
|
protected RenderBlockCraftingCPU(boolean useTesr, int range) {
|
2014-05-18 05:19:23 +02:00
|
|
|
super( useTesr, range );
|
|
|
|
}
|
|
|
|
|
2014-07-11 06:46:51 +02:00
|
|
|
public RenderBlockCraftingCPU() {
|
2014-05-14 04:42:14 +02:00
|
|
|
super( false, 20 );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void renderInventory(AEBaseBlock blk, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj)
|
|
|
|
{
|
|
|
|
super.renderInventory( blk, is, renderer, type, obj );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-05-15 16:34:38 +02:00
|
|
|
public boolean renderInWorld(AEBaseBlock blk, IBlockAccess w, int x, int y, int z, RenderBlocks renderer)
|
2014-05-14 04:42:14 +02:00
|
|
|
{
|
2014-05-15 16:34:38 +02:00
|
|
|
IIcon theIcon = null;
|
|
|
|
boolean formed = false;
|
2014-05-18 05:19:23 +02:00
|
|
|
boolean emitsLight = false;
|
2014-05-15 16:34:38 +02:00
|
|
|
|
|
|
|
TileCraftingTile ct = blk.getTileEntity( w, x, y, z );
|
2014-05-14 04:42:14 +02:00
|
|
|
if ( ct != null && ct.isFormed() )
|
|
|
|
{
|
2014-05-18 05:19:23 +02:00
|
|
|
formed = true;
|
|
|
|
emitsLight = ct.isPowered();
|
2014-05-15 16:34:38 +02:00
|
|
|
}
|
2014-05-18 05:19:23 +02:00
|
|
|
int meta = w.getBlockMetadata( x, y, z ) & 3;
|
|
|
|
|
|
|
|
boolean isMonitor = blk.getClass() == BlockCraftingMonitor.class;
|
2014-07-10 07:44:01 +02:00
|
|
|
theIcon = blk.getIcon( ForgeDirection.SOUTH.ordinal(), meta | (formed ? 8 : 0) );
|
|
|
|
|
|
|
|
IIcon nonForward = theIcon;
|
2014-07-11 06:46:51 +02:00
|
|
|
if ( isMonitor )
|
2014-07-10 07:44:01 +02:00
|
|
|
nonForward = AEApi.instance().blocks().blockCraftingUnit.block().getIcon( 0, meta | (formed ? 8 : 0) );
|
2014-05-15 16:34:38 +02:00
|
|
|
|
2014-07-12 03:28:10 +02:00
|
|
|
if ( formed && renderer.overrideBlockTexture == null )
|
2014-05-15 16:34:38 +02:00
|
|
|
{
|
|
|
|
renderer = BusRenderer.instance.renderer;
|
|
|
|
BusRenderHelper i = BusRenderHelper.instance;
|
2014-07-11 06:46:51 +02:00
|
|
|
BusRenderer.instance.renderer.isFacade = true;
|
|
|
|
|
2014-05-15 16:34:38 +02:00
|
|
|
renderer.blockAccess = w;
|
|
|
|
i.setPass( 0 );
|
2014-07-02 07:05:46 +02:00
|
|
|
i.setOrientation( ForgeDirection.EAST, ForgeDirection.UP, ForgeDirection.SOUTH );
|
2014-05-15 16:34:38 +02:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
ct.lightCache = i.useSimpliedRendering( x, y, z, null, ct.lightCache );
|
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2014-07-11 06:46:51 +02:00
|
|
|
|
2014-05-15 16:34:38 +02:00
|
|
|
float highX = isConnected( w, x, y, z, ForgeDirection.EAST ) ? 16 : 13.01f;
|
|
|
|
float lowX = isConnected( w, x, y, z, ForgeDirection.WEST ) ? 0 : 2.99f;
|
|
|
|
|
|
|
|
float highY = isConnected( w, x, y, z, ForgeDirection.UP ) ? 16 : 13.01f;
|
|
|
|
float lowY = isConnected( w, x, y, z, ForgeDirection.DOWN ) ? 0 : 2.99f;
|
|
|
|
|
|
|
|
float highZ = isConnected( w, x, y, z, ForgeDirection.SOUTH ) ? 16 : 13.01f;
|
|
|
|
float lowZ = isConnected( w, x, y, z, ForgeDirection.NORTH ) ? 0 : 2.99f;
|
|
|
|
|
|
|
|
renderCorner( i, renderer, w, x, y, z, ForgeDirection.UP, ForgeDirection.EAST, ForgeDirection.NORTH );
|
|
|
|
renderCorner( i, renderer, w, x, y, z, ForgeDirection.UP, ForgeDirection.EAST, ForgeDirection.SOUTH );
|
|
|
|
renderCorner( i, renderer, w, x, y, z, ForgeDirection.UP, ForgeDirection.WEST, ForgeDirection.NORTH );
|
|
|
|
renderCorner( i, renderer, w, x, y, z, ForgeDirection.UP, ForgeDirection.WEST, ForgeDirection.SOUTH );
|
|
|
|
renderCorner( i, renderer, w, x, y, z, ForgeDirection.DOWN, ForgeDirection.EAST, ForgeDirection.NORTH );
|
|
|
|
renderCorner( i, renderer, w, x, y, z, ForgeDirection.DOWN, ForgeDirection.EAST, ForgeDirection.SOUTH );
|
|
|
|
renderCorner( i, renderer, w, x, y, z, ForgeDirection.DOWN, ForgeDirection.WEST, ForgeDirection.NORTH );
|
|
|
|
renderCorner( i, renderer, w, x, y, z, ForgeDirection.DOWN, ForgeDirection.WEST, ForgeDirection.SOUTH );
|
|
|
|
|
|
|
|
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
|
|
|
|
{
|
|
|
|
i.setBounds( fso( side, lowX, ForgeDirection.WEST ), fso( side, lowY, ForgeDirection.DOWN ), fso( side, lowZ, ForgeDirection.NORTH ),
|
|
|
|
fso( side, highX, ForgeDirection.EAST ), fso( side, highY, ForgeDirection.UP ), fso( side, highZ, ForgeDirection.SOUTH ) );
|
|
|
|
i.prepareBounds( renderer );
|
|
|
|
|
2014-07-11 06:46:51 +02:00
|
|
|
boolean LocalEmit = emitsLight;
|
|
|
|
if ( blk instanceof BlockCraftingMonitor && !ct.getForward().equals( side ) )
|
|
|
|
LocalEmit = false;
|
|
|
|
|
|
|
|
handleSide( blk, meta, x, y, z, i, renderer, ct.getForward().equals( side ) ? theIcon : nonForward, LocalEmit, isMonitor, side, w );
|
2014-05-15 16:34:38 +02:00
|
|
|
}
|
|
|
|
|
2014-07-11 06:46:51 +02:00
|
|
|
BusRenderer.instance.renderer.isFacade = false;
|
2014-05-15 16:34:38 +02:00
|
|
|
i.setFacesToRender( EnumSet.allOf( ForgeDirection.class ) );
|
|
|
|
i.normalRendering();
|
|
|
|
|
|
|
|
return true;
|
2014-05-14 04:42:14 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-05-15 16:34:38 +02:00
|
|
|
double a = 0.0 / 16.0;
|
|
|
|
double o = 16.0 / 16.0;
|
|
|
|
renderer.setRenderBounds( a, a, a, o, o, o );
|
2014-05-14 04:42:14 +02:00
|
|
|
boolean out = renderer.renderStandardBlock( blk, x, y, z );
|
|
|
|
|
|
|
|
return out;
|
|
|
|
}
|
|
|
|
}
|
2014-05-15 16:34:38 +02:00
|
|
|
|
|
|
|
private void renderCorner(BusRenderHelper i, RenderBlocks renderer, IBlockAccess w, int x, int y, int z, ForgeDirection up, ForgeDirection east,
|
|
|
|
ForgeDirection south)
|
|
|
|
{
|
|
|
|
if ( isConnected( w, x, y, z, up ) )
|
|
|
|
return;
|
|
|
|
if ( isConnected( w, x, y, z, east ) )
|
|
|
|
return;
|
|
|
|
if ( isConnected( w, x, y, z, south ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
i.setBounds( gso( east, 3, ForgeDirection.WEST ), gso( up, 3, ForgeDirection.DOWN ), gso( south, 3, ForgeDirection.NORTH ),
|
|
|
|
gso( east, 13, ForgeDirection.EAST ), gso( up, 13, ForgeDirection.UP ), gso( south, 13, ForgeDirection.SOUTH ) );
|
|
|
|
i.prepareBounds( renderer );
|
2014-05-26 03:58:44 +02:00
|
|
|
i.setTexture( ExtraBlockTextures.BlockCraftingUnitRing.getIcon() );
|
2014-05-15 16:34:38 +02:00
|
|
|
i.renderBlockCurrentBounds( x, y, z, renderer );
|
|
|
|
}
|
|
|
|
|
|
|
|
private float gso(ForgeDirection side, float def, ForgeDirection target)
|
|
|
|
{
|
|
|
|
if ( side != target )
|
|
|
|
{
|
|
|
|
if ( side.offsetX > 0 || side.offsetY > 0 || side.offsetZ > 0 )
|
|
|
|
return 16;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
|
|
|
private float fso(ForgeDirection side, float def, ForgeDirection target)
|
|
|
|
{
|
|
|
|
if ( side == target )
|
|
|
|
{
|
|
|
|
if ( side.offsetX > 0 || side.offsetY > 0 || side.offsetZ > 0 )
|
|
|
|
return 16;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return def;
|
|
|
|
}
|
|
|
|
|
2014-05-18 05:19:23 +02:00
|
|
|
private void handleSide(AEBaseBlock blk, int meta, int x, int y, int z, BusRenderHelper i, RenderBlocks renderer, IIcon color, boolean emitsLight,
|
|
|
|
boolean isMonitor, ForgeDirection side, IBlockAccess w)
|
2014-05-15 16:34:38 +02:00
|
|
|
{
|
|
|
|
if ( isConnected( w, x, y, z, side ) )
|
|
|
|
return;
|
|
|
|
|
|
|
|
i.setFacesToRender( EnumSet.of( side ) );
|
2014-05-18 05:19:23 +02:00
|
|
|
|
|
|
|
if ( meta == 0 && blk.getClass() == BlockCraftingUnit.class )
|
|
|
|
{
|
2014-05-26 03:58:44 +02:00
|
|
|
i.setTexture( ExtraBlockTextures.BlockCraftingUnitFit.getIcon() );
|
2014-05-18 05:19:23 +02:00
|
|
|
i.renderBlockCurrentBounds( x, y, z, renderer );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-17 06:44:02 +02:00
|
|
|
if ( color == ExtraBlockTextures.BlockCraftingMonitorFit_Light.getIcon() )
|
2014-05-26 03:58:44 +02:00
|
|
|
i.setTexture( ExtraBlockTextures.BlockCraftingMonitorOuter.getIcon() );
|
2014-05-18 05:19:23 +02:00
|
|
|
else
|
2014-05-26 03:58:44 +02:00
|
|
|
i.setTexture( ExtraBlockTextures.BlockCraftingFitSolid.getIcon() );
|
2014-05-18 05:19:23 +02:00
|
|
|
|
|
|
|
i.renderBlockCurrentBounds( x, y, z, renderer );
|
|
|
|
|
|
|
|
if ( color != null )
|
|
|
|
{
|
|
|
|
i.setTexture( color );
|
|
|
|
|
|
|
|
if ( !emitsLight )
|
|
|
|
{
|
2014-07-17 06:44:02 +02:00
|
|
|
if ( color == ExtraBlockTextures.BlockCraftingMonitorFit_Light.getIcon() )
|
|
|
|
{
|
|
|
|
int b = w.getLightBrightnessForSkyBlocks( x + side.offsetX, y + side.offsetY, z + side.offsetZ, 0 );
|
|
|
|
|
|
|
|
TileCraftingMonitorTile sr = blk.getTileEntity( w, x, y, z );
|
|
|
|
AEColor col = sr.getColor();
|
|
|
|
|
|
|
|
Tessellator.instance.setBrightness( b );
|
|
|
|
Tessellator.instance.setColorOpaque_I( col.whiteVariant );
|
|
|
|
i.renderFace( x, y, z, color, side, renderer );
|
|
|
|
|
|
|
|
Tessellator.instance.setColorOpaque_I( col.mediumVariant );
|
|
|
|
i.renderFace( x, y, z, ExtraBlockTextures.BlockCraftingMonitorFit_Medium.getIcon(), side, renderer );
|
|
|
|
|
|
|
|
Tessellator.instance.setColorOpaque_I( col.blackVariant );
|
|
|
|
i.renderFace( x, y, z, ExtraBlockTextures.BlockCraftingMonitorFit_Dark.getIcon(), side, renderer );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
i.renderBlockCurrentBounds( x, y, z, renderer );
|
2014-05-18 05:19:23 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-07-17 06:44:02 +02:00
|
|
|
if ( isMonitor )
|
|
|
|
{
|
|
|
|
TileCraftingMonitorTile sr = blk.getTileEntity( w, x, y, z );
|
|
|
|
AEColor col = sr.getColor();
|
|
|
|
|
|
|
|
Tessellator.instance.setColorOpaque_I( col.whiteVariant );
|
|
|
|
Tessellator.instance.setBrightness( 13 << 20 | 13 << 4 );
|
|
|
|
i.renderFace( x, y, z, color, side, renderer );
|
|
|
|
|
|
|
|
Tessellator.instance.setColorOpaque_I( col.mediumVariant );
|
|
|
|
Tessellator.instance.setBrightness( 13 << 20 | 13 << 4 );
|
|
|
|
i.renderFace( x, y, z, ExtraBlockTextures.BlockCraftingMonitorFit_Medium.getIcon(), side, renderer );
|
|
|
|
|
|
|
|
Tessellator.instance.setColorOpaque_I( col.blackVariant );
|
|
|
|
Tessellator.instance.setBrightness( 13 << 20 | 13 << 4 );
|
|
|
|
i.renderFace( x, y, z, ExtraBlockTextures.BlockCraftingMonitorFit_Dark.getIcon(), side, renderer );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Tessellator.instance.setColorOpaque_F( 1.0f, 1.0f, 1.0f );
|
|
|
|
Tessellator.instance.setBrightness( 13 << 20 | 13 << 4 );
|
|
|
|
i.renderFace( x, y, z, color, side, renderer );
|
|
|
|
}
|
2014-05-18 05:19:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2014-05-15 16:34:38 +02:00
|
|
|
|
|
|
|
for (ForgeDirection a : ForgeDirection.VALID_DIRECTIONS)
|
|
|
|
{
|
|
|
|
if ( a == side || a == side.getOpposite() )
|
|
|
|
continue;
|
|
|
|
|
2014-07-11 06:46:51 +02:00
|
|
|
if ( (side.offsetX != 0 || side.offsetZ != 0)
|
|
|
|
&& (a == ForgeDirection.NORTH || a == ForgeDirection.EAST || a == ForgeDirection.WEST || a == ForgeDirection.SOUTH) )
|
|
|
|
i.setTexture( ExtraBlockTextures.BlockCraftingUnitRingLongRotated.getIcon() );
|
|
|
|
else if ( (side.offsetY != 0) && (a == ForgeDirection.EAST || a == ForgeDirection.WEST) )
|
|
|
|
i.setTexture( ExtraBlockTextures.BlockCraftingUnitRingLongRotated.getIcon() );
|
|
|
|
else
|
|
|
|
i.setTexture( ExtraBlockTextures.BlockCraftingUnitRingLong.getIcon() );
|
|
|
|
|
2014-05-15 16:34:38 +02:00
|
|
|
double width = 3.0 / 16.0;
|
|
|
|
|
|
|
|
if ( !(i.getBound( a ) < 0.001 || i.getBound( a ) > 15.999) )
|
|
|
|
{
|
|
|
|
switch (a)
|
|
|
|
{
|
|
|
|
case DOWN:
|
|
|
|
renderer.renderMinY = 0;
|
|
|
|
renderer.renderMaxY = width;
|
|
|
|
break;
|
|
|
|
case EAST:
|
|
|
|
renderer.renderMaxX = 1;
|
|
|
|
renderer.renderMinX = 1.0 - width;
|
|
|
|
renderer.uvRotateTop = 1;
|
|
|
|
renderer.uvRotateBottom = 1;
|
|
|
|
renderer.uvRotateWest = 1;
|
|
|
|
renderer.uvRotateEast = 1;
|
|
|
|
break;
|
|
|
|
case NORTH:
|
|
|
|
renderer.renderMinZ = 0;
|
|
|
|
renderer.renderMaxZ = width;
|
|
|
|
renderer.uvRotateWest = 1;
|
|
|
|
renderer.uvRotateNorth = 1;
|
|
|
|
renderer.uvRotateSouth = 1;
|
|
|
|
break;
|
|
|
|
case SOUTH:
|
|
|
|
renderer.renderMaxZ = 1;
|
|
|
|
renderer.renderMinZ = 1.0 - width;
|
|
|
|
renderer.uvRotateNorth = 1;
|
|
|
|
renderer.uvRotateSouth = 1;
|
|
|
|
break;
|
|
|
|
case UP:
|
|
|
|
renderer.renderMaxY = 1;
|
|
|
|
renderer.renderMinY = 1.0 - width;
|
|
|
|
break;
|
|
|
|
case WEST:
|
|
|
|
renderer.renderMinX = 0;
|
|
|
|
renderer.renderMaxX = width;
|
|
|
|
renderer.uvRotateTop = 1;
|
|
|
|
renderer.uvRotateBottom = 1;
|
|
|
|
renderer.uvRotateWest = 1;
|
|
|
|
renderer.uvRotateEast = 1;
|
|
|
|
break;
|
|
|
|
case UNKNOWN:
|
|
|
|
default:
|
|
|
|
}
|
|
|
|
|
|
|
|
i.renderBlockCurrentBounds( x, y, z, renderer );
|
|
|
|
i.prepareBounds( renderer );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private boolean isConnected(IBlockAccess w, int x, int y, int z, ForgeDirection side)
|
|
|
|
{
|
|
|
|
return w.getTileEntity( x + side.offsetX, y + side.offsetY, z + side.offsetZ ) instanceof TileCraftingTile;
|
|
|
|
}
|
2014-05-14 04:42:14 +02:00
|
|
|
}
|