package common.block;

import common.entity.npc.EntityNPC;
import common.init.Blocks;
import common.init.Items;
import common.item.Item;
import common.model.Model;
import common.model.ModelProvider;
import common.model.ModelRotation;
import common.model.ParticleType;
import common.properties.IProperty;
import common.properties.PropertyBool;
import common.properties.PropertyInteger;
import common.rng.Random;
import common.util.BlockPos;
import common.util.Facing;
import common.world.IWorldAccess;
import common.world.AWorldClient;
import common.world.State;
import common.world.World;
import common.world.AWorldServer;

public class BlockRedstoneRepeater extends BlockRedstoneDiode
{
    public static final PropertyBool LOCKED = PropertyBool.create("locked");
    public static final PropertyInteger DELAY = PropertyInteger.create("delay", 1, 4);

    public BlockRedstoneRepeater(boolean powered)
    {
        super(powered);
        this.setDefaultState(this.getBaseState().withProperty(FACING, Facing.NORTH).withProperty(DELAY, Integer.valueOf(1)).withProperty(LOCKED, Boolean.valueOf(false)));
    }

//    /**
//     * Gets the localized name of this block. Used for the statistics page.
//     */
//    public String getLocalizedName()
//    {
//        return "Redstone-Verstärker";
//    }

    /**
     * Get the actual Block state of this Block at the given position. This applies properties not visible in the
     * metadata, such as fence connections.
     */
    public State getActualState(State state, IWorldAccess worldIn, BlockPos pos)
    {
        return state.withProperty(LOCKED, Boolean.valueOf(this.isLocked(worldIn, pos, state)));
    }

    public boolean onBlockActivated(World worldIn, BlockPos pos, State state, EntityNPC playerIn, Facing side, float hitX, float hitY, float hitZ)
    {
//        if (!playerIn.capabilities.allowEdit)
//        {
//            return false;
//        }
//        else
//        {
        worldIn.setState(pos, state.cycleProperty(DELAY), 3);
        return true;
//        }
    }

    protected int getDelay(State state)
    {
        return ((Integer)state.getValue(DELAY)).intValue() * 2;
    }

    protected State getPoweredState(State unpoweredState)
    {
        Integer integer = (Integer)unpoweredState.getValue(DELAY);
        Boolean obool = (Boolean)unpoweredState.getValue(LOCKED);
        Facing enumfacing = (Facing)unpoweredState.getValue(FACING);
        return Blocks.powered_repeater.getState().withProperty(FACING, enumfacing).withProperty(DELAY, integer).withProperty(LOCKED, obool);
    }

    protected State getUnpoweredState(State poweredState)
    {
        Integer integer = (Integer)poweredState.getValue(DELAY);
        Boolean obool = (Boolean)poweredState.getValue(LOCKED);
        Facing enumfacing = (Facing)poweredState.getValue(FACING);
        return Blocks.repeater.getState().withProperty(FACING, enumfacing).withProperty(DELAY, integer).withProperty(LOCKED, obool);
    }

    /**
     * Get the Item that this Block should drop when harvested.
     */
    public Item getItemDropped(State state, Random rand, int fortune)
    {
        return Items.repeater;
    }

    public Item getItem(World worldIn, BlockPos pos)
    {
        return Items.repeater;
    }

    public boolean isLocked(IWorldAccess worldIn, BlockPos pos, State state)
    {
        return this.getPowerOnSides(worldIn, pos, state) > 0;
    }

    protected boolean canPowerSide(Block blockIn)
    {
        return isRedstoneRepeaterBlockID(blockIn);
    }

    public void randomDisplayTick(AWorldClient worldIn, BlockPos pos, State state, Random rand)
    {
        if (this.isRepeaterPowered)
        {
            Facing enumfacing = (Facing)state.getValue(FACING);
            double d0 = (double)((float)pos.getX() + 0.5F) + (double)(rand.floatv() - 0.5F) * 0.2D;
            double d1 = (double)((float)pos.getY() + 0.4F) + (double)(rand.floatv() - 0.5F) * 0.2D;
            double d2 = (double)((float)pos.getZ() + 0.5F) + (double)(rand.floatv() - 0.5F) * 0.2D;
            float f = -5.0F;

            if (rand.chance())
            {
                f = (float)(((Integer)state.getValue(DELAY)).intValue() * 2 - 1);
            }

            f = f / 16.0F;
            double d3 = (double)(f * (float)enumfacing.getFrontOffsetX());
            double d4 = (double)(f * (float)enumfacing.getFrontOffsetZ());
            worldIn.spawnParticle(ParticleType.REDSTONE, d0 + d3, d1, d2 + d4, 0.0D, 0.0D, 0.0D);
        }
    }

