package com.jaquadro.minecraft.gardenstuff.block;

import com.jaquadro.minecraft.gardencore.api.IPlantProxy;
import com.jaquadro.minecraft.gardencore.api.block.IChainAttachable;
import com.jaquadro.minecraft.gardencore.block.tile.TileEntityGarden;
import com.jaquadro.minecraft.gardencore.core.ModBlocks;
import com.jaquadro.minecraft.gardencore.core.ModCreativeTabs;
import com.jaquadro.minecraft.gardenstuff.GardenStuff;
import com.jaquadro.minecraft.gardenstuff.core.ClientProxy;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

public class BlockLightChain extends Block implements IPlantProxy
{
    private static final Vec3[] defaultAttachPoints = new Vec3[] {
        Vec3.createVectorHelper(.03125, 1, .03125), Vec3.createVectorHelper(.03125, 1, 1 - .03125),
        Vec3.createVectorHelper(1 - .03125, 1, .03125), Vec3.createVectorHelper(1 - .03125, 1, 1 - .03125),
    };
    private static final Vec3[] singleAttachPoint = new Vec3[] {
        Vec3.createVectorHelper(.5, 1, .5),
    };

    public BlockLightChain (String blockName) {
        super(Material.iron);

        setBlockName(blockName);
        setHardness(2.5f);
        setResistance(5f);
        setStepSound(Block.soundTypeMetal);
        setBlockBounds(.5f - .0625f, 0, .5f - .0625f, .5f + .0625f, 1, .5f + .0625f);
        setBlockTextureName(GardenStuff.MOD_ID + ":chain_light");
        setCreativeTab(ModCreativeTabs.tabGardenCore);
    }

    @Override
    public boolean isOpaqueCube () {
        return false;
    }

    @Override
    public boolean renderAsNormalBlock () {
        return false;
    }

    @Override
    public int getRenderType () {
        return ClientProxy.lightChainRenderID; // Crossed Squares
    }

    @Override
    public AxisAlignedBB getCollisionBoundingBoxFromPool (World world, int x, int y, int z) {
        return null;
    }

    @Override
    public boolean applyBonemeal (World world, int x, int y, int z) {
        return ModBlocks.gardenProxy.applyBonemeal(world, x, y, z);
    }

    @Override
    public TileEntityGarden getGardenEntity (IBlockAccess blockAccess, int x, int y, int z) {
        return ModBlocks.gardenProxy.getGardenEntity(blockAccess, x, y, z);
    }

    public int findMinY (IBlockAccess world, int x, int y, int z) {
        while (y > 0) {
            if (world.getBlock(x, --y, z) != this)
                return y + 1;
        }

        return y;
    }

    public int findMaxY (IBlockAccess world, int x, int y, int z) {
        while (y < world.getHeight() - 1) {
            if (world.getBlock(x, ++y, z) != this)
                return y - 1;
        }

        return y;
    }

    public Vec3[] getAttachPoints (IBlockAccess world, int x, int y, int z) {
        int yMin = findMinY(world, x, y, z);
        Block bottomBlock = world.getBlock(x, yMin - 1, z);

        Vec3[] attachPoints = singleAttachPoint;
        if (bottomBlock instanceof IChainAttachable)
            attachPoints = ((IChainAttachable) bottomBlock).getChainAttachPoints();
        else if (bottomBlock.isSideSolid(world, x, y, z, ForgeDirection.UP))
            attachPoints = defaultAttachPoints;

        return attachPoints;
    }
}

@@ -556,16 +556,52 @@
 terial;%0A
+import net.minecraft.entity.Entity;%0A
 import n
@@ -633,16 +633,16 @@
 gnedBB;%0A
-
 import n
@@ -795,16 +795,40 @@
 ction;%0A%0A
+import java.util.List;%0A%0A
 public c
@@ -1699,24 +1699,66 @@
 ardenCore);%0A
+        setBlockBounds(0, 0, 0, 1, 1, 1);%0A
     %7D%0A%0A    @
@@ -2140,32 +2140,32 @@
 int y, int z) %7B%0A
-
         return n
@@ -2168,32 +2168,962 @@
 rn null;%0A    %7D%0A%0A
+    @Override%0A    public AxisAlignedBB getSelectedBoundingBoxFromPool (World world, int x, int y, int z) %7B%0A        float minX = 1;%0A        float minZ = 1;%0A        float maxX = 0;%0A        float maxZ = 0;%0A        for (Vec3 point : getAttachPoints(world, x, y, z)) %7B%0A            if (point.xCoord %3C minX)%0A                minX = (float) point.xCoord;%0A            if (point.zCoord %3C minZ)%0A                minZ = (float) point.zCoord;%0A            if (point.xCoord %3E maxX)%0A                maxX = (float) point.xCoord;%0A            if (point.zCoord %3E maxZ)%0A                maxZ = (float) point.zCoord;%0A        %7D%0A%0A        if (maxX - minX %3C .125) %7B%0A            minX = .5f - .0625f;%0A            maxX = .5f + .0625f;%0A        %7D%0A        if (maxZ - minZ %3C .125) %7B%0A            minZ = .5f - .0625f;%0A            maxZ = .5f + .0625f;%0A        %7D%0A%0A        return AxisAlignedBB.getBoundingBox(x + minX, y + 0, z + minZ, x + maxX, y + 1, z + maxZ);%0A    %7D%0A%0A
     @Override%0A  

Fix chain wireframe