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

187 lines
6.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>.
*/
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-12-29 21:59:05 +01:00
import appeng.block.misc.BlockPaint;
2014-06-01 03:50:56 +02:00
import appeng.client.render.BaseBlockRender;
2014-07-20 10:53:05 +02:00
import appeng.client.texture.ExtraBlockTextures;
2014-12-29 21:59:05 +01:00
import appeng.helpers.Splotch;
2014-07-20 10:53:05 +02:00
import appeng.tile.misc.TilePaint;
2014-06-01 03:50:56 +02:00
public class RenderBlockPaint extends BaseBlockRender<BlockPaint, TilePaint>
2014-06-01 03:50:56 +02:00
{
public RenderBlockPaint()
{
2014-06-01 03:50:56 +02:00
super( false, 0 );
}
@Override
public void renderInventory( final BlockPaint block, final ItemStack is, final RenderBlocks renderer, final ItemRenderType type, final Object[] obj )
2014-06-01 03:50:56 +02:00
{
2014-07-20 10:53:05 +02:00
2014-06-01 03:50:56 +02:00
}
@Override
public boolean renderInWorld( final BlockPaint imb, final IBlockAccess world, final int x, final int y, final int z, final RenderBlocks renderer )
2014-06-01 03:50:56 +02:00
{
final TilePaint tp = imb.getTileEntity( world, x, y, z );
2014-07-20 10:53:05 +02:00
boolean out = false;
if( tp != null )
2014-07-20 10:53:05 +02:00
{
// super.renderInWorld( imb, world, x, y, z, renderer );
final IIcon[] icoSet = { imb.getIcon( 0, 0 ), ExtraBlockTextures.BlockPaint2.getIcon(), ExtraBlockTextures.BlockPaint3.getIcon() };
2014-07-20 10:53:05 +02:00
final Tessellator tess = Tessellator.instance;
2014-07-20 10:53:05 +02:00
final int brightness = imb.getMixedBrightnessForBlock( world, x, y, z );
2014-07-20 10:53:05 +02:00
final EnumSet<ForgeDirection> validSides = EnumSet.noneOf( ForgeDirection.class );
for( final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS )
{
if( tp.isSideValid( side ) )
2015-04-29 02:30:53 +02:00
{
validSides.add( side );
2015-04-29 02:30:53 +02:00
}
}
2015-09-25 22:52:41 +02:00
double offsetConstant = 0.001;
final int lumen = 14 << 20 | 14 << 4;
for( final Splotch s : tp.getDots() )
2014-07-20 10:53:05 +02:00
{
if( !validSides.contains( s.getSide() ) )
2015-04-29 02:30:53 +02:00
{
continue;
2015-04-29 02:30:53 +02:00
}
if( s.isLumen() )
2014-07-20 10:53:05 +02:00
{
tess.setColorOpaque_I( s.getColor().whiteVariant );
2014-07-20 10:53:05 +02:00
tess.setBrightness( lumen );
}
else
{
tess.setColorOpaque_I( s.getColor().mediumVariant );
tess.setBrightness( brightness );
2014-07-20 10:53:05 +02:00
}
double offset = offsetConstant;
offsetConstant += 0.001;
2014-07-20 10:53:05 +02:00
final double buffer = 0.1;
2014-07-20 10:53:05 +02:00
double pos_x = s.x();
double pos_y = s.y();
pos_x = Math.max( buffer, Math.min( 1.0 - buffer, pos_x ) );
pos_y = Math.max( buffer, Math.min( 1.0 - buffer, pos_y ) );
2014-07-20 10:53:05 +02:00
if( s.getSide() == ForgeDirection.SOUTH || s.getSide() == ForgeDirection.NORTH )
2014-07-20 10:53:05 +02:00
{
pos_x += x;
pos_y += y;
}
else if( s.getSide() == ForgeDirection.UP || s.getSide() == ForgeDirection.DOWN )
2014-07-20 10:53:05 +02:00
{
pos_x += x;
pos_y += z;
}
else
{
pos_x += y;
pos_y += z;
}
final IIcon ico = icoSet[s.getSeed() % icoSet.length];
2014-07-20 10:53:05 +02:00
switch( s.getSide() )
2014-07-20 10:53:05 +02:00
{
case UP:
offset = 1.0 - offset;
tess.addVertexWithUV( pos_x - buffer, y + offset, pos_y - buffer, ico.getMinU(), ico.getMinV() );
tess.addVertexWithUV( pos_x + buffer, y + offset, pos_y - buffer, ico.getMaxU(), ico.getMinV() );
tess.addVertexWithUV( pos_x + buffer, y + offset, pos_y + buffer, ico.getMaxU(), ico.getMaxV() );
tess.addVertexWithUV( pos_x - buffer, y + offset, pos_y + buffer, ico.getMinU(), ico.getMaxV() );
break;
case DOWN:
tess.addVertexWithUV( pos_x + buffer, y + offset, pos_y - buffer, ico.getMinU(), ico.getMinV() );
tess.addVertexWithUV( pos_x - buffer, y + offset, pos_y - buffer, ico.getMaxU(), ico.getMinV() );
tess.addVertexWithUV( pos_x - buffer, y + offset, pos_y + buffer, ico.getMaxU(), ico.getMaxV() );
tess.addVertexWithUV( pos_x + buffer, y + offset, pos_y + buffer, ico.getMinU(), ico.getMaxV() );
break;
case EAST:
offset = 1.0 - offset;
tess.addVertexWithUV( x + offset, pos_x + buffer, pos_y - buffer, ico.getMinU(), ico.getMinV() );
tess.addVertexWithUV( x + offset, pos_x - buffer, pos_y - buffer, ico.getMaxU(), ico.getMinV() );
tess.addVertexWithUV( x + offset, pos_x - buffer, pos_y + buffer, ico.getMaxU(), ico.getMaxV() );
tess.addVertexWithUV( x + offset, pos_x + buffer, pos_y + buffer, ico.getMinU(), ico.getMaxV() );
break;
case WEST:
tess.addVertexWithUV( x + offset, pos_x - buffer, pos_y - buffer, ico.getMinU(), ico.getMinV() );
tess.addVertexWithUV( x + offset, pos_x + buffer, pos_y - buffer, ico.getMaxU(), ico.getMinV() );
tess.addVertexWithUV( x + offset, pos_x + buffer, pos_y + buffer, ico.getMaxU(), ico.getMaxV() );
tess.addVertexWithUV( x + offset, pos_x - buffer, pos_y + buffer, ico.getMinU(), ico.getMaxV() );
break;
case SOUTH:
offset = 1.0 - offset;
tess.addVertexWithUV( pos_x + buffer, pos_y - buffer, z + offset, ico.getMinU(), ico.getMinV() );
tess.addVertexWithUV( pos_x - buffer, pos_y - buffer, z + offset, ico.getMaxU(), ico.getMinV() );
tess.addVertexWithUV( pos_x - buffer, pos_y + buffer, z + offset, ico.getMaxU(), ico.getMaxV() );
tess.addVertexWithUV( pos_x + buffer, pos_y + buffer, z + offset, ico.getMinU(), ico.getMaxV() );
break;
case NORTH:
tess.addVertexWithUV( pos_x - buffer, pos_y - buffer, z + offset, ico.getMinU(), ico.getMinV() );
tess.addVertexWithUV( pos_x + buffer, pos_y - buffer, z + offset, ico.getMaxU(), ico.getMinV() );
tess.addVertexWithUV( pos_x + buffer, pos_y + buffer, z + offset, ico.getMaxU(), ico.getMaxV() );
tess.addVertexWithUV( pos_x - buffer, pos_y + buffer, z + offset, ico.getMinU(), ico.getMaxV() );
break;
default:
2014-07-20 10:53:05 +02:00
}
}
out = true;
}
2014-06-01 03:50:56 +02:00
return out;
}
}