Java Code Examples for net.minecraft.util.math.MathHelper#getPositionRandom()

The following examples show how to use net.minecraft.util.math.MathHelper#getPositionRandom() . 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: BlockModelRendererSchematic.java    From litematica with GNU Lesser General Public License v3.0 6 votes vote down vote up
public boolean renderModel(IBlockAccess worldIn, IBakedModel modelIn, IBlockState stateIn, BlockPos posIn, BufferBuilder buffer)
{
    boolean ao = Minecraft.isAmbientOcclusionEnabled() && stateIn.getLightValue() == 0 && modelIn.isAmbientOcclusion();
    long rand = MathHelper.getPositionRandom(posIn);

    try
    {
        if (ao)
        {
            return this.renderModelSmooth(worldIn, modelIn, stateIn, posIn, buffer, rand);
        }
        else
        {
            return this.renderModelFlat(worldIn, modelIn, stateIn, posIn, buffer, rand);
        }
    }
    catch (Throwable throwable)
    {
        CrashReport crashreport = CrashReport.makeCrashReport(throwable, "Tesselating block model");
        CrashReportCategory crashreportcategory = crashreport.makeCategory("Block model being tesselated");
        CrashReportCategory.addBlockInfo(crashreportcategory, posIn, stateIn);
        crashreportcategory.addCrashSection("Using AO", Boolean.valueOf(ao));
        throw new ReportedException(crashreport);
    }
}
 
Example 2
Source File: MetaTileEntityRenderer.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) {
    MetaTileEntity metaTileEntity = BlockMachine.getMetaTileEntity(world, pos);
    if (metaTileEntity == null) {
        return false;
    }
    CCRenderState renderState = CCRenderState.instance();
    renderState.reset();
    renderState.bind(buffer);
    Matrix4 translation = new Matrix4().translate(pos.getX(), pos.getY(), pos.getZ());
    BlockRenderLayer renderLayer = MinecraftForgeClient.getRenderLayer();
    if (metaTileEntity.canRenderInLayer(renderLayer)) {
        renderState.lightMatrix.locate(world, pos);
        IVertexOperation[] pipeline = new IVertexOperation[]{renderState.lightMatrix};
        metaTileEntity.renderMetaTileEntity(renderState, translation.copy(), pipeline);
    }
    Matrix4 coverTranslation = new Matrix4().translate(pos.getX(), pos.getY(), pos.getZ());
    metaTileEntity.renderCovers(renderState, coverTranslation, renderLayer);

    if (metaTileEntity.isFragile() && renderLayer == BlockRenderLayer.CUTOUT) {
        TextureMap textureMap = Minecraft.getMinecraft().getTextureMapBlocks();
        Random posRand = new Random(MathHelper.getPositionRandom(pos));
        int destroyStage = posRand.nextInt(10);
        TextureAtlasSprite atlasSprite = textureMap.getAtlasSprite("minecraft:blocks/destroy_stage_" + destroyStage);
        for (EnumFacing face : EnumFacing.VALUES) {
            Textures.renderFace(renderState, translation, new IVertexOperation[0], face, Cuboid6.full, atlasSprite);
        }
    }
    return true;
}
 
Example 3
Source File: StoneRenderer.java    From GregTech with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static CCModel getActualModel(IBlockAccess world, BlockPos pos) {
    TileEntitySurfaceRock tileEntity = BlockSurfaceRockNew.getTileEntity(world, pos);
    if (tileEntity != null) {
        if (tileEntity.cachedModel == null) {
            Random random = new Random(MathHelper.getPositionRandom(pos));
            tileEntity.cachedModel = generateModel(random);
        }
        return (CCModel) tileEntity.cachedModel;
    }
    return placeholderModels[0];
}
 
Example 4
Source File: RenderUtils.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Assumes a BufferBuilder in the GL_LINES mode has been initialized
 */
public static void drawBlockModelOutlinesBatched(IBakedModel model, IBlockState state, BlockPos pos, Color4f color, BufferBuilder buffer)
{
    long rand = MathHelper.getPositionRandom(pos);

    for (final EnumFacing side : PositionUtils.FACING_ALL)
    {
        renderModelQuadOutlines(pos, buffer, color, model.getQuads(state, side, rand));
    }

    renderModelQuadOutlines(pos, buffer, color, model.getQuads(state, null, rand));
}
 
Example 5
Source File: RenderUtils.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static void drawBlockModelQuadOverlayBatched(IBakedModel model, IBlockState state, BlockPos pos, Color4f color, double expand, BufferBuilder buffer)
{
    long rand = MathHelper.getPositionRandom(pos);

    for (final EnumFacing side : PositionUtils.FACING_ALL)
    {
        renderModelQuadOverlayBatched(pos, buffer, color, model.getQuads(state, side, rand));
    }

    renderModelQuadOverlayBatched(pos, buffer, color, model.getQuads(state, null, rand));
}
 
Example 6
Source File: RenderUtils.java    From litematica with GNU Lesser General Public License v3.0 4 votes vote down vote up
public static void drawBlockModelQuadOverlayBatched(IBakedModel model, IBlockState state, BlockPos pos, EnumFacing side, Color4f color, double expand, BufferBuilder buffer)
{
    long rand = MathHelper.getPositionRandom(pos);
    renderModelQuadOverlayBatched(pos, buffer, color, model.getQuads(state, side, rand));
}