Browse Source

creative: Update for compatibility with minetest.creative_is_enabled (#2691)

sfan5 3 years ago
parent
commit
6d2a897e1b
2 changed files with 16 additions and 9 deletions
  1. 3 5
      game_api.txt
  2. 13 4
      mods/creative/init.lua

+ 3 - 5
game_api.txt

@@ -93,11 +93,9 @@ For example,
 is used to show all tools. Name is used in the sfinv page name, title is the
 is used to show all tools. Name is used in the sfinv page name, title is the
 human readable title.
 human readable title.
 
 
-`is_enabled_for` is used to check whether a player is in creative mode:
-
-    creative.is_enabled_for(name)
-
-Override this to allow per-player game modes.
+Creative provides `creative.is_enabled_for(name)`, which is identical in
+functionality to the engine's `minetest.creative_is_enabled(name)`.
+Its use is deprecated and it should also not be overriden.
 
 
 The contents of `creative.formspec_add` is appended to every creative inventory
 The contents of `creative.formspec_add` is appended to every creative inventory
 page. Mods can use it to add additional formspec elements onto the default
 page. Mods can use it to add additional formspec elements onto the default

+ 13 - 4
mods/creative/init.lua

@@ -27,16 +27,25 @@ minetest.register_privilege("creative", {
 	on_revoke = update_sfinv,
 	on_revoke = update_sfinv,
 })
 })
 
 
-local creative_mode_cache = minetest.settings:get_bool("creative_mode")
+-- Override the engine's creative mode function
+local old_is_creative_enabled = minetest.is_creative_enabled
 
 
+function minetest.is_creative_enabled(name)
+	if name == "" then
+		return old_is_creative_enabled(name)
+	end
+	return minetest.check_player_privs(name, {creative = true}) or
+		old_is_creative_enabled(name)
+end
+
+-- For backwards compatibility:
 function creative.is_enabled_for(name)
 function creative.is_enabled_for(name)
-	return creative_mode_cache or
-		minetest.check_player_privs(name, {creative = true})
+	return minetest.is_creative_enabled(name)
 end
 end
 
 
 dofile(minetest.get_modpath("creative") .. "/inventory.lua")
 dofile(minetest.get_modpath("creative") .. "/inventory.lua")
 
 
-if creative_mode_cache then
+if minetest.is_creative_enabled("") then
 	-- Dig time is modified according to difference (leveldiff) between tool
 	-- Dig time is modified according to difference (leveldiff) between tool
 	-- 'maxlevel' and node 'level'. Digtime is divided by the larger of
 	-- 'maxlevel' and node 'level'. Digtime is divided by the larger of
 	-- leveldiff and 1.
 	-- leveldiff and 1.