codechicken.lib.vec.Vector3 Java Examples

The following examples show how to use codechicken.lib.vec.Vector3. 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: VectorUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Calculates the int direction a normal is facing.
 *
 * @param normal The normal to calculate from.
 * @return The direction the normal is facing.
 */
public static int findSide(Vector3 normal) {
    if (normal.y <= -0.99) {
        return 0;
    }
    if (normal.y >= 0.99) {
        return 1;
    }
    if (normal.z <= -0.99) {
        return 2;
    }
    if (normal.z >= 0.99) {
        return 3;
    }
    if (normal.x <= -0.99) {
        return 4;
    }
    if (normal.x >= 0.99) {
        return 5;
    }
    return -1;
}
 
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: Quad.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Re-calculates the Orientation of this quad,
 * optionally the normal vector.
 *
 * @param setNormal If the normal vector should be updated.
 */
public void calculateOrientation(boolean setNormal) {
    v1.set(vertices[3].vec).subtract(t.set(vertices[1].vec));
    v2.set(vertices[2].vec).subtract(t.set(vertices[0].vec));

    Vector3 normal = v2.crossProduct(v1).normalize();

    if (format.hasNormal && setNormal) {
        for (Vertex vertex : vertices) {
            vertex.normal[0] = (float) normal.x;
            vertex.normal[1] = (float) normal.y;
            vertex.normal[2] = (float) normal.z;
            vertex.normal[3] = 0;
        }
    }
    orientation = Direction.getFacingFromVector(normal.x, normal.y, normal.z);
}
 
Example #4
Source File: AbstractBakedPropertiesModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
protected boolean checkDepth(BakedQuad quad, Vector3 hit, Direction hitFace) {
    int[] quadData = quad.getVertexData();
    CachedFormat format = CachedFormat.lookup(DefaultVertexFormats.BLOCK);

    Vector3 posVec = new Vector3();
    float[] pos = new float[4];
    for (int v = 0; v < 4; v++) {
        LightUtil.unpack(quadData, pos, format.format, v, format.positionIndex);
        posVec.add(pos[0], pos[1], pos[2]);
    }
    posVec.divide(4);

    double diff = 0;
    switch (hitFace.getAxis()) {
        case X:
            diff = Math.abs(hit.x - posVec.x);
            break;
        case Y:
            diff = Math.abs(hit.y - posVec.y);
            break;
        case Z:
            diff = Math.abs(hit.z - posVec.z);
            break;
    }
    return !(diff > 0.01);
}
 
Example #5
Source File: EnderDyeButton.java    From EnderStorage with MIT License 6 votes vote down vote up
public EnderDyeButton(int index)
{
    button = index;
    
    verts = new Vector3[8];
    verts[0] = new Vector3(0, -0.25, -0.0625);
    verts[1] = new Vector3(0.125, -0.25, -0.0625);
    verts[2] = new Vector3(0.125, -0.25, 0);
    verts[3] = new Vector3(0, -0.25, 0);
    verts[4] = new Vector3(0, 0, -0.0625);
    verts[5] = new Vector3(0.125, 0, -0.0625);
    verts[6] = new Vector3(0.125, 0, 0);
    verts[7] = new Vector3(0, 0, 0);
    
    for(int i = 0; i < 8; i++)
    {
        verts[i].add(0.25 + 0.1875*index, -0.375, 0.9375);
    }

    Quat quat2 = Quat.aroundAxis(1, 0, 0, -0.5 * 3.14159);
    for(int i = 0; i < 8; i++)
    {
        quat2.rotate(verts[i]);
    }
}
 
Example #6
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 #7
Source File: BlockTranslocator.java    From Translocators with MIT License 6 votes vote down vote up
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ) {
    if (world.isRemote)
        return true;

    MovingObjectPosition hit = RayTracer.retraceBlock(world, player, x, y, z);
    TileTranslocator ttrans = (TileTranslocator) world.getTileEntity(x, y, z);

    if (hit != null) {
        if (hit.subHit < 6) {
            Vector3 vhit = new Vector3(hit.hitVec);
            vhit.add(-x - 0.5, -y - 0.5, -z - 0.5);
            vhit.apply(sideRotations[hit.subHit % 6].inverse());
            if (MathHelper.between(-2 / 16D, vhit.x, 2 / 16D) && MathHelper.between(-2 / 16D, vhit.z, 2 / 16D))
                hit.subHit += 6;
        }

        return ttrans.attachments[hit.subHit % 6].activate(player, hit.subHit / 6);
    }

    return false;
}
 
