Search in sources :

Example 1 with IBlockPaintableBlock

use of crazypants.enderio.base.paint.IPaintable.IBlockPaintableBlock in project EnderIO by SleepyTrousers.

the class BlockStateWrapperBase method bakeModel.

@Override
public void bakeModel() {
    long start = Profiler.instance.start();
    QuadCollector quads = null;
    QuadCollector overlayQuads = null;
    @Nonnull QuadCollector paintQuads = new QuadCollector();
    boolean hasPaintRendered = false;
    String cacheResult;
    if (block instanceof IBlockPaintableBlock && (!(block instanceof IWrenchHideablePaint) || !getYetaDisplayMode().isHideFacades())) {
        hasPaintRendered = PaintWrangler.wrangleBakedModel(world, pos, ((IBlockPaintableBlock) block).getPaintSource(state, world, pos), paintQuads);
    }
    boolean fromCache = doCaching && MinecraftForgeClient.getRenderLayer() != null;
    if (!hasPaintRendered || renderMapper instanceof IRenderMapper.IBlockRenderMapper.IRenderLayerAware.IPaintAware) {
        if (fromCache) {
            quads = getFromCache();
            cacheResult = quads == null ? "miss" : "hit";
        } else {
            cacheResult = "not cachable";
        }
        if (quads == null) {
            quads = new QuadCollector();
            bakeBlockLayer(quads);
            if (fromCache) {
                putIntoCache(quads);
            }
        }
    } else {
        cacheResult = "paint only";
    }
    overlayQuads = OverlayHolder.getOverlay(renderMapper.mapOverlayLayer(this, world, pos, hasPaintRendered));
    model = new CollectedQuadBakedBlockModel(paintQuads.combine(overlayQuads).combine(quads));
    Profiler.instance.stop(start, state.getBlock().getLocalizedName() + " (bake, cache=" + cacheResult + ")");
}
Also used : IWrenchHideablePaint(crazypants.enderio.base.paint.IPaintable.IWrenchHideablePaint) QuadCollector(crazypants.enderio.base.render.util.QuadCollector) Nonnull(javax.annotation.Nonnull) IRenderMapper(crazypants.enderio.base.render.IRenderMapper) IBlockPaintableBlock(crazypants.enderio.base.paint.IPaintable.IBlockPaintableBlock) CollectedQuadBakedBlockModel(crazypants.enderio.base.render.model.CollectedQuadBakedBlockModel)

Example 2 with IBlockPaintableBlock

use of crazypants.enderio.base.paint.IPaintable.IBlockPaintableBlock in project EnderIO by SleepyTrousers.

the class BlockStateWrapperRelay method bakeModel.

@Override
public void bakeModel() {
    long start = Profiler.instance.start();
    @Nonnull QuadCollector paintQuads = new QuadCollector();
    boolean hasPaintRendered = false;
    String cacheResult;
    if (block instanceof IBlockPaintableBlock && (!(block instanceof IWrenchHideablePaint) || !getYetaDisplayMode().isHideFacades())) {
        hasPaintRendered = PaintWrangler.wrangleBakedModel(world, pos, ((IBlockPaintableBlock) block).getPaintSource(state, world, pos), paintQuads);
    }
    if (!hasPaintRendered) {
        if (MinecraftForgeClient.getRenderLayer() == null || MinecraftForgeClient.getRenderLayer() == block.getBlockLayer()) {
            model = null;
            cacheResult = "relaying";
        } else {
            model = NULL;
            cacheResult = "none";
        }
    } else {
        model = new CollectedQuadBakedBlockModel(paintQuads);
        cacheResult = "paint only";
    }
    Profiler.instance.stop(start, state.getBlock().getLocalizedName() + " (bake, cache=" + cacheResult + ")");
}
Also used : IWrenchHideablePaint(crazypants.enderio.base.paint.IPaintable.IWrenchHideablePaint) Nonnull(javax.annotation.Nonnull) QuadCollector(crazypants.enderio.base.render.util.QuadCollector) IBlockPaintableBlock(crazypants.enderio.base.paint.IPaintable.IBlockPaintableBlock) CollectedQuadBakedBlockModel(crazypants.enderio.base.render.model.CollectedQuadBakedBlockModel)

Example 3 with IBlockPaintableBlock

use of crazypants.enderio.base.paint.IPaintable.IBlockPaintableBlock 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 4 with IBlockPaintableBlock

