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;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-07-21 05:45:08 +02:00
|
|
|
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
|
|
|
|
2015-05-09 12:18:43 +02: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
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2015-05-09 12:18:43 +02:00
|
|
|
public class RenderBlockPaint extends BaseBlockRender<BlockPaint, TilePaint>
|
2014-06-01 03:50:56 +02:00
|
|
|
{
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
public RenderBlockPaint()
|
|
|
|
{
|
2014-06-01 03:50:56 +02:00
|
|
|
super( false, 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-09-25 23:10:56 +02:00
|
|
|
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
|
2015-09-25 23:10:56 +02:00
|
|
|
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
|
|
|
{
|
2015-09-25 23:10:56 +02:00
|
|
|
final TilePaint tp = imb.getTileEntity( world, x, y, z );
|
2014-07-20 10:53:05 +02:00
|
|
|
boolean out = false;
|
2015-04-03 08:54:31 +02:00
|
|
|
if( tp != null )
|
2014-07-20 10:53:05 +02:00
|
|
|
{
|
|
|
|
// super.renderInWorld( imb, world, x, y, z, renderer );
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final IIcon[] icoSet = { imb.getIcon( 0, 0 ), ExtraBlockTextures.BlockPaint2.getIcon(), ExtraBlockTextures.BlockPaint3.getIcon() };
|
2014-07-20 10:53:05 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final Tessellator tess = Tessellator.instance;
|
2014-07-20 10:53:05 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final int brightness = imb.getMixedBrightnessForBlock( world, x, y, z );
|
2014-07-20 10:53:05 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final EnumSet<ForgeDirection> validSides = EnumSet.noneOf( ForgeDirection.class );
|
2014-07-21 05:45:08 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
for( final ForgeDirection side : ForgeDirection.VALID_DIRECTIONS )
|
2014-07-21 05:45:08 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
if( tp.isSideValid( side ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-21 05:45:08 +02:00
|
|
|
validSides.add( side );
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-21 05:45:08 +02:00
|
|
|
}
|
|
|
|
|
2015-09-25 22:52:41 +02:00
|
|
|
double offsetConstant = 0.001;
|
2015-09-25 23:10:56 +02:00
|
|
|
final int lumen = 14 << 20 | 14 << 4;
|
|
|
|
for( final Splotch s : tp.getDots() )
|
2014-07-20 10:53:05 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
if( !validSides.contains( s.getSide() ) )
|
2015-04-29 02:30:53 +02:00
|
|
|
{
|
2014-07-21 05:45:08 +02:00
|
|
|
continue;
|
2015-04-29 02:30:53 +02:00
|
|
|
}
|
2014-07-21 05:45:08 +02:00
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
if( s.isLumen() )
|
2014-07-20 10:53:05 +02:00
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
tess.setColorOpaque_I( s.getColor().whiteVariant );
|
2014-07-20 10:53:05 +02:00
|
|
|
tess.setBrightness( lumen );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2015-10-08 15:42:42 +02:00
|
|
|
tess.setColorOpaque_I( s.getColor().mediumVariant );
|
2014-09-28 11:47:17 +02:00
|
|
|
tess.setBrightness( brightness );
|
2014-07-20 10:53:05 +02:00
|
|
|
}
|
|
|
|
|
2014-09-28 11:47:17 +02:00
|
|
|
double offset = offsetConstant;
|
|
|
|
offsetConstant += 0.001;
|
2014-07-20 10:53:05 +02:00
|
|
|
|
2015-09-25 23:10:56 +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();
|
|
|
|
|
2015-05-08 23:34:24 +02:00
|
|
|
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
|
|
|
|
2015-10-08 15:42:42 +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;
|
|
|
|
}
|
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
final IIcon ico = icoSet[s.getSeed() % icoSet.length];
|
2014-07-20 10:53:05 +02:00
|
|
|
|
2015-10-08 15:42:42 +02:00
|
|
|
switch( s.getSide() )
|
2014-07-20 10:53:05 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
case UP:
|
|
|
|
offset = 1.0 - offset;
|
2015-05-08 23:34:24 +02:00
|
|
|
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() );
|
2015-04-03 08:54:31 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case DOWN:
|
2015-05-08 23:34:24 +02:00
|
|
|
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() );
|
2015-04-03 08:54:31 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case EAST:
|
|
|
|
offset = 1.0 - offset;
|
2015-05-08 23:34:24 +02:00
|
|
|
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() );
|
2015-04-03 08:54:31 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WEST:
|
2015-05-08 23:34:24 +02:00
|
|
|
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() );
|
2015-04-03 08:54:31 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SOUTH:
|
|
|
|
offset = 1.0 - offset;
|
2015-05-08 23:34:24 +02:00
|
|
|
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() );
|
2015-04-03 08:54:31 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NORTH:
|
2015-05-08 23:34:24 +02:00
|
|
|
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() );
|
2015-04-03 08:54:31 +02:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2014-07-20 10:53:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
out = true;
|
|
|
|
}
|
|
|
|
|
2014-06-01 03:50:56 +02:00
|
|
|
return out;
|
|
|
|
}
|
|
|
|
}
|