1
0
Fork 0

Use minetest.is_creative_enabled

This commit is contained in:
Wuzzy 2020-07-10 16:08:40 +02:00
parent 47dd29c930
commit c106a62979
62 changed files with 133 additions and 119 deletions

View File

@ -12,7 +12,6 @@ under the LGPLv2.1 license.
mcl_explosions = {}
local creative_mode = minetest.settings:get_bool("creative_mode")
local mod_death_messages = minetest.get_modpath("mcl_death_messages") ~= nil
local mod_fire = minetest.get_modpath("mcl_fire") ~= nil
local CONTENT_FIRE = minetest.get_content_id("mcl_fire:fire")
@ -143,7 +142,7 @@ end
-- Note that this function has been optimized, it contains code which has been
-- inlined to avoid function calls and unnecessary table creation. This was
-- measured to give a significant performance increase.
local function trace_explode(pos, strength, raydirs, radius, drop_chance, fire, puncher)
local function trace_explode(pos, strength, raydirs, radius, drop_chance, fire, puncher, creative_enabled)
local vm = minetest.get_voxel_manip()
local emin, emax = vm:read_from_map(vector.subtract(pos, radius),
@ -308,7 +307,7 @@ local function trace_explode(pos, strength, raydirs, radius, drop_chance, fire,
-- Remove destroyed blocks and drop items
for hash, idx in pairs(destroy) do
local do_drop = not creative_mode and math.random() <= drop_chance
local do_drop = not creative_enabled and math.random() <= drop_chance
local on_blast = node_on_blast[data[idx]]
local remove = true
@ -384,7 +383,8 @@ function mcl_explosions.explode(pos, strength, info, puncher)
end
local shape = sphere_shapes[radius]
trace_explode(pos, strength, shape, radius, (info and info.drop_chance) or 1 / strength, info.fire == true, puncher)
local creative_enabled = minetest.is_creative_enabled("")
trace_explode(pos, strength, shape, radius, (info and info.drop_chance) or 1 / strength, info.fire == true, puncher, creative_enabled)
if not (info and info.no_sound) then
add_particles(pos, radius)

View File

@ -92,7 +92,7 @@ end
-- Similar to minetest.rotate_node.
function mcl_util.rotate_axis(itemstack, placer, pointed_thing)
mcl_util.rotate_axis_and_place(itemstack, placer, pointed_thing,
minetest.settings:get_bool("creative_mode"),
minetest.is_creative_enabled(placer:get_player_name()),
placer:get_player_control().sneak)
return itemstack
end

View File

@ -133,7 +133,7 @@ function boat.on_punch(self, puncher)
if not self._driver then
self._removed = true
-- Drop boat as item on the ground after punching
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(puncher:get_player_name()) then
minetest.add_item(self.object:get_pos(), self._itemstring)
else
local inv = puncher:get_inventory()
@ -328,7 +328,7 @@ for b=1, #boat_ids do
boat:get_luaentity()._itemstring = itemstring
boat:set_properties({textures = { "mcl_boats_texture_"..images[b].."_boat.png" }})
boat:set_yaw(placer:get_look_horizontal())
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(placer:get_player_name()) then
itemstack:take_item()
end
return itemstack

View File

@ -213,7 +213,7 @@ function minetest.handle_node_drops(pos, drops, digger)
-- by hand. Creative Mode is intentionally ignored in this case.
local doTileDrops = minetest.settings:get_bool("mcl_doTileDrops", true)
if (digger ~= nil and minetest.settings:get_bool("creative_mode")) or doTileDrops == false then
if (digger ~= nil and minetest.is_creative_enabled(digger:get_player_name())) or doTileDrops == false then
return
end

View File

@ -133,7 +133,7 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o
end
-- Drop items and remove cart entity
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(puncher:get_player_name()) then
for d=1, #drop do
minetest.add_item(self.object:get_pos(), drop[d])
end
@ -190,13 +190,14 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o
node = minetest.get_node(rou_pos)
local g = minetest.get_item_group(node.name, "connect_to_raillike")
if g ~= self._railtype and self._railtype ~= nil then
local player
-- Detach driver
if self._driver then
if self._old_pos then
self.object:set_pos(self._old_pos)
end
mcl_player.player_attached[self._driver] = nil
local player = minetest.get_player_by_name(self._driver)
player = minetest.get_player_by_name(self._driver)
if player then
player:set_detach()
player:set_eye_offset({x=0, y=0, z=0},{x=0, y=0, z=0})
@ -211,7 +212,11 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o
end
-- Drop items and remove cart entity
if not minetest.settings:get_bool("creative_mode") then
local pname = ""
if player then
pname = player:get_player_name()
end
if not minetest.is_creative_enabled(pname) then
for d=1, #drop do
minetest.add_item(self.object:get_pos(), drop[d])
end
@ -486,7 +491,7 @@ local function register_entity(entity_id, mesh, textures, drop, on_rightclick, o
end
-- Place a minecart at pointed_thing
mcl_minecarts.place_minecart = function(itemstack, pointed_thing)
mcl_minecarts.place_minecart = function(itemstack, pointed_thing, placer)
if not pointed_thing.type == "node" then
return
end
@ -519,7 +524,11 @@ mcl_minecarts.place_minecart = function(itemstack, pointed_thing)
local cart_dir = mcl_minecarts:get_rail_direction(railpos, {x=1, y=0, z=0}, nil, nil, railtype)
cart:set_yaw(minetest.dir_to_yaw(cart_dir))
if not minetest.settings:get_bool("creative_mode") then
local pname = ""
if placer then
pname = placer:get_player_name()
end
if not minetest.is_creative_enabled(pname) then
itemstack:take_item()
end
return itemstack
@ -548,7 +557,7 @@ local register_craftitem = function(itemstring, entity_id, description, tt_help,
end
end
return mcl_minecarts.place_minecart(itemstack, pointed_thing)
return mcl_minecarts.place_minecart(itemstack, pointed_thing, placer)
end,
_on_dispense = function(stack, pos, droppos, dropnode, dropdir)
-- Place minecart as entity on rail. If there's no rail, just drop it.
@ -683,7 +692,7 @@ register_minecart(
if minetest.get_item_group(held:get_name(), "coal") == 1 then
self._fueltime = self._fueltime + 180
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(clicker:get_player_name()) then
held:take_item()
local index = clicker:get_wield_index()
local inv = clicker:get_inventory()
@ -773,7 +782,7 @@ register_minecart(
end
local held = clicker:get_wielded_item()
if held:get_name() == "mcl_fire:flint_and_steel" then
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(clicker:get_player_name()) then
held:add_wear(65535/65) -- 65 uses
local index = clicker:get_wield_index()
local inv = clicker:get_inventory()

View File

@ -28,9 +28,8 @@ end
-- creative check
local creative_mode_cache = minetest.settings:get_bool("creative_mode")
function mobs.is_creative(name)
return creative_mode_cache or minetest.check_player_privs(name, {creative = true})
return minetest.is_creative_enabled(name)
end
@ -60,7 +59,6 @@ local mobs_spawn = minetest.settings:get_bool("mobs_spawn", true) ~= false
local disable_blood = minetest.settings:get_bool("mobs_disable_blood")
local mobs_drop_items = minetest.settings:get_bool("mobs_drop_items") ~= false
local mobs_griefing = minetest.settings:get_bool("mobs_griefing") ~= false
local creative = minetest.settings:get_bool("creative_mode")
local spawn_protected = minetest.settings:get_bool("mobs_spawn_protected") ~= false
local remove_far = false
local difficulty = tonumber(minetest.settings:get("mob_difficulty")) or 1.0
@ -1600,7 +1598,7 @@ local monster_attack = function(self)
if self.type ~= "monster"
or not damage_enabled
or creative
or minetest.is_creative_enabled("")
or self.state == "attack"
or day_docile(self) then
return
@ -2674,7 +2672,7 @@ local mob_punch = function(self, hitter, tflp, tool_capabilities, dir)
-- add weapon wear manually
-- Required because we have custom health handling ("health" property)
if minetest.settings:get_bool("creative_mode") ~= true
if minetest.is_creative_enabled("") ~= true
and tool_capabilities then
if tool_capabilities.punch_attack_uses then
-- Without this delay, the wear does not work. Quite hacky ...
@ -3933,7 +3931,7 @@ function mobs:register_egg(mob, desc, background, addegg, no_creative)
return itemstack
end
mcl_mobspawners.setup_spawner(pointed_thing.under, itemstack:get_name())
if not minetest.settings:get_bool("creative_mode") then
if not mobs.is_creative(name) then
itemstack:take_item()
end
return itemstack

View File

@ -167,7 +167,11 @@ minetest.register_entity("mcl_paintings:painting", {
end,
on_death = function(self, killer)
-- Drop as item on death
if not minetest.settings:get_bool("creative_mode") then
local kname = ""
if killer and killer:is_player() then
kname = killer:get_player_name()
end
if not minetest.is_creative_enabled(kname) then
local pos = self._pos
if not pos then
pos = self.object:get_pos()
@ -279,7 +283,7 @@ minetest.register_craftitem("mcl_paintings:painting", {
else
return itemstack
end
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(placer:get_player_name()) then
itemstack:take_item()
end
return itemstack

View File

@ -552,7 +552,7 @@ if c("totem") then
if player:get_breath() < 11 then
player:set_breath(10)
end
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(player:get_player_name()) then
wield:take_item()
player:set_wielded_item(wield)
end

View File

@ -123,7 +123,7 @@ local arrows = {
local throwing_shoot_arrow = function(itemstack, player)
for _,arrow in ipairs(arrows) do
if player:get_inventory():get_stack("main", player:get_wield_index()+1):get_name() == arrow[1] then
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(player:get_player_name()) then
player:get_inventory():remove_item("main", arrow[1])
end
local playerpos = player:get_pos()
@ -171,7 +171,7 @@ if c("bow") then
inventory_image = "mcl_bows_bow.png",
on_use = function(itemstack, user, pointed_thing)
if throwing_shoot_arrow(itemstack, user, pointed_thing) then
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(user:get_player_name()) then
itemstack:add_wear(65535/50)
end
end
@ -296,7 +296,7 @@ if c("egg") then
local ent2 = obj:get_luaentity()
ent2.playername = player:get_player_name()
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(player:get_player_name()) then
item:take_item()
end
@ -380,7 +380,7 @@ if c("snowball") then
local ent2 = obj:get_luaentity()
ent2.playername = player:get_player_name()
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(player:get_player_name()) then
item:take_item()
end

View File

@ -101,7 +101,7 @@ mooshroom_def.on_rightclick = function(self, clicker)
local cow = minetest.add_entity(pos, "mobs_mc:cow")
cow:set_yaw(oldyaw)
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(clicker:get_player_name()) then
item:add_wear(mobs_mc.misc.shears_wear)
clicker:get_inventory():set_stack("main", clicker:get_wield_index(), item)
end

View File

@ -51,7 +51,7 @@ mobs:register_mob("mobs_mc:creeper", {
end
local item = clicker:get_wielded_item()
if item:get_name() == mobs_mc.items.flint_and_steel then
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(clicker:get_player_name()) then
-- Wear tool
local wdef = item:get_definition()
item:add_wear(1000)

View File

@ -233,7 +233,7 @@ local horse = {
-- Put on saddle and take saddle from player's inventory
local w = clicker:get_wielded_item()
self._saddle = true
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(clicker:get_player_name()) then
w:take_item()
clicker:set_wielded_item(w)
end
@ -257,7 +257,7 @@ local horse = {
local armor = minetest.get_item_group(iname, "horse_armor")
self._horse_armor = iname
local w = clicker:get_wielded_item()
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(clicker:get_player_name()) then
w:take_item()
clicker:set_wielded_item(w)
end

View File

@ -135,7 +135,7 @@ mobs:register_mob("mobs_mc:llama", {
if minetest.get_item_group(item:get_name(), "carpet") == 1 and not self.carpet then
for group, carpetdata in pairs(carpets) do
if minetest.get_item_group(item:get_name(), group) == 1 then
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(clicker:get_player_name()) then
item:take_item()
clicker:set_wielded_item(item)
end

View File

@ -74,7 +74,7 @@ local ocelot = {
-- Try to tame ocelot (mobs:feed_tame is intentionally NOT used)
local item = clicker:get_wielded_item()
if is_food(item:get_name()) then
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(clicker:get_player_name()) then
item:take_item()
clicker:set_wielded_item(item)
end

View File

@ -64,7 +64,7 @@ mobs:register_mob("mobs_mc:parrot", {
self.health = 0
-- Doomed to die
self._doomed = true
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(clicker:get_player_name()) then
item:take_item()
clicker:set_wielded_item(item)
end

View File

@ -120,7 +120,7 @@ mobs:register_mob("mobs_mc:pig", {
min = 1,
max = 1,},
}
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(clicker:get_player_name()) then
local inv = clicker:get_inventory()
local stack = inv:get_stack("main", clicker:get_wield_index())
stack:take_item()
@ -142,7 +142,7 @@ mobs:register_mob("mobs_mc:pig", {
mobs.attach(self, clicker)
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(clicker:get_player_name()) then
local inv = self.driver:get_inventory()
-- 26 uses

View File

@ -166,7 +166,7 @@ mobs:register_mob("mobs_mc:sheep", {
self.object:set_properties({
textures = self.base_texture,
})
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(clicker:get_player_name()) then
item:add_wear(mobs_mc.misc.shears_wear)
clicker:get_inventory():set_stack("main", clicker:get_wield_index(), item)
end
@ -183,7 +183,7 @@ mobs:register_mob("mobs_mc:sheep", {
minetest.log("verbose", "[mobs_mc] " ..item:get_name() .. " " .. minetest.get_item_group(item:get_name(), "dye"))
for group, colordata in pairs(colors) do
if minetest.get_item_group(item:get_name(), group) == 1 then
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(clicker:get_player_name()) then
item:take_item()
clicker:set_wielded_item(item)
end

View File

@ -50,7 +50,7 @@ mobs:register_egg("mobs_mc:silverfish", S("Silverfish"), "mobs_mc_spawn_icon_sil
-- Monster egg blocks (Minetest Game)
if minetest.get_modpath("default") and mobs_mc.create_monster_egg_nodes then
local spawn_silverfish = function(pos, oldnode, oldmetadata, digger)
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(digger:get_player_name()) then
minetest.add_entity(pos, "mobs_mc:silverfish")
end
end

View File

@ -119,7 +119,7 @@ mobs:register_mob("mobs_mc:snowman", {
minetest.sound_play("shears", {pos = pos}, true)
-- Wear out
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(clicker:get_player_name()) then
item:add_wear(mobs_mc.misc.shears_wear)
clicker:get_inventory():set_stack("main", clicker:get_wield_index(), item)
end

View File

@ -53,7 +53,7 @@ local wolf = {
local dog, ent
if tool:get_name() == mobs_mc.items.bone then
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(clicker:get_player_name()) then
tool:take_item()
clicker:set_wielded_item(tool)
end
@ -154,7 +154,7 @@ dog.on_rightclick = function(self, clicker)
if new_hp > self.hp_max then
new_hp = self.hp_max
end
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(clicker:get_player_name()) then
item:take_item()
clicker:set_wielded_item(item)
end
@ -172,7 +172,7 @@ dog.on_rightclick = function(self, clicker)
self.object:set_properties({
textures = self.base_texture
})
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(clicker:get_player_name()) then
item:take_item()
clicker:set_wielded_item(item)
end

View File

@ -128,7 +128,7 @@ local function init(player)
local playername = player:get_player_name()
local inv = minetest.create_detached_inventory("creative_"..playername, {
allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
if minetest.settings:get_bool("creative_mode") then
if minetest.is_creative_enabled(playername) then
return count
else
return 0
@ -138,7 +138,7 @@ local function init(player)
return 0
end,
allow_take = function(inv, listname, index, stack, player)
if minetest.settings:get_bool("creative_mode") then
if minetest.is_creative_enabled(player:get_player_name()) then
return -1
else
return 0
@ -151,7 +151,7 @@ end
-- Create the trash field
local trash = minetest.create_detached_inventory("trash", {
allow_put = function(inv, listname, index, stack, player)
if minetest.settings:get_bool("creative_mode") then
if minetest.is_creative_enabled(player:get_player_name()) then
return stack:get_count()
else
return 0
@ -459,7 +459,8 @@ end
minetest.register_on_player_receive_fields(function(player, formname, fields)
local page = nil
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(player:get_player_name()) then
return
end
if formname ~= "" or fields.quit == "true" then
@ -579,7 +580,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end)
if minetest.settings:get_bool("creative_mode") then
if minetest.is_creative_enabled("") then
minetest.register_on_placenode(function(pos, newnode, placer, oldnode, itemstack)
-- Place infinite nodes, except for shulker boxes
local group = minetest.get_item_group(itemstack:get_name(), "shulker_box")

View File

@ -46,7 +46,7 @@ local function return_fields(player, name)
end
local function set_inventory(player, armor_change_only)
if minetest.settings:get_bool("creative_mode") then
if minetest.is_creative_enabled(player:get_player_name()) then
if armor_change_only then
-- Stay on survival inventory plage if only the armor has been changed
mcl_inventory.set_creative_formspec(player, 0, 0, nil, nil, "inv")
@ -137,13 +137,13 @@ end
minetest.register_on_player_receive_fields(function(player, formname, fields)
if fields.quit then
return_fields(player,"craft")
if not minetest.settings:get_bool("creative_mode") and (formname == "" or formname == "main") then
if not minetest.is_creative_enabled(player:get_player_name()) and (formname == "" or formname == "main") then
set_inventory(player)
end
end
end)
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled("") then
mcl_inventory.update_inventory_formspec = function(player)
set_inventory(player)
end
@ -180,7 +180,7 @@ minetest.register_on_joinplayer(function(player)
end
-- In Creative Mode, the initial inventory setup is handled in creative.lua
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(player:get_player_name()) then
set_inventory(player)
end
@ -191,7 +191,7 @@ minetest.register_on_joinplayer(function(player)
return_fields(player, "craft")
end)
if minetest.settings:get_bool("creative_mode") then
if minetest.is_creative_enabled("") then
dofile(minetest.get_modpath("mcl_inventory").."/creative.lua")
end

View File

@ -131,7 +131,7 @@ end
local on_rightclick = function(pos, node, player, itemstack, pointed_thing)
local can_edit = true
-- Only allow write access in Creative Mode
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(player:get_player_name()) then
can_edit = false
end
local pname = player:get_player_name()
@ -285,7 +285,7 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
if index ~= nil and x ~= nil and y ~= nil and z ~= nil then
local pos = {x=tonumber(x), y=tonumber(y), z=tonumber(z)}
local meta = minetest.get_meta(pos)
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(player:get_player_name()) then
minetest.chat_send_player(player:get_player_name(), S("Editing the command block has failed! You can only change the command block in Creative Mode!"))
return
end

View File

@ -455,7 +455,7 @@ for colorid, colortab in pairs(mcl_banners.colors) do
banner_entity:set_yaw(final_yaw)
end
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(placer:get_player_name()) then
itemstack:take_item()
end
minetest.sound_play({name="default_place_node_hard", gain=1.0}, {pos = place_pos}, true)

View File

@ -133,7 +133,7 @@ function mcl_beds.register_bed(name, def)
minetest.set_node(pos, {name = name .. "_bottom", param2 = dir})
minetest.set_node(botpos, {name = name .. "_top", param2 = dir})
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(placer:get_player_name()) then
itemstack:take_item()
end
return itemstack

View File

@ -99,7 +99,7 @@ local ARROW_ENTITY={
-- Destroy arrow entity self at pos and drops it as an item
local spawn_item = function(self, pos)
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled("") then
local item = minetest.add_item(pos, "mcl_bows:arrow")
item:set_velocity({x=0, y=0, z=0})
item:set_yaw(self.object:get_yaw())
@ -138,7 +138,7 @@ ARROW_ENTITY.on_step = function(self, dtime)
local objects = minetest.get_objects_inside_radius(pos, 1)
for _,obj in ipairs(objects) do
if obj:is_player() then
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(obj:get_player_name()) then
if obj:get_inventory():room_for_item("main", "mcl_bows:arrow") then
obj:get_inventory():add_item("main", "mcl_bows:arrow")
minetest.sound_play("item_drop_pickup", {

View File

@ -75,7 +75,7 @@ end
local player_shoot_arrow = function(itemstack, player, power, damage)
local arrow_stack, arrow_stack_id = get_arrow(player)
local arrow_itemstring
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(player:get_player_name()) then
if not arrow_stack then
return false
end
@ -209,7 +209,7 @@ controls.register_on_release(function(player, key, time)
has_shot = player_shoot_arrow(wielditem, player, speed, damage)
wielditem:set_name("mcl_bows:bow")
if has_shot and minetest.settings:get_bool("creative_mode") == false then
if has_shot and not minetest.is_creative_enabled(player:get_player_name()) then
wielditem:add_wear(65535/BOW_DURABILITY)
end
player:set_wielded_item(wielditem)
@ -224,7 +224,8 @@ controls.register_on_hold(function(player, key, time)
local name = player:get_player_name()
local inv = minetest.get_inventory({type="player", name=name})
local wielditem = player:get_wielded_item()
if bow_load[name] == nil and wielditem:get_name()=="mcl_bows:bow" and (minetest.settings:get_bool("creative_mode") or inv:contains_item("main", "mcl_bows:arrow")) then
local creative = minetest.is_creative_enabled(name)
if bow_load[name] == nil and wielditem:get_name()=="mcl_bows:bow" and (creative or inv:contains_item("main", "mcl_bows:arrow")) then
wielditem:set_name("mcl_bows:bow_0")
player:set_wielded_item(wielditem)
if minetest.get_modpath("playerphysics") then

View File

@ -141,7 +141,7 @@ function mcl_buckets.register_liquid(source_place, source_take, itemname, invent
end
-- Handle bucket item and inventory stuff
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(user:get_player_name()) then
-- Add empty bucket and put it into inventory, if possible.
-- Drop empty bucket otherwise.
local new_bucket = ItemStack("mcl_buckets:bucket_empty")
@ -220,7 +220,7 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", {
if liquiddef ~= nil and liquiddef.itemname ~= nil and (nn == liquiddef.source_take) then
-- Fill bucket, but not in Creative Mode
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(user:get_player_name()) then
new_bucket = ItemStack({name = liquiddef.itemname, metadata = tostring(node.param2)})
end
@ -234,14 +234,14 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", {
elseif nn == "mcl_cauldrons:cauldron_3" then
-- Take water out of full cauldron
minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron"})
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(user:get_player_name()) then
new_bucket = ItemStack("mcl_buckets:bucket_water")
end
sound_take("mcl_core:water_source", pointed_thing.under)
elseif nn == "mcl_cauldrons:cauldron_3r" then
-- Take river water out of full cauldron
minetest.set_node(pointed_thing.under, {name="mcl_cauldrons:cauldron"})
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(user:get_player_name()) then
new_bucket = ItemStack("mcl_buckets:bucket_river_water")
end
sound_take("mclx_core:river_water_source", pointed_thing.under)
@ -259,7 +259,7 @@ minetest.register_craftitem("mcl_buckets:bucket_empty", {
else
minetest.add_item(user:get_pos(), new_bucket)
end
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(user:get_player_name()) then
itemstack:take_item()
end
return itemstack

View File

@ -62,7 +62,7 @@ minetest.register_node("mcl_cake:cake", {
end
local newcake = minetest.do_item_eat(2, ItemStack("mcl_cake:cake_6"), ItemStack("mcl_cake:cake"), clicker, {type="nothing"})
-- Check if we were allowed to eat
if newcake:get_name() ~= "mcl_cake:cake" or minetest.settings:get_bool("creative_mode") == true then
if newcake:get_name() ~= "mcl_cake:cake" or minetest.is_creative_enabled(clicker:get_player_name()) then
minetest.add_node(pos,{type="node",name="mcl_cake:cake_6",param2=0})
end
end,
@ -87,7 +87,7 @@ local register_slice = function(level, nodebox, desc)
end
local newcake = minetest.do_item_eat(CAKE_HUNGER_POINTS, ItemStack(after_eat), ItemStack(this), clicker, {type="nothing"})
-- Check if we were allowed to eat
if newcake:get_name() ~= this or minetest.settings:get_bool("creative_mode") == true then
if newcake:get_name() ~= this or minetest.is_creative_enabled(clicker:get_player_name()) then
minetest.add_node(pos,{type="node",name=after_eat,param2=0})
end
end
@ -101,7 +101,7 @@ local register_slice = function(level, nodebox, desc)
end
local newcake = minetest.do_item_eat(CAKE_HUNGER_POINTS, ItemStack("mcl:cake:cake 0"), ItemStack("mcl_cake:cake_1"), clicker, {type="nothing"})
-- Check if we were allowed to eat
if newcake:get_name() ~= this or minetest.settings:get_bool("creative_mode") == true then
if newcake:get_name() ~= this or minetest.is_creative_enabled(clicker:get_player_name()) then
minetest.remove_node(pos)
core.check_for_falling(pos)
end

View File

@ -845,7 +845,7 @@ for color, desc in pairs(boxtypes) do
local iinv_main = minetest.deserialize(imeta)
ninv:set_list("main", iinv_main)
ninv:set_size("main", 9*3)
if minetest.settings:get_bool("creative_mode") then
if minetest.is_creative_enabled(placer:get_player_name()) then
if not ninv:is_empty("main") then
return nil
else
@ -867,7 +867,7 @@ for color, desc in pairs(boxtypes) do
local boxitem = ItemStack("mcl_chests:"..color.."_shulker_box")
boxitem:set_metadata(data)
if minetest.settings:get_bool("creative_mode") then
if minetest.is_creative_enabled("") then
if not inv:is_empty("main") then
minetest.add_item(pos, boxitem)
end

View File

@ -45,7 +45,7 @@ function mcl_cocoas.place(itemstack, placer, pointed_thing, plantname)
minetest.sound_play("default_place_node", {pos = pt.above, gain = 1.0}, true)
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(placer:get_player_name()) then
itemstack:take_item()
end

View File

@ -183,7 +183,7 @@ function mcl_doors:register_door(name, def)
meta2:set_int("is_open", 0)
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(pn) then
itemstack:take_item()
end

View File

@ -337,7 +337,7 @@ minetest.register_craftitem("mcl_dye:white", {
end
-- Use the bone meal on the ground
if(mcl_dye.apply_bone_meal(pointed_thing) and not minetest.settings:get_bool("creative_mode")) then
if(mcl_dye.apply_bone_meal(pointed_thing) and (not minetest.is_creative_enabled(user:get_player_name()))) then
itemstack:take_item()
end
return itemstack

View File

@ -538,7 +538,7 @@ local eat_chorus_fruit = function(itemstack, player, pointed_thing)
local count = itemstack:get_count()
local new_itemstack = minetest.do_item_eat(4, nil, itemstack, player, pointed_thing)
local new_count = new_itemstack:get_count()
if count ~= new_count or new_itemstack:get_name() ~= "mcl_end:chorus_fruit" or (minetest.settings:get_bool("creative_mode") == true) then
if count ~= new_count or new_itemstack:get_name() ~= "mcl_end:chorus_fruit" or (minetest.is_creative_enabled(player:get_player_name()) == true) then
random_teleport(player)
end
return new_itemstack

View File

@ -29,7 +29,7 @@ minetest.register_entity("mcl_end:ender_eye", {
if self._age >= 3 then
-- End of life
local r = math.random(1,5)
if r == 1 or minetest.settings:get_bool("creative_mode") then
if r == 1 or minetest.is_creative_enabled("") then
-- 20% chance to get destroyed completely.
-- 100% if in Creative Mode
self.object:remove()
@ -89,7 +89,7 @@ minetest.register_craftitem("mcl_end:ender_eye", {
origin.y = origin.y + 1.5
local strongholds = mcl_structures.get_registered_structures("stronghold")
local dim = mcl_worlds.pos_to_dimension(origin)
local is_creative = minetest.settings:get_bool("creative_mode")
local is_creative = minetest.is_creative_enabled(user:get_player_name())
-- Just drop the eye of ender if there are no strongholds
if #strongholds <= 0 or dim ~= "overworld" then

View File

@ -41,7 +41,7 @@ local hoe_on_place_function = function(wear_divisor)
end
if create_soil(pointed_thing.under, user:get_inventory()) then
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(user:get_player_name()) then
itemstack:add_wear(65535/wear_divisor)
end
return itemstack

View File

@ -90,7 +90,7 @@ function mcl_farming:place_seed(itemstack, placer, pointed_thing, plantname)
return
end
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(placer:get_player_name()) then
itemstack:take_item()
end
return itemstack

View File

@ -36,7 +36,7 @@ minetest.register_craftitem("mcl_fire:fire_charge", {
else
mcl_fire.set_fire(pointed_thing, user, false)
end
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(user:get_player_name()) then
itemstack:take_item()
end
end

View File

@ -47,7 +47,7 @@ minetest.register_tool("mcl_fire:flint_and_steel", {
if itemstack:get_count() == 0 and idef.sound and idef.sound.breaks then
minetest.sound_play(idef.sound.breaks, {pos=user:get_pos(), gain=0.5}, true)
end
if not minetest.settings:get_bool("creative_mode") and used == true then
if (not minetest.is_creative_enabled(user:get_player_name())) and used == true then
itemstack:add_wear(65535/65) -- 65 uses
end
return itemstack
@ -57,13 +57,13 @@ minetest.register_tool("mcl_fire:flint_and_steel", {
-- Ignite air
if dropnode.name == "air" then
minetest.add_node(droppos, {name="mcl_fire:fire"})
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled("") then
stack:add_wear(65535/65) -- 65 uses
end
-- Ignite TNT
elseif dropnode.name == "mcl_tnt:tnt" then
tnt.ignite(droppos)
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled("") then
stack:add_wear(65535/65) -- 65 uses
end
end

View File

@ -101,7 +101,8 @@ local fish = function(itemstack, player)
if inv:room_for_item("main", item) then
inv:add_item("main", item)
end
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(player:get_player_name()) then
local idef = itemstack:get_definition()
itemstack:add_wear(65535/65) -- 65 uses
if itemstack:get_count() == 0 and idef.sound and idef.sound.breaks then
@ -115,7 +116,7 @@ local fish = function(itemstack, player)
local node = minetest.get_node(epos)
local def = minetest.registered_nodes[node.name]
if def.walkable then
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(player:get_player_name()) then
local idef = itemstack:get_definition()
itemstack:add_wear((65535/65)*2) -- if so and not creative then wear double like in MC.
if itemstack:get_count() == 0 and idef.sound and idef.sound.breaks then

View File

@ -66,7 +66,7 @@ minetest.register_node("mcl_flowerpots:flower_pot", {
local flower_node = row[2]
if item == flower_node then
minetest.swap_node(pos, {name="mcl_flowerpots:flower_pot_"..flower})
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(clicker:get_player_name()) then
itemstack:take_item()
end
end
@ -76,7 +76,7 @@ minetest.register_node("mcl_flowerpots:flower_pot", {
local flower_node = row[2]
if item == flower_node then
minetest.swap_node(pos, {name="mcl_flowerpots:flower_pot_"..flower})
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(clicker:get_player_name()) then
itemstack:take_item()
end
end

View File

@ -264,7 +264,7 @@ local function add_large_plant(name, desc, longdesc, bottom_img, top_img, inv_im
minetest.sound_play(minetest.registered_nodes[itemstring].sounds.place, {pos = bottom, gain=1}, true)
minetest.set_node(bottom, {name=itemstring, param2=param2})
minetest.set_node(top, {name=itemstring.."_top", param2=param2})
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(placer:get_player_name()) then
itemstack:take_item()
end
end
@ -419,7 +419,7 @@ minetest.register_node("mcl_flowers:waterlily", {
minetest.sound_play(idef.sounds.place, {pos=pointed_thing.above, gain=1}, true)
end
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(player_name) then
itemstack:take_item()
end
else

View File

@ -88,7 +88,7 @@ local update_item_entity = function(pos, node, param2)
end
local drop_item = function(pos, node, meta)
if node.name == "mcl_itemframes:item_frame" and not minetest.settings:get_bool("creative_mode") then
if node.name == "mcl_itemframes:item_frame" and not minetest.is_creative_enabled("") then
local inv = meta:get_inventory()
local item = inv:get_stack("main", 1)
if not item:is_empty() then
@ -151,7 +151,7 @@ minetest.register_node("mcl_itemframes:item_frame",{
meta:set_string("infotext", iname)
end
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(clicker:get_player_name()) then
itemstack:take_item()
end
return itemstack

View File

@ -42,7 +42,7 @@ end
-- Checks if player is still allowed to display the minimap
local function update_minimap(player)
local creative = minetest.settings:get_bool("creative_mode")
local creative = minetest.is_creative_enabled(player:get_player_name())
if creative then
player:hud_set_flags({minimap=true, minimap_radar = true})
else
@ -94,7 +94,7 @@ minetest.register_on_joinplayer(function(player)
end)
local updatetimer = 0
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled("") then
minetest.register_globalstep(function(dtime)
updatetimer = updatetimer + dtime
if updatetimer > 0.1 then

View File

@ -139,7 +139,7 @@ minetest.register_craftitem("mcl_mobitems:cooked_rabbit", {
local drink_milk = function(itemstack, player, pointed_thing)
local bucket = minetest.do_item_eat(0, "mcl_buckets:bucket_empty", itemstack, player, pointed_thing)
-- Check if we were allowed to drink this (eat delay check)
if mcl_hunger.active and (bucket:get_name() ~= "mcl_mobitems:milk_bucket" or minetest.settings:get_bool("creative_mode") == true) then
if mcl_hunger.active and (bucket:get_name() ~= "mcl_mobitems:milk_bucket" or minetest.is_creative_enabled(player:get_player_name())) then
mcl_hunger.stop_poison(player)
end
mcl_potions._reset_player_effects(player)

View File

@ -4,7 +4,7 @@
local S = minetest.get_translator("mcl_monster_eggs")
local spawn_silverfish = function(pos, oldnode, oldmetadata, digger)
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled("") then
minetest.add_entity(pos, "mobs_mc:silverfish")
end
end

View File

@ -128,7 +128,7 @@ minetest.register_craftitem("mcl_nether:nether_wart_item", {
minetest.sound_play({name="default_place_node", gain=1.0}, {pos=placepos}, true)
minetest.set_node(placepos, {name="mcl_nether:nether_wart_0", param2 = 3})
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(placer:get_player_name()) then
itemstack:take_item()
end
return itemstack

View File

@ -61,7 +61,7 @@ local function coral_on_place(itemstack, placer, pointed_thing)
if def_node.sounds then
minetest.sound_play(def_node.sounds.place, { gain = 0.5, pos = pos_under }, true)
end
if not (minetest.settings:get_bool("creative_mode")) then
if not minetest.is_creative_enabled(player_name) then
itemstack:take_item()
end

View File

@ -123,7 +123,7 @@ local function kelp_on_place(itemstack, placer, pointed_thing)
minetest.sound_play(def_node.sounds.place, { gain = 0.5, pos = pos_under }, true)
end
minetest.set_node(pos_under, node_under)
if not (minetest.settings:get_bool("creative_mode")) then
if not minetest.is_creative_enabled(player_name) then
itemstack:take_item()
end

View File

@ -54,7 +54,7 @@ local function sea_pickle_on_place(itemstack, placer, pointed_thing)
else
return itemstack
end
if not (minetest.settings:get_bool("creative_mode")) then
if not minetest.is_creative_enabled(player_name) then
itemstack:take_item()
end
return itemstack

View File

@ -70,7 +70,7 @@ local function seagrass_on_place(itemstack, placer, pointed_thing)
minetest.sound_play(def_node.sounds.place, { gain = 0.5, pos = pos_under }, true)
end
minetest.set_node(pos_under, node_under)
if not (minetest.settings:get_bool("creative_mode")) then
if not minetest.is_creative_enabled(player_name) then
itemstack:take_item()
end

View File

@ -405,7 +405,7 @@ minetest.override_item("mcl_end:ender_eye", {
minetest.sound_play(
"default_place_node_hard",
{pos = pointed_thing.under, gain = 0.5, max_hear_distance = 16}, true)
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(user:get_player_name()) then
itemstack:take_item() -- 1 use
end

View File

@ -100,7 +100,7 @@ minetest.register_craftitem("mcl_potions:glass_bottle", {
end
end
if get_water then
local creative = minetest.settings:get_bool("creative_mode") == true
local creative = minetest.is_creative_enabled(placer:get_player_name())
if from_liquid_source or creative then
-- Replace with water bottle, if possible, otherwise
-- place the water potion at a place where's space
@ -210,7 +210,7 @@ minetest.register_craftitem("mcl_potions:water", {
-- Increase water level of cauldron by 1
minetest.set_node(pointed_thing.under, {name=cauldron})
minetest.sound_play("mcl_potions_bottle_pour", {pos=pointed_thing.under, gain=0.5, max_hear_range=16}, true)
if minetest.settings:get_bool("creative_mode") == true then
if minetest.is_creative_enabled(placer:get_player_name()) then
return itemstack
else
return "mcl_potions:glass_bottle"
@ -256,7 +256,7 @@ minetest.register_craftitem("mcl_potions:river_water", {
-- Increase water level of cauldron by 1
minetest.set_node(pointed_thing.under, {name=cauldron})
minetest.sound_play("mcl_potions_bottle_pour", {pos=pointed_thing.under, gain=0.5, max_hear_range=16}, true)
if minetest.settings:get_bool("creative_mode") == true then
if minetest.is_creative_enabled(placer:get_player_name()) then
return itemstack
else
return "mcl_potions:glass_bottle"

View File

@ -81,7 +81,7 @@ local function register_lingering(name, descr, color, def)
local obj = minetest.add_entity({x=pos.x+dir.x,y=pos.y+2+dir.y,z=pos.z+dir.z}, id.."_flying")
obj:setvelocity({x=dir.x*velocity,y=dir.y*velocity,z=dir.z*velocity})
obj:setacceleration({x=0, y=-9.8, z=0})
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(placer:get_player_name()) then
item:take_item()
end
return item

View File

@ -23,7 +23,7 @@ local function register_splash(name, descr, color, def)
local obj = minetest.add_entity({x=pos.x+dir.x,y=pos.y+2+dir.y,z=pos.z+dir.z}, id.."_flying")
obj:set_velocity({x=dir.x*velocity,y=dir.y*velocity,z=dir.z*velocity})
obj:set_acceleration({x=0, y=-9.8, z=0})
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(placer:get_player_name()) then
item:take_item()
end
return item

View File

@ -362,7 +362,7 @@ minetest.register_node("mcl_signs:wall_sign", {
if not success then
return itemstack
end
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(placer:get_player_name()) then
itemstack:take_item()
end
sign_info = signtext_info_standing[rotation_level + 1]

View File

@ -82,7 +82,7 @@ minetest.register_node("mcl_sponges:sponge", {
local absorbed, wet_sponge = absorb(pos)
if absorbed then
minetest.item_place_node(ItemStack(wet_sponge), placer, pointed_thing)
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(placer:get_player_name()) then
itemstack:take_item()
end
return itemstack

View File

@ -229,7 +229,7 @@ function mcl_stairs.register_slab(subname, recipeitem, groups, images, descripti
on_place = function(itemstack, placer, pointed_thing)
local under = minetest.get_node(pointed_thing.under)
local wield_item = itemstack:get_name()
local creative_enabled = minetest.settings:get_bool("creative_mode")
local creative_enabled = minetest.is_creative_enabled(placer:get_player_name())
-- place slab using under node orientation
local dir = vector.subtract(pointed_thing.above, pointed_thing.under)

View File

@ -48,7 +48,7 @@ local player_throw_function = function(entity_name, velocity)
local playerpos = player:get_pos()
local dir = player:get_look_dir()
local obj = mcl_throwing.throw(item, {x=playerpos.x, y=playerpos.y+1.5, z=playerpos.z}, dir, velocity, player:get_player_name())
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(player:get_player_name()) then
item:take_item()
end
return item

View File

@ -26,7 +26,7 @@ dig_speed_class group:
-- The hand
local groupcaps, hand_range, hand_groups
if minetest.settings:get_bool("creative_mode") then
if minetest.is_creative_enabled("") then
-- Instant breaking in creative mode
groupcaps = {
creative_breakable = {times={[1]=0}, uses=0},
@ -213,7 +213,7 @@ local make_grass_path = function(itemstack, placer, pointed_thing)
return itemstack
end
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(placer:get_player_name()) then
-- Add wear, as if digging a level 0 shovely node
local toolname = itemstack:get_name()
local def = minetest.registered_items[toolname]
@ -247,7 +247,7 @@ if minetest.get_modpath("mcl_farming") then
return
end
if node.name == "mcl_farming:pumpkin" then
if not minetest.settings:get_bool("creative_mode") then
if not minetest.is_creative_enabled(placer:get_player_name()) then
-- Add wear (as if digging a shearsy node)
local toolname = itemstack:get_name()
local def = minetest.registered_items[toolname]

View File

@ -160,7 +160,7 @@ screwdriver.handler = function(itemstack, user, pointed_thing, mode, uses)
minetest.check_for_falling(pos)
end
if not (minetest.settings:get_bool("creative_mode")) then
if not (minetest.is_creative_enabled(user:get_player_name())) then
itemstack:add_wear(65535 / ((uses or 200) - 1))
end

View File

@ -23,7 +23,7 @@ minetest.do_item_eat = function(hp_change, replace_with_item, itemstack, user, p
local name = user:get_player_name()
local creative = minetest.settings:get_bool("creative_mode") == true
local creative = minetest.is_creative_enabled(name)
-- Special foodstuffs like the cake may disable the eating delay
local no_eat_delay = creative or (minetest.get_item_group(itemstack:get_name(), "no_eat_delay") == 1)
@ -130,7 +130,7 @@ local poisonrandomizer = PseudoRandom(os.time())
function mcl_hunger.item_eat(hunger_change, replace_with_item, poisontime, poison, exhaust, poisonchance, sound)
return function(itemstack, user, pointed_thing)
local itemname = itemstack:get_name()
local creative = minetest.settings:get_bool("creative_mode") == true
local creative = minetest.is_creative_enabled(user:get_player_name())
if itemstack:peek_item() ~= nil and user ~= nil then
if not creative then
itemstack:take_item()