Applied-Energistics-2-tiler.../src/main/java/appeng/client/render/model/RenderHelper.java
shartte 115f73de2e Implemented Glass Blocks (#51)
* Implemented connected texture glass blocks (different approach from 1.7).
2016-08-16 16:04:31 +02:00

108 lines
2.8 KiB
Java

/*
* 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.model;
import java.util.EnumMap;
import java.util.List;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.Vec3d;
final class RenderHelper
{
private static EnumMap<EnumFacing, List<Vec3d>> cornersForFacing = generateCornersForFacings();
private RenderHelper() {
}
static List<Vec3d> getFaceCorners( EnumFacing side )
{
return cornersForFacing.get( side );
}
private static EnumMap<EnumFacing, List<Vec3d>> generateCornersForFacings()
{
EnumMap<EnumFacing, List<Vec3d>> result = new EnumMap<>( EnumFacing.class );
for( EnumFacing facing : EnumFacing.values() )
{
List<Vec3d> corners;
float offset = ( facing.getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE ) ? 0 : 1;
switch( facing.getAxis() )
{
default:
case X:
corners = Lists.newArrayList(
new Vec3d( offset, 1, 1 ),
new Vec3d( offset, 0, 1 ),
new Vec3d( offset, 0, 0 ),
new Vec3d( offset, 1, 0 )
);
break;
case Y:
corners = Lists.newArrayList(
new Vec3d( 1, offset, 1 ),
new Vec3d( 1, offset, 0 ),
new Vec3d( 0, offset, 0 ),
new Vec3d( 0, offset, 1 )
);
break;
case Z:
corners = Lists.newArrayList(
new Vec3d( 0, 1, offset ),
new Vec3d( 0, 0, offset ),
new Vec3d( 1, 0, offset ),
new Vec3d( 1, 1, offset )
);
break;
}
if (facing.getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE) {
corners = Lists.reverse( corners );
}
result.put( facing, ImmutableList.copyOf( corners ) );
}
return result;
}
private static Vec3d adjust( Vec3d vec, EnumFacing.Axis axis, double delta )
{
switch( axis )
{
default:
case X:
return new Vec3d( vec.xCoord + delta, vec.yCoord, vec.zCoord );
case Y:
return new Vec3d( vec.xCoord, vec.yCoord + delta, vec.zCoord );
case Z:
return new Vec3d( vec.xCoord, vec.yCoord, vec.zCoord + delta );
}
}
}