use of crazypants.enderio.base.paint.IPaintable.IBlockPaintableBlock in project EnderIO by SleepyTrousers.

the class ItemYetaWrench method onItemUseFirst.

@Override
@Nonnull
public EnumActionResult onItemUseFirst(@Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos, @Nonnull EnumFacing side, float hitX, float hitY, float hitZ, @Nonnull EnumHand hand) {
    if (world.isRemote) {
        // If its client side we have to return pass so this method is called on server, where we need to perform the op
        return EnumActionResult.PASS;
    }
    final IBlockState blockState = world.getBlockState(pos);
    IBlockState bs = blockState;
    Block block = bs.getBlock();
    boolean ret = false;
    RightClickBlock e = new RightClickBlock(player, hand, pos, side, new Vec3d(hitX, hitY, hitZ));
    if (MinecraftForge.EVENT_BUS.post(e) || e.getResult() == Result.DENY || e.getUseBlock() == Result.DENY || e.getUseItem() == Result.DENY) {
        return EnumActionResult.PASS;
    }
    if (block instanceof BlockDoor) {
        EnumDoorHalf half = bs.getValue(BlockDoor.HALF);
        if (half == EnumDoorHalf.UPPER) {
            pos = pos.down();
        }
    }
    if (!player.isSneaking() && block.rotateBlock(world, pos, side)) {
        ret = true;
    } else if (block instanceof IBlockPaintableBlock && !player.isSneaking() && !YetaUtil.shouldHeldItemHideFacades(player)) {
        IBlockState paintSource = ((IBlockPaintableBlock) block).getPaintSource(blockState, world, pos);
        if (paintSource != null) {
            final IBlockState rotatedPaintSource = PaintUtil.rotate(paintSource);
            if (rotatedPaintSource != paintSource) {
                ((IBlockPaintableBlock) block).setPaintSource(blockState, world, pos, rotatedPaintSource);
            }
            ret = true;
        }
    }
    // so 'onBlockActivated' is never called
    if (!ret && player.isSneaking() && block instanceof BlockEio<?>) {
        BlockEio<?> beio = (BlockEio<?>) block;
        if (beio.shouldWrench(world, pos, player, side)) {
            beio.onBlockActivated(world, pos, bs, player, hand, side, hitX, hitY, hitZ);
            ret = true;
        }
    }
    if (ret) {
        player.swingArm(hand);
    }
    return ret ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
}
Also used : BlockDoor(net.minecraft.block.BlockDoor) EnumDoorHalf(net.minecraft.block.BlockDoor.EnumDoorHalf) IBlockState(net.minecraft.block.state.IBlockState) BlockEio(crazypants.enderio.base.BlockEio) RightClickBlock(net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock) IBlockPaintableBlock(crazypants.enderio.base.paint.IPaintable.IBlockPaintableBlock) IYetaAwareBlock(crazypants.enderio.base.machine.interfaces.IYetaAwareBlock) Block(net.minecraft.block.Block) RightClickBlock(net.minecraftforge.event.entity.player.PlayerInteractEvent.RightClickBlock) IBlockPaintableBlock(crazypants.enderio.base.paint.IPaintable.IBlockPaintableBlock) Vec3d(net.minecraft.util.math.Vec3d) Nonnull(javax.annotation.Nonnull)

Aggregations

IBlockPaintableBlock (crazypants.enderio.base.paint.IPaintable.IBlockPaintableBlock)4 Nonnull (javax.annotation.Nonnull)4 IWrenchHideablePaint (crazypants.enderio.base.paint.IPaintable.IWrenchHideablePaint)3 IRenderMapper (crazypants.enderio.base.render.IRenderMapper)2 CollectedQuadBakedBlockModel (crazypants.enderio.base.render.model.CollectedQuadBakedBlockModel)2 QuadCollector (crazypants.enderio.base.render.util.QuadCollector)2 Block (net.minecraft.block.Block)2 IBlockState (net.minecraft.block.state.IBlockState)2 BlockEio (crazypants.enderio.base.BlockEio)1 Registerable (crazypants.enderio.base.init.IModObject.Registerable)1 IYetaAwareBlock (crazypants.enderio.base.machine.interfaces.IYetaAwareBlock)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 ItemQuadCollector (crazypants.enderio.base.render.util.ItemQuadCollector)1 List (java.util.List)1 BlockDoor (net.minecraft.block.BlockDoor)1 EnumDoorHalf (net.minecraft.block.BlockDoor.EnumDoorHalf)1 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)1