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

161 lines
5 KiB
Java
Raw Normal View History

2014-06-01 03:50:56 +02:00
package appeng.client.render.blocks;
import java.util.EnumSet;
2014-06-01 03:50:56 +02:00
import net.minecraft.client.renderer.RenderBlocks;
2014-07-20 10:53:05 +02:00
import net.minecraft.client.renderer.Tessellator;
2014-06-01 03:50:56 +02:00
import net.minecraft.item.ItemStack;
2014-07-20 10:53:05 +02:00
import net.minecraft.util.IIcon;
2014-06-01 03:50:56 +02:00
import net.minecraft.world.IBlockAccess;
import net.minecraftforge.client.IItemRenderer.ItemRenderType;
2014-07-20 10:53:05 +02:00
import net.minecraftforge.common.util.ForgeDirection;
2014-06-01 03:50:56 +02:00
import appeng.block.AEBaseBlock;
import appeng.client.render.BaseBlockRender;
2014-07-20 10:53:05 +02:00
import appeng.client.texture.ExtraBlockTextures;
import appeng.helpers.Splot;
import appeng.tile.misc.TilePaint;
2014-06-01 03:50:56 +02:00
public class RenderBlockPaint extends BaseBlockRender
{
public RenderBlockPaint() {
super( false, 0 );
}
@Override
public void renderInventory(AEBaseBlock block, ItemStack is, RenderBlocks renderer, ItemRenderType type, Object[] obj)
{
2014-07-20 10:53:05 +02:00
2014-06-01 03:50:56 +02:00
}
@Override
public boolean renderInWorld(AEBaseBlock imb, IBlockAccess world, int x, int y, int z, RenderBlocks renderer)
{
2014-07-20 10:53:05 +02:00
TilePaint tp = imb.getTileEntity( world, x, y, z );
boolean out = false;
if ( tp != null )
{
// super.renderInWorld( imb, world, x, y, z, renderer );
IIcon icoSet[] = new IIcon[] { imb.getIcon( 0, 0 ), ExtraBlockTextures.BlockPaint2.getIcon(), ExtraBlockTextures.BlockPaint3.getIcon() };
Tessellator tess = Tessellator.instance;
int lumen = 14 << 20 | 14 << 4;
int worldb = imb.getMixedBrightnessForBlock( world, x, y, z );
double offoff = 0.001;
EnumSet<ForgeDirection> validSides = EnumSet.noneOf( ForgeDirection.class );
for (ForgeDirection side : ForgeDirection.VALID_DIRECTIONS)
{
if ( tp.isSideValid( side ) )
validSides.add( side );
}
2014-07-20 10:53:05 +02:00
for (Splot s : tp.getDots())
{
if ( !validSides.contains( s.side ) )
continue;
2014-07-20 10:53:05 +02:00
if ( s.lumen )
{
tess.setColorOpaque_I( s.color.whiteVariant );
tess.setBrightness( lumen );
}
else
{
tess.setColorOpaque_I( s.color.mediumVariant );
tess.setBrightness( worldb );
}
double offset = offoff;
offoff += 0.001;
double H = 0.1;
double pos_x = s.x();
double pos_y = s.y();
pos_x = Math.max( H, Math.min( 1.0 - H, pos_x ) );
pos_y = Math.max( H, Math.min( 1.0 - H, pos_y ) );
if ( s.side == ForgeDirection.SOUTH || s.side == ForgeDirection.NORTH )
{
pos_x += x;
pos_y += y;
}
else if ( s.side == ForgeDirection.UP || s.side == ForgeDirection.DOWN )
{
pos_x += x;
pos_y += z;
}
else
{
pos_x += y;
pos_y += z;
}
IIcon ico = icoSet[s.getSeed() % icoSet.length];
switch (s.side)
{
case UP:
offset = 1.0 - offset;
tess.addVertexWithUV( pos_x - H, y + offset, pos_y - H, ico.getMinU(), ico.getMinV() );
tess.addVertexWithUV( pos_x + H, y + offset, pos_y - H, ico.getMaxU(), ico.getMinV() );
tess.addVertexWithUV( pos_x + H, y + offset, pos_y + H, ico.getMaxU(), ico.getMaxV() );
tess.addVertexWithUV( pos_x - H, y + offset, pos_y + H, ico.getMinU(), ico.getMaxV() );
break;
case DOWN:
tess.addVertexWithUV( pos_x + H, y + offset, pos_y - H, ico.getMinU(), ico.getMinV() );
tess.addVertexWithUV( pos_x - H, y + offset, pos_y - H, ico.getMaxU(), ico.getMinV() );
tess.addVertexWithUV( pos_x - H, y + offset, pos_y + H, ico.getMaxU(), ico.getMaxV() );
tess.addVertexWithUV( pos_x + H, y + offset, pos_y + H, ico.getMinU(), ico.getMaxV() );
break;
case EAST:
offset = 1.0 - offset;
tess.addVertexWithUV( x + offset, pos_x + H, pos_y - H, ico.getMinU(), ico.getMinV() );
tess.addVertexWithUV( x + offset, pos_x - H, pos_y - H, ico.getMaxU(), ico.getMinV() );
tess.addVertexWithUV( x + offset, pos_x - H, pos_y + H, ico.getMaxU(), ico.getMaxV() );
tess.addVertexWithUV( x + offset, pos_x + H, pos_y + H, ico.getMinU(), ico.getMaxV() );
break;
case WEST:
tess.addVertexWithUV( x + offset, pos_x - H, pos_y - H, ico.getMinU(), ico.getMinV() );
tess.addVertexWithUV( x + offset, pos_x + H, pos_y - H, ico.getMaxU(), ico.getMinV() );
tess.addVertexWithUV( x + offset, pos_x + H, pos_y + H, ico.getMaxU(), ico.getMaxV() );
tess.addVertexWithUV( x + offset, pos_x - H, pos_y + H, ico.getMinU(), ico.getMaxV() );
break;
case SOUTH:
offset = 1.0 - offset;
tess.addVertexWithUV( pos_x + H, pos_y - H, z + offset, ico.getMinU(), ico.getMinV() );
tess.addVertexWithUV( pos_x - H, pos_y - H, z + offset, ico.getMaxU(), ico.getMinV() );
tess.addVertexWithUV( pos_x - H, pos_y + H, z + offset, ico.getMaxU(), ico.getMaxV() );
tess.addVertexWithUV( pos_x + H, pos_y + H, z + offset, ico.getMinU(), ico.getMaxV() );
break;
case NORTH:
tess.addVertexWithUV( pos_x - H, pos_y - H, z + offset, ico.getMinU(), ico.getMinV() );
tess.addVertexWithUV( pos_x + H, pos_y - H, z + offset, ico.getMaxU(), ico.getMinV() );
tess.addVertexWithUV( pos_x + H, pos_y + H, z + offset, ico.getMaxU(), ico.getMaxV() );
tess.addVertexWithUV( pos_x - H, pos_y + H, z + offset, ico.getMinU(), ico.getMaxV() );
break;
default:
}
}
out = true;
}
2014-06-01 03:50:56 +02:00
return out;
}
}