About MH2O water algorithm

Some days ago I got the idea to make a little table with HTML that can show if a chunck have water or not.

First i need to understand how the molecular formula for water works, it’s a bit ugly because some years ago when we have the MCLQ chuck was pretty easy to make a water editor (Like AllWater.exe by Cryect).

Here is the PHP Code that read 256 values from water:

//===================================
//ADT MH2O INFO
//===================================
$OFFVALUE = "0x".EndianConverter($STRUCT_INFO["MH2O_Offset"]);
fseek($ADT_Handle,0x14+0x04+0x04+$OFFVALUE,SEEK_SET);
 
$NumWater = 256;
$WATER_DATAZ = array(array());
 
for($x = 0;$x < $NumWater;$x++):
 
$WATER_DATA = bin2hex(fread($ADT_Handle,4));
$WATER_DATAZ[$x][WATER_OFFSET] = EndianConverter($WATER_DATA);
$WATER_DATA = bin2hex(fread($ADT_Handle,4));
$WATER_DATAZ[$x][WATER_LAYERCOUNT] = EndianConverter($WATER_DATA);
$WATER_DATA = bin2hex(fread($ADT_Handle,4));
$WATER_DATAZ[$x][WATER_OFSRENDERMASK] = EndianConverter($WATER_DATA);
 
endfor;

This will generate an array like this:

........
    [14] => Array
        (
            [WATER_OFFSET] => 00000c18
            [WATER_LAYERCOUNT] => 00000001
            [WATER_OFSRENDERMASK] => 0000108f
        )
 
    [15] => Array
        (
            [WATER_OFFSET] => 00000c30
            [WATER_LAYERCOUNT] => 00000001
            [WATER_OFSRENDERMASK] => 00001234
        )
 
    [16] => Array
        (
            [WATER_OFFSET] => 00000000
            [WATER_LAYERCOUNT] => 00000000
            [WATER_OFSRENDERMASK] => 00000000
        )
 
.......

And here is the code that show the water inside HTML table ( 16 * 16 = 256 cells):

echo '<table width="50%" border="0.5" cellpadding="0" cellspacing="0"> ';
echo ' <tr>';
$i = 1;
for($x = 0;$x<256;$x++){
if($WATER_DATAZ[$x][WATER_OFFSET] == "00000000"){
$water = false;
}else{
$water = true;
}
if($water){ $BACKGOUND = 'bgcolor="blue"'; } else { $BACKGOUND = ''; }
echo ' <td '.$BACKGOUND.'> ';
 
echo ' <td> ';
if($i%16 == 0) {
echo ' </tr>';
echo ' <tr>';
}
 
$i++;
}
echo " </tr>";
echo "</table>";

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.