Example #8
Source File: ParticleHandlerUtil.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
public static void addBlockLandingEffects(World worldObj, Vector3 entityPos, TextureAtlasSprite atlasSprite, int spriteColor, ParticleManager manager, int numParticles) {
    Vector3 start = entityPos.copy();
    Vector3 end = start.copy().add(Vector3.down.copy().multiply(4));
    RayTraceResult traceResult = worldObj.rayTraceBlocks(start.vec3(), end.vec3(), true, false, true);
    double speed = 0.15;
    Random randy = new Random();

    float red = (spriteColor >> 16 & 255) / 255.0F;
    float green = (spriteColor >> 8 & 255) / 255.0F;
    float blue = (spriteColor & 255) / 255.0F;

    if (traceResult != null && traceResult.typeOfHit == Type.BLOCK && numParticles != 0) {
        for (int i = 0; i < numParticles; i++) {
            double mX = randy.nextGaussian() * speed;
            double mY = randy.nextGaussian() * speed;
            double mZ = randy.nextGaussian() * speed;
            DigIconParticle digIconParticle = DigIconParticle.newLandingParticle(worldObj, entityPos.x, entityPos.y, entityPos.z, mX, mY, mZ, atlasSprite);
            digIconParticle.setRBGColorF(red, green, blue);
            manager.addEffect(digIconParticle);
        }
    }
}
 
Example #9
Source File: EnderDyeButton.java    From EnderStorage with MIT License 6 votes vote down vote up
public Vector3 getMax()
{
    int maxindex = 0;
    double maxdist = 0;
    for(int i = 0; i < 8; i++)
    {
        double dist = verts[i].x + verts[i].y + verts[i].z;
        if(dist > maxdist)
        {
            maxdist = dist;
            maxindex = i;
        }
    }
    
    return verts[maxindex];
}
 
Example #10
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 #11
Source File: PartPressureTube.java    From PneumaticCraft with GNU General Public License v3.0 6 votes vote down vote up
@SideOnly(Side.CLIENT)
@Override
public void renderDynamic(Vector3 pos, float partialTicks, int renderPass){
    if(renderPass == 0) {
        /*   GL11.glPushMatrix(); // start
           // GL11.glDisable(GL11.GL_TEXTURE_2D);
           // GL11.glEnable(GL11.GL_BLEND);
           // GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
           FMLClientHandler.instance().getClient().getTextureManager().bindTexture(getTexture());

           // GL11.glColor4f(0.82F, 0.56F, 0.09F, 1.0F);
           GL11.glTranslatef((float)pos.x + 0.5F, (float)pos.y + 1.5F, (float)pos.z + 0.5F); // size
           GL11.glRotatef(0, 0.0F, 1.0F, 0.0F);

           GL11.glScalef(1.0F, -1F, -1F);
           if(tubeModel == null) tubeModel = new ModelPressureTube();
           tubeModel.renderModel(0.0625F, tube.sidesConnected);
           GL11.glPopMatrix();*/
        TileEntityRendererDispatcher.instance.getSpecialRenderer(tube).renderTileEntityAt(tube, pos.x, pos.y, pos.z, partialTicks);

    }
}
 
