Example usage for net.minecraftforge.client MinecraftForgeClient getRenderLayer

List of usage examples for net.minecraftforge.client MinecraftForgeClient getRenderLayer

Introduction

In this page you can find the example usage for net.minecraftforge.client MinecraftForgeClient getRenderLayer.

Prototype

public static RenderType getRenderLayer() 

Source Link

Usage

From source file:appeng.client.render.cablebus.CableBusBakedModel.java

License:Open Source License

@Override
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
    CableBusRenderState renderState = getRenderingState(state);

    if (renderState == null || side != null) {
        return Collections.emptyList();
    }//  w w w .  j av  a2  s  .  c o m

    BlockRenderLayer layer = MinecraftForgeClient.getRenderLayer();

    List<BakedQuad> quads = new ArrayList<>();

    // The core parts of the cable will only be rendered in the CUTOUT layer. TRANSLUCENT is used only for translucent facades further down below.
    if (layer == BlockRenderLayer.CUTOUT) {
        // First, handle the cable at the center of the cable bus
        addCableQuads(renderState, quads);

        // Then handle attachments
        for (EnumFacing facing : EnumFacing.values()) {
            List<ResourceLocation> models = renderState.getAttachments().get(facing);
            if (models == null) {
                continue;
            }

            for (ResourceLocation model : models) {
                IBakedModel bakedModel = partModels.get(model);

                if (bakedModel == null) {
                    throw new IllegalStateException("Trying to use an unregistered part model: " + model);
                }

                List<BakedQuad> partQuads = bakedModel.getQuads(state, null, rand);

                // Rotate quads accordingly
                QuadRotator rotator = new QuadRotator();
                partQuads = rotator.rotateQuads(partQuads, facing, EnumFacing.UP);

                quads.addAll(partQuads);
            }
        }
    }

    facadeBuilder.addFacades(layer, renderState.getFacades(), renderState.getBoundingBoxes(),
            renderState.getAttachments().keySet(), rand, quads);

    return quads;
}

From source file:appeng.client.render.cablebus.FacadeBuilder.java

License:Open Source License

public static TextureAtlasAndTint getSprite(IBakedModel blockModel, IBlockState state, EnumFacing facing,
        long rand) {

    TextureAtlasAndTint firstFound = null;
    BlockRenderLayer orgLayer = MinecraftForgeClient.getRenderLayer();

    try {// w  ww.j a  v a2 s.  c  o  m
        // Some other mods also distinguish between layers, so we're doing this in a loop from most likely to least likely
        for (BlockRenderLayer layer : BlockRenderLayer.values()) {

            ForgeHooksClient.setRenderLayer(layer);

            for (BakedQuad bakedQuad : blockModel.getQuads(state, facing, rand)) {
                return new TextureAtlasAndTint(bakedQuad);
            }

            for (BakedQuad bakedQuad : blockModel.getQuads(state, null, rand)) {
                if (firstFound == null) {
                    firstFound = new TextureAtlasAndTint(bakedQuad);
                }
                if (bakedQuad.getFace() == facing) {
                    return new TextureAtlasAndTint(bakedQuad);
                }
            }
        }
    } catch (Exception e) {
        if (warnedFor.add(state.getBlock().getRegistryName())) {
            AELog.warn(
                    "Unable to get facade sprite for blockstate %s. Supressing further warnings for this block.",
                    state);
            AELog.debug(e);
        }
    } finally {
        ForgeHooksClient.setRenderLayer(orgLayer);
    }

    // Fall back to the particle texture, if we havent found anything else so far.
    if (firstFound == null) {
        try {
            return new TextureAtlasAndTint(blockModel.getParticleTexture(), -1);
        } catch (Exception e) {
            if (warnedFor.add(state.getBlock().getRegistryName())) {
                AELog.warn(
                        "Unable to get facade sprite particle texture fallback for blockstate %s. Supressing further warnings for this block.",
                        state);
                AELog.debug(e);
            }
        }
    }

    return firstFound;
}

From source file:blusunrize.immersiveengineering.client.models.IESmartObjModel.java

