codechicken.lib.raytracer.IndexedCuboid6 Java Examples

The following examples show how to use codechicken.lib.raytracer.IndexedCuboid6. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetaTileEntityRenderer.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void handleRenderBlockDamage(IBlockAccess world, BlockPos pos, IBlockState state, TextureAtlasSprite sprite, BufferBuilder buffer) {
    MetaTileEntity metaTileEntity = BlockMachine.getMetaTileEntity(world, pos);
    ArrayList<IndexedCuboid6> boundingBox = new ArrayList<>();
    if (metaTileEntity != null) {
        metaTileEntity.addCollisionBoundingBox(boundingBox);
        metaTileEntity.addCoverCollisionBoundingBox(boundingBox);
    }
    CCRenderState renderState = CCRenderState.instance();
    renderState.reset();
    renderState.bind(buffer);
    renderState.setPipeline(new Vector3(new Vec3d(pos)).translation(), new IconTransformation(sprite));
    for (Cuboid6 cuboid : boundingBox) {
        BlockRenderer.renderCuboid(renderState, cuboid, 0);
    }
}
 
Example #2
Source File: TileTranslocator.java    From Translocators with MIT License 6 votes vote down vote up
public void addTraceableCuboids(List<IndexedCuboid6> cuboids)
{
    Vector3 pos = Vector3.fromTileEntity(this);
    Cuboid6 base = new Cuboid6(3/16D, 0, 3/16D, 13/16D, 2/16D, 13/16D);
    
    for(int i = 0; i < 6; i++)
    {
        Attachment a = attachments[i];
        if(a != null)
        {
            cuboids.add(new IndexedCuboid6(i, transformPart(base, pos, i)));
            cuboids.add(new IndexedCuboid6(i+6, transformPart(
                    new Cuboid6(6/16D, 0, 6/16D, 10/16D, a.a_insertpos*2/16D+1/16D, 10/16D), 
                    pos, i)));
        }
    }
}
 
Example #3
Source File: BlockPipe.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
private List<IndexedCuboid6> getCollisionBox(IBlockAccess world, BlockPos pos) {
    IPipeTile<PipeType, NodeDataType> pipeTile = getPipeTileEntity(world, pos);
    if (pipeTile == null) {
        return Collections.emptyList();
    }
    PipeType pipeType = pipeTile.getPipeType();
    if (pipeType == null) {
        return Collections.emptyList();
    }
    int actualConnections = getActualConnections(pipeTile, world);
    float thickness = pipeType.getThickness();
    ArrayList<IndexedCuboid6> result = new ArrayList<>();
    result.add(new IndexedCuboid6(new PrimaryBoxData(false), getSideBox(null, thickness)));
    ICoverable coverable = pipeTile.getCoverableImplementation();
    for (EnumFacing side : EnumFacing.VALUES) {
        if ((actualConnections & 1 << side.getIndex()) > 0) {
            result.add(new IndexedCuboid6(new PipeConnectionData(side), getSideBox(side, thickness)));
        }
    }
    coverable.addCoverCollisionBoundingBox(result);
    return result;
}
 
Example #4
Source File: BlockCraftingGrid.java    From Translocators with MIT License 6 votes vote down vote up
public List<IndexedCuboid6> getParts(World world, int x, int y, int z) {
    LinkedList<IndexedCuboid6> parts = new LinkedList<IndexedCuboid6>();
    parts.add(new IndexedCuboid6(0,
            new Cuboid6(0, 0, 0, 1, 0.005, 1)
                    .add(new Vector3(x, y, z))
    ));

    TileCraftingGrid tcraft = (TileCraftingGrid) world.getTileEntity(x, y, z);

    for (int i = 0; i < 9; i++) {
        Cuboid6 box = new Cuboid6(1 / 16D, 0, 1 / 16D, 5 / 16D, 0.01, 5 / 16D)
                .apply(new Translation((i % 3) * 5 / 16D, 0, (i / 3) * 5 / 16D)
                        .with(Rotation.quarterRotations[tcraft.rotation].at(center))
                        .with(new Translation(x, y, z)));

        parts.add(new IndexedCuboid6(i + 1, box));
    }
    return parts;
}
 