Example #12
Source File: FluidPipeRenderer.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) {
    CCRenderState renderState = CCRenderState.instance();
    renderState.reset();
    renderState.bind(buffer);
    renderState.setPipeline(new Vector3(new Vec3d(pos)).translation(), new IconTransformation(sprite));
    BlockFluidPipe blockFluidPipe = (BlockFluidPipe) state.getBlock();
    IPipeTile<FluidPipeType, FluidPipeProperties> tileEntityPipe = blockFluidPipe.getPipeTileEntity(world, pos);
    if (tileEntityPipe == null) {
        return;
    }
    FluidPipeType fluidPipeType = tileEntityPipe.getPipeType();
    if (fluidPipeType == null) {
        return;
    }
    float thickness = fluidPipeType.getThickness();
    int connectedSidesMask = blockFluidPipe.getActualConnections(tileEntityPipe, world);
    Cuboid6 baseBox = BlockFluidPipe.getSideBox(null, thickness);
    BlockRenderer.renderCuboid(renderState, baseBox, 0);
    for (EnumFacing renderSide : EnumFacing.VALUES) {
        if ((connectedSidesMask & (1 << renderSide.getIndex())) > 0) {
            Cuboid6 sideBox = BlockFluidPipe.getSideBox(renderSide, thickness);
            BlockRenderer.renderCuboid(renderState, sideBox, 0);
        }
    }
}
 
Example #13
Source File: RenderUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
public static void renderFluidGauge(FluidStack stack, Rectangle4i rect, double density, double res) {
    if (!shouldRenderFluid(stack))
        return;

    int alpha = 255;
    if (stack.getFluid().isGaseous())
        alpha = (int) (fluidDensityToAlpha(density) * 255);
    else {
        int height = (int) (rect.h * density);
        rect.y += rect.h - height;
        rect.h = height;
    }

    TextureAtlasSprite tex = prepareFluidRender(stack, alpha);
    CCRenderState.startDrawing();
    renderFluidQuad(
            new Vector3(rect.x, rect.y + rect.h, 0),
            new Vector3(rect.w, 0, 0),
            new Vector3(0, -rect.h, 0), tex, res);
    CCRenderState.draw();
    postFluidRender();
}
 
Example #14
Source File: InvPipeRenderer.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) {
    CCRenderState renderState = CCRenderState.instance();
    renderState.reset();
    renderState.bind(buffer);
    renderState.setPipeline(new Vector3(new Vec3d(pos)).translation(), new IconTransformation(sprite));
    BlockInventoryPipe block = (BlockInventoryPipe) state.getBlock();
    TileEntityInventoryPipe tileEntity = (TileEntityInventoryPipe) block.getPipeTileEntity(world, pos);
    if (tileEntity == null) {
        return;
    }
    InventoryPipeType pipeType = tileEntity.getPipeType();
    if (pipeType == null) {
        return;
    }
    float thickness = pipeType.getThickness();
    int connectedSidesMask = block.getActualConnections(tileEntity, world);
    Cuboid6 baseBox = BlockPipe.getSideBox(null, thickness);
    BlockRenderer.renderCuboid(renderState, baseBox, 0);
    for (EnumFacing renderSide : EnumFacing.VALUES) {
        if ((connectedSidesMask & (1 << renderSide.getIndex())) > 0) {
            Cuboid6 sideBox = BlockPipe.getSideBox(renderSide, thickness);
            BlockRenderer.renderCuboid(renderState, sideBox, 0);
        }
    }
}
 
Example #15
Source File: CustomParticleHandler.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
@OnlyIn (Dist.CLIENT)
public static void addLandingEffects(World world, BlockPos pos, BlockState state, Vector3 entityPos, int numParticles) {
    //Spoof a raytrace from the feet.
    BlockRayTraceResult traceResult = new BlockRayTraceResult(new Vec3d(entityPos.x, pos.getY() + 1, entityPos.z), Direction.UP, pos, false);
    ParticleManager manager = Minecraft.getInstance().particles;
    Random randy = new Random();
    BlockModelShapes modelShapes = Minecraft.getInstance().getBlockRendererDispatcher().getBlockModelShapes();
    IBakedModel model = modelShapes.getModel(state);
    if (model instanceof IModelParticleProvider) {
        IModelData modelData = ModelDataManager.getModelData(world, pos);
        List<TextureAtlasSprite> sprites = new ArrayList<>(((IModelParticleProvider) model).getHitEffects(traceResult, state, world, pos, modelData));

        double speed = 0.15000000596046448D;
        if (numParticles != 0) {
            for (int i = 0; i < numParticles; i++) {
                double mX = randy.nextGaussian() * speed;
                double mY = randy.nextGaussian() * speed;
                double mZ = randy.nextGaussian() * speed;
                manager.addEffect(CustomBreakingParticle.newLandingParticle(world, entityPos.x, entityPos.y, entityPos.z, mX, mY, mZ, sprites.get(randy.nextInt(sprites.size()))));
            }
        }
    }
}
 