public List<BakedQuad> getQuads(IBlockState blockState, EnumFacing side, long rand, OBJState objstate,
        Map<String, String> tex, boolean addAnimationAndTex) {
    texReplace = tex;//  w ww .j av a 2 s .c  om
    this.tempState = blockState;
    if (blockState instanceof IExtendedBlockState) {
        IExtendedBlockState exState = (IExtendedBlockState) blockState;
        ExtBlockstateAdapter adapter;
        if (objstate != null) {
            if (objstate.parent == null || objstate.parent == TRSRTransformation.identity())
                objstate.parent = this.getState();
            if (objstate.getVisibilityMap().containsKey(Group.ALL)
                    || objstate.getVisibilityMap().containsKey(Group.ALL_EXCEPT))
                this.updateStateVisibilityMap(objstate);
        }
        if (addAnimationAndTex)
            adapter = new ExtBlockstateAdapter(exState, MinecraftForgeClient.getRenderLayer(),
                    ExtBlockstateAdapter.CONNS_OBJ_CALLBACK, new Object[] { objstate, tex });
        else
            adapter = new ExtBlockstateAdapter(exState, MinecraftForgeClient.getRenderLayer(),
                    ExtBlockstateAdapter.CONNS_OBJ_CALLBACK);
        List<BakedQuad> quads = modelCache.get(adapter);
        if (quads == null) {
            IESmartObjModel model = null;
            if (objstate != null)
                model = new IESmartObjModel(baseModel, getModel(), objstate, getFormat(), getTextures(),
                        transformationMap, isDynamic);
            if (model == null)
                model = new IESmartObjModel(baseModel, getModel(), this.getState(), getFormat(), getTextures(),
                        transformationMap, isDynamic);
            model.tempState = blockState;
            model.texReplace = tex;
            quads = model.buildQuads();
            modelCache.put(adapter, quads);
        }
        return Collections.synchronizedList(Lists.newArrayList(quads));
    }
    if (bakedQuads == null)
        bakedQuads = buildQuads();
    List<BakedQuad> quadList = Lists.newArrayList(bakedQuads);
    return Collections.synchronizedList(quadList);
}

From source file:blusunrize.immersiveengineering.client.models.multilayer.BakedMultiLayerModel.java

@Nonnull
@Override/*from www  .  j  a v  a 2s.  c  o  m*/
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
    BlockRenderLayer current = MinecraftForgeClient.getRenderLayer();
    if (current == null) {
        ImmutableList.Builder<BakedQuad> ret = new Builder<>();
        for (List<IBakedModel> forLayer : models.values())
            for (IBakedModel model : forLayer)
                ret.addAll(model.getQuads(state, side, rand));
        return ret.build();
    } else if (models.containsKey(current)) {
        ImmutableList.Builder<BakedQuad> ret = new Builder<>();
        for (IBakedModel model : models.get(current))
            ret.addAll(model.getQuads(state, side, rand));
        return ret.build();
    } else
        return ImmutableList.of();
}

From source file:blusunrize.immersiveengineering.client.models.smart.ConnModelReal.java

@Nonnull
@Override//from   w  w  w  .ja  v  a2s .co m
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
    if (side == null && state instanceof IExtendedBlockState) {
        IExtendedBlockState ext = (IExtendedBlockState) state;
        Object[] additional = null;
        if (ext.getUnlistedProperties().containsKey(IEProperties.TILEENTITY_PASSTHROUGH)) {
            TileEntity te = ext.getValue(IEProperties.TILEENTITY_PASSTHROUGH);
            if (te instanceof IEBlockInterfaces.ICacheData)
                additional = ((IEBlockInterfaces.ICacheData) te).getCacheData();
        }
        int x = 0, z = 0;
        if (ext.getUnlistedProperties().containsKey(IEProperties.CONNECTIONS)) {
            Set<Connection> conns = ext.getValue(IEProperties.CONNECTIONS);
            if (conns != null && conns.size() > 0) {
                BlockPos tmp = conns.iterator().next().start;
                x = (tmp.getX() % 16 + 16) % 16;
                z = (tmp.getZ() % 16 + 16) % 16;
            }
        }
        ExtBlockstateAdapter ad = new ExtBlockstateAdapter(ext, null, ExtBlockstateAdapter.ONLY_OBJ_CALLBACK,
                additional);
        Pair<Byte, ExtBlockstateAdapter> key = new ImmutablePair<>((byte) ((x << 4) | z), ad);
        try {
            IBakedModel ret = cache.get(key,
                    () -> new AssembledBakedModel(ext, textureAtlasSprite, base, layers));
            return ret.getQuads(state, null, rand);
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
    }
    return getBaseQuads(MinecraftForgeClient.getRenderLayer(), state, side, rand);
}

