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

286 lines
7.4 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>.
*/
package appeng.client.render;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.Minecraft;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockRenderLayer;
2015-06-16 02:44:59 +02:00
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
2015-06-16 02:44:59 +02:00
import net.minecraftforge.client.MinecraftForgeClient;
2015-12-24 02:07:03 +01:00
2014-08-27 07:57:37 +02:00
import appeng.api.parts.IFacadeContainer;
import appeng.api.parts.IFacadePart;
import appeng.api.parts.IPart;
2015-06-16 02:44:59 +02:00
import appeng.api.util.AEAxisAlignedBB;
import appeng.api.util.AEPartLocation;
import appeng.api.util.ModelGenerator;
import appeng.parts.BusCollisionHelper;
import appeng.parts.CableBusContainer;
public class CableRenderHelper
{
2015-01-01 22:13:10 +01:00
private static final CableRenderHelper INSTANCE = new CableRenderHelper();
public static CableRenderHelper getInstance()
{
2015-01-01 22:13:10 +01:00
return INSTANCE;
}
2015-09-30 14:24:40 +02:00
public void renderStatic( final CableBusContainer cableBusContainer, final IFacadeContainer iFacadeContainer )
{
2015-09-30 14:24:40 +02:00
final TileEntity te = cableBusContainer.getTile();
final ModelGenerator renderer = BusRenderer.INSTANCE.getRenderer();
if( renderer.getOverrideBlockTexture() != null )
2015-04-29 02:30:53 +02:00
{
2015-01-01 22:13:10 +01:00
BusRenderHelper.INSTANCE.setPass( 0 );
2015-04-29 02:30:53 +02:00
}
2015-06-16 02:44:59 +02:00
else
{
BusRenderHelper.INSTANCE.setPass( MinecraftForgeClient.getRenderLayer() == BlockRenderLayer.TRANSLUCENT ? 1 : 0 );
2015-06-16 02:44:59 +02:00
}
if( renderer.getBlockAccess() == null )
2015-04-29 02:30:53 +02:00
{
renderer.setBlockAccess( Minecraft.getMinecraft().theWorld );
2015-04-29 02:30:53 +02:00
}
2015-09-30 14:24:40 +02:00
for( final AEPartLocation s : AEPartLocation.values() )
{
2015-09-30 14:24:40 +02:00
final IPart part = cableBusContainer.getPart( s );
if( part != null )
{
2014-12-29 15:13:47 +01:00
this.setSide( s );
renderer.setRenderAllFaces( true );
2014-07-13 05:23:58 +02:00
// renderer.flipTexture = false;
renderer.setUvRotateBottom( 0 );
renderer.setUvRotateEast( 0 );
renderer.setUvRotateNorth( 0 );
renderer.setUvRotateSouth( 0 );
renderer.setUvRotateTop( 0 );
renderer.setUvRotateWest( 0 );
2015-06-16 02:44:59 +02:00
renderer.setOverrideBlockTexture( null );
2014-07-13 05:23:58 +02:00
2015-06-16 02:44:59 +02:00
part.renderStatic( te.getPos(), BusRenderHelper.INSTANCE, renderer );
// renderer.faces = EnumSet.allOf( EnumFacing.class );
// renderer.useTextures = true;
}
}
if( !iFacadeContainer.isEmpty() )
{
/**
* snag list of boxes...
*/
2015-09-30 14:24:40 +02:00
final List<AxisAlignedBB> boxes = new ArrayList<AxisAlignedBB>();
for( final AEPartLocation s : AEPartLocation.values() )
{
2015-09-30 14:24:40 +02:00
final IPart part = cableBusContainer.getPart( s );
if( part != null )
{
2014-12-29 15:13:47 +01:00
this.setSide( s );
2015-09-30 14:24:40 +02:00
final BusRenderHelper brh = BusRenderHelper.INSTANCE;
final BusCollisionHelper bch = new BusCollisionHelper( boxes, brh.getWorldX(), brh.getWorldY(), brh.getWorldZ(), null, true );
part.getBoxes( bch );
}
}
boolean useThinFacades = false;
2015-09-30 14:24:40 +02:00
final double min = 2.0 / 16.0;
final double max = 14.0 / 16.0;
2015-09-30 14:24:40 +02:00
for( final AxisAlignedBB bb : boxes )
{
int o = 0;
o += bb.maxX > max ? 1 : 0;
o += bb.maxY > max ? 1 : 0;
o += bb.maxZ > max ? 1 : 0;
o += bb.minX < min ? 1 : 0;
o += bb.minY < min ? 1 : 0;
o += bb.minZ < min ? 1 : 0;
if( o >= 2 )
2015-04-29 02:30:53 +02:00
{
useThinFacades = true;
2015-04-29 02:30:53 +02:00
}
}
2015-09-30 14:24:40 +02:00
for( final AEPartLocation s : AEPartLocation.SIDE_LOCATIONS )
{
2015-09-30 14:24:40 +02:00
final IFacadePart fPart = iFacadeContainer.getFacade( s );
if( fPart != null )
{
fPart.setThinFacades( useThinFacades );
2015-09-30 14:24:40 +02:00
final AxisAlignedBB pb = fPart.getPrimaryBox();
2015-09-30 14:22:21 +02:00
AEAxisAlignedBB b = null;
2015-09-30 14:24:40 +02:00
for( final AxisAlignedBB bb : boxes )
{
if( bb.intersectsWith( pb ) )
{
if( b == null )
2015-04-29 02:30:53 +02:00
{
2015-06-16 02:44:59 +02:00
b = AEAxisAlignedBB.fromBounds( bb );
2015-04-29 02:30:53 +02:00
}
else
{
b.maxX = Math.max( b.maxX, bb.maxX );
b.maxY = Math.max( b.maxY, bb.maxY );
b.maxZ = Math.max( b.maxZ, bb.maxZ );
b.minX = Math.min( b.minX, bb.minX );
b.minY = Math.min( b.minY, bb.minY );
b.minZ = Math.min( b.minZ, bb.minZ );
}
}
}
renderer.setFlipTexture( false );
renderer.setUvRotateBottom( 0 );
renderer.setUvRotateEast( 0 );
renderer.setUvRotateNorth( 0 );
renderer.setUvRotateSouth( 0 );
renderer.setUvRotateTop( 0 );
renderer.setUvRotateWest( 0 );
2015-06-16 02:44:59 +02:00
renderer.setOverrideBlockTexture( null );
2014-07-13 05:23:58 +02:00
2014-12-29 15:13:47 +01:00
this.setSide( s );
2015-06-16 02:44:59 +02:00
fPart.renderStatic( te.getPos(), BusRenderHelper.INSTANCE, renderer, iFacadeContainer, b == null ? null : b.getBoundingBox(), cableBusContainer.getPart( s ) == null );
}
}
// renderer.isFacade = false;
// renderer.enableAO = false;
2015-06-16 02:44:59 +02:00
// renderer.sett
}
}
2015-09-30 14:24:40 +02:00
private void setSide( final AEPartLocation s )
{
2015-09-30 14:24:40 +02:00
final EnumFacing ax;
final EnumFacing ay;
final EnumFacing az;
switch( s )
{
case DOWN:
2015-06-16 02:44:59 +02:00
ax = EnumFacing.EAST;
ay = EnumFacing.NORTH;
az = EnumFacing.DOWN;
break;
case UP:
2015-06-16 02:44:59 +02:00
ax = EnumFacing.EAST;
ay = EnumFacing.SOUTH;
az = EnumFacing.UP;
break;
case EAST:
2015-06-16 02:44:59 +02:00
ax = EnumFacing.SOUTH;
ay = EnumFacing.UP;
az = EnumFacing.EAST;
break;
case WEST:
2015-06-16 02:44:59 +02:00
ax = EnumFacing.NORTH;
ay = EnumFacing.UP;
az = EnumFacing.WEST;
break;
case NORTH:
2015-06-16 02:44:59 +02:00
ax = EnumFacing.WEST;
ay = EnumFacing.UP;
az = EnumFacing.NORTH;
break;
case SOUTH:
2015-06-16 02:44:59 +02:00
ax = EnumFacing.EAST;
ay = EnumFacing.UP;
az = EnumFacing.SOUTH;
break;
default:
2015-06-16 02:44:59 +02:00
ax = EnumFacing.EAST;
ay = EnumFacing.UP;
az = EnumFacing.SOUTH;
break;
}
BusRenderHelper.INSTANCE.setOrientation( ax, ay, az );
}
2015-09-30 14:24:40 +02:00
public void renderDynamic( final CableBusContainer cableBusContainer, final double x, final double y, final double z )
{
2015-09-30 14:24:40 +02:00
for( final EnumFacing s : EnumFacing.values() )
{
2015-09-30 14:24:40 +02:00
final IPart part = cableBusContainer.getPart( s );
if( part != null )
{
2015-09-30 14:24:40 +02:00
final EnumFacing ax;
final EnumFacing ay;
final EnumFacing az;
switch( s )
{
case DOWN:
2015-06-16 02:44:59 +02:00
ax = EnumFacing.EAST;
ay = EnumFacing.NORTH;
az = EnumFacing.DOWN;
break;
case UP:
2015-06-16 02:44:59 +02:00
ax = EnumFacing.EAST;
ay = EnumFacing.SOUTH;
az = EnumFacing.UP;
break;
case EAST:
2015-06-16 02:44:59 +02:00
ax = EnumFacing.SOUTH;
ay = EnumFacing.UP;
az = EnumFacing.EAST;
break;
case WEST:
2015-06-16 02:44:59 +02:00
ax = EnumFacing.NORTH;
ay = EnumFacing.UP;
az = EnumFacing.WEST;
break;
case NORTH:
2015-06-16 02:44:59 +02:00
ax = EnumFacing.WEST;
ay = EnumFacing.UP;
az = EnumFacing.NORTH;
break;
case SOUTH:
2015-06-16 02:44:59 +02:00
ax = EnumFacing.EAST;
ay = EnumFacing.UP;
az = EnumFacing.SOUTH;
break;
default:
2015-06-16 02:44:59 +02:00
ax = EnumFacing.EAST;
ay = EnumFacing.UP;
az = EnumFacing.SOUTH;
break;
}
2015-01-01 22:13:10 +01:00
BusRenderHelper.INSTANCE.setOrientation( ax, ay, az );
part.renderDynamic( x, y, z, BusRenderHelper.INSTANCE, BusRenderer.INSTANCE.getRenderer() );
}
}
}
}