Example #5
Source File: PartFrame.java    From Framez with GNU General Public License v3.0 6 votes vote down vote up
@Override
public Iterable<IndexedCuboid6> getSubParts() {

    List<IndexedCuboid6> l = new ArrayList<IndexedCuboid6>();

    Vec3dCube c1 = new Vec3dCube(0, 0, 0, 2 / 16D, 2 / 16D, 1);
    Vec3dCube c2 = new Vec3dCube(0, 2 / 16D, 0, 2 / 16D, 14 / 16D, 2 / 16D);
    Vec3dCube c3 = new Vec3dCube(0, 14 / 16D, 0, 2 / 16D, 1, 1);
    for (int i = 0; i < 4; i++) {
        l.add(new IndexedCuboid6(0, new Cuboid6(c1.clone().rotate(0, i * 90, 0, Vec3d.center).toAABB())));
        l.add(new IndexedCuboid6(0, new Cuboid6(c2.clone().rotate(0, i * 90, 0, Vec3d.center).toAABB())));
        l.add(new IndexedCuboid6(0, new Cuboid6(c3.clone().rotate(0, i * 90, 0, Vec3d.center).toAABB())));
    }
    if (getWorld() != null && (!getWorld().isRemote || !Config.click_through_frames))
        if (is2D())
            l.add(new IndexedCuboid6(0, new Cuboid6(0, 0, 0, 1, 1, 1).expand(-0.001)));
        else
            l.add(new IndexedCuboid6(0, new Cuboid6(1 / 16D, 1 / 16D, 1 / 16D, 15 / 16D, 15 / 16D, 15 / 16D)));

    return l;
}
 
Example #6
Source File: TileEnderChest.java    From EnderStorage with MIT License 6 votes vote down vote up
@Override
public void addTraceableCuboids(List<IndexedCuboid6> cuboids)
{
    cuboids.add(new IndexedCuboid6(0, new Cuboid6(xCoord+1/16D, yCoord, zCoord+1/16D, xCoord+15/16D, yCoord+14/16D, zCoord+15/16D)));
    if(getRadianLidAngle(0) < 0)
        return;
    
    for(int button = 0; button < 3; button++)
    {
        EnderDyeButton ebutton = TileEnderChest.buttons[button].copy();
        ebutton.rotate(0, 0.5625, 0.0625, 1, 0, 0, 0);
        ebutton.rotateMeta(rotation);
        
        cuboids.add(new IndexedCuboid6(button+1, new Cuboid6(ebutton.getMin(), ebutton.getMax()).add(Vector3.fromTileEntity(this))));
    }
    
    cuboids.add(new IndexedCuboid6(4, new Cuboid6(new EnderKnobSlot(rotation).getSelectionBB()).add(Vector3.fromTileEntity(this))));
}
 
Example #7
Source File: StonePileModelGenerator.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static List<IndexedCuboid6> generateCuboidList(Random random) {
    ArrayList<IndexedCuboid6> result = new ArrayList<>();
    List<PositionedRect> occupiedAreas = new ArrayList<>();
    int stonePlaceAttempts = 64;
    int maxStones = 8;
    int stonesPlaced = 0;
    for (int i = 0; i < stonePlaceAttempts && stonesPlaced < maxStones; i++) {
        int sizeX = 2 + random.nextInt(3);
        int sizeZ = 2 + random.nextInt(3);
        int stoneHeight = 4 + random.nextInt(4);
        int posX = random.nextInt(16 - sizeX);
        int posZ = random.nextInt(16 - sizeZ);
        PositionedRect rect = new PositionedRect(new Position(posX, posZ), new Size(sizeX, sizeZ));
        if (occupiedAreas.stream().noneMatch(rect::intersects)) {
            Vector3 minVector = new Vector3(posX / 16.0, 0 / 16.0, posZ / 16.0);
            Cuboid6 bounds = new Cuboid6(minVector, minVector.copy());
            bounds.max.add(sizeX / 16.0, stoneHeight / 16.0, sizeZ / 16.0);
            int brightness = 100 + random.nextInt(130);
            result.add(new IndexedCuboid6(brightness, bounds));
            occupiedAreas.add(rect);
            stonesPlaced++;
        }
    }
    return result;
}
 
