Search in sources :

Example 1 with ItemQuadCollector

use of crazypants.enderio.base.render.util.ItemQuadCollector 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)

Example 2 with ItemQuadCollector

use of crazypants.enderio.base.render.util.ItemQuadCollector in project EnderIO by SleepyTrousers.

the class FusedQuartzItemRenderMapper method mapItemDynamicOverlayRender.

@Override
@SideOnly(Side.CLIENT)
public ItemQuadCollector mapItemDynamicOverlayRender(@Nonnull Block block, @Nonnull ItemStack stack) {
    if (NbtValue.FAKE.hasTag(stack)) {
        // this is for the TOP overlay, kind of a hack putting it here, but the alternative would be adding a new item just for this...
        SmartTank tank = ItemTankHelper.getTank(stack);
        HalfBakedList buffer = TankRenderHelper.mkTank(tank, 0, 0, 16, true);
        if (buffer != null) {
            ItemQuadCollector result = new ItemQuadCollector();
            List<BakedQuad> quads = new ArrayList<BakedQuad>();
            buffer.bake(quads);
            result.addQuads(null, quads);
            return result;
        }
    }
    return null;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) ArrayList(java.util.ArrayList) SmartTank(com.enderio.core.common.fluid.SmartTank) HalfBakedList(crazypants.enderio.base.render.util.HalfBakedQuad.HalfBakedList) ItemQuadCollector(crazypants.enderio.base.render.util.ItemQuadCollector) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 3 with ItemQuadCollector

use of crazypants.enderio.base.render.util.ItemQuadCollector in project EnderIO by SleepyTrousers.

the class TankItemRenderMapper method mapItemDynamicOverlayRender.

@Override
@SideOnly(Side.CLIENT)
public ItemQuadCollector mapItemDynamicOverlayRender(@Nonnull Block block, @Nonnull ItemStack stack) {
    ItemQuadCollector result = new ItemQuadCollector();
    if (stack.hasTagCompound()) {
        SmartTank tank = ItemTankHelper.getTank(stack);
        HalfBakedList buffer = TankRenderHelper.mkTank(tank, 0.5, 0.5, 15.5, false);
        if (buffer != null) {
            List<BakedQuad> quads = new ArrayList<BakedQuad>();
            buffer.bake(quads);
            result.addQuads(null, quads);
        }
    }
    if (!NbtValue.FAKE.hasTag(stack)) {
        result.addBlockState(block.getStateFromMeta(stack.getMetadata()).withProperty(EnumRenderMode.RENDER, EnumRenderMode.FRONT_ON), stack, true);
    }
    return result;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) ArrayList(java.util.ArrayList) SmartTank(com.enderio.core.common.fluid.SmartTank) HalfBakedList(crazypants.enderio.base.render.util.HalfBakedQuad.HalfBakedList) ItemQuadCollector(crazypants.enderio.base.render.util.ItemQuadCollector) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 4 with ItemQuadCollector

use of crazypants.enderio.base.render.util.ItemQuadCollector in project EnderIO by SleepyTrousers.

the class CapBankItemRenderMapper method mapItemDynamicOverlayRender.

@Override
@SideOnly(Side.CLIENT)
public ItemQuadCollector mapItemDynamicOverlayRender(@Nonnull Block block, @Nonnull ItemStack stack) {
    IEnergyStorage energyItem = PowerHandlerUtil.getCapability(stack, null);
    if (energyItem != null) {
        int maxEnergy = energyItem.getMaxEnergyStored();
        if (maxEnergy > 0) {
            int energy = energyItem.getEnergyStored();
            FillGaugeBakery gauge = new FillGaugeBakery(BlockCapBank.getGaugeIcon(), (double) energy / maxEnergy);
            if (gauge.canRender()) {
                ItemQuadCollector result = new ItemQuadCollector();
                List<BakedQuad> quads = new ArrayList<BakedQuad>();
                gauge.bake(quads);
                result.addQuads(null, quads);
                return result;
            }
        }
    }
    return null;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) IEnergyStorage(net.minecraftforge.energy.IEnergyStorage) ArrayList(java.util.ArrayList) ItemQuadCollector(crazypants.enderio.base.render.util.ItemQuadCollector) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 5 with ItemQuadCollector

use of crazypants.enderio.base.render.util.ItemQuadCollector in project EnderIO by SleepyTrousers.

the class RenderMapperGauge method mapItemDynamicOverlayRender.

@Override
public ItemQuadCollector mapItemDynamicOverlayRender(@Nonnull Block block, @Nonnull ItemStack stack) {
    double v = EnderIO.proxy.getTickCount() % 120;
    if (v > 60) {
        v = 120 - v;
    }
    double ratio = v / 60d;
    FillGaugeBakery gauge = new FillGaugeBakery(BlockGauge.gaugeIcon.get(TextureAtlasSprite.class), ratio);
    if (gauge.canRender()) {
        ItemQuadCollector result = new ItemQuadCollector();
        List<BakedQuad> quads = new ArrayList<BakedQuad>();
        gauge.bake(quads);
        result.addQuads(null, quads);
        return result;
    }
    return null;
}
Also used : BakedQuad(net.minecraft.client.renderer.block.model.BakedQuad) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) FillGaugeBakery(crazypants.enderio.powertools.machine.capbank.render.FillGaugeBakery) ArrayList(java.util.ArrayList) ItemQuadCollector(crazypants.enderio.base.render.util.ItemQuadCollector)

Aggregations

ItemQuadCollector (crazypants.enderio.base.render.util.ItemQuadCollector)6 ArrayList (java.util.ArrayList)4 BakedQuad (net.minecraft.client.renderer.block.model.BakedQuad)4 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)4 SmartTank (com.enderio.core.common.fluid.SmartTank)2 HalfBakedList (crazypants.enderio.base.render.util.HalfBakedQuad.HalfBakedList)2 Registerable (crazypants.enderio.base.init.IModObject.Registerable)1 IBlockPaintableBlock (crazypants.enderio.base.paint.IPaintable.IBlockPaintableBlock)1 IWrenchHideablePaint (crazypants.enderio.base.paint.IPaintable.IWrenchHideablePaint)1 IRenderMapper (crazypants.enderio.base.render.IRenderMapper)1 IItemRenderMapper (crazypants.enderio.base.render.IRenderMapper.IItemRenderMapper)1 ISmartRenderAwareBlock (crazypants.enderio.base.render.ISmartRenderAwareBlock)1 ITESRItemBlock (crazypants.enderio.base.render.ITESRItemBlock)1 CollectedItemQuadBakedBlockModel (crazypants.enderio.base.render.model.CollectedItemQuadBakedBlockModel)1 FillGaugeBakery (crazypants.enderio.powertools.machine.capbank.render.FillGaugeBakery)1 List (java.util.List)1 Nonnull (javax.annotation.Nonnull)1 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)1