Example #16
Source File: RenderWireless.java    From WirelessRedstone with MIT License 6 votes vote down vote up
public static void renderPearl(Vector3 pos, WirelessPart p) {
    GL11.glPushMatrix();

    pos.translation().glApply();
    p.rotationT().at(center).glApply();
    p.getPearlPos().translation().glApply();
    p.getPearlRotation().glApply();
    new Scale(p.getPearlScale()).glApply();
    float light = 1;
    if (p.tile() != null) {
        GL11.glRotatef((float) (p.getPearlSpin() * MathHelper.todeg), 0, 1, 0);
        light = p.getPearlLight();
    }

    GL11.glDisable(GL11.GL_LIGHTING);
    CCRenderState.reset();
    CCRenderState.changeTexture("wrcbe_core:textures/hedronmap.png");
    CCRenderState.pullLightmap();
    CCRenderState.setColour(new ColourRGBA(light, light, light, 1).rgba());
    CCRenderState.startDrawing(4);
    CCModelLibrary.icosahedron4.render();
    CCRenderState.draw();
    GL11.glEnable(GL11.GL_LIGHTING);

    GL11.glPopMatrix();
}
 
Example #17
Source File: LightModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * @param colour The pre-lighting vertex colour. RGBA format
 * @param normal The normal at the vertex
 * @return The lighting applied colour
 */
public int apply(int colour, Vector3 normal) {
    Vector3 n_colour = ambient.copy();
    for (int l = 0; l < lightCount; l++) {
        Light light = lights[l];
        double n_l = light.position.dotProduct(normal);
        double f = n_l > 0 ? 1 : 0;
        n_colour.x += light.ambient.x + f * light.diffuse.x * n_l;
        n_colour.y += light.ambient.y + f * light.diffuse.y * n_l;
        n_colour.z += light.ambient.z + f * light.diffuse.z * n_l;
    }

    if (n_colour.x > 1)
        n_colour.x = 1;
    if (n_colour.y > 1)
        n_colour.y = 1;
    if (n_colour.z > 1)
        n_colour.z = 1;

    n_colour.multiply((colour >>> 24) / 255D, (colour >> 16 & 0xFF) / 255D, (colour >> 8 & 0xFF) / 255D);
    return (int) (n_colour.x * 255) << 24 | (int) (n_colour.y * 255) << 16 | (int) (n_colour.z * 255) << 8 | colour & 0xFF;
}
 
Example #18
Source File: EnderKnobSlot.java    From EnderStorage with MIT License 6 votes vote down vote up
public static AxisAlignedBB cornersToAABB(Vector3[] corners)
{
    Vector3 min = corners[0].copy();
    Vector3 max = corners[0].copy();
    for(int i = 1; i < corners.length; i++)
    {
        Vector3 vec = corners[i];
        if(vec.x < min.x)
            min.x = vec.x;
        else if(vec.x > max.x)
            max.x = vec.x;
        if(vec.y < min.y)
            min.y = vec.y;
        else if(vec.y > max.y)
            max.y = vec.y;
        if(vec.z < min.z)
            min.z = vec.z;
        else if(vec.z > max.z)
            max.z = vec.z;
    }
    return AxisAlignedBB.getBoundingBox(min.x, min.y, min.z, max.x, max.y, max.z);
}
 
