Skip to content

Commit

Permalink
Combine Block.c/DefaultSet.c, rename all BlockId to BLOCK
Browse files Browse the repository at this point in the history
  • Loading branch information
UnknownShadow200 committed Nov 17, 2017
1 parent ac35685 commit fa18717
Show file tree
Hide file tree
Showing 20 changed files with 394 additions and 426 deletions.
144 changes: 126 additions & 18 deletions src/Client/Block.c
@@ -1,5 +1,4 @@
#include "Block.h"
#include "DefaultSet.h"
#include "Funcs.h"
#include "ExtMath.h"
#include "TerrainAtlas.h"
Expand Down Expand Up @@ -33,25 +32,25 @@ void Block_Init(void) {
}

Int32 block;
for (block = BlockID_Air; block < BLOCK_COUNT; block++) {
for (block = BLOCK_AIR; block < BLOCK_COUNT; block++) {
Block_ResetProps((BlockID)block);
}
Block_UpdateCullingAll();
}

void Block_SetDefaultPerms(void) {
Int32 block;
for (block = BlockID_Air; block <= BLOCK_MAX_DEFINED; block++) {
for (block = BLOCK_AIR; block <= BLOCK_MAX_DEFINED; block++) {
Block_CanPlace[block] = true;
Block_CanDelete[block] = true;
}

Block_CanPlace[BlockID_Air] = false; Block_CanDelete[BlockID_Air] = false;
Block_CanPlace[BlockID_Lava] = false; Block_CanDelete[BlockID_Lava] = false;
Block_CanPlace[BlockID_Water] = false; Block_CanDelete[BlockID_Water] = false;
Block_CanPlace[BlockID_StillLava] = false; Block_CanDelete[BlockID_StillLava] = false;
Block_CanPlace[BlockID_StillWater] = false; Block_CanDelete[BlockID_StillWater] = false;
Block_CanPlace[BlockID_Bedrock] = false; Block_CanDelete[BlockID_Bedrock] = false;
Block_CanPlace[BLOCK_AIR] = false; Block_CanDelete[BLOCK_AIR] = false;
Block_CanPlace[BLOCK_LAVA] = false; Block_CanDelete[BLOCK_LAVA] = false;
Block_CanPlace[BLOCK_WATER] = false; Block_CanDelete[BLOCK_WATER] = false;
Block_CanPlace[BLOCK_STILL_LAVA] = false; Block_CanDelete[BLOCK_STILL_LAVA] = false;
Block_CanPlace[BLOCK_STILL_WATER] = false; Block_CanDelete[BLOCK_STILL_WATER] = false;
Block_CanPlace[BLOCK_BEDROCK] = false; Block_CanDelete[BLOCK_BEDROCK] = false;
}

void Block_SetCollide(BlockID block, UInt8 collide) {
Expand Down Expand Up @@ -166,7 +165,7 @@ void Block_ResetProps(BlockID block) {

Int32 Block_FindID(STRING_PURE String* name) {
Int32 block;
for (block = BlockID_Air; block < BLOCK_COUNT; block++) {
for (block = BLOCK_AIR; block < BLOCK_COUNT; block++) {
if (String_CaselessEquals(&Block_Name[block], name)) return block;
}
return -1;
Expand Down Expand Up @@ -263,7 +262,7 @@ UInt8 Block_CalcLightOffset(BlockID block) {

void Block_RecalculateSpriteBB(void) {
Int32 block;
for (block = BlockID_Air; block < BLOCK_COUNT; block++) {
for (block = BLOCK_AIR; block < BLOCK_COUNT; block++) {
if (Block_Draw[block] != DrawType_Sprite) continue;

Block_RecalculateBB((BlockID)block);
Expand Down Expand Up @@ -386,11 +385,11 @@ void Block_CalcCulling(BlockID block, BlockID other) {

void Block_UpdateCullingAll(void) {
Int32 block, neighbour;
for (block = BlockID_Air; block < BLOCK_COUNT; block++)
for (block = BLOCK_AIR; block < BLOCK_COUNT; block++)
Block_CanStretch[block] = 0x3F;

for (block = BlockID_Air; block < BLOCK_COUNT; block++) {
for (neighbour = BlockID_Air; neighbour < BLOCK_COUNT; neighbour++) {
for (block = BLOCK_AIR; block < BLOCK_COUNT; block++) {
for (neighbour = BLOCK_AIR; neighbour < BLOCK_COUNT; neighbour++) {
Block_CalcCulling((BlockID)block, (BlockID)neighbour);
}
}
Expand All @@ -400,7 +399,7 @@ void Block_UpdateCulling(BlockID block) {
Block_CanStretch[block] = 0x3F;

Int32 other;
for (other = BlockID_Air; other < BLOCK_COUNT; other++) {
for (other = BLOCK_AIR; other < BLOCK_COUNT; other++) {
Block_CalcCulling(block, (BlockID)other);
Block_CalcCulling((BlockID)other, block);
}
Expand All @@ -411,8 +410,8 @@ bool Block_IsHidden(BlockID block, BlockID other) {
if (Block_Draw[block] == DrawType_Sprite) return false;

/* NOTE: Water is always culled by lava. */
if ((block == BlockID_Water || block == BlockID_StillWater)
&& (other == BlockID_Lava || other == BlockID_StillLava))
if ((block == BLOCK_WATER || block == BLOCK_STILL_WATER)
&& (other == BLOCK_LAVA || other == BLOCK_STILL_LAVA))
return true;

/* All blocks (except for say leaves) cull with themselves. */
Expand Down Expand Up @@ -483,7 +482,7 @@ BlockID AutoRotate_RotateVertical(BlockID block, String* name, Vector3 offset) {

BlockID AutoRotate_RotateOther(BlockID block, String* name, Vector3 offset) {
/* Fence type blocks */
if (AutoRotate_Find(BlockID_Invalid, name, "-UD") == BlockID_Invalid) {
if (AutoRotate_Find(BLOCK_Invalid, name, "-UD") == BLOCK_Invalid) {
Real32 headY = LocalPlayer_Instance.Base.Base.HeadY;
headY = LocationUpdate_Clamp(headY);

Expand Down Expand Up @@ -556,4 +555,113 @@ BlockID AutoRotate_RotateBlock(BlockID block) {
return AutoRotate_RotateOther(block, &baseName, offset);
}
return block;
}


Real32 DefaultSet_Height(BlockID b) {
if (b == BLOCK_SLAB) return 0.5f;
if (b == BLOCK_COBBLE_SLAB) return 0.5f;
if (b == BLOCK_SNOW) return 0.25f;
return 1.0f;
}

bool DefaultSet_FullBright(BlockID b) {
return b == BLOCK_LAVA || b == BLOCK_STILL_LAVA
|| b == BLOCK_MAGMA || b == BLOCK_FIRE;
}

Real32 DefaultSet_FogDensity(BlockID b) {
if (b == BLOCK_WATER || b == BLOCK_STILL_WATER)
return 0.1f;
if (b == BLOCK_LAVA || b == BLOCK_STILL_LAVA)
return 1.8f;
return 0.0f;
}

PackedCol DefaultSet_FogColour(BlockID b) {
if (b == BLOCK_WATER || b == BLOCK_STILL_WATER)
return PackedCol_Create3(5, 5, 51);
if (b == BLOCK_LAVA || b == BLOCK_STILL_LAVA)
return PackedCol_Create3(153, 25, 0);
return PackedCol_Create4(0, 0, 0, 0);
}

CollideType DefaultSet_Collide(BlockID b) {
if (b == BLOCK_ICE) return CollideType_Ice;
if (b == BLOCK_WATER || b == BLOCK_STILL_WATER)
return CollideType_LiquidWater;
if (b == BLOCK_LAVA || b == BLOCK_STILL_LAVA)
return CollideType_LiquidLava;

if (b == BLOCK_SNOW || b == BLOCK_AIR || DefaultSet_Draw(b) == DrawType_Sprite)
return CollideType_Gas;
return CollideType_Solid;
}

CollideType DefaultSet_MapOldCollide(BlockID b, CollideType collide) {
if (b == BLOCK_ICE && collide == CollideType_Solid)
return CollideType_Ice;
if ((b == BLOCK_WATER || b == BLOCK_STILL_WATER) && collide == CollideType_Liquid)
return CollideType_LiquidWater;
if ((b == BLOCK_LAVA || b == BLOCK_STILL_LAVA) && collide == CollideType_Liquid)
return CollideType_LiquidLava;
return collide;
}

bool DefaultSet_BlocksLight(BlockID b) {
return !(b == BLOCK_GLASS || b == BLOCK_LEAVES
|| b == BLOCK_AIR || DefaultSet_Draw(b) == DrawType_Sprite);
}

SoundType DefaultSet_StepSound(BlockID b) {
if (b == BLOCK_GLASS) return SoundType_Stone;
if (b == BLOCK_ROPE) return SoundType_Cloth;
if (DefaultSet_Draw(b) == DrawType_Sprite) return SoundType_None;
return DefaultSet_DigSound(b);
}

DrawType DefaultSet_Draw(BlockID b) {
if (b == BLOCK_AIR || b == BLOCK_Invalid) return DrawType_Gas;
if (b == BLOCK_LEAVES) return DrawType_TransparentThick;

if (b == BLOCK_ICE || b == BLOCK_WATER || b == BLOCK_STILL_WATER)
return DrawType_Translucent;
if (b == BLOCK_GLASS || b == BLOCK_LEAVES)
return DrawType_Transparent;

if (b >= BLOCK_DANDELION && b <= BLOCK_RED_SHROOM)
return DrawType_Sprite;
if (b == BLOCK_SAPLING || b == BLOCK_ROPE || b == BLOCK_FIRE)
return DrawType_Sprite;
return DrawType_Opaque;
}

SoundType DefaultSet_DigSound(BlockID b) {
if (b >= BLOCK_RED && b <= BLOCK_WHITE)
return SoundType_Cloth;
if (b >= BLOCK_LIGHT_PINK && b <= BLOCK_TURQUOISE)
return SoundType_Cloth;
if (b == BLOCK_IRON || b == BLOCK_GOLD)
return SoundType_Metal;

if (b == BLOCK_BOOKSHELF || b == BLOCK_WOOD || b == BLOCK_LOG || b == BLOCK_CRATE || b == BLOCK_FIRE)
return SoundType_Wood;

if (b == BLOCK_ROPE) return SoundType_Cloth;
if (b == BLOCK_SAND) return SoundType_Sand;
if (b == BLOCK_SNOW) return SoundType_Snow;
if (b == BLOCK_GLASS) return SoundType_Glass;
if (b == BLOCK_DIRT || b == BLOCK_GRAVEL)
return SoundType_Gravel;

if (b == BLOCK_GRASS || b == BLOCK_SAPLING || b == BLOCK_TNT || b == BLOCK_LEAVES || b == BLOCK_SPONGE)
return SoundType_Grass;

if (b >= BLOCK_DANDELION && b <= BLOCK_RED_SHROOM)
return SoundType_Grass;
if (b >= BLOCK_WATER && b <= BLOCK_STILL_LAVA)
return SoundType_None;
if (b >= BLOCK_STONE && b <= BLOCK_STONE_BRICK)
return SoundType_Stone;
return SoundType_None;
}
12 changes: 12 additions & 0 deletions src/Client/Block.h
Expand Up @@ -118,4 +118,16 @@ void Block_SetHidden(BlockID block, BlockID other, Face face, bool value);

/* Attempts to find the rotated block based on the user's orientation and offset on selected block. */
BlockID AutoRotate_RotateBlock(BlockID block);

Real32 DefaultSet_Height(BlockID b);
bool DefaultSet_FullBright(BlockID b);
Real32 DefaultSet_FogDensity(BlockID b);
PackedCol DefaultSet_FogColour(BlockID b);
CollideType DefaultSet_Collide(BlockID b);
/* Gets a backwards compatible collide type of a block. */
CollideType DefaultSet_MapOldCollide(BlockID b, CollideType collide);
bool DefaultSet_BlocksLight(BlockID b);
SoundType DefaultSet_StepSound(BlockID b);
DrawType DefaultSet_Draw(BlockID b);
SoundType DefaultSet_DigSound(BlockID b);
#endif
138 changes: 69 additions & 69 deletions src/Client/BlockID.h
Expand Up @@ -5,81 +5,81 @@
*/

/* Classic blocks */
#define BlockID_Air 0
#define BlockID_Stone 1
#define BlockID_Grass 2
#define BlockID_Dirt 3
#define BlockID_Cobblestone 4
#define BlockID_Wood 5
#define BlockID_Sapling 6
#define BlockID_Bedrock 7
#define BlockID_Water 8
#define BlockID_StillWater 9
#define BlockID_Lava 10
#define BlockID_StillLava 11
#define BlockID_Sand 12
#define BlockID_Gravel 13
#define BlockID_GoldOre 14
#define BlockID_IronOre 15
#define BlockID_CoalOre 16
#define BlockID_Log 17
#define BlockID_Leaves 18
#define BlockID_Sponge 19
#define BlockID_Glass 20
#define BlockID_Red 21
#define BlockID_Orange 22
#define BlockID_Yellow 23
#define BlockID_Lime 24
#define BlockID_Green 25
#define BlockID_Teal 26
#define BlockID_Aqua 27
#define BlockID_Cyan 28
#define BlockID_Blue 29
#define BlockID_Indigo 30
#define BlockID_Violet 31
#define BlockID_Magenta 32
#define BlockID_Pink 33
#define BlockID_Black 34
#define BlockID_Gray 35
#define BlockID_White 36
#define BlockID_Dandelion 37
#define BlockID_Rose 38
#define BlockID_BrownMushroom 39
#define BlockID_RedMushroom 40
#define BlockID_Gold 41
#define BlockID_Iron 42
#define BlockID_DoubleSlab 43
#define BlockID_Slab 44
#define BlockID_Brick 45
#define BlockID_TNT 46
#define BlockID_Bookshelf 47
#define BlockID_MossyRocks 48
#define BlockID_Obsidian 49
#define BLOCK_AIR 0
#define BLOCK_STONE 1
#define BLOCK_GRASS 2
#define BLOCK_DIRT 3
#define BLOCK_COBBLE 4
#define BLOCK_WOOD 5
#define BLOCK_SAPLING 6
#define BLOCK_BEDROCK 7
#define BLOCK_WATER 8
#define BLOCK_STILL_WATER 9
#define BLOCK_LAVA 10
#define BLOCK_STILL_LAVA 11
#define BLOCK_SAND 12
#define BLOCK_GRAVEL 13
#define BLOCK_GOLD_ORE 14
#define BLOCK_IRON_ORE 15
#define BLOCK_COAL_ORE 16
#define BLOCK_LOG 17
#define BLOCK_LEAVES 18
#define BLOCK_SPONGE 19
#define BLOCK_GLASS 20
#define BLOCK_RED 21
#define BLOCK_ORANGE 22
#define BLOCK_YELLOW 23
#define BLOCK_LIME 24
#define BLOCK_GREEN 25
#define BLOCK_TEAL 26
#define BLOCK_AQUA 27
#define BLOCK_CYAN 28
#define BLOCK_BLUE 29
#define BLOCK_INDIGO 30
#define BLOCK_VIOLET 31
#define BLOCK_MAGENTA 32
#define BLOCK_PINK 33
#define BLOCK_BLACK 34
#define BLOCK_GRAY 35
#define BLOCK_WHITE 36
#define BLOCK_DANDELION 37
#define BLOCK_ROSE 38
#define BLOCK_BROWN_SHROOM 39
#define BLOCK_RED_SHROOM 40
#define BLOCK_GOLD 41
#define BLOCK_IRON 42
#define BLOCK_DOUBLE_SLAB 43
#define BLOCK_SLAB 44
#define BLOCK_BRICK 45
#define BLOCK_TNT 46
#define BLOCK_BOOKSHELF 47
#define BLOCK_MOSSY_ROCKS 48
#define BLOCK_OBSIDIAN 49

/* CPE blocks */
#define BlockID_CobblestoneSlab 50
#define BlockID_Rope 51
#define BlockID_Sandstone 52
#define BlockID_Snow 53
#define BlockID_Fire 54
#define BlockID_LightPink 55
#define BlockID_ForestGreen 56
#define BlockID_Brown 57
#define BlockID_DeepBlue 58
#define BlockID_Turquoise 59
#define BlockID_Ice 60
#define BlockID_CeramicTile 61
#define BlockID_Magma 62
#define BlockID_Pillar 63
#define BlockID_Crate 64
#define BlockID_StoneBrick 65
#define BLOCK_COBBLE_SLAB 50
#define BLOCK_ROPE 51
#define BLOCK_SANDSTONE 52
#define BLOCK_SNOW 53
#define BLOCK_FIRE 54
#define BLOCK_LIGHT_PINK 55
#define BLOCK_FOREST_GREEN 56
#define BLOCK_BROWN 57
#define BLOCK_DEEP_BLUE 58
#define BLOCK_TURQUOISE 59
#define BLOCK_ICE 60
#define BLOCK_CERAMIC_TILE 61
#define BLOCK_MAGMA 62
#define BLOCK_PILLAR 63
#define BLOCK_CRATE 64
#define BLOCK_STONE_BRICK 65

/* Max block ID used in original classic */
#define BLOCK_MAX_ORIGINAL BlockID_Obsidian
#define BLOCK_MAX_ORIGINAL BLOCK_OBSIDIAN
/* Number of blocks in original classic. */
#define BLOCK_ORIGINAL_COUNT (BLOCK_MAX_ORIGINAL + 1)
/* Max block ID used in original classic plus CPE blocks. */
#define BLOCK_MAX_CPE BlockID_StoneBrick
#define BLOCK_MAX_CPE BLOCK_STONE_BRICK
/* Number of blocks in original classic plus CPE blocks. */
#define BLOCK_CPE_COUNT (BLOCK_MAX_CPE + 1)

Expand All @@ -96,5 +96,5 @@
" ForestGreen Brown DeepBlue Turquoise Ice CeramicTile Magma Pillar Crate StoneBrick"

#define BLOCK_COUNT (BLOCK_MAX_DEFINED + 1)
#define BlockID_Invalid BLOCK_MAX_DEFINED
#define BLOCK_Invalid BLOCK_MAX_DEFINED
#endif

0 comments on commit fa18717

Please sign in to comment.