codechicken.lib.vec.Translation Java Examples

The following examples show how to use codechicken.lib.vec.Translation. 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: InvPipeRenderer.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean renderBlock(IBlockAccess world, BlockPos pos, IBlockState state, BufferBuilder buffer) {
    CCRenderState renderState = CCRenderState.instance();
    renderState.reset();
    renderState.bind(buffer);
    renderState.setBrightness(world, pos);
    IVertexOperation[] pipeline = {new Translation(pos)};

    BlockInventoryPipe block = (BlockInventoryPipe) state.getBlock();
    TileEntityInventoryPipe tileEntity = (TileEntityInventoryPipe) block.getPipeTileEntity(world, pos);
    if (tileEntity == null) {
        return false;
    }
    int paintingColor = tileEntity.getInsulationColor();
    int connectedSidesMask = block.getActualConnections(tileEntity, world);

    BlockRenderLayer renderLayer = MinecraftForgeClient.getRenderLayer();
    if (renderLayer == BlockRenderLayer.SOLID) {
        renderPipe(renderState, pipeline, paintingColor, connectedSidesMask);
    }
    ICoverable coverable = tileEntity.getCoverableImplementation();
    coverable.renderCovers(renderState, new Matrix4().translate(pos.getX(), pos.getY(), pos.getZ()), renderLayer);
    return true;
}
 
Example #2
Source File: CableRenderer.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public boolean renderBlock(IBlockAccess world, BlockPos pos, IBlockState state, BufferBuilder buffer) {
    CCRenderState renderState = CCRenderState.instance();
    renderState.reset();
    renderState.bind(buffer);
    renderState.setBrightness(world, pos);
    IVertexOperation[] pipeline = {new Translation(pos)};

    BlockCable blockCable = (BlockCable) state.getBlock();
    TileEntityCable tileEntityCable = (TileEntityCable) blockCable.getPipeTileEntity(world, pos);
    if (tileEntityCable == null) return false;
    int paintingColor = tileEntityCable.getInsulationColor();
    int connectedSidesMask = blockCable.getActualConnections(tileEntityCable, world);
    Insulation insulation = tileEntityCable.getPipeType();
    Material material = tileEntityCable.getPipeMaterial();
    if (insulation != null && material != null) {
        BlockRenderLayer renderLayer = MinecraftForgeClient.getRenderLayer();
        if (renderLayer == BlockRenderLayer.CUTOUT) {
            renderCableBlock(material, insulation, paintingColor, renderState, pipeline, connectedSidesMask);
        }
        ICoverable coverable = tileEntityCable.getCoverableImplementation();
        coverable.renderCovers(renderState, new Matrix4().translate(pos.getX(), pos.getY(), pos.getZ()), renderLayer);
    }
    return true;
}
 
Example #3
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 #4
Source File: TextureArea.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static Transformation createOrientation(Size areaSize, int orientation) {
    Transformation transformation = new Rotation(Math.toRadians(orientation * 90.0), 0.0, 0.0, 1.0)
        .at(new Vector3(areaSize.width / 2.0, areaSize.height / 2.0, 0.0));
    Size orientedSize = transformSize(transformation, areaSize);
    double offsetX = (areaSize.width - orientedSize.width) / 2.0;
    double offsetY = (areaSize.height - orientedSize.height) / 2.0;
    return transformation.with(new Translation(-offsetX, -offsetY, 0.0));
}
 
Example #5
Source File: FluidPipeRenderer.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean renderBlock(IBlockAccess world, BlockPos pos, IBlockState state, BufferBuilder buffer) {
    CCRenderState renderState = CCRenderState.instance();
    renderState.reset();
    renderState.bind(buffer);
    renderState.setBrightness(world, pos);

    BlockFluidPipe blockPipe = ((BlockFluidPipe) state.getBlock());
    TileEntityFluidPipe tileEntityPipe = (TileEntityFluidPipe) blockPipe.getPipeTileEntity(world, pos);

    if (tileEntityPipe == null) {
        return false;
    }

    FluidPipeType fluidPipeType = tileEntityPipe.getPipeType();
    Material pipeMaterial = tileEntityPipe.getPipeMaterial();
    int paintingColor = tileEntityPipe.getInsulationColor();

    if (fluidPipeType != null && pipeMaterial != null) {
        BlockRenderLayer renderLayer = MinecraftForgeClient.getRenderLayer();

        if (renderLayer == BlockRenderLayer.CUTOUT) {
            int connectedSidesMask = blockPipe.getActualConnections(tileEntityPipe, world);
            IVertexOperation[] pipeline = new IVertexOperation[] {new Translation(pos)};
            renderPipeBlock(pipeMaterial, fluidPipeType, paintingColor, renderState, pipeline, connectedSidesMask);
        }

        ICoverable coverable = tileEntityPipe.getCoverableImplementation();
        coverable.renderCovers(renderState, new Matrix4().translate(pos.getX(), pos.getY(), pos.getZ()), renderLayer);
    }
    return true;
}
 
