Search in sources :

Example 1 with ICamouflageItemHandler

use of forestry.api.core.ICamouflageItemHandler in project ForestryMC by ForestryMC.

the class ModelCamouflaged method addCamouflageModel.

private void addCamouflageModel(B block, IModelBaker baker, BlockRenderLayer layer, IBlockAccess world, BlockPos pos) {
    if (world == null || pos == null) {
        TextureAtlasSprite defaultSprite = block.getDefaultSprite();
        baker.addBlockModel(pos, defaultSprite, DEFAULT_COLOR_INDEX);
        baker.setParticleSprite(defaultSprite);
    } else {
        ItemStack camouflageStack = block.getCamouflageBlock(world, pos);
        if (camouflageStack.isEmpty()) {
            camouflageStack = GreenhouseController.createDefaultCamouflageBlock();
        }
        Block camouflageBlock = Block.getBlockFromItem(camouflageStack.getItem());
        ICamouflageItemHandler itemHandler = CamouflageManager.camouflageAccess.getHandler(camouflageStack);
        if (itemHandler != null) {
            Pair<IBlockState, IBakedModel> modelPair = itemHandler.getModel(camouflageStack);
            IBlockState blockState = modelPair.getLeft();
            if (camouflageBlock.canRenderInLayer(blockState, layer)) {
                IBakedModel bakedModel = modelPair.getRight();
                baker.addBakedModel(blockState, bakedModel);
                baker.setParticleSprite(bakedModel.getParticleTexture());
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) TextureAtlasSprite(net.minecraft.client.renderer.texture.TextureAtlasSprite) Block(net.minecraft.block.Block) IBakedModel(net.minecraft.client.renderer.block.model.IBakedModel) ItemStack(net.minecraft.item.ItemStack) ICamouflageItemHandler(forestry.api.core.ICamouflageItemHandler)

Example 2 with ICamouflageItemHandler

use of forestry.api.core.ICamouflageItemHandler in project ForestryMC by ForestryMC.

the class WidgetCamouflageSlot method handleMouseClick.

@Override
public void handleMouseClick(int mouseX, int mouseY, int mouseButton) {
    super.handleMouseClick(mouseX, mouseY, mouseButton);
    if (GuiScreen.isShiftKeyDown()) {
        camouflageHandler.setCamouflageBlock(camouflageHandler.getDefaultCamouflageBlock(), true);
    } else {
        EntityPlayer player = Minecraft.getMinecraft().player;
        ItemStack stack = player.inventory.getItemStack();
        if (!stack.isEmpty()) {
            if (!CamouflageManager.camouflageAccess.isItemBlackListed(stack)) {
                for (ICamouflageItemHandler handler : CamouflageManager.camouflageAccess.getItemHandlers()) {
                    if (handler != null && handler.canHandle(stack)) {
                        camouflageHandler.setCamouflageBlock(stack.copy(), true);
                    }
                }
            }
        }
    }
}
Also used : EntityPlayer(net.minecraft.entity.player.EntityPlayer) ItemStack(net.minecraft.item.ItemStack) ICamouflageItemHandler(forestry.api.core.ICamouflageItemHandler)

Aggregations

ICamouflageItemHandler (forestry.api.core.ICamouflageItemHandler)2 ItemStack (net.minecraft.item.ItemStack)2 Block (net.minecraft.block.Block)1 IBlockState (net.minecraft.block.state.IBlockState)1 IBakedModel (net.minecraft.client.renderer.block.model.IBakedModel)1 TextureAtlasSprite (net.minecraft.client.renderer.texture.TextureAtlasSprite)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1