Simplify block permissions reset code

This commit is contained in:
UnknownShadow200 2020-10-07 19:53:46 +11:00
parent 18dcbd710f
commit 168143fecc
2 changed files with 12 additions and 26 deletions

View File

@ -687,13 +687,6 @@ static void OnReset(void) {
Blocks.CanPlace[block] = true; Blocks.CanPlace[block] = true;
Blocks.CanDelete[block] = true; Blocks.CanDelete[block] = true;
} }
Blocks.CanPlace[BLOCK_AIR] = false; Blocks.CanDelete[BLOCK_AIR] = false;
Blocks.CanPlace[BLOCK_LAVA] = false; Blocks.CanDelete[BLOCK_LAVA] = false;
Blocks.CanPlace[BLOCK_WATER] = false; Blocks.CanDelete[BLOCK_WATER] = false;
Blocks.CanPlace[BLOCK_STILL_LAVA] = false; Blocks.CanDelete[BLOCK_STILL_LAVA] = false;
Blocks.CanPlace[BLOCK_STILL_WATER] = false; Blocks.CanDelete[BLOCK_STILL_WATER] = false;
Blocks.CanPlace[BLOCK_BEDROCK] = false; Blocks.CanDelete[BLOCK_BEDROCK] = false;
} }
static void OnAtlasChanged(void* obj) { Block_RecalculateAllSpriteBB(); } static void OnAtlasChanged(void* obj) { Block_RecalculateAllSpriteBB(); }

View File

@ -118,17 +118,6 @@ int Ping_AveragePingMS(void) {
/*########################################################################################################################* /*########################################################################################################################*
*-------------------------------------------------Singleplayer connection-------------------------------------------------* *-------------------------------------------------Singleplayer connection-------------------------------------------------*
*#########################################################################################################################*/ *#########################################################################################################################*/
static void SPConnection_ResetBlockPerms(void) {
int i, count;
count = Game_UseCPEBlocks ? BLOCK_CPE_COUNT : BLOCK_ORIGINAL_COUNT;
for (i = 1; i < count; i++) {
Blocks.CanPlace[i] = true;
Blocks.CanDelete[i] = true;
}
Event_RaiseVoid(&BlockEvents.PermissionsChanged);
}
#define SP_HasDir(path) (String_IndexOf(&path, '/') >= 0 || String_IndexOf(&path, '\\') >= 0) #define SP_HasDir(path) (String_IndexOf(&path, '/') >= 0 || String_IndexOf(&path, '\\') >= 0)
static void SPConnection_BeginConnect(void) { static void SPConnection_BeginConnect(void) {
static const String logName = String_FromConst("Singleplayer"); static const String logName = String_FromConst("Singleplayer");
@ -136,7 +125,6 @@ static void SPConnection_BeginConnect(void) {
RNGState rnd; RNGState rnd;
Chat_SetLogName(&logName); Chat_SetLogName(&logName);
Game_UseCPEBlocks = Game_UseCPE; Game_UseCPEBlocks = Game_UseCPE;
SPConnection_ResetBlockPerms();
/* For when user drops a map file onto ClassiCube.exe */ /* For when user drops a map file onto ClassiCube.exe */
path = Game_Username; path = Game_Username;
@ -301,6 +289,14 @@ static void MPConnection_BeginConnect(void) {
cc_result res; cc_result res;
String_InitArray(title, titleBuffer); String_InitArray(title, titleBuffer);
/* Default block permissions (in case server supports SetBlockPermissions but doesn't send) */
Blocks.CanPlace[BLOCK_AIR] = false; Blocks.CanDelete[BLOCK_AIR] = false;
Blocks.CanPlace[BLOCK_LAVA] = false; Blocks.CanDelete[BLOCK_LAVA] = false;
Blocks.CanPlace[BLOCK_WATER] = false; Blocks.CanDelete[BLOCK_WATER] = false;
Blocks.CanPlace[BLOCK_STILL_LAVA] = false; Blocks.CanDelete[BLOCK_STILL_LAVA] = false;
Blocks.CanPlace[BLOCK_STILL_WATER] = false; Blocks.CanDelete[BLOCK_STILL_WATER] = false;
Blocks.CanPlace[BLOCK_BEDROCK] = false; Blocks.CanDelete[BLOCK_BEDROCK] = false;
res = Socket_Create(&net_socket); res = Socket_Create(&net_socket);
if (res) { MPConnection_FailConnect(res); return; } if (res) { MPConnection_FailConnect(res); return; }
Server.Disconnected = false; Server.Disconnected = false;
@ -493,12 +489,9 @@ static void OnNewMap(void) {
} }
static void OnReset(void) { static void OnReset(void) {
if (Server.IsSinglePlayer) { if (Server.IsSinglePlayer) return;
SPConnection_ResetBlockPerms();
} else {
net_writeFailed = false; net_writeFailed = false;
OnFree(); OnFree();
}
} }
static void OnInit(void) { static void OnInit(void) {