Example #19
Source File: WirelessBolt.java    From WirelessRedstone with MIT License 6 votes vote down vote up
private float rayTraceResistance(Vector3 start, Vector3 end, float prevresistance) {
    MovingObjectPosition mop = world.rayTraceBlocks(start.toVec3D(), end.toVec3D());

    if (mop == null)
        return prevresistance;

    if (mop.typeOfHit == MovingObjectType.BLOCK) {
        Block block = world.getBlock(mop.blockX, mop.blockY, mop.blockZ);
        if (block.isAir(world, mop.blockX, mop.blockY, mop.blockZ))
            return prevresistance;
        
        /*if(Block.blocksList[blockID] instanceof ISpecialResistance) 
        {
            ISpecialResistance isr = (ISpecialResistance) Block.blocksList[blockID];
             return prevresistance + (isr.getSpecialExplosionResistance(world, mop.blockX, mop.blockY, mop.blockZ, 
                     start.x, start.y, start.z, wrapper) + 0.3F);
        } 
        else 
        {*/
        return prevresistance + block.getExplosionResistance(wrapper) + 0.3F;
        //}
    }
    return prevresistance;
}
 
Example #20
Source File: EnderKnobSlot.java    From EnderStorage with MIT License 6 votes vote down vote up
public EnderKnobSlot(int meta) {
    Vector3[] verts = new Vector3[8];
    verts[0] = new Vector3(-0.0625, 0.4375, -0.5);
    verts[1] = new Vector3(0.0625, 0.4375, -0.5);
    verts[3] = new Vector3(-0.0625, 0.4375, -0.4375);
    verts[2] = new Vector3(0.0625, 0.4375, -0.4375);
    verts[5] = new Vector3(-0.0625, 0.6875, -0.5);
    verts[4] = new Vector3(0.0625, 0.6875, -0.5);
    verts[6] = new Vector3(-0.0625, 0.6875, -0.4375);
    verts[7] = new Vector3(0.0625, 0.6875, -0.4375);

    for (int i = 0; i < 8; i++) {
        verts[i].rotate((meta + 2) * -0.5 * 3.14159, new Vector3(0, 1, 0));
        verts[i].add(0.5, 0, 0.5);
    }

    aabb = cornersToAABB(verts);
}
 
Example #21
Source File: LightModel.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * @param colour The pre-lighting vertex colour. RGBA format
 * @param normal The normal at the vertex
 * @return The lighting applied colour
 */
public int apply(int colour, Vector3 normal) {
    Vector3 n_colour = ambient.copy();
    for (int l = 0; l < lightCount; l++) {
        Light light = lights[l];
        double n_l = light.position.dotProduct(normal);
        double f = n_l > 0 ? 1 : 0;
        n_colour.x += light.ambient.x + f * light.diffuse.x * n_l;
        n_colour.y += light.ambient.y + f * light.diffuse.y * n_l;
        n_colour.z += light.ambient.z + f * light.diffuse.z * n_l;
    }

    if (n_colour.x > 1) {
        n_colour.x = 1;
    }
    if (n_colour.y > 1) {
        n_colour.y = 1;
    }
    if (n_colour.z > 1) {
        n_colour.z = 1;
    }

    n_colour.multiply((colour >>> 24) / 255D, (colour >> 16 & 0xFF) / 255D, (colour >> 8 & 0xFF) / 255D);
    return (int) (n_colour.x * 255) << 24 | (int) (n_colour.y * 255) << 16 | (int) (n_colour.z * 255) << 8 | colour & 0xFF;
}
 
Example #22
Source File: WirelessBolt.java    From WirelessRedstone with MIT License 6 votes vote down vote up
private void vecBBDamageSegment(Vector3 start, Vector3 end, ArrayList<Entity> entitylist) {
    Vec3 start3D = start.toVec3D();
    Vec3 end3D = end.toVec3D();

    for (Iterator<Entity> iterator = entitylist.iterator(); iterator.hasNext(); ) {
        Entity entity = iterator.next();
        if (entity instanceof EntityLivingBase &&
                (entity.boundingBox.isVecInside(start3D) || entity.boundingBox.isVecInside(end3D))) {
            if (entity instanceof EntityPlayer)
                entity.attackEntityFrom(WirelessRedstoneCore.damagebolt, playerdamage);
            else
                entity.attackEntityFrom(WirelessRedstoneCore.damagebolt, entitydamage);

            ether.jamEntity((EntityLivingBase) entity, true);
        }
    }
}
 
