use of crazypants.enderio.base.render.ISmartRenderAwareBlock 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;
}
Aggregations