using System;
using OpenTK;
namespace ClassicalSharp {
/// Stores various properties about the blocks in Minecraft Classic.
public partial class BlockInfo {
/// 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 = new bool[BlocksCount];
/// 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 = new bool[BlocksCount];
/// Gets whether the given block id is opaque/not partially see through.
public bool[] IsOpaque = new bool[BlocksCount];
/// Gets whether the given block id is opaque/not partially see through on the y axis.
public bool[] IsOpaqueY = new bool[BlocksCount];
/// Gets whether the given block id is a sprite. (e.g. flowers, saplings, fire)
public bool[] IsSprite = new bool[BlocksCount];
/// Gets whether the given block id is a liquid. (e.g. water and lava)
public bool[] IsLiquid = new bool[BlocksCount];
/// Gets the block height of the given block id.
public float[] Height = new float[BlocksCount];
/// Gets whether the given block blocks sunlight.
public bool[] BlocksLight = new bool[BlocksCount];
/// Gets whether the given block should draw all it faces with a full white colour component.
public bool[] FullBright = new bool[BlocksCount];
public string[] Name = new string[BlocksCount];
/// Gets the custom fog colour that should be used when the player is standing within this block.
/// Note that this is only used for exponential fog mode.
public FastColour[] FogColour = new FastColour[BlocksCount];
public float[] FogDensity = new float[BlocksCount];
public BlockCollideType[] CollideType = new BlockCollideType[BlocksCount];
public float[] SpeedMultiplier = new float[BlocksCount];
public bool[] CullWithNeighbours = new bool[BlocksCount];
public const byte MaxDefinedCpeBlock = (byte)Block.StoneBrick;
public const int CpeBlocksCount = MaxDefinedCpeBlock + 1;
public const byte MaxDefinedBlock = byte.MaxValue;
public const int BlocksCount = MaxDefinedBlock + 1;
public void Init() {
for( int tile = 1; tile < BlocksCount; tile++ ) {
Height[tile] = 1f;
BlocksLight[tile] = true;
IsOpaque[tile] = true;
IsOpaqueY[tile] = true;
CollideType[tile] = BlockCollideType.Solid;
SpeedMultiplier[tile] = 1;
CullWithNeighbours[tile] = true;
}
for( int i = 0; i < CpeBlocksCount; i++ ) {
Name[i] = Enum.GetName( typeof( Block ), (byte)i );
}
for( int i = CpeBlocksCount; i < BlocksCount; i++ ) {
Name[i] = "Invalid";
}
FogDensity[(byte)Block.StillWater] = 0.1f;
FogColour[(byte)Block.StillWater] = new FastColour( 5, 5, 51 );
FogDensity[(byte)Block.Water] = 0.1f;
FogColour[(byte)Block.Water] = new FastColour( 5, 5, 51 );
FogDensity[(byte)Block.StillLava] = 2f;
FogColour[(byte)Block.StillLava] = new FastColour( 153, 25, 0 );
FogDensity[(byte)Block.Lava] = 2f;
FogColour[(byte)Block.Lava] = new FastColour( 153, 25, 0 );
CollideType[(byte)Block.Snow] = BlockCollideType.WalkThrough;
SpeedMultiplier[0] = 1f;
CullWithNeighbours[(byte)Block.Leaves] = false;
SetupTextures();
SetBlockHeight( Block.Slab, 8/16f );
SetBlockHeight( Block.CobblestoneSlab, 8/16f );
SetBlockHeight( Block.Snow, 2/16f );
MarkTranslucent( Block.StillWater ); MarkTranslucent( Block.Water );
MarkTranslucent( Block.Ice );
MarkTransparent( Block.Glass, false ); MarkTransparent( Block.Leaves, false );
MarkTransparent( Block.Slab, true ); MarkTransparent( Block.Snow, true );
MarkTransparent( Block.CobblestoneSlab, true );
MarkSprite( Block.Rose ); MarkSprite( Block.Sapling );
MarkSprite( Block.Dandelion ); MarkSprite( Block.BrownMushroom );
MarkSprite( Block.RedMushroom ); MarkSprite( Block.Rope );
MarkSprite( Block.Fire );
SetIsLiquid( Block.StillWater ); SetIsLiquid( Block.Water );
SetIsLiquid( Block.StillLava ); SetIsLiquid( Block.Lava );
SetFullBright( Block.Lava, true ); SetFullBright( Block.StillLava, true );
SetFullBright( Block.Magma, true ); SetFullBright( Block.Fire, true );
IsOpaqueY[(byte)Block.Slab] = true;
IsOpaqueY[(byte)Block.CobblestoneSlab] = true;
IsOpaqueY[(byte)Block.Snow] = true;
SetupCullingCache();
InitBoundingBoxes();
InitSounds();
}
public void SetDefaultBlockPermissions( InventoryPermissions canPlace, InventoryPermissions canDelete ) {
for( int tile = (int)Block.Stone; tile <= (int)Block.Obsidian; tile++ ) {
canPlace[tile] = true;
canDelete[tile] = true;
}
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 MarkTransparent( Block id, bool blocks ) {
IsTransparent[(int)id] = true;
BlocksLight[(int)id] = blocks;
IsOpaque[(int)id] = false;
IsOpaqueY[(int)id] = false;
}
void MarkSprite( Block id ) {
IsSprite[(int)id] = true;
IsTransparent[(int)id] = true;
BlocksLight[(int)id] = false;
IsOpaque[(int)id] = false;
IsOpaqueY[(int)id] = false;
CollideType[(int)id] = BlockCollideType.WalkThrough;
}
void MarkTranslucent( Block id ) {
IsTranslucent[(int)id] = true;
IsOpaque[(int)id] = false;
IsOpaqueY[(int)id] = false;
}
void SetIsLiquid( Block id ) {
IsLiquid[(int)id] = true;
CollideType[(int)id] = BlockCollideType.SwimThrough;
}
void SetBlockHeight( Block id, float height ) {
Height[(int)id] = height;
}
void SetBlocksLight( Block id, bool blocks ) {
BlocksLight[(int)id] = blocks;
}
void SetFullBright( Block id, bool emits ) {
FullBright[(int)id] = emits;
}
public void ResetBlockInfo( byte id ) {
IsTransparent[id] = false;
IsTranslucent[id] = false;
IsOpaque[id] = true;
IsSprite[id] = false;
IsLiquid[id] = false;
Height[id] = 1;
BlocksLight[id] = true;
FullBright[id] = false;
CullWithNeighbours[id] = true;
Name[id] = "Invalid";
FogColour[id] = default( FastColour );
FogDensity[id] = 0;
CollideType[id] = BlockCollideType.Solid;
SpeedMultiplier[id] = 1;
SetAll( 0, (Block)id );
SetupCullingCache();
MinBB[id] = Vector3.Zero;
MaxBB[id] = Vector3.One;
}
}
public enum BlockCollideType : byte {
WalkThrough, // i.e. gas or sprite
SwimThrough, // i.e. liquid
Solid, // i.e. solid
}
}