Search in sources :

Example 31 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project TechReborn by TechReborn.

the class SlotConfigPopupElement method draw.

@Override
public void draw(GuiBase gui) {
    drawDefaultBackground(gui, adjustX(gui, getX() - 8), adjustY(gui, getY() - 7), 84, 105 + (filter ? 15 : 0));
    super.draw(gui);
    TileLegacyMachineBase machine = ((TileLegacyMachineBase) gui.tile);
    IBlockAccess blockAccess = machine.getWorld();
    BlockPos pos = machine.getPos();
    IBlockState state = blockAccess.getBlockState(pos);
    IBlockState actualState = state.getBlock().getDefaultState().getActualState(blockAccess, pos);
    BlockRendererDispatcher dispatcher = FMLClientHandler.instance().getClient().getBlockRendererDispatcher();
    IBakedModel model = dispatcher.getBlockModelShapes().getModelForState(state.getBlock().getDefaultState());
    FMLClientHandler.instance().getClient().renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    // left
    drawState(gui, blockAccess, model, actualState, pos, dispatcher, 4, 23);
    // top
    drawState(gui, blockAccess, model, actualState, pos, dispatcher, 23, -12, -90F, 1F, 0F, 0F);
    // centre
    drawState(gui, blockAccess, model, actualState, pos, dispatcher, 23, 23, -90F, 0F, 1F, 0F);
    // bottom
    drawState(gui, blockAccess, model, actualState, pos, dispatcher, 23, 42, 90F, 1F, 0F, 0F);
    // right
    drawState(gui, blockAccess, model, actualState, pos, dispatcher, 26, 23, 180F, 0F, 1F, 0F);
    // back
    drawState(gui, blockAccess, model, actualState, pos, dispatcher, 26, 42, 90F, 0F, 1F, 0F);
    drawSlotSateColor(gui.getMachine(), MachineFacing.UP.getFacing(machine), id, 22, -1, gui);
    drawSlotSateColor(gui.getMachine(), MachineFacing.FRONT.getFacing(machine), id, 22, 18, gui);
    drawSlotSateColor(gui.getMachine(), MachineFacing.DOWN.getFacing(machine), id, 22, 37, gui);
    drawSlotSateColor(gui.getMachine(), MachineFacing.RIGHT.getFacing(machine), id, 41, 18, gui);
    drawSlotSateColor(gui.getMachine(), MachineFacing.BACK.getFacing(machine), id, 41, 37, gui);
    drawSlotSateColor(gui.getMachine(), MachineFacing.LEFT.getFacing(machine), id, 3, 18, gui);
}
Also used : TileLegacyMachineBase(reborncore.common.tile.TileLegacyMachineBase) IBlockState(net.minecraft.block.state.IBlockState) IBlockAccess(net.minecraft.world.IBlockAccess) BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) BlockRendererDispatcher(net.minecraft.client.renderer.BlockRendererDispatcher)

Example 32 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project Tropicraft by Tropicraft.

the class ClientProxy method onModelBake.

