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-09-24 02:26:27 +02:00
|
|
|
package appeng.parts;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.util.AxisAlignedBB;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
2014-12-29 21:59:05 +01:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
import appeng.api.parts.IPartCollisionHelper;
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
|
2014-09-24 02:26:27 +02:00
|
|
|
public class BusCollisionHelper implements IPartCollisionHelper
|
|
|
|
{
|
|
|
|
|
|
|
|
final List<AxisAlignedBB> boxes;
|
|
|
|
|
2015-04-06 00:35:42 +02:00
|
|
|
private final ForgeDirection x;
|
|
|
|
private final ForgeDirection y;
|
|
|
|
private final ForgeDirection z;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-06 00:35:42 +02:00
|
|
|
private final Entity entity;
|
|
|
|
private final boolean isVisual;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
public BusCollisionHelper( final List<AxisAlignedBB> boxes, final ForgeDirection x, final ForgeDirection y, final ForgeDirection z, final Entity e, final boolean visual )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
this.boxes = boxes;
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
|
|
|
this.z = z;
|
2014-12-29 15:13:47 +01:00
|
|
|
this.entity = e;
|
|
|
|
this.isVisual = visual;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-09-25 23:10:56 +02:00
|
|
|
public BusCollisionHelper( final List<AxisAlignedBB> boxes, final ForgeDirection s, final Entity e, final boolean visual )
|
2015-04-03 08:54:31 +02:00
|
|
|
{
|
2014-09-24 02:26:27 +02:00
|
|
|
this.boxes = boxes;
|
2014-12-29 15:13:47 +01:00
|
|
|
this.entity = e;
|
|
|
|
this.isVisual = visual;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
switch( s )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
2015-04-03 08:54:31 +02:00
|
|
|
case DOWN:
|
|
|
|
this.x = ForgeDirection.EAST;
|
|
|
|
this.y = ForgeDirection.NORTH;
|
|
|
|
this.z = ForgeDirection.DOWN;
|
|
|
|
break;
|
|
|
|
case UP:
|
|
|
|
this.x = ForgeDirection.EAST;
|
|
|
|
this.y = ForgeDirection.SOUTH;
|
|
|
|
this.z = ForgeDirection.UP;
|
|
|
|
break;
|
|
|
|
case EAST:
|
|
|
|
this.x = ForgeDirection.SOUTH;
|
|
|
|
this.y = ForgeDirection.UP;
|
|
|
|
this.z = ForgeDirection.EAST;
|
|
|
|
break;
|
|
|
|
case WEST:
|
|
|
|
this.x = ForgeDirection.NORTH;
|
|
|
|
this.y = ForgeDirection.UP;
|
|
|
|
this.z = ForgeDirection.WEST;
|
|
|
|
break;
|
|
|
|
case NORTH:
|
|
|
|
this.x = ForgeDirection.WEST;
|
|
|
|
this.y = ForgeDirection.UP;
|
|
|
|
this.z = ForgeDirection.NORTH;
|
|
|
|
break;
|
|
|
|
case SOUTH:
|
|
|
|
this.x = ForgeDirection.EAST;
|
|
|
|
this.y = ForgeDirection.UP;
|
|
|
|
this.z = ForgeDirection.SOUTH;
|
|
|
|
break;
|
|
|
|
case UNKNOWN:
|
|
|
|
default:
|
|
|
|
this.x = ForgeDirection.EAST;
|
|
|
|
this.y = ForgeDirection.UP;
|
|
|
|
this.z = ForgeDirection.SOUTH;
|
|
|
|
break;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* pretty much useless...
|
|
|
|
*/
|
|
|
|
public Entity getEntity()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.entity;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-04-03 08:54:31 +02:00
|
|
|
public void addBox( double minX, double minY, double minZ, double maxX, double maxY, double maxZ )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
minX /= 16.0;
|
|
|
|
minY /= 16.0;
|
|
|
|
minZ /= 16.0;
|
|
|
|
maxX /= 16.0;
|
|
|
|
maxY /= 16.0;
|
|
|
|
maxZ /= 16.0;
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
double aX = minX * this.x.offsetX + minY * this.y.offsetX + minZ * this.z.offsetX;
|
|
|
|
double aY = minX * this.x.offsetY + minY * this.y.offsetY + minZ * this.z.offsetY;
|
|
|
|
double aZ = minX * this.x.offsetZ + minY * this.y.offsetZ + minZ * this.z.offsetZ;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
double bX = maxX * this.x.offsetX + maxY * this.y.offsetX + maxZ * this.z.offsetX;
|
|
|
|
double bY = maxX * this.x.offsetY + maxY * this.y.offsetY + maxZ * this.z.offsetY;
|
|
|
|
double bZ = maxX * this.x.offsetZ + maxY * this.y.offsetZ + maxZ * this.z.offsetZ;
|
2014-09-24 02:26:27 +02:00
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.x.offsetX + this.y.offsetX + this.z.offsetX < 0 )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
aX += 1;
|
|
|
|
bX += 1;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.x.offsetY + this.y.offsetY + this.z.offsetY < 0 )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
aY += 1;
|
|
|
|
bY += 1;
|
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
if( this.x.offsetZ + this.y.offsetZ + this.z.offsetZ < 0 )
|
2014-09-24 02:26:27 +02:00
|
|
|
{
|
|
|
|
aZ += 1;
|
|
|
|
bZ += 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
minX = Math.min( aX, bX );
|
|
|
|
minY = Math.min( aY, bY );
|
|
|
|
minZ = Math.min( aZ, bZ );
|
|
|
|
maxX = Math.max( aX, bX );
|
|
|
|
maxY = Math.max( aY, bY );
|
|
|
|
maxZ = Math.max( aZ, bZ );
|
|
|
|
|
2014-12-29 15:13:47 +01:00
|
|
|
this.boxes.add( AxisAlignedBB.getBoundingBox( minX, minY, minZ, maxX, maxY, maxZ ) );
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ForgeDirection getWorldX()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.x;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ForgeDirection getWorldY()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.y;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ForgeDirection getWorldZ()
|
|
|
|
{
|
2014-12-29 15:13:47 +01:00
|
|
|
return this.z;
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|
|
|
|
|
2015-04-03 08:54:31 +02:00
|
|
|
@Override
|
|
|
|
public boolean isBBCollision()
|
|
|
|
{
|
|
|
|
return !this.isVisual;
|
|
|
|
}
|
2014-09-24 02:26:27 +02:00
|
|
|
}
|