package carpentersblocks.util.collapsible;

import carpentersblocks.data.Collapsible;
import carpentersblocks.tileentity.TEBase;

public class CollapsibleUtil {

    public static double CENTER_YMAX;

    public static double offset_XZNN;
    public static double offset_XZNP;
    public static double offset_XZPN;
    public static double offset_XZPP;

    /**
     * Fills Y-offsets for each corner and center of block for rendering purposes.
     */
    public static void computeOffsets(TEBase TE)
    {
        offset_XZNN = Collapsible.getQuadHeight(TE, Collapsible.QUAD_XZNN) / 16.0D;
        offset_XZNP = Collapsible.getQuadHeight(TE, Collapsible.QUAD_XZNP) / 16.0D;
        offset_XZPN = Collapsible.getQuadHeight(TE, Collapsible.QUAD_XZPN) / 16.0D;
        offset_XZPP = Collapsible.getQuadHeight(TE, Collapsible.QUAD_XZPP) / 16.0D;

        /* Find primary corners and set center yMax offset. */

        double NW_SE = Math.abs(offset_XZNN - offset_XZPP);
        double NE_SW = Math.abs(offset_XZPN - offset_XZNP);

        /*
         * Changing this to NW_SE > NE_SW will change how slopes are split.
         * It's really a matter of personal preference.
         */
        if (NW_SE < NE_SW) {
            CENTER_YMAX = (offset_XZPN + offset_XZNP) / 2.0F;
        } else {
            CENTER_YMAX = (offset_XZNN + offset_XZPP) / 2.0F;
        }
    }

}

@@ -501,16 +501,108 @@
 )%0A    %7B%0A
+        double BIAS = 1.0D / 1024.0D; /* small offset to prevent Z-fighting at height 1 */%0A%0A
         
@@ -611,24 +611,25 @@
 fset_XZNN = 
+(
 Collapsible.
@@ -668,24 +668,39 @@
 AD_XZNN)
+ - 1.0D)
  / 1
-6
+5
 .0D
+ + BIAS
 ;%0A      
@@ -711,24 +711,25 @@
 fset_XZNP = 
+(
 Collapsible.
@@ -768,24 +768,39 @@
 AD_XZNP)
+ - 1.0D)
  / 1
-6
+5
 .0D
+ + BIAS
 ;%0A      
@@ -815,16 +815,17 @@
 _XZPN = 
+(
 Collapsi
@@ -868,24 +868,39 @@
 AD_XZPN)
+ - 1.0D)
  / 1
-6
+5
 .0D
+ + BIAS
 ;%0A      
@@ -915,16 +915,17 @@
 _XZPP = 
+(
 Collapsi
@@ -972,16 +972,31 @@
 ZPP)
+ - 1.0D)
  / 1
-6
+5
 .0D
+ + BIAS
 ;%0A%0A 

Fix seams between adjacent CollapsibleBlocks