    public void onBlockRemoved(AWorldServer worldIn, BlockPos pos, State state)
    {
        super.onBlockRemoved(worldIn, pos, state);
        this.notifyNeighbors(worldIn, pos, state);
    }

    /**
     * Convert the given metadata into a BlockState for this Block
     */
    public State getStateFromMeta(int meta)
    {
        return this.getState().withProperty(FACING, Facing.getHorizontal(meta)).withProperty(LOCKED, Boolean.valueOf(false)).withProperty(DELAY, Integer.valueOf(1 + (meta >> 2)));
    }

    /**
     * Convert the BlockState into the correct metadata value
     */
    public int getMetaFromState(State state)
    {
        int i = 0;
        i = i | ((Facing)state.getValue(FACING)).getHorizontalIndex();
        i = i | ((Integer)state.getValue(DELAY)).intValue() - 1 << 2;
        return i;
    }

    protected IProperty[] getProperties()
    {
        return new IProperty[] {FACING, DELAY, LOCKED};
    }
    
    private static Model getModelOff(int delay) {
    	switch(delay) {
    	case 1:
    	default:
    		return ModelProvider.getModelProvider().getModel("repeater_off").noOcclude()
    				.add(0, 0, 0, 16, 2, 16)
    				.d("double_stone_top").uv(0, 0, 16, 16)
    				.u().uv(0, 0, 16, 16).noCull()
    				.n("double_stone_top").uv(0, 14, 16, 16)
    				.s("double_stone_top").uv(0, 14, 16, 16)
    				.w("double_stone_top").uv(0, 14, 16, 16)
    				.e("double_stone_top").uv(0, 14, 16, 16)
    			.add(7, 2, 6, 9, 7, 8)
    				.d("unlit_redstone_torch").uv(7, 13, 9, 15).noCull()
    				.u("unlit_redstone_torch").uv(7, 6, 9, 8).noCull()
    				.n("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.s("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.w("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.e("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    			.add(7, 2, 2, 9, 7, 4)
    				.d("unlit_redstone_torch").uv(7, 13, 9, 15).noCull()
    				.u("unlit_redstone_torch").uv(7, 6, 9, 8).noCull()
    				.n("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.s("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.w("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.e("unlit_redstone_torch").uv(7, 6, 9, 11).noCull();
    	case 2:
    		return ModelProvider.getModelProvider().getModel("repeater_off").noOcclude()
    				.add(0, 0, 0, 16, 2, 16)
    				.d("double_stone_top").uv(0, 0, 16, 16)
    				.u().uv(0, 0, 16, 16).noCull()
    				.n("double_stone_top").uv(0, 14, 16, 16)
    				.s("double_stone_top").uv(0, 14, 16, 16)
    				.w("double_stone_top").uv(0, 14, 16, 16)
    				.e("double_stone_top").uv(0, 14, 16, 16)
    			.add(7, 2, 8, 9, 7, 10)
    				.d("unlit_redstone_torch").uv(7, 13, 9, 15).noCull()
    				.u("unlit_redstone_torch").uv(7, 6, 9, 8).noCull()
    				.n("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.s("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.w("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.e("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    			.add(7, 2, 2, 9, 7, 4)
    				.d("unlit_redstone_torch").uv(7, 13, 9, 15).noCull()
    				.u("unlit_redstone_torch").uv(7, 6, 9, 8).noCull()
    				.n("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.s("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.w("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.e("unlit_redstone_torch").uv(7, 6, 9, 11).noCull();
    	case 3:
    		return ModelProvider.getModelProvider().getModel("repeater_off").noOcclude()
    				.add(0, 0, 0, 16, 2, 16)
    				.d("double_stone_top").uv(0, 0, 16, 16)
    				.u().uv(0, 0, 16, 16).noCull()
    				.n("double_stone_top").uv(0, 14, 16, 16)
    				.s("double_stone_top").uv(0, 14, 16, 16)
    				.w("double_stone_top").uv(0, 14, 16, 16)
    				.e("double_stone_top").uv(0, 14, 16, 16)
    			.add(7, 2, 10, 9, 7, 12)
    				.d("unlit_redstone_torch").uv(7, 13, 9, 15).noCull()
    				.u("unlit_redstone_torch").uv(7, 6, 9, 8).noCull()
    				.n("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.s("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.w("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.e("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    			.add(7, 2, 2, 9, 7, 4)
    				.d("unlit_redstone_torch").uv(7, 13, 9, 15).noCull()
    				.u("unlit_redstone_torch").uv(7, 6, 9, 8).noCull()
    				.n("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.s("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.w("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.e("unlit_redstone_torch").uv(7, 6, 9, 11).noCull();
    	case 4:
    		return ModelProvider.getModelProvider().getModel("repeater_off").noOcclude()
    				.add(0, 0, 0, 16, 2, 16)
    				.d("double_stone_top").uv(0, 0, 16, 16)
    				.u().uv(0, 0, 16, 16).noCull()
    				.n("double_stone_top").uv(0, 14, 16, 16)
    				.s("double_stone_top").uv(0, 14, 16, 16)
    				.w("double_stone_top").uv(0, 14, 16, 16)
    				.e("double_stone_top").uv(0, 14, 16, 16)
    			.add(7, 2, 12, 9, 7, 14)
    				.d("unlit_redstone_torch").uv(7, 13, 9, 15).noCull()
    				.u("unlit_redstone_torch").uv(7, 6, 9, 8).noCull()
    				.n("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.s("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.w("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.e("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    			.add(7, 2, 2, 9, 7, 4)
    				.d("unlit_redstone_torch").uv(7, 13, 9, 15).noCull()
    				.u("unlit_redstone_torch").uv(7, 6, 9, 8).noCull()
    				.n("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.s("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.w("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.e("unlit_redstone_torch").uv(7, 6, 9, 11).noCull();
    	}
    }
    
    private static Model getModelOn(int delay) {
    	switch(delay) {
    	case 1:
    	default:
    		return ModelProvider.getModelProvider().getModel("repeater_on").noOcclude()
    				.add(0, 0, 0, 16, 2, 16)
    				.d("double_stone_top").uv(0, 0, 16, 16)
    				.u().uv(0, 0, 16, 16).noCull()
    				.n("double_stone_top").uv(0, 14, 16, 16)
    				.s("double_stone_top").uv(0, 14, 16, 16)
    				.w("double_stone_top").uv(0, 14, 16, 16)
    				.e("double_stone_top").uv(0, 14, 16, 16)
    			.add(7, 7, 6, 9, 7, 8)
    				.u("redstone_torch").uv(7, 6, 9, 8).noCull()
    			.add(7, 2, 5, 9, 8, 9)
    				.w("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.e("redstone_torch").uv(6, 5, 10, 11).noCull()
    			.add(6, 2, 6, 10, 8, 8)
    				.n("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.s("redstone_torch").uv(6, 5, 10, 11).noCull()
    			.add(7, 7, 2, 9, 7, 4)
    				.u("redstone_torch").uv(7, 6, 9, 8).noCull()
    			.add(7, 2, 1, 9, 8, 5)
    				.w("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.e("redstone_torch").uv(6, 5, 10, 11).noCull()
    			.add(6, 2, 2, 10, 8, 4)
    				.n("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.s("redstone_torch").uv(6, 5, 10, 11).noCull();
    	case 2:
    		return ModelProvider.getModelProvider().getModel("repeater_on").noOcclude()
    				.add(0, 0, 0, 16, 2, 16)
    				.d("double_stone_top").uv(0, 0, 16, 16)
    				.u().uv(0, 0, 16, 16).noCull()
    				.n("double_stone_top").uv(0, 14, 16, 16)
    				.s("double_stone_top").uv(0, 14, 16, 16)
    				.w("double_stone_top").uv(0, 14, 16, 16)
    				.e("double_stone_top").uv(0, 14, 16, 16)
    			.add(7, 7, 8, 9, 7, 10)
    				.u("redstone_torch").uv(7, 6, 9, 8).noCull()
    			.add(7, 2, 7, 9, 8, 11)
    				.w("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.e("redstone_torch").uv(6, 5, 10, 11).noCull()
    			.add(6, 2, 8, 10, 8, 10)
    				.n("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.s("redstone_torch").uv(6, 5, 10, 11).noCull()
    			.add(7, 7, 2, 9, 7, 4)
    				.u("redstone_torch").uv(7, 6, 9, 8).noCull()
    			.add(7, 2, 1, 9, 8, 5)
    				.w("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.e("redstone_torch").uv(6, 5, 10, 11).noCull()
    			.add(6, 2, 2, 10, 8, 4)
    				.n("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.s("redstone_torch").uv(6, 5, 10, 11).noCull();
    	case 3:
    		return ModelProvider.getModelProvider().getModel("repeater_on").noOcclude()
    				.add(0, 0, 0, 16, 2, 16)
    				.d("double_stone_top").uv(0, 0, 16, 16)
    				.u().uv(0, 0, 16, 16).noCull()
    				.n("double_stone_top").uv(0, 14, 16, 16)
    				.s("double_stone_top").uv(0, 14, 16, 16)
    				.w("double_stone_top").uv(0, 14, 16, 16)
    				.e("double_stone_top").uv(0, 14, 16, 16)
    			.add(7, 7, 10, 9, 7, 12)
    				.u("redstone_torch").uv(7, 6, 9, 8).noCull()
    			.add(7, 2, 9, 9, 8, 13)
    				.w("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.e("redstone_torch").uv(6, 5, 10, 11).noCull()
    			.add(6, 2, 10, 10, 8, 12)
    				.n("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.s("redstone_torch").uv(6, 5, 10, 11).noCull()
    			.add(7, 7, 2, 9, 7, 4)
    				.u("redstone_torch").uv(7, 6, 9, 8).noCull()
    			.add(7, 2, 1, 9, 8, 5)
    				.w("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.e("redstone_torch").uv(6, 5, 10, 11).noCull()
    			.add(6, 2, 2, 10, 8, 4)
    				.n("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.s("redstone_torch").uv(6, 5, 10, 11).noCull();
    	case 4:
    		return ModelProvider.getModelProvider().getModel("repeater_on").noOcclude()
    				.add(0, 0, 0, 16, 2, 16)
    				.d("double_stone_top").uv(0, 0, 16, 16)
    				.u().uv(0, 0, 16, 16).noCull()
    				.n("double_stone_top").uv(0, 14, 16, 16)
    				.s("double_stone_top").uv(0, 14, 16, 16)
    				.w("double_stone_top").uv(0, 14, 16, 16)
    				.e("double_stone_top").uv(0, 14, 16, 16)
    			.add(7, 7, 12, 9, 7, 14)
    				.u("redstone_torch").uv(7, 6, 9, 8).noCull()
    			.add(7, 2, 11, 9, 8, 15)
    				.w("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.e("redstone_torch").uv(6, 5, 10, 11).noCull()
    			.add(6, 2, 12, 10, 8, 14)
    				.n("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.s("redstone_torch").uv(6, 5, 10, 11).noCull()
    			.add(7, 7, 2, 9, 7, 4)
    				.u("redstone_torch").uv(7, 6, 9, 8).noCull()
    			.add(7, 2, 1, 9, 8, 5)
    				.w("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.e("redstone_torch").uv(6, 5, 10, 11).noCull()
    			.add(6, 2, 2, 10, 8, 4)
    				.n("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.s("redstone_torch").uv(6, 5, 10, 11).noCull();
    	}
    }
    
    private static Model getModelOffLocked(int delay) {
    	switch(delay) {
    	case 1:
    	default:
    		return ModelProvider.getModelProvider().getModel("repeater_off").noOcclude()
    				.add(0, 0, 0, 16, 2, 16)
    				.d("double_stone_top").uv(0, 0, 16, 16)
    				.u().uv(0, 0, 16, 16).noCull()
    				.n("double_stone_top").uv(0, 14, 16, 16)
    				.s("double_stone_top").uv(0, 14, 16, 16)
    				.w("double_stone_top").uv(0, 14, 16, 16)
    				.e("double_stone_top").uv(0, 14, 16, 16)
    			.add(2, 2, 6, 14, 4, 8)
    				.d("bedrock").uv(7, 2, 9, 14).rot(90).noCull()
    				.u("bedrock").uv(7, 2, 9, 14).rot(90).noCull()
    				.n("bedrock").uv(2, 7, 14, 9).noCull()
    				.s("bedrock").uv(2, 7, 14, 9).noCull()
    				.w("bedrock").uv(6, 7, 8, 9).noCull()
    				.e("bedrock").uv(6, 7, 8, 9).noCull()
    			.add(7, 2, 2, 9, 7, 4)
    				.d("unlit_redstone_torch").uv(7, 13, 9, 15).noCull()
    				.u("unlit_redstone_torch").uv(7, 6, 9, 8).noCull()
    				.n("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.s("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.w("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.e("unlit_redstone_torch").uv(7, 6, 9, 11).noCull();
    	case 2:
    		return ModelProvider.getModelProvider().getModel("repeater_off").noOcclude()
    				.add(0, 0, 0, 16, 2, 16)
    				.d("double_stone_top").uv(0, 0, 16, 16)
    				.u().uv(0, 0, 16, 16).noCull()
    				.n("double_stone_top").uv(0, 14, 16, 16)
    				.s("double_stone_top").uv(0, 14, 16, 16)
    				.w("double_stone_top").uv(0, 14, 16, 16)
    				.e("double_stone_top").uv(0, 14, 16, 16)
    			.add(2, 2, 8, 14, 4, 10)
    				.d("bedrock").uv(7, 2, 9, 14).rot(90).noCull()
    				.u("bedrock").uv(7, 2, 9, 14).rot(90).noCull()
    				.n("bedrock").uv(2, 7, 14, 9).noCull()
    				.s("bedrock").uv(2, 7, 14, 9).noCull()
    				.w("bedrock").uv(6, 7, 8, 9).noCull()
    				.e("bedrock").uv(6, 7, 8, 9).noCull()
    			.add(7, 2, 2, 9, 7, 4)
    				.d("unlit_redstone_torch").uv(7, 13, 9, 15).noCull()
    				.u("unlit_redstone_torch").uv(7, 6, 9, 8).noCull()
    				.n("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.s("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.w("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.e("unlit_redstone_torch").uv(7, 6, 9, 11).noCull();
    	case 3:
    		return ModelProvider.getModelProvider().getModel("repeater_off").noOcclude()
    				.add(0, 0, 0, 16, 2, 16)
    				.d("double_stone_top").uv(0, 0, 16, 16)
    				.u().uv(0, 0, 16, 16).noCull()
    				.n("double_stone_top").uv(0, 14, 16, 16)
    				.s("double_stone_top").uv(0, 14, 16, 16)
    				.w("double_stone_top").uv(0, 14, 16, 16)
    				.e("double_stone_top").uv(0, 14, 16, 16)
    			.add(2, 2, 10, 14, 4, 12)
    				.d("bedrock").uv(7, 2, 9, 14).rot(90).noCull()
    				.u("bedrock").uv(7, 2, 9, 14).rot(90).noCull()
    				.n("bedrock").uv(2, 7, 14, 9).noCull()
    				.s("bedrock").uv(2, 7, 14, 9).noCull()
    				.w("bedrock").uv(6, 7, 8, 9).noCull()
    				.e("bedrock").uv(6, 7, 8, 9).noCull()
    			.add(7, 2, 2, 9, 7, 4)
    				.d("unlit_redstone_torch").uv(7, 13, 9, 15).noCull()
    				.u("unlit_redstone_torch").uv(7, 6, 9, 8).noCull()
    				.n("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.s("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.w("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.e("unlit_redstone_torch").uv(7, 6, 9, 11).noCull();
    	case 4:
    		return ModelProvider.getModelProvider().getModel("repeater_off").noOcclude()
    				.add(0, 0, 0, 16, 2, 16)
    				.d("double_stone_top").uv(0, 0, 16, 16)
    				.u().uv(0, 0, 16, 16).noCull()
    				.n("double_stone_top").uv(0, 14, 16, 16)
    				.s("double_stone_top").uv(0, 14, 16, 16)
    				.w("double_stone_top").uv(0, 14, 16, 16)
    				.e("double_stone_top").uv(0, 14, 16, 16)
    			.add(2, 2, 12, 14, 4, 14)
    				.d("bedrock").uv(7, 2, 9, 14).rot(90).noCull()
    				.u("bedrock").uv(7, 2, 9, 14).rot(90).noCull()
    				.n("bedrock").uv(2, 7, 14, 9).noCull()
    				.s("bedrock").uv(2, 7, 14, 9).noCull()
    				.w("bedrock").uv(6, 7, 8, 9).noCull()
    				.e("bedrock").uv(6, 7, 8, 9).noCull()
    			.add(7, 2, 2, 9, 7, 4)
    				.d("unlit_redstone_torch").uv(7, 13, 9, 15).noCull()
    				.u("unlit_redstone_torch").uv(7, 6, 9, 8).noCull()
    				.n("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.s("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.w("unlit_redstone_torch").uv(7, 6, 9, 11).noCull()
    				.e("unlit_redstone_torch").uv(7, 6, 9, 11).noCull();
    	}
    }
    
    private static Model getModelOnLocked(int delay) {
    	switch(delay) {
    	case 1:
    	default:
    		return ModelProvider.getModelProvider().getModel("repeater_on").noOcclude()
    				.add(0, 0, 0, 16, 2, 16)
    				.d("double_stone_top").uv(0, 0, 16, 16)
    				.u().uv(0, 0, 16, 16).noCull()
    				.n("double_stone_top").uv(0, 14, 16, 16)
    				.s("double_stone_top").uv(0, 14, 16, 16)
    				.w("double_stone_top").uv(0, 14, 16, 16)
    				.e("double_stone_top").uv(0, 14, 16, 16)
    			.add(2, 2, 6, 14, 4, 8)
    				.d("bedrock").uv(7, 2, 9, 14).rot(90).noCull()
    				.u("bedrock").uv(7, 2, 9, 14).rot(90).noCull()
    				.n("bedrock").uv(2, 7, 14, 9).noCull()
    				.s("bedrock").uv(2, 7, 14, 9).noCull()
    				.w("bedrock").uv(6, 7, 8, 9).noCull()
    				.e("bedrock").uv(6, 7, 8, 9).noCull()
    			.add(7, 7, 2, 9, 7, 4)
    				.u("redstone_torch").uv(7, 6, 9, 8).noCull()
    			.add(7, 2, 1, 9, 8, 5)
    				.w("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.e("redstone_torch").uv(6, 5, 10, 11).noCull()
    			.add(6, 2, 2, 10, 8, 4)
    				.n("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.s("redstone_torch").uv(6, 5, 10, 11).noCull();
    	case 2:
    		return ModelProvider.getModelProvider().getModel("repeater_on").noOcclude()
    				.add(0, 0, 0, 16, 2, 16)
    				.d("double_stone_top").uv(0, 0, 16, 16)
    				.u().uv(0, 0, 16, 16).noCull()
    				.n("double_stone_top").uv(0, 14, 16, 16)
    				.s("double_stone_top").uv(0, 14, 16, 16)
    				.w("double_stone_top").uv(0, 14, 16, 16)
    				.e("double_stone_top").uv(0, 14, 16, 16)
    			.add(2, 2, 8, 14, 4, 10)
    				.d("bedrock").uv(7, 2, 9, 14).rot(90).noCull()
    				.u("bedrock").uv(7, 2, 9, 14).rot(90).noCull()
    				.n("bedrock").uv(2, 7, 14, 9).noCull()
    				.s("bedrock").uv(2, 7, 14, 9).noCull()
    				.w("bedrock").uv(6, 7, 8, 9).noCull()
    				.e("bedrock").uv(6, 7, 8, 9).noCull()
    			.add(7, 7, 2, 9, 7, 4)
    				.u("redstone_torch").uv(7, 6, 9, 8).noCull()
    			.add(7, 2, 1, 9, 8, 5)
    				.w("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.e("redstone_torch").uv(6, 5, 10, 11).noCull()
    			.add(6, 2, 2, 10, 8, 4)
    				.n("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.s("redstone_torch").uv(6, 5, 10, 11).noCull();
    	case 3:
    		return ModelProvider.getModelProvider().getModel("repeater_on").noOcclude()
    				.add(0, 0, 0, 16, 2, 16)
    				.d("double_stone_top").uv(0, 0, 16, 16)
    				.u().uv(0, 0, 16, 16).noCull()
    				.n("double_stone_top").uv(0, 14, 16, 16)
    				.s("double_stone_top").uv(0, 14, 16, 16)
    				.w("double_stone_top").uv(0, 14, 16, 16)
    				.e("double_stone_top").uv(0, 14, 16, 16)
    			.add(2, 2, 10, 14, 4, 12)
    				.d("bedrock").uv(7, 2, 9, 14).rot(90).noCull()
    				.u("bedrock").uv(7, 2, 9, 14).rot(90).noCull()
    				.n("bedrock").uv(2, 7, 14, 9).noCull()
    				.s("bedrock").uv(2, 7, 14, 9).noCull()
    				.w("bedrock").uv(6, 7, 8, 9).noCull()
    				.e("bedrock").uv(6, 7, 8, 9).noCull()
    			.add(7, 7, 2, 9, 7, 4)
    				.u("redstone_torch").uv(7, 6, 9, 8).noCull()
    			.add(7, 2, 1, 9, 8, 5)
    				.w("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.e("redstone_torch").uv(6, 5, 10, 11).noCull()
    			.add(6, 2, 2, 10, 8, 4)
    				.n("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.s("redstone_torch").uv(6, 5, 10, 11).noCull();
    	case 4:
    		return ModelProvider.getModelProvider().getModel("repeater_on").noOcclude()
    				.add(0, 0, 0, 16, 2, 16)
    				.d("double_stone_top").uv(0, 0, 16, 16)
    				.u().uv(0, 0, 16, 16).noCull()
    				.n("double_stone_top").uv(0, 14, 16, 16)
    				.s("double_stone_top").uv(0, 14, 16, 16)
    				.w("double_stone_top").uv(0, 14, 16, 16)
    				.e("double_stone_top").uv(0, 14, 16, 16)
    			.add(2, 2, 12, 14, 4, 14)
    				.d("bedrock").uv(7, 2, 9, 14).rot(90).noCull()
    				.u("bedrock").uv(7, 2, 9, 14).rot(90).noCull()
    				.n("bedrock").uv(2, 7, 14, 9).noCull()
    				.s("bedrock").uv(2, 7, 14, 9).noCull()
    				.w("bedrock").uv(6, 7, 8, 9).noCull()
    				.e("bedrock").uv(6, 7, 8, 9).noCull()
    			.add(7, 7, 2, 9, 7, 4)
    				.u("redstone_torch").uv(7, 6, 9, 8).noCull()
    			.add(7, 2, 1, 9, 8, 5)
    				.w("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.e("redstone_torch").uv(6, 5, 10, 11).noCull()
    			.add(6, 2, 2, 10, 8, 4)
    				.n("redstone_torch").uv(6, 5, 10, 11).noCull()
    				.s("redstone_torch").uv(6, 5, 10, 11).noCull();
    	}
    }
    
    public Model getModel(ModelProvider provider, String name, State state) {
    	return (this.isRepeaterPowered ? (state.getValue(LOCKED) ? getModelOnLocked(state.getValue(DELAY)) : 
    			getModelOn(state.getValue(DELAY))) : (state.getValue(LOCKED) ? getModelOffLocked(state.getValue(DELAY)) : 
    			getModelOff(state.getValue(DELAY))))
    			.rotate(ModelRotation.getNorthRot(state.getValue(FACING).getOpposite()));
    }
}