Example #23
Source File: LC.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
public LC compute(Vector3 vec, int side) {
    boolean offset = false;
    switch (side) {
        case 0:
            offset = vec.y <= 0;
            break;
        case 1:
            offset = vec.y >= 1;
            break;
        case 2:
            offset = vec.z <= 0;
            break;
        case 3:
            offset = vec.z >= 1;
            break;
        case 4:
            offset = vec.x <= 0;
            break;
        case 5:
            offset = vec.x >= 1;
            break;
    }
    if (!offset)
        side += 6;
    return computeO(vec, side);
}
 
Example #24
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 #25
Source File: RayTracer.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Ray traces from start to end, if the ray intercepts the cuboid it returns a new CuboidRayTraceResult.
 *
 * @param pos    The BlockPosition to subtract from the start and end vector.
 * @param start  The vector to start RayTracing from.
 * @param end    The vector to end RayTracing at.
 * @param cuboid The cuboid to check for an intercept.
 * @return A new CuboidRayTraceResult if successful, null if fail.
 */
public static CuboidRayTraceResult rayTrace(BlockPos pos, Vector3 start, Vector3 end, IndexedCuboid6 cuboid) {
    BlockRayTraceResult bbResult = VoxelShapes.create(cuboid.aabb()).rayTrace(start.vec3(), end.vec3(), pos);

    if (bbResult != null) {
        Vector3 hitVec = new Vector3(bbResult.getHitVec());
        Direction sideHit = bbResult.getFace();
        double dist = hitVec.copy().subtract(start).magSquared();
        return new CuboidRayTraceResult(hitVec, sideHit, pos, bbResult.isInside(), cuboid, dist);
    }
    return null;
}
 
Example #26
Source File: TileTranslocatorRenderer.java    From Translocators with MIT License 5 votes vote down vote up
private static Vector3 getPathNormal(int src, int dst, double d)
{
    if((src^1) == dst)
        return sideVec[(src+4)%6].copy();
    
    double sind = MathHelper.sin(d*Math.PI/2);
    double cosd = MathHelper.cos(d*Math.PI/2);

    Vector3 vsrc = sideVec[src^1].copy();
    Vector3 vdst = sideVec[dst^1].copy();
    
    return vsrc.multiply(sind).add(vdst.multiply(cosd)).normalize();
}
 
Example #27
Source File: EnderTankRenderer.java    From EnderStorage with MIT License 5 votes vote down vote up
public static void renderLiquid(FluidStack liquid, double x, double y, double z)
{
    RenderUtils.renderFluidCuboid(liquid, 
            new Cuboid6(0.22, 0.12, 0.22, 0.78, 0.121+0.63, 0.78)
                .add(new Vector3(x, y, z)), 
            liquid.amount/(16D*FluidUtils.B), 0.75);
}
 
Example #28
Source File: ReceiverPart.java    From WirelessRedstone with MIT License 5 votes vote down vote up
@Override
public Vector3 getPearlPos()
{
    return new Vector3(0, getFloating()*0.02, 0)
        .apply(getPearlRotation())
        .add(0.5, 0.755, 0.545);
}
 
Example #29
Source File: LC.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public LC computeO(Vector3 vec, int side) {
    Vector3 v1 = Rotation.axes[((side & 0xE) + 3) % 6];
    Vector3 v2 = Rotation.axes[((side & 0xE) + 5) % 6];
    float d1 = (float) vec.scalarProject(v1);
    float d2 = 1 - d1;
    float d3 = (float) vec.scalarProject(v2);
    float d4 = 1 - d3;
    return set(side, d2 * d4, d2 * d3, d1 * d4, d1 * d3);
}
 
Example #30
Source File: RayTracer.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
public void rayTraceCuboids(Vector3 start, Vector3 end, List<IndexedCuboid6> cuboids, BlockCoord pos, Block block, List<ExtendedMOP> hitList) {
    for (IndexedCuboid6 cuboid : cuboids) {
        ExtendedMOP mop = rayTraceCuboid(start, end, cuboid, pos, cuboid.data);
        if (mop != null)
            hitList.add(mop);
    }
}