Example #8
Source File: PartPressureTube.java    From PneumaticCraft with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Iterable<IndexedCuboid6> getSubParts(){
    Iterable<Cuboid6> boxList = getCollisionBoxes();
    LinkedList<IndexedCuboid6> partList = new LinkedList<IndexedCuboid6>();
    for(Cuboid6 c : boxList)
        partList.add(new IndexedCuboid6(0, c));
    return partList;
}
 
Example #9
Source File: BlockTranslocator.java    From Translocators with MIT License 5 votes vote down vote up
@Override
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB ebb, List list, Entity entity) {
    List<IndexedCuboid6> cuboids = getParts(world, x, y, z);
    for (IndexedCuboid6 cb : cuboids) {
        AxisAlignedBB aabb = cb.toAABB();
        if (aabb.intersectsWith(ebb))
            list.add(aabb);
    }
}
 
Example #10
Source File: BlockTranslocator.java    From Translocators with MIT License 5 votes vote down vote up
public List<IndexedCuboid6> getParts(World world, int x, int y, int z) {
    TileTranslocator tile = (TileTranslocator) world.getTileEntity(x, y, z);
    if (tile == null)
        return null;

    List<IndexedCuboid6> cuboids = new LinkedList<IndexedCuboid6>();
    tile.addTraceableCuboids(cuboids);
    return cuboids;
}
 
Example #11
Source File: TileEnderTank.java    From EnderStorage with MIT License 5 votes vote down vote up
@Override
public void addTraceableCuboids(List<IndexedCuboid6> cuboids) {
    Vector3 pos = new Vector3(xCoord, yCoord, zCoord);
    cuboids.add(new IndexedCuboid6(0, new Cuboid6(0.15, 0, 0.15, 0.85, 0.916, 0.85).add(pos)));

    for (int i = 0; i < 4; i++)
        cuboids.add(new IndexedCuboid6(i + 1, selectionBoxes[i].copy()
                .apply(Rotation.quarterRotations[rotation ^ 2].at(center)).add(pos)));
}
 
Example #12
Source File: BlockEnderStorage.java    From EnderStorage with MIT License 5 votes vote down vote up
@Override
public MovingObjectPosition collisionRayTrace(World world, int x, int y, int z, Vec3 start, Vec3 end) {
    TileFrequencyOwner tile = (TileFrequencyOwner) world.getTileEntity(x, y, z);
    if (tile == null)
        return null;

    List<IndexedCuboid6> cuboids = new LinkedList<IndexedCuboid6>();
    tile.addTraceableCuboids(cuboids);
    return rayTracer.rayTraceCuboids(new Vector3(start), new Vector3(end), cuboids, new BlockCoord(x, y, z), this);
}
 
Example #13
Source File: StonePileModelGenerator.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static CCModel generatePebblePileModel(Random random) {
    List<IndexedCuboid6> cuboid6s = generateCuboidList(random);
    CCModel ccModel = CCModel.quadModel(cuboid6s.size() * 24);
    for (int i = 0; i < cuboid6s.size(); i++) {
        IndexedCuboid6 cuboid6 = cuboid6s.get(i);
        ccModel.generateBlock(i * 24, cuboid6);
        int b = (int) cuboid6.data;
        int[] colours = ccModel.getOrAllocate(ColourAttribute.attributeKey);
        int color = (b & 0xFF) << 24 | (b & 0xFF) << 16 | (b & 0xFF) << 8 | (0xFF);
        Arrays.fill(colours, i * 24, i* 24 + 24, color);
    }
    return ccModel;
}
 
