Files
zzz_REBIRTH__Utils/Harmony/Harmony_Chunk.cs
2025-06-04 16:44:53 +09:30

72 lines
3.2 KiB
C#

namespace Harmony.ChunkPatches
{
[HarmonyPatch(typeof(Chunk))]
[HarmonyPatch("updateFullMap")]
public class updateFullMapPatch
{
public static bool Prefix(Chunk __instance,
ref ushort[] ___mapColors,
byte[] ___m_HeightMap,
ChunkBlockLayer[] ___m_BlockLayers,
ref bool ___bMapDirty,
byte[] ___m_NormalX,
byte[] ___m_NormalY,
byte[] ___m_NormalZ
)
{
if (___mapColors == null)
{
___mapColors = new ushort[256];
}
for (int i = 0; i < 16; i++)
{
for (int j = 0; j < 16; j++)
{
int num = i + j * 16;
int num2 = (int)___m_HeightMap[num];
int num3 = num2 >> 2;
BlockValue blockValue = (___m_BlockLayers[num3] != null) ? ___m_BlockLayers[num3].GetAt(i, num2, j) : BlockValue.Air;
WaterValue water = __instance.GetWater(i, num2, j);
while (num2 > 0 && (blockValue.isair || blockValue.Block.IsTerrainDecoration) && !water.HasMass())
{
num2--;
blockValue = ((___m_BlockLayers[num3] != null) ? ___m_BlockLayers[num3].GetAt(i, num2, j) : BlockValue.Air);
water = __instance.GetWater(i, num2, j);
}
Color col = BlockLiquidv2.Color;
if (!water.HasMass())
{
float x = (float)((sbyte)___m_NormalX[num]) / 127f;
float y = (float)((sbyte)___m_NormalY[num]) / 127f;
float z = (float)((sbyte)___m_NormalZ[num]) / 127f;
//Log.Out("ChunkPatches-updateFullMap block: " + blockValue.Block.GetBlockName());
Vector3i pos = __instance.ToWorldPos(new Vector3i(i, num2, j));
//Log.Out("ChunkPatches-updateFullMap x: " + pos.x);
//Log.Out("ChunkPatches-updateFullMap y: " + pos.y);
//Log.Out("ChunkPatches-updateFullMap z: " + pos.z);
if (blockValue.Block.Properties.Values.ContainsKey("IgnoreMapColor"))
{
col = blockValue.Block.GetMapColor(blockValue, new Vector3(pos.x, pos.y, pos.z), pos.y);
//Log.Out("ChunkPatches-updateFullMap 1, col: " + col.ToString());
}
else
{
col = blockValue.Block.GetMapColor(blockValue, new Vector3(x, y, z), num2);
//Log.Out("ChunkPatches-updateFullMap 3, col: " + col.ToString());
}
}
___mapColors[num] = Utils.ToColor5(col);
}
}
___bMapDirty = false;
ModEvents.CalcChunkColorsDone.Invoke(__instance);
return false;
}
}
}