Make cable collision boxes more accurate for cables

Each cable segment is added to the list, meaning you can get close and
snugly with the cables.
This commit is contained in:
SquidDev 2017-05-06 23:45:15 +01:00
parent d87b0e9435
commit f34a319b79
3 changed files with 42 additions and 38 deletions

View File

@ -218,6 +218,12 @@ public final AxisAlignedBB getBoundingBox( IBlockState state, IBlockAccess world
return FULL_BLOCK_AABB;
}
@Override
public AxisAlignedBB getSelectedBoundingBox( IBlockState state, World worldIn, BlockPos pos )
{
return getBoundingBox( state, worldIn, pos ).offset( pos );
}
@Override
public final AxisAlignedBB getCollisionBoundingBox( IBlockState state, World world, BlockPos pos )
{

View File

@ -37,6 +37,19 @@
public class TileCable extends TileModemBase
implements INetwork
{
private static final double MIN = 0.375;
private static final double MAX = 1 - MIN;
private static final AxisAlignedBB BOX_CENTRE = new AxisAlignedBB( MIN, MIN, MIN, MAX, MAX, MAX );
private static final AxisAlignedBB[] BOXES = new AxisAlignedBB[]{
new AxisAlignedBB( MIN, 0, MIN, MAX, MIN, MAX ), // Down
new AxisAlignedBB( MIN, MAX, MIN, MAX, 1, MAX ), // Up
new AxisAlignedBB( MIN, MIN, 0, MAX, MAX, MIN ), // North
new AxisAlignedBB( MIN, MIN, MAX, MAX, MAX, 1 ), // South
new AxisAlignedBB( 0, MIN, MIN, MIN, MAX, MAX ), // West
new AxisAlignedBB( MAX, MIN, MIN, 1, MAX, MAX ), // East
};
// Statics
private static class Peripheral extends ModemPeripheral
@ -415,14 +428,7 @@ public AxisAlignedBB getBounds()
{
AxisAlignedBB modem = getModemBounds();
AxisAlignedBB cable = getCableBounds();
return new AxisAlignedBB(
Math.min( modem.minX, cable.minX ),
Math.min( modem.minY, cable.minY ),
Math.min( modem.minZ, cable.minZ ),
Math.max( modem.maxX, cable.maxX ),
Math.max( modem.maxY, cable.maxY ),
Math.max( modem.maxZ, cable.maxZ )
);
return modem.union( cable );
}
}
}
@ -437,7 +443,15 @@ public void getCollisionBounds( List<AxisAlignedBB> bounds )
}
if( type == PeripheralType.Cable || type == PeripheralType.WiredModemWithCable )
{
bounds.add( getCableBounds() );
bounds.add( BOX_CENTRE );
BlockPos pos = getPos();
for (EnumFacing facing : EnumFacing.VALUES)
{
if( BlockCable.isCable( worldObj, pos.offset( facing ) ) )
{
bounds.add( BOXES[ facing.ordinal() ] );
}
}
}
}

View File

@ -9,12 +9,22 @@
import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.shared.common.BlockGeneric;
import dan200.computercraft.shared.peripheral.common.TilePeripheralBase;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
public abstract class TileModemBase extends TilePeripheralBase
{
private static final AxisAlignedBB[] BOXES = new AxisAlignedBB[] {
new AxisAlignedBB( 0.125, 0.0, 0.125, 0.875, 0.1875, 0.875 ), // Down
new AxisAlignedBB( 0.125, 0.8125, 0.125, 0.875, 1.0, 0.875 ), // Up
new AxisAlignedBB( 0.125, 0.125, 0.0, 0.875, 0.875, 0.1875 ), // North
new AxisAlignedBB( 0.125, 0.125, 0.8125, 0.875, 0.875, 1.0 ), // South
new AxisAlignedBB( 0.0, 0.125, 0.125, 0.1875, 0.875, 0.875 ), // West
new AxisAlignedBB( 0.8125, 0.125, 0.125, 1.0, 0.875, 0.875 ), // East
};
protected ModemPeripheral m_modem;
protected TileModemBase()
@ -58,34 +68,8 @@ public void onNeighbourChange()
@Override
public AxisAlignedBB getBounds()
{
switch( getDirection() )
{
case UP:
default:
{
return new AxisAlignedBB( 0.125, 0.8125, 0.125, 0.875, 1.0, 0.875 );
}
case DOWN:
{
return new AxisAlignedBB( 0.125, 0.0, 0.125, 0.875, 0.1875, 0.875 );
}
case NORTH:
{
return new AxisAlignedBB( 0.125, 0.125, 0.0, 0.875, 0.875, 0.1875 );
}
case SOUTH:
{
return new AxisAlignedBB( 0.125, 0.125, 0.8125, 0.875, 0.875, 1.0 );
}
case WEST:
{
return new AxisAlignedBB( 0.0, 0.125, 0.125, 0.1875, 0.875, 0.875 );
}
case EAST:
{
return new AxisAlignedBB( 0.8125, 0.125, 0.125, 1.0, 0.875, 0.875 );
}
}
int direction = getDirection().ordinal();
return direction >= 0 && direction < BOXES.length ? BOXES[ direction ] : Block.FULL_BLOCK_AABB;
}
@Override