@SubscribeEvent
public void onModelBake(ModelBakeEvent event) {
    for (Entry<String, String[]> e : blockVariants.entrySet()) {
        for (String variant : e.getValue()) {
            ModelResourceLocation loc = new ModelResourceLocation(Info.MODID + ":" + e.getKey(), variant);
            IModel model = ModelLoaderRegistry.getModelOrLogError(loc, "Could not load arbitrary block variant " + variant + " for block " + e.getKey());
            event.getModelRegistry().putObject(loc, model.bake(model.getDefaultState(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter()));
        }
    }
    try {
        IModel waterTop = ModelLoaderRegistry.getModel(new ResourceLocation("tropicraft:block/tropics_water_top"));
        final IBakedModel waterTopBaked = waterTop.bake(waterTop.getDefaultState(), DefaultVertexFormats.ITEM, ModelLoader.defaultTextureGetter());
        Block[] fences = new Block[] { BlockRegistry.bambooFence, BlockRegistry.chunkFence, BlockRegistry.mahoganyFence, BlockRegistry.palmFence, BlockRegistry.thatchFence };
        for (Block block : fences) {
            ModelResourceLocation loc = new ModelResourceLocation(block.getRegistryName(), "normal");
            final IBakedModel fenceModel = event.getModelRegistry().getObject(loc);
            event.getModelRegistry().putObject(loc, new IBakedModel() {

                @Override
                @Nonnull
                public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
                    BlockRenderLayer layer = MinecraftForgeClient.getRenderLayer();
                    if (layer == null || layer == BlockRenderLayer.SOLID) {
                        return fenceModel.getQuads(state, side, rand);
                    } else if (layer == BlockRenderLayer.TRANSLUCENT && state.getValue(BlockTropicraftFence.WATER) == WaterState.SURFACE) {
                        return waterTopBaked.getQuads(state, side, rand);
                    }
                    return Collections.emptyList();
                }

                @Override
                public boolean isGui3d() {
                    return true;
                }

                @Override
                public boolean isBuiltInRenderer() {
                    return false;
                }

                @Override
                public boolean isAmbientOcclusion() {
                    return true;
                }

                @Override
                @Nonnull
                public TextureAtlasSprite getParticleTexture() {
                    return fenceModel.getParticleTexture();
                }

                @Override
                @Nonnull
                public ItemOverrideList getOverrides() {
                    return fenceModel.getOverrides();
                }
            });
        }
    } catch (Exception e1) {
        e1.printStackTrace();
    }
}
Also used : IModel(net.minecraftforge.client.model.IModel) IBlockState(net.minecraft.block.state.IBlockState) Nonnull(javax.annotation.Nonnull) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) EnumFacing(net.minecraft.util.EnumFacing) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) ResourceLocation(net.minecraft.util.ResourceLocation) ItemOverrideList(net.minecraft.client.renderer.block.model.ItemOverrideList) Block(net.minecraft.block.Block) ITropicraftBlock(net.tropicraft.core.common.block.ITropicraftBlock) ItemOverrideList(net.minecraft.client.renderer.block.model.ItemOverrideList) NonNullList(net.minecraft.util.NonNullList) List(java.util.List) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 33 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project Tropicraft by Tropicraft.

the class RenderBambooItemFrame method doRender.

/**
 * Renders the desired {@code T} type Entity.
 */
@Override
public void doRender(EntityBambooItemFrame entity, double x, double y, double z, float entityYaw, float partialTicks) {
    GlStateManager.pushMatrix();
    BlockPos blockpos = entity.getHangingPosition();
    double d0 = (double) blockpos.getX() - entity.posX + x;
    double d1 = (double) blockpos.getY() - entity.posY + y;
    double d2 = (double) blockpos.getZ() - entity.posZ + z;
    GlStateManager.translate(d0 + 0.5D, d1 + 0.5D, d2 + 0.5D);
    GlStateManager.rotate(180.0F - entity.rotationYaw, 0.0F, 1.0F, 0.0F);
    this.renderManager.renderEngine.bindTexture(TextureMap.LOCATION_BLOCKS_TEXTURE);
    BlockRendererDispatcher blockrendererdispatcher = this.mc.getBlockRendererDispatcher();
    ModelManager modelmanager = blockrendererdispatcher.getBlockModelShapes().getModelManager();
    IBakedModel ibakedmodel;
    if (entity.getDisplayedItem() != null && entity.getDisplayedItem().getItem() == Items.FILLED_MAP) {
        ibakedmodel = modelmanager.getModel(this.mapModel);
    } else {
        ibakedmodel = modelmanager.getModel(this.itemFrameModel);
    }
    GlStateManager.pushMatrix();
    GlStateManager.translate(-0.5F, -0.5F, -0.5F);
    if (this.renderOutlines) {
        GlStateManager.enableColorMaterial();
        GlStateManager.enableOutlineMode(this.getTeamColor(entity));
    }
    blockrendererdispatcher.getBlockModelRenderer().renderModelBrightnessColor(ibakedmodel, 1.0F, 1.0F, 1.0F, 1.0F);
    if (this.renderOutlines) {
        GlStateManager.disableOutlineMode();
        GlStateManager.disableColorMaterial();
    }
    GlStateManager.popMatrix();
    GlStateManager.translate(0.0F, 0.0F, 0.4375F);
    this.renderItem(entity);
    GlStateManager.popMatrix();
    this.renderName(entity, x + (double) ((float) entity.facingDirection.getFrontOffsetX() * 0.3F), y - 0.25D, z + (double) ((float) entity.facingDirection.getFrontOffsetZ() * 0.3F));
}
Also used : BlockPos(net.minecraft.util.math.BlockPos) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ModelManager(net.minecraft.client.renderer.block.model.ModelManager) BlockRendererDispatcher(net.minecraft.client.renderer.BlockRendererDispatcher)

