mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-10-06 04:25:05 -04:00
44 lines
1.7 KiB
C#
44 lines
1.7 KiB
C#
using System;
|
|
|
|
namespace ClassicalSharp {
|
|
|
|
/// <summary> Stores various properties about the blocks in Minecraft Classic. </summary>
|
|
public partial class BlockInfo {
|
|
|
|
bool[] hidden = new bool[BlocksCount * BlocksCount * TileSide.Sides];
|
|
|
|
internal void SetupCullingCache() {
|
|
for( int tileI = 1; tileI < BlocksCount; tileI++ ) {
|
|
for( int neighbourI = 1; neighbourI < BlocksCount; neighbourI++ ) {
|
|
byte tile = (byte)tileI, neighbour = (byte)neighbourI;
|
|
bool hidden = IsHidden( tile, neighbour );
|
|
if( tile == neighbour && !CullWithNeighbours[tile] )
|
|
hidden = false;
|
|
|
|
SetHidden( tile, neighbour, TileSide.Left, hidden );
|
|
SetHidden( tile, neighbour, TileSide.Right, hidden );
|
|
SetHidden( tile, neighbour, TileSide.Front, hidden );
|
|
SetHidden( tile, neighbour, TileSide.Back, hidden );
|
|
SetHidden( tile, neighbour, TileSide.Top, hidden && Height[tile] == 1 );
|
|
SetHidden( tile, neighbour, TileSide.Bottom, hidden && Height[neighbour] == 1 );
|
|
}
|
|
}
|
|
}
|
|
|
|
bool IsHidden( byte tile, byte block ) {
|
|
return
|
|
((tile == block || (IsOpaque[block] && !IsLiquid[block])) && !IsSprite[tile]) ||
|
|
((tile == (byte)Block.Water || tile == (byte)Block.StillWater) && block == (byte)Block.Ice);
|
|
}
|
|
|
|
void SetHidden( byte tile, byte block, int tileSide, bool value ) {
|
|
hidden[( tile * BlocksCount + block ) * TileSide.Sides + tileSide] = value;
|
|
}
|
|
|
|
/// <summary> Returns whether the face at the given face of the tile
|
|
/// should be drawn with the neighbour 'block' present on the other side of the face. </summary>
|
|
public bool IsFaceHidden( byte tile, byte block, int tileSide ) {
|
|
return hidden[( tile * BlocksCount + block ) * TileSide.Sides + tileSide];
|
|
}
|
|
}
|
|
} |