From source file:blusunrize.immersiveengineering.client.models.smart.FeedthroughModel.java

@Nonnull
@Override//from w w w.  j av  a2s  . c  om
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
    IBlockState baseState = Blocks.STONE.getDefaultState();
    WireType wire = WireType.COPPER;
    EnumFacing facing = EnumFacing.NORTH;
    int offset = 1;
    BlockPos p = null;
    World w = null;
    if (state instanceof IExtendedBlockState) {
        TileEntity te = ((IExtendedBlockState) state).getValue(IEProperties.TILEENTITY_PASSTHROUGH);
        if (te instanceof TileEntityFeedthrough) {
            baseState = ((TileEntityFeedthrough) te).stateForMiddle;
            wire = ((TileEntityFeedthrough) te).reference;
            facing = ((TileEntityFeedthrough) te).getFacing();
            offset = ((TileEntityFeedthrough) te).offset;
            p = te.getPos();
            w = te.getWorld();
        }
    }
    final BlockPos pFinal = p;
    final World wFinal = w;
    FeedthroughCacheKey key = new FeedthroughCacheKey(wire, baseState, offset, facing,
            MinecraftForgeClient.getRenderLayer());
    try {
        return CACHE.get(key, () -> new SpecificFeedthroughModel(key, wFinal, pFinal)).getQuads(state, side,
                rand);
    } catch (ExecutionException e) {
        e.printStackTrace();
        return ImmutableList.of();
    }
}

From source file:blusunrize.immersiveengineering.common.blocks.metal.TileEntityConnectorProbe.java

@SideOnly(Side.CLIENT)
@Override//www  . j  a v  a 2  s  .c  o m
public boolean shouldRenderGroup(IBlockState object, String group) {
    if ("glass".equals(group))
        return MinecraftForgeClient.getRenderLayer() == BlockRenderLayer.TRANSLUCENT;
    return MinecraftForgeClient.getRenderLayer() == BlockRenderLayer.CUTOUT;
}

From source file:blusunrize.immersiveengineering.common.blocks.metal.TileEntityFloodlight.java

@SideOnly(Side.CLIENT)
@Override/*  w w w .  j  a  v a  2s. c o m*/
public boolean shouldRenderGroup(IBlockState object, String group) {
    if ("glass".equals(group))
        return MinecraftForgeClient.getRenderLayer() == BlockRenderLayer.TRANSLUCENT;
    else
        return MinecraftForgeClient.getRenderLayer() == BlockRenderLayer.SOLID;
}

From source file:blusunrize.immersiveengineering.common.blocks.metal.TileEntityFluidPipe.java

@Override
@SideOnly(Side.CLIENT)/*from  ww  w.jav a 2  s. co m*/
public List<BakedQuad> modifyQuads(IBlockState object, List<BakedQuad> quads) {
    if (!pipeCover.isEmpty()) {
        Block b = Block.getBlockFromItem(pipeCover.getItem());
        IBlockState state = b != null ? b.getStateFromMeta(pipeCover.getMetadata())
                : Blocks.STONE.getDefaultState();
        IBakedModel model = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes()
                .getModelForState(state);
        BlockRenderLayer curL = MinecraftForgeClient.getRenderLayer();
        if (model != null)
            for (BlockRenderLayer layer : BlockRenderLayer.values()) {
                ForgeHooksClient.setRenderLayer(layer);
                for (EnumFacing facing : EnumFacing.VALUES)
                    quads.addAll(model.getQuads(state, facing, 0));
                quads.addAll(model.getQuads(state, null, 0));
            }
        ForgeHooksClient.setRenderLayer(curL);
    }
    return quads;
}