Example 34 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project EnderIO by SleepyTrousers.

the class ItemModelRegistry method bakeModels.

@SubscribeEvent()
public void bakeModels(@Nonnull ModelBakeEvent event) {
    for (Entry<ModelResourceLocation, Registry> entry : registries.entrySet()) {
        final ModelResourceLocation resource = entry.getKey();
        if (resource != null) {
            IBakedModel model = event.getModelRegistry().getObject(resource);
            final Registry registry = entry.getValue();
            if (registry != null && model != null) {
                event.getModelRegistry().putObject(resource, registry.wrap(model));
            }
        }
    }
}
Also used : ModelResourceLocation(net.minecraft.client.renderer.block.model.ModelResourceLocation) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 35 with IBakedModel

use of net.minecraft.client.renderer.block.model.IBakedModel in project EnderIO by SleepyTrousers.

the class EnderItemOverrideList method handleItemState.

@SuppressWarnings("deprecation")
@Override
@Nonnull
public IBakedModel handleItemState(@Nonnull IBakedModel originalModel, @Nonnull ItemStack stack, @Nullable World world, @Nullable EntityLivingBase entity) {
    if (Prep.isInvalid(stack)) {
        return Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelManager().getMissingModel();
    }
    Block block = Block.getBlockFromItem(stack.getItem());
    if (block == Blocks.AIR) {
        Registerable modObject = ModObjectRegistry.getModObject(stack.getItem());
        if (modObject != null) {
            block = modObject.getBlock();
        }
        if (block == null || block == Blocks.AIR) {
            throw new NullPointerException("Wrong parameter 'ItemStack stack', not an ItemBlock and not registered with ModObjectRegistry");
        }
    }
    if (block instanceof ITESRItemBlock) {
        return RelayingBakedModel.wrapModelForTESRRendering(originalModel);
    }
    if (block instanceof IBlockPaintableBlock && (!(block instanceof IWrenchHideablePaint) || !YetaUtil.shouldHeldItemHideFacadesClient())) {
        IBlockState paintSource = ((IBlockPaintableBlock) block).getPaintSource(block, stack);
        if (paintSource != null && paintSource != Blocks.AIR.getDefaultState()) {
            Pair<Block, Long> cacheKey = NullHelper.notnull(Pair.of((Block) null, new CacheKey().addCacheKey(paintSource).getCacheKey()), "no way");
            ItemQuadCollector quads = cache.getIfPresent(cacheKey);
            if (quads == null) {
                quads = new ItemQuadCollector();
                quads.addItemBlockState(paintSource, Prep.getEmpty());
                quads.addBlockState(ModObject.block_machine_base.getBlockNN().getDefaultState().withProperty(EnumRenderPart.SUB, EnumRenderPart.PAINT_OVERLAY), Prep.getEmpty());
                cache.put(cacheKey, quads);
            }
            return new CollectedItemQuadBakedBlockModel(originalModel, quads);
        }
    }
    if (block instanceof ISmartRenderAwareBlock) {
        IRenderMapper.IItemRenderMapper renderMapper = ((ISmartRenderAwareBlock) block).getItemRenderMapper();
        Pair<Block, Long> cacheKey = Pair.of(block, renderMapper.getCacheKey(block, stack, new CacheKey().addCacheKey(stack.getMetadata())).getCacheKey());
        ItemQuadCollector quads = cacheKey.getRight() == null ? null : cache.getIfPresent(cacheKey);
        if (quads == null) {
            quads = new ItemQuadCollector();
            if (renderMapper instanceof IRenderMapper.IItemRenderMapper.IItemStateMapper) {
                quads.addBlockStates(((IRenderMapper.IItemRenderMapper.IItemStateMapper) renderMapper).mapItemRender(block, stack, quads), stack, block);
            } else if (renderMapper instanceof IRenderMapper.IItemRenderMapper.IItemModelMapper) {
                List<IBakedModel> bakedModels = ((IRenderMapper.IItemRenderMapper.IItemModelMapper) renderMapper).mapItemRender(block, stack);
                if (bakedModels != null) {
                    for (IBakedModel bakedModel : bakedModels) {
                        quads.addItemBakedModel(bakedModel);
                    }
                }
            } else {
                return Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getModelManager().getMissingModel();
            }
            if (cacheKey.getRight() != null) {
                cache.put(cacheKey, quads);
            }
        }
        if (renderMapper instanceof IItemRenderMapper.IDynamicOverlayMapper) {
            quads = quads.combine(((IItemRenderMapper.IDynamicOverlayMapper) renderMapper).mapItemDynamicOverlayRender(block, stack));
        }
        return new CollectedItemQuadBakedBlockModel(originalModel, quads);
    }
    return originalModel;
}
Also used : ITESRItemBlock(crazypants.enderio.base.render.ITESRItemBlock) IBlockState(net.minecraft.block.state.IBlockState) ISmartRenderAwareBlock(crazypants.enderio.base.render.ISmartRenderAwareBlock) IBlockPaintableBlock(crazypants.enderio.base.paint.IPaintable.IBlockPaintableBlock) IItemRenderMapper(crazypants.enderio.base.render.IRenderMapper.IItemRenderMapper) CollectedItemQuadBakedBlockModel(crazypants.enderio.base.render.model.CollectedItemQuadBakedBlockModel) IItemRenderMapper(crazypants.enderio.base.render.IRenderMapper.IItemRenderMapper) ItemQuadCollector(crazypants.enderio.base.render.util.ItemQuadCollector) IWrenchHideablePaint(crazypants.enderio.base.paint.IPaintable.IWrenchHideablePaint) IRenderMapper(crazypants.enderio.base.render.IRenderMapper) IBlockPaintableBlock(crazypants.enderio.base.paint.IPaintable.IBlockPaintableBlock) Block(net.minecraft.block.Block) ITESRItemBlock(crazypants.enderio.base.render.ITESRItemBlock) ISmartRenderAwareBlock(crazypants.enderio.base.render.ISmartRenderAwareBlock) Registerable(crazypants.enderio.base.init.IModObject.Registerable) ItemOverrideList(net.minecraft.client.renderer.block.model.ItemOverrideList) List(java.util.List) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) Nonnull(javax.annotation.Nonnull) ItemOverride(net.minecraft.client.renderer.block.model.ItemOverride)

Aggregations

IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)197 IBlockState (net.minecraft.block.state.IBlockState)94 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)42 BlockPos (net.minecraft.util.math.BlockPos)40 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)38 EnumFacing (net.minecraft.util.EnumFacing)38 ResourceLocation (net.minecraft.util.ResourceLocation)36 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)30 ItemStack (net.minecraft.item.ItemStack)27 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)24 Block (net.minecraft.block.Block)23 IModel (net.minecraftforge.client.model.IModel)22 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)22 ArrayList (java.util.ArrayList)20 IExtendedBlockState (net.minecraftforge.common.property.IExtendedBlockState)17 Minecraft (net.minecraft.client.Minecraft)15 BlockRendererDispatcher (net.minecraft.client.renderer.BlockRendererDispatcher)15 List (java.util.List)14 ItemOverride (net.minecraft.client.renderer.block.model.ItemOverride)14 ImmutableList (com.google.common.collect.ImmutableList)13