1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-05-04 16:34:14 +00:00

Merge pull request #195 from SquidDev-CC/hotfix/selection-boxes

Fix selection boxes not being shown
This commit is contained in:
Daniel Ratcliffe 2017-05-06 23:55:45 +01:00 committed by GitHub
commit a6e3d4fd26
3 changed files with 38 additions and 40 deletions

View File

@ -219,9 +219,9 @@ public abstract class BlockGeneric extends Block implements
} }
@Override @Override
public final AxisAlignedBB getSelectedBoundingBox( IBlockState state, World world, BlockPos pos ) public AxisAlignedBB getSelectedBoundingBox( IBlockState state, World worldIn, BlockPos pos )
{ {
return getBoundingBox( state, world, pos ); return getBoundingBox( state, worldIn, pos ).offset( pos );
} }
@Override @Override

View File

@ -37,6 +37,19 @@ import java.util.*;
public class TileCable extends TileModemBase public class TileCable extends TileModemBase
implements INetwork 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 // Statics
private static class Peripheral extends ModemPeripheral private static class Peripheral extends ModemPeripheral
@ -415,14 +428,7 @@ public class TileCable extends TileModemBase
{ {
AxisAlignedBB modem = getModemBounds(); AxisAlignedBB modem = getModemBounds();
AxisAlignedBB cable = getCableBounds(); AxisAlignedBB cable = getCableBounds();
return new AxisAlignedBB( return modem.union( cable );
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 )
);
} }
} }
} }
@ -437,7 +443,15 @@ public class TileCable extends TileModemBase
} }
if( type == PeripheralType.Cable || type == PeripheralType.WiredModemWithCable ) 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 @@ package dan200.computercraft.shared.peripheral.modem;
import dan200.computercraft.api.peripheral.IPeripheral; import dan200.computercraft.api.peripheral.IPeripheral;
import dan200.computercraft.shared.common.BlockGeneric; import dan200.computercraft.shared.common.BlockGeneric;
import dan200.computercraft.shared.peripheral.common.TilePeripheralBase; import dan200.computercraft.shared.peripheral.common.TilePeripheralBase;
import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.AxisAlignedBB;
public abstract class TileModemBase extends TilePeripheralBase 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 ModemPeripheral m_modem;
protected TileModemBase() protected TileModemBase()
@ -58,34 +68,8 @@ public abstract class TileModemBase extends TilePeripheralBase
@Override @Override
public AxisAlignedBB getBounds() public AxisAlignedBB getBounds()
{ {
switch( getDirection() ) int direction = getDirection().ordinal();
{ return direction >= 0 && direction < BOXES.length ? BOXES[ direction ] : Block.FULL_BLOCK_AABB;
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 );
}
}
} }
@Override @Override