using System; namespace ClassicalSharp { /// Stores various properties about the blocks in Minecraft Classic. public partial class BlockInfo { internal bool[] isTransparent = new bool[BlocksCount]; internal bool[] isTranslucent = new bool[BlocksCount]; internal bool[] isOpaque = new bool[BlocksCount]; internal bool[] isSprite = new bool[BlocksCount]; internal bool[] isLiquid = new bool[BlocksCount]; internal float[] heights = new float[BlocksCount]; internal bool[] blocksLight = new bool[BlocksCount]; internal bool[] emitsLight = new bool[BlocksCount]; public const byte MaxDefinedBlock = (byte)Block.StoneBrick; public const byte BlocksCount = MaxDefinedBlock + 1; public void Init() { for( int tile = 1; tile < BlocksCount; tile++ ) { heights[tile] = 1f; blocksLight[tile] = true; isOpaque[tile] = true; } SetupOptimTextures(); SetIsTranslucent( Block.StillWater, Block.Water ); SetIsTransparent( Block.Glass, Block.Leaves, Block.Sapling, Block.RedMushroom, Block.BrownMushroom, Block.Rose, Block.Dandelion, Block.Slab ); SetIsSprite( Block.Rose, Block.Sapling, Block.Dandelion, Block.BrownMushroom, Block.RedMushroom ); SetBlockHeight( 8 / 16f, Block.Slab ); SetBlocksLight( false, Block.Glass, Block.Leaves, Block.Sapling, Block.RedMushroom, Block.BrownMushroom, Block.Rose, Block.Dandelion ); SetIsLiquid( Block.StillWater, Block.Water, Block.StillLava, Block.Lava ); SetIsTransparent( Block.Snow, Block.Fire, Block.Rope, Block.CobblestoneSlab ); SetBlocksLight( false, Block.Fire, Block.Rope ); SetIsTranslucent( Block.Ice ); SetIsSprite( Block.Rope, Block.Fire ); SetBlockHeight( 8 / 16f, Block.CobblestoneSlab ); SetBlockHeight( 2 / 16f, Block.Snow ); SetEmitsLight( true, Block.Lava, Block.StillLava ); SetupCullingCache(); } public void SetDefaultBlockPermissions( bool[] canPlace, bool[] canDelete ) { for( int tile = (int)Block.Stone; tile <= (int)Block.Obsidian; tile++ ) { canPlace[tile] = true; canDelete[tile] = true; } canPlace[(int)Block.Grass] = false; canPlace[(int)Block.Lava] = false; canPlace[(int)Block.Water] = false; canPlace[(int)Block.StillLava] = false; canPlace[(int)Block.StillWater] = false; canPlace[(int)Block.Bedrock] = false; canDelete[(int)Block.Bedrock] = false; canDelete[(int)Block.Lava] = false; canDelete[(int)Block.Water] = false; canDelete[(int)Block.StillWater] = false; canDelete[(int)Block.StillLava] = false; } void SetIsTransparent( params Block[] ids ) { for( int i = 0; i < ids.Length; i++ ) { isTransparent[(int)ids[i]] = true; isOpaque[(int)ids[i]] = false; } } void SetIsSprite( params Block[] ids ) { for( int i = 0; i < ids.Length; i++ ) { isSprite[(int)ids[i]] = true; } } void SetIsTranslucent( params Block[] ids ) { for( int i = 0; i < ids.Length; i++ ) { isTranslucent[(int)ids[i]] = true; isOpaque[(int)ids[i]] = false; } } void SetIsLiquid( params Block[] ids ) { for( int i = 0; i < ids.Length; i++ ) { isLiquid[(int)ids[i]] = true; } } void SetBlockHeight( float height, params Block[] ids ) { for( int i = 0; i < ids.Length; i++ ) { heights[(int)ids[i]] = height; } } void SetBlocksLight( bool blocks, params Block[] ids ) { for( int i = 0; i < ids.Length; i++ ) { blocksLight[(int)ids[i]] = blocks; } } void SetEmitsLight( bool emits, params Block[] ids ) { for( int i = 0; i < ids.Length; i++ ) { emitsLight[(int)ids[i]] = emits; } } /// Gets whether the given block id is opaque/not see through. public bool IsOpaque( byte id ) { return isOpaque[id]; } /// Gets whether the given block id is opaque/not see through, and occupies a full block. public bool IsFullAndOpaque( byte id ) { return isOpaque[id] && heights[id] == 1; } /// Gets whether the given block id is transparent/fully see through. /// Alpha values are treated as either 'fully see through' or 'fully solid'. public bool IsTransparent( byte id ) { return isTransparent[id]; } /// Gets the tile height of the given block id. public float BlockHeight( byte id ) { return heights[id]; } /// Gets whether the given block id is translucent/partially see through. /// Colour values are blended into both the transparent and opaque blocks behind them. public bool IsTranslucent( byte id ) { return isTranslucent[id]; } /// Gets whether the given block blocks sunlight. public bool BlocksLight( byte id ) { return blocksLight[id]; } /// Gets whether the given block id is a sprite. (flowers, saplings, fire, etc) public bool IsSprite( byte id ) { return isSprite[id]; } /// Gets whether the given block id is a liquid. (water or lava) public bool IsLiquid( byte id ) { return isLiquid[id]; } public bool EmitsLight( byte id ) { return emitsLight[id]; } } }