Builtin: update game
This commit is contained in:
parent
7d0f3170e4
commit
9bce637615
@ -19,8 +19,6 @@ ui = {}
|
|||||||
ui.childlist = {}
|
ui.childlist = {}
|
||||||
ui.default = nil
|
ui.default = nil
|
||||||
|
|
||||||
local maintab = core.settings:get("maintab_LAST")
|
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
function ui.add(child)
|
function ui.add(child)
|
||||||
--TODO check child
|
--TODO check child
|
||||||
@ -79,6 +77,7 @@ local function wordwrap_quickhack(str)
|
|||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
local maintab = core.settings:get("maintab_LAST")
|
||||||
local connect_time = tonumber(core.settings:get("connect_time"))
|
local connect_time = tonumber(core.settings:get("connect_time"))
|
||||||
|
|
||||||
function ui.update()
|
function ui.update()
|
||||||
@ -203,7 +202,7 @@ end
|
|||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
core.button_handler = function(fields)
|
core.button_handler = function(fields)
|
||||||
if fields["btn_reconnect_yes"] then
|
if fields["btn_reconnect_yes"] then
|
||||||
if core.settings:get("maintab_LAST") == "local" then
|
if maintab == "local" then
|
||||||
gamedata.singleplayer = true
|
gamedata.singleplayer = true
|
||||||
gamedata.selected_world =
|
gamedata.selected_world =
|
||||||
tonumber(core.settings:get("mainmenu_last_selected_world"))
|
tonumber(core.settings:get("mainmenu_last_selected_world"))
|
||||||
|
@ -400,6 +400,9 @@ core.register_chatcommand("teleport", {
|
|||||||
end
|
end
|
||||||
local teleportee = core.get_player_by_name(name)
|
local teleportee = core.get_player_by_name(name)
|
||||||
if teleportee then
|
if teleportee then
|
||||||
|
if teleportee:get_attach() then
|
||||||
|
return false, "Can't teleport, you're attached to an object!"
|
||||||
|
end
|
||||||
teleportee:set_pos(p)
|
teleportee:set_pos(p)
|
||||||
return true, "Teleporting to " .. core.pos_to_string(p, 1)
|
return true, "Teleporting to " .. core.pos_to_string(p, 1)
|
||||||
end
|
end
|
||||||
@ -417,6 +420,9 @@ core.register_chatcommand("teleport", {
|
|||||||
end
|
end
|
||||||
|
|
||||||
if teleportee and p then
|
if teleportee and p then
|
||||||
|
if teleportee:get_attach() then
|
||||||
|
return false, "Can't teleport, you're attached to an object!"
|
||||||
|
end
|
||||||
p = find_free_position_near(p)
|
p = find_free_position_near(p)
|
||||||
teleportee:set_pos(p)
|
teleportee:set_pos(p)
|
||||||
return true, "Teleporting to " .. target_name
|
return true, "Teleporting to " .. target_name
|
||||||
@ -437,6 +443,9 @@ core.register_chatcommand("teleport", {
|
|||||||
teleportee = core.get_player_by_name(teleportee_name)
|
teleportee = core.get_player_by_name(teleportee_name)
|
||||||
end
|
end
|
||||||
if teleportee and p.x and p.y and p.z then
|
if teleportee and p.x and p.y and p.z then
|
||||||
|
if teleportee:get_attach() then
|
||||||
|
return false, "Can't teleport, player is attached to an object!"
|
||||||
|
end
|
||||||
teleportee:set_pos(p)
|
teleportee:set_pos(p)
|
||||||
return true, "Teleporting " .. teleportee_name
|
return true, "Teleporting " .. teleportee_name
|
||||||
.. " to " .. core.pos_to_string(p, 1)
|
.. " to " .. core.pos_to_string(p, 1)
|
||||||
@ -455,6 +464,9 @@ core.register_chatcommand("teleport", {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
if teleportee and p then
|
if teleportee and p then
|
||||||
|
if teleportee:get_attach() then
|
||||||
|
return false, "Can't teleport, player is attached to an object!"
|
||||||
|
end
|
||||||
p = find_free_position_near(p)
|
p = find_free_position_near(p)
|
||||||
teleportee:set_pos(p)
|
teleportee:set_pos(p)
|
||||||
return true, "Teleporting " .. teleportee_name
|
return true, "Teleporting " .. teleportee_name
|
||||||
@ -984,13 +996,13 @@ core.register_chatcommand("clearobjects", {
|
|||||||
end
|
end
|
||||||
|
|
||||||
core.log("action", name .. " clears all objects ("
|
core.log("action", name .. " clears all objects ("
|
||||||
.. options.mode .. " mode, by "
|
.. options.mode .. " mode).")
|
||||||
.. name .. ").")
|
core.chat_send_all("Clearing all objects. This may take a long time."
|
||||||
core.chat_send_all("Clearing all objects. This may take long."
|
|
||||||
.. " You may experience a timeout.")
|
.. " You may experience a timeout.")
|
||||||
core.clear_objects(options)
|
core.clear_objects(options)
|
||||||
core.log("action", "Object clearing done.")
|
core.log("action", "Object clearing done.")
|
||||||
core.chat_send_all("*** Cleared all objects.")
|
core.chat_send_all("*** Cleared all objects.")
|
||||||
|
return true
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -1,44 +1,18 @@
|
|||||||
-- Minetest: builtin/item.lua
|
-- Minetest: builtin/item.lua
|
||||||
|
|
||||||
|
local random = math.random
|
||||||
|
local vequals, vround, vadd = vector.equals, vector.round, vector.add
|
||||||
|
|
||||||
local builtin_shared = ...
|
local builtin_shared = ...
|
||||||
|
|
||||||
local gravity = tonumber(core.settings:get("movement_gravity")) or 9.81
|
local gravity = tonumber(core.settings:get("movement_gravity")) or 9.81
|
||||||
local vequals, vround, vadd = vector.equals, vector.round, vector.add
|
|
||||||
|
|
||||||
--
|
--
|
||||||
-- Falling stuff
|
-- Falling stuff
|
||||||
--
|
--
|
||||||
|
|
||||||
local random = math.random
|
local drop_attached_node
|
||||||
local function drop_attached_node(p)
|
|
||||||
local n = core.get_node(p)
|
|
||||||
local drops = core.get_node_drops(n, "")
|
|
||||||
local def = core.registered_items[n.name]
|
|
||||||
if def and def.preserve_metadata then
|
|
||||||
local oldmeta = core.get_meta(p):to_table().fields
|
|
||||||
-- Copy pos and node because the callback can modify them.
|
|
||||||
local pos_copy = {x=p.x, y=p.y, z=p.z}
|
|
||||||
local node_copy = {name=n.name, param1=n.param1, param2=n.param2}
|
|
||||||
local drop_stacks = {}
|
|
||||||
for k, v in pairs(drops) do
|
|
||||||
drop_stacks[k] = ItemStack(v)
|
|
||||||
end
|
|
||||||
drops = drop_stacks
|
|
||||||
def.preserve_metadata(pos_copy, node_copy, oldmeta, drops)
|
|
||||||
end
|
|
||||||
if def and def.sounds and def.sounds.fall then
|
|
||||||
core.sound_play(def.sounds.fall, {pos = p})
|
|
||||||
end
|
|
||||||
core.remove_node(p)
|
|
||||||
for _, item in pairs(drops) do
|
|
||||||
local pos = {
|
|
||||||
x = p.x + random()/2 - 0.25,
|
|
||||||
y = p.y + random()/2 - 0.25,
|
|
||||||
z = p.z + random()/2 - 0.25,
|
|
||||||
}
|
|
||||||
core.add_item(pos, item)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
core.register_entity(":__builtin:falling_node", {
|
core.register_entity(":__builtin:falling_node", {
|
||||||
initial_properties = {
|
initial_properties = {
|
||||||
@ -47,7 +21,7 @@ core.register_entity(":__builtin:falling_node", {
|
|||||||
textures = {},
|
textures = {},
|
||||||
physical = true,
|
physical = true,
|
||||||
is_visible = false,
|
is_visible = false,
|
||||||
collide_with_objects = false,
|
collide_with_objects = true,
|
||||||
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
|
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -159,22 +133,22 @@ core.register_entity(":__builtin:falling_node", {
|
|||||||
if def then
|
if def then
|
||||||
core.add_node(np, self.node)
|
core.add_node(np, self.node)
|
||||||
if self.meta then
|
if self.meta then
|
||||||
local meta = core.get_meta(np)
|
core.get_meta(np):from_table(self.meta)
|
||||||
meta:from_table(self.meta)
|
|
||||||
end
|
end
|
||||||
-- Drop node if falls into a protected area
|
-- Drop node if falls into a protected area
|
||||||
if core.is_protected(np, "") then
|
if core.is_protected(np, "") then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
drop_attached_node(np)
|
drop_attached_node(np)
|
||||||
return
|
return true
|
||||||
end
|
end
|
||||||
if def.sounds and def.sounds.place then
|
if def.sounds and def.sounds.place then
|
||||||
core.sound_play(def.sounds.place, {pos = np})
|
core.sound_play(def.sounds.place, {pos = np})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
|
||||||
core.check_for_falling(np)
|
core.check_for_falling(np)
|
||||||
return
|
return true
|
||||||
end
|
end
|
||||||
local vel = self.object:get_velocity()
|
local vel = self.object:get_velocity()
|
||||||
if vequals(vel, {x = 0, y = 0, z = 0}) then
|
if vequals(vel, {x = 0, y = 0, z = 0}) then
|
||||||
@ -217,6 +191,36 @@ function core.spawn_falling_node(pos)
|
|||||||
return convert_to_falling_node(pos, node)
|
return convert_to_falling_node(pos, node)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function drop_attached_node(p)
|
||||||
|
local n = core.get_node(p)
|
||||||
|
local drops = core.get_node_drops(n, "")
|
||||||
|
local def = core.registered_items[n.name]
|
||||||
|
if def and def.preserve_metadata then
|
||||||
|
local oldmeta = core.get_meta(p):to_table().fields
|
||||||
|
-- Copy pos and node because the callback can modify them.
|
||||||
|
local pos_copy = {x=p.x, y=p.y, z=p.z}
|
||||||
|
local node_copy = {name=n.name, param1=n.param1, param2=n.param2}
|
||||||
|
local drop_stacks = {}
|
||||||
|
for k, v in pairs(drops) do
|
||||||
|
drop_stacks[k] = ItemStack(v)
|
||||||
|
end
|
||||||
|
drops = drop_stacks
|
||||||
|
def.preserve_metadata(pos_copy, node_copy, oldmeta, drops)
|
||||||
|
end
|
||||||
|
if def and def.sounds and def.sounds.fall then
|
||||||
|
core.sound_play(def.sounds.fall, {pos = p})
|
||||||
|
end
|
||||||
|
core.remove_node(p)
|
||||||
|
for _, item in pairs(drops) do
|
||||||
|
local pos = {
|
||||||
|
x = p.x + random()/2 - 0.25,
|
||||||
|
y = p.y + random()/2 - 0.25,
|
||||||
|
z = p.z + random()/2 - 0.25,
|
||||||
|
}
|
||||||
|
core.add_item(pos, item)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function builtin_shared.check_attached_node(p, n)
|
function builtin_shared.check_attached_node(p, n)
|
||||||
local def = core.registered_nodes[n.name]
|
local def = core.registered_nodes[n.name]
|
||||||
local d = {x = 0, y = 0, z = 0}
|
local d = {x = 0, y = 0, z = 0}
|
||||||
@ -285,22 +289,19 @@ function core.check_single_for_falling(p)
|
|||||||
local pa = vadd(p, check_connected[i])
|
local pa = vadd(p, check_connected[i])
|
||||||
local nc = core.get_node(pa)
|
local nc = core.get_node(pa)
|
||||||
if core.get_item_group(nc.name, "attached_node2") ~= 0 then
|
if core.get_item_group(nc.name, "attached_node2") ~= 0 then
|
||||||
local connected
|
|
||||||
for j = 1, 4 do
|
for j = 1, 4 do
|
||||||
local ptwo = vadd(pa, check_connected[j])
|
local ptwo = vadd(pa, check_connected[j])
|
||||||
local ntwo = core.get_node(ptwo)
|
local ntwo = core.get_node(ptwo)
|
||||||
local def = core.registered_nodes[ntwo.name]
|
local def = core.registered_nodes[ntwo.name]
|
||||||
if def and def.walkable then
|
if def and def.walkable then
|
||||||
connected = true
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if not connected then
|
|
||||||
drop_attached_node(pa)
|
drop_attached_node(pa)
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
|
||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
@ -1,19 +1,22 @@
|
|||||||
--From Better HUD mod
|
--[[
|
||||||
--Copyright (C) BlockMen (2013-2016)
|
From Better HUD mod
|
||||||
|
Copyright (C) BlockMen (2013-2016)
|
||||||
|
Copyright (C) MultiCraft Development Team (2019-2020)
|
||||||
|
|
||||||
--This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
the Free Software Foundation; either version 3.0 of the License, or
|
||||||
--(at your option) any later version.
|
(at your option) any later version.
|
||||||
--
|
|
||||||
--This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
||||||
--but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
--GNU Lesser General Public License for more details.
|
GNU Lesser General Public License for more details.
|
||||||
--
|
|
||||||
--You should have received a copy of the GNU Lesser General Public License along
|
You should have received a copy of the GNU Lesser General Public License along
|
||||||
--with this program; if not, write to the Free Software Foundation, Inc.,
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
]]
|
||||||
|
|
||||||
hud, hud_id = {}, {}
|
hud, hud_id = {}, {}
|
||||||
|
|
||||||
@ -113,6 +116,7 @@ function hud.remove_item(player, name)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local i_name = player:get_player_name() .. "_" .. name
|
||||||
local elem = hud_id[i_name]
|
local elem = hud_id[i_name]
|
||||||
|
|
||||||
if not elem then
|
if not elem then
|
||||||
@ -121,7 +125,6 @@ function hud.remove_item(player, name)
|
|||||||
end
|
end
|
||||||
|
|
||||||
player:hud_remove(elem.id)
|
player:hud_remove(elem.id)
|
||||||
elem = nil
|
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
@ -1,24 +1,27 @@
|
|||||||
--From Stamina mod
|
--[[
|
||||||
--Copyright (C) BlockMen (2013-2015)
|
From Stamina mod
|
||||||
--Copyright (C) Auke Kok <sofar@foo-projects.org> (2016)
|
Copyright (C) BlockMen (2013-2015)
|
||||||
--Copyright (C) Minetest Mods Team (2016-2019)
|
Copyright (C) Auke Kok <sofar@foo-projects.org> (2016)
|
||||||
--Copyright (C) MultiCraft Development Team (2016-2020)
|
Copyright (C) Minetest Mods Team (2016-2019)
|
||||||
|
Copyright (C) MultiCraft Development Team (2016-2020)
|
||||||
|
|
||||||
--This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
||||||
--it under the terms of the GNU Lesser General Public License as published by
|
it under the terms of the GNU Lesser General Public License as published by
|
||||||
--the Free Software Foundation; either version 3.0 of the License, or
|
the Free Software Foundation; either version 3.0 of the License, or
|
||||||
--(at your option) any later version.
|
(at your option) any later version.
|
||||||
--
|
|
||||||
--This program is distributed in the hope that it will be useful,
|
|
||||||
--but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
--MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
--GNU Lesser General Public License for more details.
|
|
||||||
--
|
|
||||||
--You should have received a copy of the GNU Lesser General Public License along
|
|
||||||
--with this program; if not, write to the Free Software Foundation, Inc.,
|
|
||||||
--51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
||||||
|
|
||||||
if not core.settings:get_bool("enable_damage") then
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU Lesser General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU Lesser General Public License along
|
||||||
|
with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
|
]]
|
||||||
|
|
||||||
|
if not core.settings:get_bool("enable_damage")
|
||||||
|
or not core.settings:get_bool("enable_hunger") then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -135,10 +138,10 @@ end
|
|||||||
|
|
||||||
function hunger.set_poisoned(player, poisoned)
|
function hunger.set_poisoned(player, poisoned)
|
||||||
if poisoned then
|
if poisoned then
|
||||||
hud.change_item(player, "hunger", {text = "hunger_statbar_poisen.png"})
|
hud.change_item(player, "hunger", {text = "hunger_poisen.png"})
|
||||||
player:set_attribute(attribute.poisoned, "yes")
|
player:set_attribute(attribute.poisoned, "yes")
|
||||||
else
|
else
|
||||||
hud.change_item(player, "hunger", {text = "hunger_statbar_fg.png"})
|
hud.change_item(player, "hunger", {text = "hunger.png"})
|
||||||
player:set_attribute(attribute.poisoned, "no")
|
player:set_attribute(attribute.poisoned, "no")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -316,44 +319,14 @@ core.register_globalstep(function(dtime)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
function core.do_item_eat(hp_change, replace_with_item, poison, itemstack, player, pointed_thing)
|
function hunger.item_eat(hp_change, user, poison)
|
||||||
for _, callback in pairs(core.registered_on_item_eats) do
|
|
||||||
local result = callback(hp_change, replace_with_item, poison, itemstack, player, pointed_thing)
|
|
||||||
if result then
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if not is_player(player) or not itemstack then
|
|
||||||
return itemstack
|
|
||||||
end
|
|
||||||
|
|
||||||
if not poison then
|
if not poison then
|
||||||
hunger.change_saturation(player, hp_change)
|
hunger.change_saturation(user, hp_change)
|
||||||
hunger.set_exhaustion(player, 0)
|
hunger.set_exhaustion(user, 0)
|
||||||
else
|
else
|
||||||
hunger.change_saturation(player, hp_change)
|
hunger.change_saturation(user, hp_change)
|
||||||
hunger.poison(player, -poison, settings.poison_tick)
|
hunger.poison(user, -poison, settings.poison_tick)
|
||||||
end
|
end
|
||||||
|
|
||||||
itemstack:take_item()
|
|
||||||
|
|
||||||
if replace_with_item then
|
|
||||||
if itemstack:is_empty() then
|
|
||||||
itemstack:add_item(replace_with_item)
|
|
||||||
else
|
|
||||||
local inv = player:get_inventory()
|
|
||||||
if inv:room_for_item("main", {name=replace_with_item}) then
|
|
||||||
inv:add_item("main", replace_with_item)
|
|
||||||
else
|
|
||||||
local pos = player:getpos()
|
|
||||||
pos.y = math.floor(pos.y - 1.0)
|
|
||||||
core.add_item(pos, replace_with_item)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return itemstack
|
|
||||||
end
|
end
|
||||||
|
|
||||||
hud.register("hunger", {
|
hud.register("hunger", {
|
||||||
@ -362,8 +335,8 @@ hud.register("hunger", {
|
|||||||
alignment = {x = -1, y = -1},
|
alignment = {x = -1, y = -1},
|
||||||
offset = {x = 8, y = -94},
|
offset = {x = 8, y = -94},
|
||||||
size = {x = 24, y = 24},
|
size = {x = 24, y = 24},
|
||||||
text = "hunger_statbar_fg.png",
|
text = "hunger.png",
|
||||||
background = "hunger_statbar_bg.png",
|
background = "hunger_gone.png",
|
||||||
number = settings.visual_max
|
number = settings.visual_max
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -2,10 +2,13 @@
|
|||||||
|
|
||||||
local builtin_shared = ...
|
local builtin_shared = ...
|
||||||
|
|
||||||
local abs, atan2, cos, floor, max, sin, random = math.abs, math.atan2, math.cos, math.floor, math.max, math.sin, math.random
|
local abs, atan2, cos, floor, max, sin, random =
|
||||||
local vadd, vnew, vmultiply, vnormalize, vsubtract = vector.add, vector.new, vector.multiply, vector.normalize, vector.subtract
|
math.abs, math.atan2, math.cos, math.floor, math.max, math.sin, math.random
|
||||||
|
local vadd, vnew, vmultiply, vnormalize, vsubtract =
|
||||||
|
vector.add, vector.new, vector.multiply, vector.normalize, vector.subtract
|
||||||
|
|
||||||
local creative_mode = core.settings:get_bool("creative_mode")
|
local creative_mode = core.settings:get_bool("creative_mode")
|
||||||
|
local node_drop = core.settings:get_bool("node_drop") ~= false
|
||||||
|
|
||||||
local function copy_pointed_thing(pointed_thing)
|
local function copy_pointed_thing(pointed_thing)
|
||||||
return {
|
return {
|
||||||
@ -550,22 +553,45 @@ function core.item_drop(itemstack, dropper, pos)
|
|||||||
-- environment failed
|
-- environment failed
|
||||||
end
|
end
|
||||||
|
|
||||||
local enable_damage = core.settings:get_bool("enable_damage")
|
local enable_hunger = core.settings:get_bool("enable_damage") and core.settings:get_bool("enable_hunger")
|
||||||
function core.item_eat(hp_change, replace_with_item, poison)
|
function core.do_item_eat(hp_change, replace_with_item, itemstack, user, pointed_thing, poison)
|
||||||
return function(itemstack, user, pointed_thing) -- closure
|
for _, callback in pairs(core.registered_on_item_eats) do
|
||||||
if user then
|
local result = callback(hp_change, replace_with_item, itemstack, user, pointed_thing)
|
||||||
|
if result then
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local def = itemstack:get_definition()
|
||||||
|
if itemstack:take_item() ~= nil then
|
||||||
|
if enable_hunger then
|
||||||
|
hunger.item_eat(hp_change, user, poison)
|
||||||
|
else
|
||||||
|
user:set_hp(user:get_hp() + hp_change)
|
||||||
|
end
|
||||||
|
|
||||||
local pos = user:get_pos()
|
local pos = user:get_pos()
|
||||||
pos.y = pos.y + 1.3
|
|
||||||
if not core.is_valid_pos(pos) then
|
if not core.is_valid_pos(pos) then
|
||||||
return
|
return itemstack
|
||||||
|
end
|
||||||
|
|
||||||
|
if def and def.sound and def.sound.eat then
|
||||||
|
core.sound_play(def.sound.eat, {
|
||||||
|
pos = pos,
|
||||||
|
max_hear_distance = 16})
|
||||||
|
else
|
||||||
|
core.sound_play("player_eat", {
|
||||||
|
pos = pos,
|
||||||
|
max_hear_distance = 10,
|
||||||
|
gain = 0.3})
|
||||||
end
|
end
|
||||||
|
|
||||||
local dir = user:get_look_dir()
|
local dir = user:get_look_dir()
|
||||||
|
local ppos = {x = pos.x, y = pos.y + 1.3, z = pos.z}
|
||||||
core.add_particlespawner({
|
core.add_particlespawner({
|
||||||
amount = 20,
|
amount = 20,
|
||||||
time = 0.1,
|
time = 0.1,
|
||||||
minpos = pos,
|
minpos = ppos,
|
||||||
maxpos = pos,
|
maxpos = ppos,
|
||||||
minvel = {x = dir.x - 1, y = 2, z = dir.z - 1},
|
minvel = {x = dir.x - 1, y = 2, z = dir.z - 1},
|
||||||
maxvel = {x = dir.x + 1, y = 2, z = dir.z + 1},
|
maxvel = {x = dir.x + 1, y = 2, z = dir.z + 1},
|
||||||
minacc = {x = 0, y = -5, z = 0},
|
minacc = {x = 0, y = -5, z = 0},
|
||||||
@ -575,15 +601,34 @@ function core.item_eat(hp_change, replace_with_item, poison)
|
|||||||
minsize = 1,
|
minsize = 1,
|
||||||
maxsize = 1,
|
maxsize = 1,
|
||||||
vertical = false,
|
vertical = false,
|
||||||
texture = core.registered_items[itemstack:get_name()].inventory_image
|
texture = def.inventory_image
|
||||||
})
|
})
|
||||||
core.sound_play("player_eat", {pos = pos, max_hear_distance = 10, gain = 0.3})
|
|
||||||
if enable_damage then
|
if replace_with_item then
|
||||||
return core.do_item_eat(hp_change, replace_with_item, poison, itemstack, user, pointed_thing)
|
if itemstack:is_empty() then
|
||||||
|
itemstack:add_item(replace_with_item)
|
||||||
|
else
|
||||||
|
local inv = user:get_inventory()
|
||||||
|
-- Check if inv is null, since non-players don't have one
|
||||||
|
if inv and inv:room_for_item("main", {name=replace_with_item}) then
|
||||||
|
inv:add_item("main", replace_with_item)
|
||||||
|
else
|
||||||
|
pos.y = pos.y + 0.5
|
||||||
|
core.add_item(pos, replace_with_item)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return itemstack
|
||||||
|
end
|
||||||
|
|
||||||
|
function core.item_eat(hp_change, replace_with_item, poison)
|
||||||
|
return function(itemstack, user, pointed_thing) -- closure
|
||||||
|
if user then
|
||||||
|
return core.do_item_eat(hp_change, replace_with_item, itemstack, user, pointed_thing, poison)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function core.node_punch(pos, node, puncher, pointed_thing)
|
function core.node_punch(pos, node, puncher, pointed_thing)
|
||||||
-- Run script hook
|
-- Run script hook
|
||||||
@ -600,7 +645,7 @@ function core.handle_node_drops(pos, drops, digger)
|
|||||||
-- Add dropped items to object's inventory
|
-- Add dropped items to object's inventory
|
||||||
local inv = digger and digger:get_inventory()
|
local inv = digger and digger:get_inventory()
|
||||||
local give_item
|
local give_item
|
||||||
if creative_mode and inv then
|
if (not node_drop or creative_mode) and inv then
|
||||||
give_item = function(item)
|
give_item = function(item)
|
||||||
return inv:add_item("main", item)
|
return inv:add_item("main", item)
|
||||||
end
|
end
|
||||||
|
@ -19,13 +19,15 @@ end
|
|||||||
|
|
||||||
local time_to_live = tonumber(core.settings:get("item_entity_ttl")) or 600
|
local time_to_live = tonumber(core.settings:get("item_entity_ttl")) or 600
|
||||||
local gravity = tonumber(core.settings:get("movement_gravity")) or 9.81
|
local gravity = tonumber(core.settings:get("movement_gravity")) or 9.81
|
||||||
local collection = core.settings:get_bool("item_collection") or true
|
local collection = core.settings:get_bool("item_collection") ~= false
|
||||||
local water_flow = core.settings:get_bool("item_water_flow") or true
|
local water_flow = core.settings:get_bool("item_water_flow") ~= false
|
||||||
|
local lava_destroy = core.settings:get_bool("item_lava_destroy") ~= false
|
||||||
|
|
||||||
-- Water flow functions, based on QwertyMine3 (WTFPL), and TenPlus1 (MIT) mods
|
-- Water flow functions, based on QwertyMine3 (WTFPL), and TenPlus1 (MIT) mods
|
||||||
local function quick_flow_logic(node, pos_testing, dir)
|
local function quick_flow_logic(node, pos_testing, dir)
|
||||||
local node_testing = core.get_node_or_nil(pos_testing)
|
local node_testing = core.get_node_or_nil(pos_testing)
|
||||||
local liquid = node_testing and core.registered_nodes[node_testing.name].liquidtype
|
if not node_testing then return 0 end
|
||||||
|
local liquid = core.registered_nodes[node_testing.name] and core.registered_nodes[node_testing.name].liquidtype
|
||||||
|
|
||||||
if not liquid or liquid ~= "flowing" and liquid ~= "source" then
|
if not liquid or liquid ~= "flowing" and liquid ~= "source" then
|
||||||
return 0
|
return 0
|
||||||
@ -210,7 +212,8 @@ core.register_entity(":__builtin:item", {
|
|||||||
local is_slippery = false
|
local is_slippery = false
|
||||||
|
|
||||||
-- Destroy item when dropped into lava
|
-- Destroy item when dropped into lava
|
||||||
if def_inside and def_inside.groups and def_inside.groups.lava then
|
if lava_destroy and def_inside
|
||||||
|
and def_inside.groups and def_inside.groups.lava then
|
||||||
core.sound_play("default_cool_lava", {
|
core.sound_play("default_cool_lava", {
|
||||||
pos = pos, max_hear_distance = 10})
|
pos = pos, max_hear_distance = 10})
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
|
@ -137,6 +137,9 @@ function core.register_item(name, itemdef)
|
|||||||
core.log("warning", "Node 'light_source' value exceeds maximum," ..
|
core.log("warning", "Node 'light_source' value exceeds maximum," ..
|
||||||
" limiting to maximum: " ..name)
|
" limiting to maximum: " ..name)
|
||||||
end
|
end
|
||||||
|
if itemdef.light_source == nil then
|
||||||
|
itemdef.light_source = 0
|
||||||
|
end
|
||||||
setmetatable(itemdef, {__index = core.nodedef_default})
|
setmetatable(itemdef, {__index = core.nodedef_default})
|
||||||
core.registered_nodes[itemdef.name] = itemdef
|
core.registered_nodes[itemdef.name] = itemdef
|
||||||
elseif itemdef.type == "craft" then
|
elseif itemdef.type == "craft" then
|
||||||
@ -404,8 +407,7 @@ end
|
|||||||
|
|
||||||
|
|
||||||
function core.add_group(name, adding)
|
function core.add_group(name, adding)
|
||||||
local addgroup = {}
|
local addgroup = table.copy(core.registered_items[name].groups) or {}
|
||||||
addgroup = table.copy(core.registered_items[name].groups)
|
|
||||||
for k, v in pairs(adding) do
|
for k, v in pairs(adding) do
|
||||||
addgroup[k] = v
|
addgroup[k] = v
|
||||||
end
|
end
|
||||||
|
@ -9,7 +9,7 @@ local health_bar_definition = {
|
|||||||
offset = {x = -247, y = -94},
|
offset = {x = -247, y = -94},
|
||||||
size = {x = 24, y = 24},
|
size = {x = 24, y = 24},
|
||||||
text = "heart.png",
|
text = "heart.png",
|
||||||
background = "heart_bg.png",
|
background = "heart_gone.png",
|
||||||
number = 20
|
number = 20
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user