Example #6
Source File: RenderTileEnderChest.java    From EnderStorage with MIT License 5 votes vote down vote up
public static void renderChest(CCRenderState ccrs, MatrixStack mStack, IRenderTypeBuffer getter, int rotation, double yToCamera, Frequency freq, float lidAngle, int pearlOffset) {
    Matrix4 mat = new Matrix4(mStack);
    if (lidAngle != 0) {//Micro optimization, lid closed, dont render starfield.
        renderEndPortal.render(mat, getter, yToCamera);
    }
    ccrs.reset();
    mStack.push();
    mStack.translate(0, 1.0, 1.0);
    mStack.scale(1.0F, -1.0F, -1.0F);
    mStack.translate(0.5, 0.5, 0.5);
    mStack.rotate(new Quaternion(0, rotation * 90, 0, true));
    mStack.translate(-0.5, -0.5, -0.5);
    model.chestLid.rotateAngleX = lidAngle;
    model.render(mStack, getter.getBuffer(chestType), ccrs.brightness, ccrs.overlay, freq.hasOwner());
    mStack.pop();

    //Buttons
    ccrs.bind(buttonType, getter);
    EnumColour[] colours = freq.toArray();
    for (int i = 0; i < 3; i++) {
        CCModel button = ButtonModelLibrary.button.copy();
        button.apply(BlockEnderChest.buttonT[i]);
        button.apply(new Translation(0.5, 0, 0.5));
        button.apply(new Rotation(lidAngle, 1, 0, 0).at(new Vector3(0, 9D / 16D, 1 / 16D)));
        button.apply(new Rotation((-90 * (rotation)) * MathHelper.torad, Vector3.Y_POS).at(new Vector3(0.5, 0, 0.5)));
        button.render(ccrs, mat, new UVTranslation(0.25 * (colours[i].getWoolMeta() % 4), 0.25 * (colours[i].getWoolMeta() / 4)));
    }
    mat.translate(0.5, 0, 0.5);

    //Pearl
    if (lidAngle != 0) {//Micro optimization, lid closed, dont render pearl.
        double time = ClientUtils.getRenderTime() + pearlOffset;
        Matrix4 pearlMat = RenderUtils.getMatrix(mat.copy(), new Vector3(0, 0.2 + lidAngle * -0.5 + RenderUtils.getPearlBob(time), 0), new Rotation(time / 3, new Vector3(0, 1, 0)), 0.04);
        ccrs.brightness = 15728880;
        ccrs.bind(pearlType, getter);
        CCModelLibrary.icosahedron4.render(ccrs, pearlMat);
    }
    ccrs.reset();
}
 
Example #7
Source File: RenderWireless.java    From WirelessRedstone with MIT License 5 votes vote down vote up
public static void renderWorld(WirelessPart p) {
    CCRenderState.setBrightness(p.world(), p.x(), p.y(), p.z());

    Transformation t = new Translation(p.x(), p.y(), p.z());
    CCRenderState.setPipeline(p.rotationT().at(center).with(t), base_icont[p.textureSet()], rlm);
    BlockRenderer.renderCuboid(p.baseRenderBounds, p.baseRenderMask);
    models[p.modelId()][p.side() << 2 | p.rotation()].render(t, model_icont);
}
 
Example #8
Source File: WorldSceneRenderer.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Renders scene on given coordinates with given width and height, and RGB background color
 * Note that this will ignore any transformations applied currently to projection/view matrix,
 * so specified coordinates are scaled MC gui coordinates.
 * It will return matrices of projection and view in previous state after rendering
 */
public void render(int x, int y, int width, int height, int backgroundColor) {
    Vec2f mousePosition = setupCamera(x, y, width, height, backgroundColor);
    if (renderCallback != null) {
        renderCallback.preRenderScene(this);
    }
    Minecraft minecraft = Minecraft.getMinecraft();
    minecraft.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    BlockRendererDispatcher dispatcher = minecraft.getBlockRendererDispatcher();
    BlockRenderLayer oldRenderLayer = MinecraftForgeClient.getRenderLayer();
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder bufferBuilder = tessellator.getBuffer();

    bufferBuilder.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
    for (BlockPos pos : renderedBlocks) {
        if (renderFilter != null && !renderFilter.test(pos))
            continue; //do not render if position is skipped
        IBlockState blockState = world.getBlockState(pos);
        for(BlockRenderLayer renderLayer : BlockRenderLayer.values()) {
            if (!blockState.getBlock().canRenderInLayer(blockState, renderLayer)) continue;
            ForgeHooksClient.setRenderLayer(renderLayer);
            dispatcher.renderBlock(blockState, pos, world, bufferBuilder);
        }
    }
    tessellator.draw();
    ForgeHooksClient.setRenderLayer(oldRenderLayer);

    if (mousePosition != null) {
        this.lastHitBlock = handleMouseHit(mousePosition);
    } else {
        this.lastHitBlock = null;
    }

    if (lastHitBlock != null) {
        GlStateManager.disableTexture2D();
        CCRenderState renderState = CCRenderState.instance();
        renderState.startDrawing(GL11.GL_QUADS, DefaultVertexFormats.POSITION_COLOR, tessellator.getBuffer());
        ColourMultiplier multiplier = new ColourMultiplier(0);
        renderState.setPipeline(new Translation(lastHitBlock), multiplier);
        BlockFace blockFace = new BlockFace();
        renderState.setModel(blockFace);
        for (EnumFacing renderSide : EnumFacing.VALUES) {
            float diffuse = LightUtil.diffuseLight(renderSide);
            int color = (int) (255 * diffuse);
            multiplier.colour = RenderUtil.packColor(color, color, color, 100);
            blockFace.loadCuboidFace(Cuboid6.full, renderSide.getIndex());
            renderState.render();
        }
        renderState.draw();
        GlStateManager.enableTexture2D();
    }

    resetCamera();
}