Java Code Examples for net.minecraft.util.BlockRenderLayer#values()

The following examples show how to use net.minecraft.util.BlockRenderLayer#values() . 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: MultiLayerModel.java    From OpenModsLib with MIT License 6 votes vote down vote up
public MultiLayerBakedModel(Map<BlockRenderLayer, IBakedModel> models, IBakedModel base, IBakedModel missing, ImmutableMap<TransformType, TRSRTransformation> cameraTransforms) {
	super(base, cameraTransforms);
	this.models = ImmutableMap.copyOf(models);
	this.missing = missing;

	final List<BakedQuad> quads = Lists.newArrayList();

	for (BlockRenderLayer layer : BlockRenderLayer.values()) {
		final IBakedModel model = models.get(layer);
		if (model != null) {
			buildQuadsForLayer(quads, model);
		}
	}

	this.quads = ImmutableList.copyOf(quads);
}
 
Example 2
Source File: GuiComponentSideSelector.java    From OpenModsLib with MIT License 6 votes vote down vote up
private void drawBlock() {
	final Tessellator tessellator = Tessellator.getInstance();
	final BufferBuilder wr = tessellator.getBuffer();
	final BlockRendererDispatcher dispatcher = parent.getMinecraft().getBlockRendererDispatcher();
	for (BlockRenderLayer layer : BlockRenderLayer.values()) {
		if (blockState.getBlock().canRenderInLayer(blockState, layer)) {
			net.minecraftforge.client.ForgeHooksClient.setRenderLayer(layer);
			wr.setTranslation(-0.5, -0.5, -0.5);
			wr.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
			dispatcher.renderBlock(blockState, FakeBlockAccess.ORIGIN, access, wr);
			tessellator.draw();
		}
	}
	wr.setTranslation(0.0D, 0.0D, 0.0D);

	net.minecraftforge.client.ForgeHooksClient.setRenderLayer(null);
}
 
Example 3
Source File: BufferBuilderCache.java    From litematica with GNU Lesser General Public License v3.0 5 votes vote down vote up
public BufferBuilderCache()
{
    this.worldRenderers = new BufferBuilder[BlockRenderLayer.values().length];
    this.overlayBufferBuilders = new BufferBuilder[OverlayRenderType.values().length];

    this.worldRenderers[BlockRenderLayer.SOLID.ordinal()] = new BufferBuilder(2097152);
    this.worldRenderers[BlockRenderLayer.CUTOUT.ordinal()] = new BufferBuilder(131072);
    this.worldRenderers[BlockRenderLayer.CUTOUT_MIPPED.ordinal()] = new BufferBuilder(131072);
    this.worldRenderers[BlockRenderLayer.TRANSLUCENT.ordinal()] = new BufferBuilder(262144);

    for (int i = 0; i < this.overlayBufferBuilders.length; ++i)
    {
        this.overlayBufferBuilders[i] = new BufferBuilder(262144);
    }
}
 
Example 4
Source File: MultiLayerModel.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Override
public MultiLayerModel process(ImmutableMap<String, String> customData) {
	final ModelUpdater updater = new ModelUpdater(customData);

	final Optional<ResourceLocation> base = updater.get("base", ModelUpdater.MODEL_LOCATION, this.base);

	final Map<BlockRenderLayer, ResourceLocation> models = Maps.newHashMap();
	for (BlockRenderLayer layer : BlockRenderLayer.values()) {
		final ResourceLocation result = updater.get(layer.toString(), ModelUpdater.MODEL_LOCATION, this.models.get(layer));
		if (result != null) models.put(layer, result);
	}

	return updater.hasChanged()? new MultiLayerModel(base, models) : this;

}
 
Example 5
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();
}