2013-12-27 23:59:59 +01:00
|
|
|
package appeng.client.render;
|
|
|
|
|
|
|
|
import java.util.EnumSet;
|
|
|
|
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.client.renderer.RenderBlocks;
|
|
|
|
import net.minecraft.client.renderer.Tessellator;
|
2014-02-09 02:34:52 +01:00
|
|
|
import net.minecraft.util.IIcon;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.AEApi;
|
2014-01-01 10:00:13 +01:00
|
|
|
import appeng.api.parts.IPart;
|
|
|
|
import appeng.api.parts.IPartCollsionHelper;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.api.parts.IPartRenderHelper;
|
2014-02-15 07:30:06 +01:00
|
|
|
import appeng.api.parts.ISimplifiedBundle;
|
2013-12-27 23:59:59 +01:00
|
|
|
import appeng.block.AEBaseBlock;
|
2014-05-05 02:51:05 +02:00
|
|
|
import appeng.core.AEConfig;
|
|
|
|
import appeng.core.features.AEFeature;
|
2014-02-07 06:51:19 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2013-12-27 23:59:59 +01:00
|
|
|
|
2014-02-07 06:51:19 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-12-27 23:59:59 +01:00
|
|
|
public class BusRenderHelper implements IPartRenderHelper
|
|
|
|
{
|
|
|
|
|
|
|
|
final public static BusRenderHelper instance = new BusRenderHelper();
|
|
|
|
|
|
|
|
double minX = 0;
|
|
|
|
double minY = 0;
|
|
|
|
double minZ = 0;
|
|
|
|
double maxX = 16;
|
|
|
|
double maxY = 16;
|
|
|
|
double maxZ = 16;
|
|
|
|
|
|
|
|
AEBaseBlock blk = (AEBaseBlock) AEApi.instance().blocks().blockMultiPart.block();
|
|
|
|
BaseBlockRender bbr = new BaseBlockRender();
|
|
|
|
|
|
|
|
public ForgeDirection ax;
|
|
|
|
public ForgeDirection ay;
|
|
|
|
public ForgeDirection az;
|
|
|
|
|
|
|
|
int color = 0xffffff;
|
|
|
|
|
2014-01-01 10:00:13 +01:00
|
|
|
class BoundBoxCalculator implements IPartCollsionHelper
|
|
|
|
{
|
|
|
|
|
|
|
|
public boolean started = false;
|
|
|
|
|
|
|
|
float minX;
|
|
|
|
float minY;
|
|
|
|
float minZ;
|
|
|
|
|
|
|
|
float maxX;
|
|
|
|
float maxY;
|
|
|
|
float maxZ;
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addBox(double minX, double minY, double minZ, double maxX, double maxY, double maxZ)
|
|
|
|
{
|
|
|
|
if ( started )
|
|
|
|
{
|
|
|
|
this.minX = Math.min( this.minX, (float) minX );
|
|
|
|
this.minY = Math.min( this.minY, (float) minY );
|
|
|
|
this.minZ = Math.min( this.minZ, (float) minZ );
|
|
|
|
this.maxX = Math.max( this.maxX, (float) maxX );
|
|
|
|
this.maxY = Math.max( this.maxY, (float) maxY );
|
|
|
|
this.maxZ = Math.max( this.maxZ, (float) maxZ );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
started = true;
|
|
|
|
this.minX = (float) minX;
|
|
|
|
this.minY = (float) minY;
|
|
|
|
this.minZ = (float) minZ;
|
|
|
|
this.maxX = (float) maxX;
|
|
|
|
this.maxY = (float) maxY;
|
|
|
|
this.maxZ = (float) maxZ;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ForgeDirection getWorldX()
|
|
|
|
{
|
|
|
|
return ax;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ForgeDirection getWorldY()
|
|
|
|
{
|
|
|
|
return ay;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ForgeDirection getWorldZ()
|
|
|
|
{
|
|
|
|
return az;
|
|
|
|
}
|
|
|
|
|
2014-01-31 18:11:50 +01:00
|
|
|
@Override
|
|
|
|
public boolean isBBCollision()
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-01 10:00:13 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
BoundBoxCalculator bbc = new BoundBoxCalculator();
|
|
|
|
|
2014-05-05 02:51:05 +02:00
|
|
|
int renderingForPass = 0;
|
|
|
|
int currentPass = 0;
|
|
|
|
int itemsRendered = 0;
|
|
|
|
boolean noAlphaPass = AEConfig.instance.isFeatureEnabled( AEFeature.AlphaPass ) == false;
|
|
|
|
|
|
|
|
public int getItemsRendered()
|
|
|
|
{
|
|
|
|
return itemsRendered;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setPass(int pass)
|
|
|
|
{
|
|
|
|
renderingForPass = 0;
|
|
|
|
currentPass = pass;
|
|
|
|
itemsRendered = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void renderForPass(int pass)
|
|
|
|
{
|
|
|
|
renderingForPass = pass;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean renderThis()
|
|
|
|
{
|
|
|
|
if ( renderingForPass == currentPass || noAlphaPass )
|
|
|
|
{
|
|
|
|
itemsRendered++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-01-01 10:00:13 +01:00
|
|
|
@Override
|
|
|
|
public void normalRendering()
|
|
|
|
{
|
|
|
|
RenderBlocksWorkaround rbw = BusRenderer.instance.renderer;
|
|
|
|
rbw.calculations = true;
|
|
|
|
rbw.useTextures = true;
|
|
|
|
rbw.enableAO = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-15 07:30:06 +01:00
|
|
|
public ISimplifiedBundle useSimpliedRendering(int x, int y, int z, IPart p, ISimplifiedBundle sim)
|
2014-01-01 10:00:13 +01:00
|
|
|
{
|
|
|
|
RenderBlocksWorkaround rbw = BusRenderer.instance.renderer;
|
|
|
|
|
2014-02-15 07:30:06 +01:00
|
|
|
if ( sim != null && rbw.similarLighting( blk, rbw.blockAccess, x, y, z, sim ) )
|
|
|
|
{
|
|
|
|
rbw.populate( sim );
|
|
|
|
rbw.faces = EnumSet.allOf( ForgeDirection.class );
|
|
|
|
rbw.calculations = false;
|
|
|
|
rbw.useTextures = false;
|
|
|
|
|
|
|
|
return sim;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rbw.calculations = true;
|
|
|
|
rbw.faces.clear();
|
|
|
|
|
|
|
|
bbc.started = false;
|
|
|
|
p.getBoxes( bbc );
|
2014-01-01 10:00:13 +01:00
|
|
|
|
2014-02-16 09:27:28 +01:00
|
|
|
if ( bbc.minX < 1 )
|
|
|
|
bbc.minX = 1;
|
|
|
|
if ( bbc.minY < 1 )
|
|
|
|
bbc.minY = 1;
|
|
|
|
if ( bbc.minZ < 1 )
|
|
|
|
bbc.minZ = 1;
|
|
|
|
|
|
|
|
if ( bbc.maxX > 15 )
|
|
|
|
bbc.maxX = 15;
|
|
|
|
if ( bbc.maxY > 15 )
|
|
|
|
bbc.maxY = 15;
|
|
|
|
if ( bbc.maxZ > 15 )
|
|
|
|
bbc.maxZ = 15;
|
|
|
|
|
2014-02-15 07:30:06 +01:00
|
|
|
setBounds( bbc.minX, bbc.minY, bbc.minZ, bbc.maxX, bbc.maxY, bbc.maxZ );
|
2014-01-01 10:00:13 +01:00
|
|
|
|
2014-02-15 07:30:06 +01:00
|
|
|
bbr.renderBlockBounds( rbw, minX, minY, minZ, maxX, maxY, maxZ, ax, ay, az );
|
|
|
|
rbw.renderStandardBlock( blk, x, y, z );
|
2014-01-01 10:00:13 +01:00
|
|
|
|
2014-02-15 07:30:06 +01:00
|
|
|
rbw.faces = EnumSet.allOf( ForgeDirection.class );
|
|
|
|
rbw.calculations = false;
|
|
|
|
rbw.useTextures = false;
|
|
|
|
|
|
|
|
return rbw.getLightingCache();
|
|
|
|
}
|
2014-01-01 10:00:13 +01:00
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
@Override
|
|
|
|
public void setBounds(float minx, float miny, float minz, float maxx, float maxy, float maxz)
|
|
|
|
{
|
|
|
|
minX = minx;
|
|
|
|
minY = miny;
|
|
|
|
minZ = minz;
|
|
|
|
maxX = maxx;
|
|
|
|
maxY = maxy;
|
|
|
|
maxZ = maxz;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setInvColor(int newColor)
|
|
|
|
{
|
|
|
|
color = newColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void setTexture(IIcon ico)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
blk.getRendererInstance().setTemporaryRenderIcon( ico );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void setTexture(IIcon Down, IIcon Up, IIcon North, IIcon South, IIcon West, IIcon East)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-02-09 02:34:52 +01:00
|
|
|
IIcon list[] = new IIcon[6];
|
2013-12-27 23:59:59 +01:00
|
|
|
|
|
|
|
list[0] = Down;
|
|
|
|
list[1] = Up;
|
|
|
|
list[2] = North;
|
|
|
|
list[3] = South;
|
|
|
|
list[4] = West;
|
|
|
|
list[5] = East;
|
|
|
|
|
2014-02-07 06:51:19 +01:00
|
|
|
blk.getRendererInstance().setTemporaryRenderIcons( list[mapRotation( ForgeDirection.UP ).ordinal()],
|
|
|
|
list[mapRotation( ForgeDirection.DOWN ).ordinal()], list[mapRotation( ForgeDirection.SOUTH ).ordinal()],
|
|
|
|
list[mapRotation( ForgeDirection.NORTH ).ordinal()], list[mapRotation( ForgeDirection.EAST ).ordinal()],
|
2013-12-27 23:59:59 +01:00
|
|
|
list[mapRotation( ForgeDirection.WEST ).ordinal()] );
|
|
|
|
}
|
|
|
|
|
|
|
|
public ForgeDirection mapRotation(ForgeDirection dir)
|
|
|
|
{
|
|
|
|
ForgeDirection forward = az;
|
|
|
|
ForgeDirection up = ay;
|
|
|
|
ForgeDirection west = ForgeDirection.UNKNOWN;
|
|
|
|
|
|
|
|
if ( forward == null || up == null )
|
|
|
|
return dir;
|
|
|
|
|
|
|
|
int west_x = forward.offsetY * up.offsetZ - forward.offsetZ * up.offsetY;
|
|
|
|
int west_y = forward.offsetZ * up.offsetX - forward.offsetX * up.offsetZ;
|
|
|
|
int west_z = forward.offsetX * up.offsetY - forward.offsetY * up.offsetX;
|
|
|
|
|
|
|
|
for (ForgeDirection dx : ForgeDirection.VALID_DIRECTIONS)
|
|
|
|
if ( dx.offsetX == west_x && dx.offsetY == west_y && dx.offsetZ == west_z )
|
|
|
|
west = dx;
|
|
|
|
|
|
|
|
if ( dir.equals( forward ) )
|
|
|
|
return ForgeDirection.SOUTH;
|
|
|
|
if ( dir.equals( forward.getOpposite() ) )
|
|
|
|
return ForgeDirection.NORTH;
|
|
|
|
|
|
|
|
if ( dir.equals( up ) )
|
|
|
|
return ForgeDirection.UP;
|
|
|
|
if ( dir.equals( up.getOpposite() ) )
|
|
|
|
return ForgeDirection.DOWN;
|
|
|
|
|
|
|
|
if ( dir.equals( west ) )
|
|
|
|
return ForgeDirection.WEST;
|
|
|
|
if ( dir.equals( west.getOpposite() ) )
|
|
|
|
return ForgeDirection.EAST;
|
|
|
|
|
|
|
|
return ForgeDirection.UNKNOWN;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void renderInventoryBox(RenderBlocks renderer)
|
|
|
|
{
|
|
|
|
renderer.setRenderBounds( minX / 16.0, minY / 16.0, minZ / 16.0, maxX / 16.0, maxY / 16.0, maxZ / 16.0 );
|
2014-03-01 04:45:30 +01:00
|
|
|
bbr.renderInvBlock( EnumSet.allOf( ForgeDirection.class ), blk, null, Tessellator.instance, color, renderer );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void renderInventoryFace(IIcon IIcon, ForgeDirection face, RenderBlocks renderer)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
|
|
|
renderer.setRenderBounds( minX / 16.0, minY / 16.0, minZ / 16.0, maxX / 16.0, maxY / 16.0, maxZ / 16.0 );
|
2014-02-09 02:34:52 +01:00
|
|
|
setTexture( IIcon );
|
2014-03-01 04:45:30 +01:00
|
|
|
bbr.renderInvBlock( EnumSet.of( face ), blk, null, Tessellator.instance, color, renderer );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void renderBlock(int x, int y, int z, RenderBlocks renderer)
|
|
|
|
{
|
2014-05-05 02:51:05 +02:00
|
|
|
if ( !renderThis() )
|
|
|
|
return;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
AEBaseBlock blk = (AEBaseBlock) AEApi.instance().blocks().blockMultiPart.block();
|
|
|
|
BlockRenderInfo info = blk.getRendererInstance();
|
|
|
|
ForgeDirection forward = BusRenderHelper.instance.az;
|
|
|
|
ForgeDirection up = BusRenderHelper.instance.ay;
|
|
|
|
|
|
|
|
renderer.uvRotateBottom = info.getTexture( ForgeDirection.DOWN ).setFlip( BaseBlockRender.getOrientation( ForgeDirection.DOWN, forward, up ) );
|
|
|
|
renderer.uvRotateTop = info.getTexture( ForgeDirection.UP ).setFlip( BaseBlockRender.getOrientation( ForgeDirection.UP, forward, up ) );
|
|
|
|
|
|
|
|
renderer.uvRotateEast = info.getTexture( ForgeDirection.EAST ).setFlip( BaseBlockRender.getOrientation( ForgeDirection.EAST, forward, up ) );
|
|
|
|
renderer.uvRotateWest = info.getTexture( ForgeDirection.WEST ).setFlip( BaseBlockRender.getOrientation( ForgeDirection.WEST, forward, up ) );
|
|
|
|
|
|
|
|
renderer.uvRotateNorth = info.getTexture( ForgeDirection.NORTH ).setFlip( BaseBlockRender.getOrientation( ForgeDirection.NORTH, forward, up ) );
|
|
|
|
renderer.uvRotateSouth = info.getTexture( ForgeDirection.SOUTH ).setFlip( BaseBlockRender.getOrientation( ForgeDirection.SOUTH, forward, up ) );
|
|
|
|
|
|
|
|
bbr.renderBlockBounds( renderer, minX, minY, minZ, maxX, maxY, maxZ, ax, ay, az );
|
|
|
|
|
2014-04-10 21:52:17 +02:00
|
|
|
renderer.renderStandardBlock( blk, x, y, z );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Block getBlock()
|
|
|
|
{
|
|
|
|
return AEApi.instance().blocks().blockMultiPart.block();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void prepareBounds(RenderBlocks renderer)
|
|
|
|
{
|
|
|
|
bbr.renderBlockBounds( renderer, minX, minY, minZ, maxX, maxY, maxZ, ax, ay, az );
|
|
|
|
}
|
|
|
|
|
2014-05-05 02:51:05 +02:00
|
|
|
@Override
|
|
|
|
public void setFacesToRender(EnumSet<ForgeDirection> faces)
|
|
|
|
{
|
|
|
|
BusRenderer.instance.renderer.faces = faces;
|
|
|
|
}
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
public void renderBlockCurrentBounds(int x, int y, int z, RenderBlocks renderer)
|
|
|
|
{
|
2014-05-05 02:51:05 +02:00
|
|
|
if ( !renderThis() )
|
|
|
|
return;
|
|
|
|
|
2014-05-10 20:27:48 +02:00
|
|
|
renderer.renderStandardBlock( blk, x, y, z );
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void renderFaceCutout(int x, int y, int z, IIcon ico, ForgeDirection face, float edgeThickness, RenderBlocks renderer)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-05-05 02:51:05 +02:00
|
|
|
if ( !renderThis() )
|
|
|
|
return;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
switch (face)
|
|
|
|
{
|
|
|
|
case DOWN:
|
|
|
|
face = ay.getOpposite();
|
|
|
|
break;
|
|
|
|
case EAST:
|
|
|
|
face = ax;
|
|
|
|
break;
|
|
|
|
case NORTH:
|
|
|
|
face = az.getOpposite();
|
|
|
|
break;
|
|
|
|
case SOUTH:
|
|
|
|
face = az;
|
|
|
|
break;
|
|
|
|
case UP:
|
|
|
|
face = ay;
|
|
|
|
break;
|
|
|
|
case WEST:
|
|
|
|
face = ax.getOpposite();
|
|
|
|
break;
|
|
|
|
case UNKNOWN:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bbr.renderCutoutFace( blk, ico, x, y, z, renderer, face, edgeThickness );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-09 02:34:52 +01:00
|
|
|
public void renderFace(int x, int y, int z, IIcon ico, ForgeDirection face, RenderBlocks renderer)
|
2013-12-27 23:59:59 +01:00
|
|
|
{
|
2014-05-05 02:51:05 +02:00
|
|
|
if ( !renderThis() )
|
|
|
|
return;
|
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
prepareBounds( renderer );
|
|
|
|
switch (face)
|
|
|
|
{
|
|
|
|
case DOWN:
|
|
|
|
face = ay.getOpposite();
|
|
|
|
break;
|
|
|
|
case EAST:
|
|
|
|
face = ax;
|
|
|
|
break;
|
|
|
|
case NORTH:
|
|
|
|
face = az.getOpposite();
|
|
|
|
break;
|
|
|
|
case SOUTH:
|
|
|
|
face = az;
|
|
|
|
break;
|
|
|
|
case UP:
|
|
|
|
face = ay;
|
|
|
|
break;
|
|
|
|
case WEST:
|
|
|
|
face = ax.getOpposite();
|
|
|
|
break;
|
|
|
|
case UNKNOWN:
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
bbr.renderFace( x, y, z, blk, ico, renderer, face );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ForgeDirection getWorldX()
|
|
|
|
{
|
|
|
|
return ax;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ForgeDirection getWorldY()
|
|
|
|
{
|
|
|
|
return ay;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ForgeDirection getWorldZ()
|
|
|
|
{
|
|
|
|
return az;
|
|
|
|
}
|
2014-01-01 10:00:13 +01:00
|
|
|
|
2013-12-27 23:59:59 +01:00
|
|
|
}
|