package com.mods.kina.KinaCore.movelib.modelloader.block;

import com.google.common.base.Function;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.block.model.BakedQuad;
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.model.IFlexibleBakedModel;
import net.minecraftforge.client.model.IModelState;
import net.minecraftforge.client.model.ISmartBlockModel;
import net.minecraftforge.client.model.ISmartItemModel;

import java.util.List;

public class BlockSwitcherBakedModel implements IFlexibleBakedModel, ISmartBlockModel, ISmartItemModel{
    private final IUseKinaBlockModel block;
    private final IModelState modelState;
    private final VertexFormat format;
    private final Function<ResourceLocation,TextureAtlasSprite> bakedTextureGetter;
    private IFlexibleBakedModel parent;

    BlockSwitcherBakedModel(IUseKinaBlockModel block, IModelState modelState, VertexFormat format, Function<ResourceLocation,TextureAtlasSprite> bakedTextureGetter){
        this.block = block;
        this.modelState = modelState;
        this.format = format;
        this.bakedTextureGetter = bakedTextureGetter;
        parent = block.getModel(modelState, format, bakedTextureGetter, block.getDefaultState());
    }

    public List<BakedQuad> getFaceQuads(EnumFacing side){
        return parent.getFaceQuads(side);
    }

    public List<BakedQuad> getGeneralQuads(){
        return parent.getGeneralQuads();
    }

    public boolean isAmbientOcclusion(){
        return parent.isAmbientOcclusion();
    }

    public boolean isGui3d(){
        return parent.isGui3d();
    }

    public boolean isBuiltInRenderer(){
        return parent.isBuiltInRenderer();
    }

    public TextureAtlasSprite getTexture(){
        return parent.getTexture();
    }

    public ItemCameraTransforms getItemCameraTransforms(){
        return parent.getItemCameraTransforms();
    }

    public VertexFormat getFormat(){
        return parent.getFormat();
    }

    public IFlexibleBakedModel handleBlockState(IBlockState state){
        parent = block.getModel(modelState, format, bakedTextureGetter, state);
        parent = parent instanceof ISmartBlockModel ? (IFlexibleBakedModel) ((ISmartBlockModel) parent).handleBlockState(state) : parent;
        return this;
    }

    public IFlexibleBakedModel handleItemState(ItemStack stack){
        parent = block.getModel(modelState, format, bakedTextureGetter, stack);
        parent = parent instanceof ISmartItemModel ? (IFlexibleBakedModel) ((ISmartItemModel) parent).handleItemState(stack) : parent;
        return this;
    }
}

@@ -1528,32 +1528,253 @@
 tate());%0A    %7D%0A%0A
+    BlockSwitcherBakedModel(BlockSwitcherBakedModel model)%7B%0A        block = model.block;%0A        modelState = model.modelState;%0A        format = model.format;%0A        bakedTextureGetter = model.bakedTextureGetter;%0A    %7D%0A%0A
     public List%3C
@@ -2559,32 +2559,113 @@
 state)%7B%0A        
+BlockSwitcherBakedModel model = new BlockSwitcherBakedModel(this);%0A        model.
 parent = block.g
@@ -2720,32 +2720,38 @@
 state);%0A        
+model.
 parent = parent 
@@ -2735,32 +2735,38 @@
  model.parent = 
+model.
 parent instanceo
@@ -2824,24 +2824,30 @@
 BlockModel) 
+model.
 parent).hand
@@ -2864,24 +2864,30 @@
 te(state) : 
+model.
 parent;%0A    
@@ -2889,36 +2889,37 @@
 %0A        return 
-this
+model
 ;%0A    %7D%0A%0A    pub
@@ -2976,32 +2976,113 @@
 stack)%7B%0A        
+BlockSwitcherBakedModel model = new BlockSwitcherBakedModel(this);%0A        model.
 parent = block.g
@@ -3137,32 +3137,38 @@
 stack);%0A        
+model.
 parent = parent 
@@ -3160,16 +3160,22 @@
 arent = 
+model.
 parent i
@@ -3243,16 +3243,22 @@
 mModel) 
+model.
 parent).
@@ -3282,16 +3282,22 @@
 tack) : 
+model.
 parent;%0A
@@ -3311,20 +3311,21 @@
  return 
-this
+model
 ;%0A    %7D%0A

fix singleton