Example #14
Source File: MetaTileEntity.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public boolean canPlaceCoverOnSide(EnumFacing side) {
    if (hasFrontFacing() && side == getFrontFacing()) {
        //covers cannot be placed on this side
        return false;
    }
    ArrayList<IndexedCuboid6> collisionList = new ArrayList<>();
    addCollisionBoundingBox(collisionList);
    //noinspection RedundantIfStatement
    if (ICoverable.doesCoverCollide(side, collisionList, getCoverPlateThickness())) {
        //cover collision box overlaps with meta tile entity collision box
        return false;
    }
    return true;
}
 
Example #15
Source File: PipeCoverableImplementation.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean canPlaceCoverOnSide(EnumFacing side) {
    List<IndexedCuboid6> pipeBox = Lists.newArrayList(new IndexedCuboid6(null, BlockPipe.getSideBox(null, holder.getPipeType().getThickness())));
    if (ICoverable.doesCoverCollide(side, pipeBox, getCoverPlateThickness())) {
        return false;
    }
    return holder.canPlaceCoverOnSide(side);
}
 
Example #16
Source File: ICoverable.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
static boolean doesCoverCollide(EnumFacing side, List<IndexedCuboid6> collisionBox, double plateThickness) {
    if (plateThickness > 0.0) {
        Cuboid6 coverPlateBox = getCoverPlateBox(side, plateThickness);
        for (Cuboid6 collisionCuboid : collisionBox) {
            if (collisionCuboid.intersects(coverPlateBox)) {
                //collision box intersects with machine bounding box -
                //cover cannot be placed on this side
                return true;
            }
        }
        return false;
    }
    return false;
}
 
Example #17
Source File: ICoverable.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
default void addCoverCollisionBoundingBox(List<? super IndexedCuboid6> collisionList) {
    double plateThickness = getCoverPlateThickness();
    if (plateThickness > 0.0) {
        for (EnumFacing side : EnumFacing.VALUES) {
            if (getCoverAtSide(side) != null) {
                Cuboid6 coverBox = getCoverPlateBox(side, plateThickness);
                CoverSideData coverSideData = new CoverSideData(side);
                collisionList.add(new IndexedCuboid6(coverSideData, coverBox));
            }
        }
    }
}
 
Example #18
Source File: BlockMachine.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private List<IndexedCuboid6> getCollisionBox(IBlockAccess blockAccess, BlockPos pos) {
    MetaTileEntity metaTileEntity = getMetaTileEntity(blockAccess, pos);
    if (metaTileEntity == null)
        return EMPTY_COLLISION_BOX;
    ArrayList<IndexedCuboid6> collisionList = new ArrayList<>();
    metaTileEntity.addCollisionBoundingBox(collisionList);
    metaTileEntity.addCoverCollisionBoundingBox(collisionList);
    return collisionList;
}
 
Example #19
Source File: TileFrequencyOwner.java    From EnderStorage with MIT License 4 votes vote down vote up
public void addTraceableCuboids(List<IndexedCuboid6> cuboids)
{
    cuboids.add(new IndexedCuboid6(0, new Cuboid6(xCoord, yCoord, zCoord, xCoord+1, yCoord+1, zCoord+1)));
}
 
Example #20
Source File: MetaTileEntityLockedSafe.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void addCollisionBoundingBox(List<IndexedCuboid6> collisionList) {
    collisionList.add(COLLISION_BOX);
}
 
Example #21
Source File: MetaTileEntityChest.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
@Override
public void addCollisionBoundingBox(List<IndexedCuboid6> collisionList) {
    collisionList.add(CHEST_COLLISION);
}
 
Example #22
Source File: WirelessPart.java    From WirelessRedstone with MIT License 4 votes vote down vote up
@Override
public Iterable<IndexedCuboid6> getSubParts() {
    return Arrays.asList(new IndexedCuboid6(0, getBounds()));
}
 
Example #23
Source File: MetaTileEntity.java    From GregTech with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Called to obtain list of AxisAlignedBB used for collision testing, highlight rendering
 * and ray tracing this meta tile entity's block in world
 */
public void addCollisionBoundingBox(List<IndexedCuboid6> collisionList) {
    collisionList.add(FULL_CUBE_COLLISION);
}