From source file:com.teambr.modularsystems.core.client.models.BakedProxyModel.java

License:Creative Commons License

@Override
public List<BakedQuad> getQuads(IBlockState state, EnumFacing side, long rand) {
    if (state != null && side != null && state instanceof ProxyState) {
        ProxyState proxyState = (ProxyState) state;
        proxyTile = proxyState.tile;//from   w  ww .  j av a 2s  .  com
        proxyBlock = (BlockProxy) proxyState.block;

        ArrayList<BakedQuad> quads = new ArrayList<>();

        // Null Checks
        if (proxyTile == null || proxyTile.getStoredBlock() == null)
            return new ArrayList<>();

        // Reference values
        BlockPartFace face = new BlockPartFace(null, 0, "",
                new BlockFaceUV(new float[] { 0.0F, 0.0F, 16.0F, 16.0F }, 0));

        if (MinecraftForgeClient.getRenderLayer() == BlockRenderLayer.TRANSLUCENT) {
            // Inside
            quads.add(faceBakery.makeBakedQuad(new Vector3f(0.0F, 0.0F, 16.002F),
                    new Vector3f(16.0F, 16.0F, 16.002F), face, proxyTile.getOverlay(), EnumFacing.SOUTH,
                    lookUpRotationForFace(side), null, true, true));
        } else {
            IBlockState storedState = proxyTile.getStoredBlock().getStateFromMeta(proxyTile.metaData());
            IBakedModel model = Minecraft.getMinecraft().getBlockRendererDispatcher()
                    .getModelForState(storedState);

            // Set stored block
            if (model != Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes()
                    .getModelManager().getMissingModel())
                quads.addAll(model.getQuads(storedState, side, rand));

            // Reference values
            ModelRotation rot = lookUpRotationForFace(side);
            boolean[] connections = proxyBlock.getConnectionArrayForFace(proxyTile.getWorld(),
                    proxyTile.getPos(), side);

            // Connected Textures Border
            quads.add(faceBakery.makeBakedQuad(new Vector3f(0.0F, 0.0F, 16.0045F),
                    new Vector3f(8.0F, 8.0F, 16.0045F),
                    new BlockPartFace(null, 0, "", new BlockFaceUV(new float[] { 0.0F, 8.0F, 8.0F, 0.0F }, 0)),
                    proxyBlock.getConnectedTextures().getTextureForCorner(2, connections), EnumFacing.SOUTH,
                    rot, null, false, true));

            quads.add(faceBakery.makeBakedQuad(new Vector3f(8.0F, 0.0F, 16.0045F),
                    new Vector3f(16.0F, 8.0F, 16.0045F),
                    new BlockPartFace(null, 0, "", new BlockFaceUV(new float[] { 8.0F, 8.0F, 16.0F, 0.0F }, 0)),
                    proxyBlock.getConnectedTextures().getTextureForCorner(3, connections), EnumFacing.SOUTH,
                    rot, null, false, true));

            quads.add(faceBakery.makeBakedQuad(new Vector3f(0.0F, 8.0F, 16.0045F),
                    new Vector3f(8.0F, 16.0F, 16.0045F),
                    new BlockPartFace(null, 0, "", new BlockFaceUV(new float[] { 0.0F, 16.0F, 8.0F, 8.0F }, 0)),
                    proxyBlock.getConnectedTextures().getTextureForCorner(0, connections), EnumFacing.SOUTH,
                    rot, null, false, true));

            quads.add(faceBakery.makeBakedQuad(new Vector3f(8.0F, 8.0F, 16.0045F),
                    new Vector3f(16.0F, 16.0F, 16.0045F),
                    new BlockPartFace(null, 0, "",
                            new BlockFaceUV(new float[] { 8.0F, 16.0F, 16.0F, 8.0F }, 0)),
                    proxyBlock.getConnectedTextures().getTextureForCorner(1, connections), EnumFacing.SOUTH,
                    rot, null, false, true));
        }

        return quads;
    }

    return new ArrayList<>();
}