Search in sources :

Example 1 with IRedstoneConduit

use of crazypants.enderio.conduits.conduit.redstone.IRedstoneConduit in project EnderIO by SleepyTrousers.

the class BlockConduitBundle method getSelectedBoundingBox.

@Override
@SideOnly(Side.CLIENT)
@Nonnull
public AxisAlignedBB getSelectedBoundingBox(@Nonnull IBlockState bs, @Nonnull World world, @Nonnull BlockPos pos) {
    TileConduitBundle te = getTileEntity(world, pos);
    EntityPlayer player = Minecraft.getMinecraft().player;
    if (te == null) {
        // FIXME is this valid?
        return new AxisAlignedBB(0, 0, 0, 0, 0, 0);
    }
    IConduitBundle con = te;
    BoundingBox minBB = null;
    if (!YetaUtil.isSolidFacadeRendered(con, player)) {
        List<RaytraceResult> results = doRayTraceAll(world, pos, player);
        Iterator<RaytraceResult> iter = results.iterator();
        while (iter.hasNext()) {
            CollidableComponent component = iter.next().component;
            if (component != null && component.conduitType == null && component.data != ConduitConnectorType.EXTERNAL) {
                iter.remove();
            }
        }
        // This is an ugly special case, TODO fix this
        for (RaytraceResult hit : results) {
            IRedstoneConduit cond = con.getConduit(IRedstoneConduit.class);
            CollidableComponent component = hit.component;
            EnumFacing dir = component == null ? null : component.dir;
            if (cond != null && component != null && dir != null && cond.getExternalConnections().contains(dir) && component.data == InsulatedRedstoneConduit.COLOR_CONTROLLER_ID) {
                minBB = component.bound;
            }
        }
        if (minBB == null) {
            RaytraceResult hit = RaytraceResult.getClosestHit(Util.getEyePosition(player), results);
            CollidableComponent component = hit == null ? null : hit.component;
            if (component != null) {
                EnumFacing dir = component.dir;
                minBB = component.bound;
                if (dir != null && component.conduitType == null) {
                    dir = dir.getOpposite();
                    float trans = 0.0125f;
                    minBB = minBB.translate(dir.getFrontOffsetX() * trans, dir.getFrontOffsetY() * trans, dir.getFrontOffsetZ() * trans);
                    float scale = 0.7f;
                    minBB = minBB.scale(1 + Math.abs(dir.getFrontOffsetX()) * scale, 1 + Math.abs(dir.getFrontOffsetY()) * scale, 1 + Math.abs(dir.getFrontOffsetZ()) * scale);
                } else {
                    minBB = minBB.scale(1.09, 1.09, 1.09);
                }
            }
        }
    } else {
        minBB = new BoundingBox(0, 0, 0, 1, 1, 1);
    }
    if (minBB == null) {
        minBB = new BoundingBox(0, 0, 0, 1, 1, 1);
    }
    return new AxisAlignedBB(pos.getX() + minBB.minX, pos.getY() + minBB.minY, pos.getZ() + minBB.minZ, pos.getX() + minBB.maxX, pos.getY() + minBB.maxY, pos.getZ() + minBB.maxZ);
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) CollidableComponent(crazypants.enderio.base.conduit.geom.CollidableComponent) BoundingBox(com.enderio.core.client.render.BoundingBox) EnumFacing(net.minecraft.util.EnumFacing) EntityPlayer(net.minecraft.entity.player.EntityPlayer) IConduitBundle(crazypants.enderio.base.conduit.IConduitBundle) IRedstoneConduit(crazypants.enderio.conduits.conduit.redstone.IRedstoneConduit) RaytraceResult(crazypants.enderio.base.conduit.RaytraceResult) Nonnull(javax.annotation.Nonnull) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Aggregations

BoundingBox (com.enderio.core.client.render.BoundingBox)1 IConduitBundle (crazypants.enderio.base.conduit.IConduitBundle)1 RaytraceResult (crazypants.enderio.base.conduit.RaytraceResult)1 CollidableComponent (crazypants.enderio.base.conduit.geom.CollidableComponent)1 IRedstoneConduit (crazypants.enderio.conduits.conduit.redstone.IRedstoneConduit)1 Nonnull (javax.annotation.Nonnull)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 EnumFacing (net.minecraft.util.EnumFacing)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)1