removed extra bones
This commit is contained in:
parent
aa39f00f41
commit
5cfd533621
360
bones.lua
360
bones.lua
@ -1,360 +0,0 @@
|
||||
|
||||
|
||||
-- Copyright (C) 2021, 2023 Sandro del Toro
|
||||
|
||||
-- This file is part of Bones Minetest Mod.
|
||||
|
||||
-- Bones is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU Affero General Public License as
|
||||
-- published by the Free Software Foundation, either version 3 of the
|
||||
-- License, or (at your option) any later version.
|
||||
|
||||
-- Bones 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 Affero General Public License for more details.
|
||||
|
||||
-- You should have received a copy of the GNU Affero General Public License
|
||||
-- along with Bones. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
|
||||
local S = minetest.get_translator(minetest.get_current_modname())
|
||||
|
||||
bones = {}
|
||||
|
||||
bones.sounds = {}
|
||||
|
||||
if minetest.get_modpath("mcl_sounds") then
|
||||
bones.sounds = mcl_sounds
|
||||
end
|
||||
|
||||
if minetest.get_modpath("default") then
|
||||
bones.sounds = default
|
||||
end
|
||||
|
||||
local function is_owner(pos, name)
|
||||
local owner = minetest.get_meta(pos):get_string("owner")
|
||||
if owner == "" or owner == name or minetest.check_player_privs(name, "protection_bypass") then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function mcl_fs()
|
||||
if minetest.get_modpath("mcl_formspec") then
|
||||
return
|
||||
"size[9,8.75]"..
|
||||
"list[current_name;main;0,0.3;9,4;]" ..
|
||||
mcl_formspec.get_itemslot_bg(0,0.3,9,4)..
|
||||
"listring[current_name;main]" ..
|
||||
-- player inv
|
||||
"list[current_player;main;0,4.5;9,3;9]"..
|
||||
mcl_formspec.get_itemslot_bg(0,4.5,9,3)..
|
||||
"list[current_player;main;0,7.74;9,1;]"..
|
||||
mcl_formspec.get_itemslot_bg(0,7.74,9,1)..
|
||||
"listring[current_player;main]"
|
||||
elseif minetest.get_modpath("default") then
|
||||
return "size[8,9]" ..
|
||||
"list[current_name;main;0,0.3;8,4;]" ..
|
||||
"list[current_player;main;0,4.85;8,1;]" ..
|
||||
"list[current_player;main;0,6.08;8,3;8]" ..
|
||||
"listring[current_name;main]" ..
|
||||
"listring[current_player;main]" ..
|
||||
default.get_hotbar_bg(0,4.85)
|
||||
else
|
||||
return "size[8,9]" ..
|
||||
"list[current_name;main;0,0.3;8,4;]" ..
|
||||
"list[current_player;main;0,4.85;8,1;]" ..
|
||||
"list[current_player;main;0,6.08;8,3;8]" ..
|
||||
"listring[current_name;main]" ..
|
||||
"listring[current_player;main]"
|
||||
end
|
||||
end
|
||||
|
||||
local bones_formspec = mcl_fs()
|
||||
|
||||
local share_bones_time = tonumber(minetest.settings:get("share_bones_time")) or 1200
|
||||
local share_bones_time_early = tonumber(minetest.settings:get("share_bones_time_early")) or share_bones_time / 4
|
||||
|
||||
-- legacy alias
|
||||
minetest.register_alias("mcl_bones:bones", "bones:bones")
|
||||
|
||||
local bones_def = {
|
||||
description = S("Bones"),
|
||||
tiles = {
|
||||
"bones_top.png^[transform2",
|
||||
"bones_bottom.png",
|
||||
"bones_side.png",
|
||||
"bones_side.png",
|
||||
"bones_rear.png",
|
||||
"bones_front.png"
|
||||
},
|
||||
inventory_image = "bones_front.png",
|
||||
wield_image = "bones_front.png",
|
||||
paramtype2 = "facedir",
|
||||
stack_max = 64,
|
||||
groups = {dig_immediate = 2},
|
||||
sounds = bones.sounds.node_sound_gravel_defaults(),
|
||||
drop = "",
|
||||
_mcl_blast_resistance = 0.5,
|
||||
_mcl_hardness = 0.5,
|
||||
|
||||
can_dig = function(pos, player)
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
local name = ""
|
||||
if player then
|
||||
name = player:get_player_name()
|
||||
end
|
||||
return is_owner(pos, name) and inv:is_empty("main")
|
||||
end,
|
||||
|
||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
if is_owner(pos, player:get_player_name()) then
|
||||
return count
|
||||
end
|
||||
return 0
|
||||
end,
|
||||
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
return 0
|
||||
end,
|
||||
|
||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
if is_owner(pos, player:get_player_name()) then
|
||||
return stack:get_count()
|
||||
end
|
||||
return 0
|
||||
end,
|
||||
|
||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if meta:get_inventory():is_empty("main") then
|
||||
local inv = player:get_inventory()
|
||||
-- if inv:room_for_item("main", {name = "bones:bones"}) then
|
||||
-- inv:add_item("main", {name = "bones:bones"})
|
||||
-- else
|
||||
-- minetest.add_item(pos, "bones:bones")
|
||||
-- end
|
||||
minetest.remove_node(pos)
|
||||
end
|
||||
end,
|
||||
|
||||
on_punch = function(pos, node, player)
|
||||
if not is_owner(pos, player:get_player_name()) then
|
||||
return
|
||||
end
|
||||
|
||||
if minetest.get_meta(pos):get_string("infotext") == "" then
|
||||
return
|
||||
end
|
||||
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
local player_inv = player:get_inventory()
|
||||
local has_space = true
|
||||
|
||||
for i = 1, inv:get_size("main") do
|
||||
local stk = inv:get_stack("main", i)
|
||||
if player_inv:room_for_item("main", stk) then
|
||||
inv:set_stack("main", i, nil)
|
||||
player_inv:add_item("main", stk)
|
||||
else
|
||||
has_space = false
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- remove bones if player emptied them
|
||||
if has_space then
|
||||
-- if player_inv:room_for_item("main", {name = "bones:bones"}) then
|
||||
-- player_inv:add_item("main", {name = "bones:bones"})
|
||||
-- else
|
||||
-- minetest.add_item(pos,"bones:bones")
|
||||
-- end
|
||||
minetest.remove_node(pos)
|
||||
end
|
||||
end,
|
||||
|
||||
on_timer = function(pos, elapsed)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local time = meta:get_int("time") + elapsed
|
||||
if time >= share_bones_time then
|
||||
meta:set_string("infotext", S("@1's old bones", meta:get_string("owner")))
|
||||
meta:set_string("owner", "")
|
||||
else
|
||||
meta:set_int("time", time)
|
||||
return true
|
||||
end
|
||||
end,
|
||||
on_blast = function(pos)
|
||||
end,
|
||||
}
|
||||
|
||||
if minetest.get_modpath("default") then
|
||||
default.set_inventory_action_loggers(bones_def, "bones")
|
||||
end
|
||||
|
||||
minetest.register_node("bones:bones", bones_def)
|
||||
|
||||
local function may_replace(pos, player)
|
||||
local node_name = minetest.get_node(pos).name
|
||||
local node_definition = minetest.registered_nodes[node_name]
|
||||
|
||||
-- if the node is unknown, we return false
|
||||
if not node_definition then
|
||||
return false
|
||||
end
|
||||
|
||||
-- allow replacing air
|
||||
if node_name == "air" then
|
||||
return true
|
||||
end
|
||||
|
||||
-- don't replace nodes inside protections
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
return false
|
||||
end
|
||||
|
||||
-- allow replacing liquids
|
||||
if node_definition.liquidtype ~= "none" then
|
||||
return true
|
||||
end
|
||||
|
||||
-- don't replace filled chests and other nodes that don't allow it
|
||||
local can_dig_func = node_definition.can_dig
|
||||
if can_dig_func and not can_dig_func(pos, player) then
|
||||
return false
|
||||
end
|
||||
|
||||
-- default to each nodes buildable_to; if a placed block would replace it, why shouldn't bones?
|
||||
-- flowers being squished by bones are more realistical than a squished stone, too
|
||||
return node_definition.buildable_to
|
||||
end
|
||||
|
||||
local drop = function(pos, itemstack)
|
||||
local obj = minetest.add_item(pos, itemstack:take_item(itemstack:get_count()))
|
||||
if obj then
|
||||
obj:set_velocity({
|
||||
x = math.random(-10, 10) / 9,
|
||||
y = 5,
|
||||
z = math.random(-10, 10) / 9,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
local player_inventory_lists = { "main", "craft" }
|
||||
bones.player_inventory_lists = player_inventory_lists
|
||||
|
||||
local function is_all_empty(player_inv)
|
||||
for _, list_name in ipairs(player_inventory_lists) do
|
||||
if not player_inv:is_empty(list_name) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
minetest.register_on_dieplayer(function(player)
|
||||
local bones_mode = minetest.settings:get("bones_mode") or "bones"
|
||||
if bones_mode ~= "bones" and bones_mode ~= "drop" and bones_mode ~= "keep" then
|
||||
bones_mode = "bones"
|
||||
end
|
||||
|
||||
local bones_position_message = minetest.settings:get_bool("bones_position_message") or true
|
||||
local player_name = player:get_player_name()
|
||||
local pos = vector.round(player:get_pos())
|
||||
local pos_string = minetest.pos_to_string(pos)
|
||||
|
||||
-- return if keep inventory set or in creative mode
|
||||
if bones_mode == "keep" or minetest.is_creative_enabled(player_name) then
|
||||
minetest.log("action", player_name .. " dies at " .. pos_string ..
|
||||
". No bones placed")
|
||||
if bones_position_message then
|
||||
minetest.chat_send_player(player_name, S("@1 died at @2.", player_name, pos_string))
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
local player_inv = player:get_inventory()
|
||||
if is_all_empty(player_inv) then
|
||||
minetest.log("action", player_name .. " dies at " .. pos_string ..
|
||||
". No bones placed")
|
||||
if bones_position_message then
|
||||
minetest.chat_send_player(player_name, S("@1 died at @2.", player_name, pos_string))
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
-- check if it's possible to place bones, if not find space near player
|
||||
if bones_mode == "bones" and not may_replace(pos, player) then
|
||||
local air = minetest.find_node_near(pos, 1, {"air"})
|
||||
if air then
|
||||
pos = air
|
||||
else
|
||||
bones_mode = "drop"
|
||||
end
|
||||
end
|
||||
|
||||
if bones_mode == "drop" then
|
||||
for _, list_name in ipairs(player_inventory_lists) do
|
||||
for i = 1, player_inv:get_size(list_name) do
|
||||
drop(pos, player_inv:get_stack(list_name, i))
|
||||
end
|
||||
player_inv:set_list(list_name, {})
|
||||
end
|
||||
drop(pos, ItemStack("bones:bones"))
|
||||
minetest.log("action", player_name .. " dies at " .. pos_string ..
|
||||
". Inventory dropped")
|
||||
if bones_position_message then
|
||||
minetest.chat_send_player(player_name, S("@1 died at @2, and dropped their inventory.", player_name, pos_string))
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
local param2 = minetest.dir_to_facedir(player:get_look_dir())
|
||||
minetest.set_node(pos, {name = "bones:bones", param2 = param2})
|
||||
|
||||
minetest.log("action", player_name .. " dies at " .. pos_string ..
|
||||
". Bones placed")
|
||||
if bones_position_message then
|
||||
minetest.chat_send_player(player_name, S("@1 died at @2, and bones were placed.", player_name, pos_string))
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
if minetest.get_modpath("mcl_inventory") then
|
||||
inv:set_size("main", 9 * 4)
|
||||
end
|
||||
if minetest.get_modpath("default") then
|
||||
inv:set_size("main", 8 * 4)
|
||||
end
|
||||
|
||||
for _, list_name in ipairs(player_inventory_lists) do
|
||||
for i = 1, player_inv:get_size(list_name) do
|
||||
local stack = player_inv:get_stack(list_name, i)
|
||||
if inv:room_for_item("main", stack) then
|
||||
inv:add_item("main", stack)
|
||||
else -- no space left
|
||||
drop(pos, stack)
|
||||
end
|
||||
end
|
||||
player_inv:set_list(list_name, {})
|
||||
end
|
||||
|
||||
meta:set_string("formspec", bones_formspec)
|
||||
meta:set_string("owner", player_name)
|
||||
|
||||
if share_bones_time ~= 0 then
|
||||
meta:set_string("infotext", S("@1's fresh bones", player_name))
|
||||
|
||||
if share_bones_time_early == 0 or not minetest.is_protected(pos, player_name) then
|
||||
meta:set_int("time", 0)
|
||||
else
|
||||
meta:set_int("time", (share_bones_time - share_bones_time_early))
|
||||
end
|
||||
|
||||
minetest.get_node_timer(pos):start(10)
|
||||
else
|
||||
meta:set_string("infotext", S("@1's bones", player_name))
|
||||
end
|
||||
end)
|
186
extra.lua
186
extra.lua
@ -1,186 +0,0 @@
|
||||
|
||||
|
||||
-- Copyright (C) 2021, 2023 Sandro del Toro
|
||||
|
||||
-- This file is part of Bones Minetest Mod.
|
||||
|
||||
-- Bones is free software: you can redistribute it and/or modify
|
||||
-- it under the terms of the GNU Affero General Public License as
|
||||
-- published by the Free Software Foundation, either version 3 of the
|
||||
-- License, or (at your option) any later version.
|
||||
|
||||
-- Bones 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 Affero General Public License for more details.
|
||||
|
||||
-- You should have received a copy of the GNU Affero General Public License
|
||||
-- along with Bones. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
local S = minetest.get_translator(minetest.get_current_modname())
|
||||
|
||||
-- skull bones
|
||||
local skull_def = {
|
||||
description = S("Skull"),
|
||||
tiles = {
|
||||
"bones_redo_side.png",
|
||||
"bones_redo_side.png",
|
||||
"bones_redo_side.png",
|
||||
"bones_redo_side.png",
|
||||
"bones_back.png",
|
||||
"bones_front_off.png"
|
||||
},
|
||||
inventory_image = "bones_front_off.png",
|
||||
wield_image = "bones_front_off.png",
|
||||
paramtype2 = "facedir",
|
||||
stack_max = 64,
|
||||
groups = {dig_immediate = 2, enderman_takable = 1, building_block = 1},
|
||||
sounds = bones.sounds.node_sound_stone_defaults(),
|
||||
_mcl_blast_resistance = 0.5,
|
||||
_mcl_hardness = 0.5,
|
||||
on_rightclick = function(pos, node, clicker, itemstack)
|
||||
local name = clicker:get_player_name() or ""
|
||||
if minetest.is_protected(pos, name) then return end
|
||||
node.name = "bones:bones_light"
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
}
|
||||
|
||||
-- glow bones
|
||||
local skull_light_def = table.copy(skull_def)
|
||||
|
||||
skull_light_def.description = S("Glowing Skull")
|
||||
|
||||
skull_light_def.tiles = {
|
||||
"bones_redo_side.png",
|
||||
"bones_redo_side.png",
|
||||
"bones_redo_side.png",
|
||||
"bones_redo_side.png",
|
||||
"bones_back.png",
|
||||
"bones_front_on.png"
|
||||
}
|
||||
|
||||
skull_light_def.paramtype = "light"
|
||||
|
||||
skull_light_def.inventory_image = "bones_front_on.png"
|
||||
|
||||
skull_light_def.wield_image = "bones_front_on.png"
|
||||
|
||||
skull_light_def.light_source = minetest.LIGHT_MAX
|
||||
|
||||
skull_light_def.on_rightclick = function(pos, node, clicker, itemstack)
|
||||
local name = clicker:get_player_name() or ""
|
||||
if minetest.is_protected(pos, name) then return end
|
||||
node.name = "bones:bones_skull"
|
||||
minetest.swap_node(pos, node)
|
||||
end
|
||||
|
||||
minetest.register_node("bones:bones_skull", skull_def)
|
||||
|
||||
minetest.register_node("bones:bones_light", skull_light_def)
|
||||
|
||||
|
||||
-- legacy alias
|
||||
minetest.register_alias("mcl_bones:bones_light", "bones:bones_light")
|
||||
|
||||
|
||||
local box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-0.125, -0.5, -0.5, 0.0625, -0.375, 0.0625}, -- NodeBox1
|
||||
{-0.1875, -0.5, 0.0625, 0.125, -0.3125, 0.25}, -- NodeBox2
|
||||
{0.0625, -0.5, -0.5, 0.3125, -0.4375, -0.375}, -- NodeBox3
|
||||
{-0.375, -0.5, -0.5, -0.125, -0.4375, -0.375}, -- NodeBox4
|
||||
{0.0625, -0.5, -0.3125, 0.3125, -0.4375, -0.25}, -- NodeBox5
|
||||
{-0.375, -0.5, -0.3125, -0.125, -0.4375, -0.25}, -- NodeBox6
|
||||
{-0.375, -0.4375, -0.3125, -0.3125, -0.3125, -0.25}, -- NodeBox7
|
||||
{0.25, -0.4375, -0.3125, 0.3125, -0.3125, -0.25}, -- NodeBox8
|
||||
{0, -0.3125, -0.3125, 0.3125, -0.25, -0.25}, -- NodeBox9
|
||||
{-0.375, -0.3125, -0.3125, -0.0625, -0.25, -0.25}, -- NodeBox10
|
||||
{-0.0625, -0.3125, -0.3125, 0, -0.25, -0.0625}, -- NodeBox11
|
||||
{-0.375, -0.5, -0.1875, -0.125, -0.4375, -0.125}, -- NodeBox12
|
||||
{-0.375, -0.3125, -0.1875, -0.0625, -0.25, -0.125}, -- NodeBox13
|
||||
{-0.375, -0.4375, -0.1875, -0.3125, -0.3125, -0.125}, -- NodeBox14
|
||||
{0.0625, -0.5, -0.1875, 0.3125, -0.4375, -0.125}, -- NodeBox15
|
||||
{0.25, -0.4375, -0.1875, 0.3125, -0.3125, -0.125}, -- NodeBox16
|
||||
{0.375, -0.5, -0.4375, 0.4375, -0.4375, -0.125}, -- NodeBox17
|
||||
{-0.4375, -0.5, -0.25, -0.375, -0.4375, 0.0625}, -- NodeBox18
|
||||
{-0.3125, -0.5, 0.125, -0.1875, -0.4375, 0.4375}, -- NodeBox19
|
||||
{0.1875, -0.5, 0, 0.25, -0.375, 0.4375}, -- NodeBox20
|
||||
{0.3125, -0.5, -0.0625, 0.5, -0.4375, 0.125}, -- NodeBox21
|
||||
{0.25, -0.375, -0.125, 0.4375, -0.1875, 0.1875}, -- NodeBox23
|
||||
{0.3125, -0.4375, -0.0625, 0.4375, -0.375, 0.125}, -- NodeBox28
|
||||
{0.3125, -0.5, 0.4375, 0.5, -0.4375, 0.5}, -- NodeBox29
|
||||
{-0.4375, -0.5, 0.1875, -0.375, -0.4375, 0.375}, -- NodeBox30
|
||||
{0.4375, -0.25, -0.125, 0.5, -0.1875, 0.1875}, -- NodeBox31
|
||||
{0.4375, -0.375, -0.125, 0.5, -0.3125, 0.1875}, -- NodeBox32
|
||||
{0.4375, -0.3125, -0.125, 0.5, -0.25, -0.0625}, -- NodeBox33
|
||||
{0.4375, -0.3125, 0.125, 0.5, -0.25, 0.1875}, -- NodeBox34
|
||||
{0.4375, -0.3125, 0, 0.5, -0.25, 0.0625}, -- NodeBox35
|
||||
}
|
||||
}
|
||||
|
||||
if minetest.get_modpath("mcl_mobitems") then
|
||||
deco_drop = {
|
||||
max_items = 1,
|
||||
items = {
|
||||
{items = {"mcl_mobitems:bone 3"},rarity = 5},
|
||||
{items = {"mcl_mobitems:bone 2"},rarity = 3},
|
||||
{items = {"mcl_mobitems:bone"}},
|
||||
}
|
||||
}
|
||||
else
|
||||
deco_drop = "bones:deco_bones"
|
||||
end
|
||||
|
||||
-- deco bones
|
||||
minetest.register_node("bones:deco_bones",{
|
||||
description = S("Bones"),
|
||||
inventory_image = "bones_inv.png",
|
||||
wield_image = "bones_inv.png",
|
||||
tiles = {"bones_color.png"},
|
||||
drawtype = "nodebox",
|
||||
node_box = box,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {
|
||||
{-8/16, -8/16, -8/16, 8/16, -3/16, 8/16}
|
||||
}},
|
||||
paramtype = "light",
|
||||
paramtype2 = "facedir",
|
||||
sunlight_propagates = true,
|
||||
stack_max = 64,
|
||||
drop = deco_drop,
|
||||
groups = {dig_immediate = 2, enderman_takable = 1, deco_block = 1},
|
||||
sounds = bones.sounds.node_sound_stone_defaults(),
|
||||
_mcl_blast_resistance = 0.5,
|
||||
_mcl_hardness = 0.5,
|
||||
})
|
||||
|
||||
-- legacy alias
|
||||
minetest.register_alias("mcl_bones:deco_bones", "bones:deco_bones")
|
||||
|
||||
|
||||
|
||||
-- crafts
|
||||
|
||||
minetest.register_craft({
|
||||
output = "bones:deco_bones",
|
||||
recipe = {
|
||||
{"mcl_core:bone_block"},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "mcl_core:bone_block",
|
||||
recipe = {
|
||||
{"bones:bones_light"},
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = "bones:bones_light",
|
||||
recipe = {"mcl_core:bone_block", "mcl_torches:torch"}
|
||||
})
|
342
init.lua
342
init.lua
@ -18,13 +18,343 @@
|
||||
-- along with Bones. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
local modpath = core.get_modpath(core.get_current_modname())
|
||||
|
||||
local extra_bones = core.settings:get_bool("bones_extra_features") or true
|
||||
local S = minetest.get_translator(minetest.get_current_modname())
|
||||
|
||||
dofile(modpath .. "/bones.lua")
|
||||
bones = {}
|
||||
|
||||
-- extra features
|
||||
if extra_bones then
|
||||
dofile(modpath .. "/extra.lua")
|
||||
bones.sounds = {}
|
||||
|
||||
if minetest.get_modpath("mcl_sounds") then
|
||||
bones.sounds = mcl_sounds
|
||||
end
|
||||
|
||||
if minetest.get_modpath("default") then
|
||||
bones.sounds = default
|
||||
end
|
||||
|
||||
local function is_owner(pos, name)
|
||||
local owner = minetest.get_meta(pos):get_string("owner")
|
||||
if owner == "" or owner == name or minetest.check_player_privs(name, "protection_bypass") then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function mcl_fs()
|
||||
if minetest.get_modpath("mcl_formspec") then
|
||||
return
|
||||
"size[9,8.75]"..
|
||||
"list[current_name;main;0,0.3;9,4;]" ..
|
||||
mcl_formspec.get_itemslot_bg(0,0.3,9,4)..
|
||||
"listring[current_name;main]" ..
|
||||
-- player inv
|
||||
"list[current_player;main;0,4.5;9,3;9]"..
|
||||
mcl_formspec.get_itemslot_bg(0,4.5,9,3)..
|
||||
"list[current_player;main;0,7.74;9,1;]"..
|
||||
mcl_formspec.get_itemslot_bg(0,7.74,9,1)..
|
||||
"listring[current_player;main]"
|
||||
elseif minetest.get_modpath("default") then
|
||||
return "size[8,9]" ..
|
||||
"list[current_name;main;0,0.3;8,4;]" ..
|
||||
"list[current_player;main;0,4.85;8,1;]" ..
|
||||
"list[current_player;main;0,6.08;8,3;8]" ..
|
||||
"listring[current_name;main]" ..
|
||||
"listring[current_player;main]" ..
|
||||
default.get_hotbar_bg(0,4.85)
|
||||
else
|
||||
return "size[8,9]" ..
|
||||
"list[current_name;main;0,0.3;8,4;]" ..
|
||||
"list[current_player;main;0,4.85;8,1;]" ..
|
||||
"list[current_player;main;0,6.08;8,3;8]" ..
|
||||
"listring[current_name;main]" ..
|
||||
"listring[current_player;main]"
|
||||
end
|
||||
end
|
||||
|
||||
local bones_formspec = mcl_fs()
|
||||
|
||||
local share_bones_time = tonumber(minetest.settings:get("share_bones_time")) or 1200
|
||||
local share_bones_time_early = tonumber(minetest.settings:get("share_bones_time_early")) or share_bones_time / 4
|
||||
|
||||
-- legacy alias
|
||||
minetest.register_alias("mcl_bones:bones", "bones:bones")
|
||||
|
||||
local bones_def = {
|
||||
description = S("Bones"),
|
||||
tiles = {
|
||||
"bones_top.png^[transform2",
|
||||
"bones_bottom.png",
|
||||
"bones_side.png",
|
||||
"bones_side.png",
|
||||
"bones_rear.png",
|
||||
"bones_front.png"
|
||||
},
|
||||
inventory_image = "bones_front.png",
|
||||
wield_image = "bones_front.png",
|
||||
paramtype2 = "facedir",
|
||||
stack_max = 64,
|
||||
groups = {dig_immediate = 2},
|
||||
sounds = bones.sounds.node_sound_gravel_defaults(),
|
||||
drop = "",
|
||||
_mcl_blast_resistance = 0.5,
|
||||
_mcl_hardness = 0.5,
|
||||
|
||||
can_dig = function(pos, player)
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
local name = ""
|
||||
if player then
|
||||
name = player:get_player_name()
|
||||
end
|
||||
return is_owner(pos, name) and inv:is_empty("main")
|
||||
end,
|
||||
|
||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
if is_owner(pos, player:get_player_name()) then
|
||||
return count
|
||||
end
|
||||
return 0
|
||||
end,
|
||||
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
return 0
|
||||
end,
|
||||
|
||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
if is_owner(pos, player:get_player_name()) then
|
||||
return stack:get_count()
|
||||
end
|
||||
return 0
|
||||
end,
|
||||
|
||||
on_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
local meta = minetest.get_meta(pos)
|
||||
if meta:get_inventory():is_empty("main") then
|
||||
local inv = player:get_inventory()
|
||||
-- if inv:room_for_item("main", {name = "bones:bones"}) then
|
||||
-- inv:add_item("main", {name = "bones:bones"})
|
||||
-- else
|
||||
-- minetest.add_item(pos, "bones:bones")
|
||||
-- end
|
||||
minetest.remove_node(pos)
|
||||
end
|
||||
end,
|
||||
|
||||
on_punch = function(pos, node, player)
|
||||
if not is_owner(pos, player:get_player_name()) then
|
||||
return
|
||||
end
|
||||
|
||||
if minetest.get_meta(pos):get_string("infotext") == "" then
|
||||
return
|
||||
end
|
||||
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
local player_inv = player:get_inventory()
|
||||
local has_space = true
|
||||
|
||||
for i = 1, inv:get_size("main") do
|
||||
local stk = inv:get_stack("main", i)
|
||||
if player_inv:room_for_item("main", stk) then
|
||||
inv:set_stack("main", i, nil)
|
||||
player_inv:add_item("main", stk)
|
||||
else
|
||||
has_space = false
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
-- remove bones if player emptied them
|
||||
if has_space then
|
||||
-- if player_inv:room_for_item("main", {name = "bones:bones"}) then
|
||||
-- player_inv:add_item("main", {name = "bones:bones"})
|
||||
-- else
|
||||
-- minetest.add_item(pos,"bones:bones")
|
||||
-- end
|
||||
minetest.remove_node(pos)
|
||||
end
|
||||
end,
|
||||
|
||||
on_timer = function(pos, elapsed)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local time = meta:get_int("time") + elapsed
|
||||
if time >= share_bones_time then
|
||||
meta:set_string("infotext", S("@1's old bones", meta:get_string("owner")))
|
||||
meta:set_string("owner", "")
|
||||
else
|
||||
meta:set_int("time", time)
|
||||
return true
|
||||
end
|
||||
end,
|
||||
on_blast = function(pos)
|
||||
end,
|
||||
}
|
||||
|
||||
if minetest.get_modpath("default") then
|
||||
default.set_inventory_action_loggers(bones_def, "bones")
|
||||
end
|
||||
|
||||
minetest.register_node("bones:bones", bones_def)
|
||||
|
||||
local function may_replace(pos, player)
|
||||
local node_name = minetest.get_node(pos).name
|
||||
local node_definition = minetest.registered_nodes[node_name]
|
||||
|
||||
-- if the node is unknown, we return false
|
||||
if not node_definition then
|
||||
return false
|
||||
end
|
||||
|
||||
-- allow replacing air
|
||||
if node_name == "air" then
|
||||
return true
|
||||
end
|
||||
|
||||
-- don't replace nodes inside protections
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
return false
|
||||
end
|
||||
|
||||
-- allow replacing liquids
|
||||
if node_definition.liquidtype ~= "none" then
|
||||
return true
|
||||
end
|
||||
|
||||
-- don't replace filled chests and other nodes that don't allow it
|
||||
local can_dig_func = node_definition.can_dig
|
||||
if can_dig_func and not can_dig_func(pos, player) then
|
||||
return false
|
||||
end
|
||||
|
||||
-- default to each nodes buildable_to; if a placed block would replace it, why shouldn't bones?
|
||||
-- flowers being squished by bones are more realistical than a squished stone, too
|
||||
return node_definition.buildable_to
|
||||
end
|
||||
|
||||
local drop = function(pos, itemstack)
|
||||
local obj = minetest.add_item(pos, itemstack:take_item(itemstack:get_count()))
|
||||
if obj then
|
||||
obj:set_velocity({
|
||||
x = math.random(-10, 10) / 9,
|
||||
y = 5,
|
||||
z = math.random(-10, 10) / 9,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
local player_inventory_lists = { "main", "craft" }
|
||||
bones.player_inventory_lists = player_inventory_lists
|
||||
|
||||
local function is_all_empty(player_inv)
|
||||
for _, list_name in ipairs(player_inventory_lists) do
|
||||
if not player_inv:is_empty(list_name) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
minetest.register_on_dieplayer(function(player)
|
||||
local bones_mode = minetest.settings:get("bones_mode") or "bones"
|
||||
if bones_mode ~= "bones" and bones_mode ~= "drop" and bones_mode ~= "keep" then
|
||||
bones_mode = "bones"
|
||||
end
|
||||
|
||||
local bones_position_message = minetest.settings:get_bool("bones_position_message") or true
|
||||
local player_name = player:get_player_name()
|
||||
local pos = vector.round(player:get_pos())
|
||||
local pos_string = minetest.pos_to_string(pos)
|
||||
|
||||
-- return if keep inventory set or in creative mode
|
||||
if bones_mode == "keep" or minetest.is_creative_enabled(player_name) then
|
||||
minetest.log("action", player_name .. " dies at " .. pos_string ..
|
||||
". No bones placed")
|
||||
if bones_position_message then
|
||||
minetest.chat_send_player(player_name, S("@1 died at @2.", player_name, pos_string))
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
local player_inv = player:get_inventory()
|
||||
if is_all_empty(player_inv) then
|
||||
minetest.log("action", player_name .. " dies at " .. pos_string ..
|
||||
". No bones placed")
|
||||
if bones_position_message then
|
||||
minetest.chat_send_player(player_name, S("@1 died at @2.", player_name, pos_string))
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
-- check if it's possible to place bones, if not find space near player
|
||||
if bones_mode == "bones" and not may_replace(pos, player) then
|
||||
local air = minetest.find_node_near(pos, 1, {"air"})
|
||||
if air then
|
||||
pos = air
|
||||
else
|
||||
bones_mode = "drop"
|
||||
end
|
||||
end
|
||||
|
||||
if bones_mode == "drop" then
|
||||
for _, list_name in ipairs(player_inventory_lists) do
|
||||
for i = 1, player_inv:get_size(list_name) do
|
||||
drop(pos, player_inv:get_stack(list_name, i))
|
||||
end
|
||||
player_inv:set_list(list_name, {})
|
||||
end
|
||||
drop(pos, ItemStack("bones:bones"))
|
||||
minetest.log("action", player_name .. " dies at " .. pos_string ..
|
||||
". Inventory dropped")
|
||||
if bones_position_message then
|
||||
minetest.chat_send_player(player_name, S("@1 died at @2, and dropped their inventory.", player_name, pos_string))
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
local param2 = minetest.dir_to_facedir(player:get_look_dir())
|
||||
minetest.set_node(pos, {name = "bones:bones", param2 = param2})
|
||||
|
||||
minetest.log("action", player_name .. " dies at " .. pos_string ..
|
||||
". Bones placed")
|
||||
if bones_position_message then
|
||||
minetest.chat_send_player(player_name, S("@1 died at @2, and bones were placed.", player_name, pos_string))
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
if minetest.get_modpath("mcl_inventory") then
|
||||
inv:set_size("main", 9 * 4)
|
||||
end
|
||||
if minetest.get_modpath("default") then
|
||||
inv:set_size("main", 8 * 4)
|
||||
end
|
||||
|
||||
for _, list_name in ipairs(player_inventory_lists) do
|
||||
for i = 1, player_inv:get_size(list_name) do
|
||||
local stack = player_inv:get_stack(list_name, i)
|
||||
if inv:room_for_item("main", stack) then
|
||||
inv:add_item("main", stack)
|
||||
else -- no space left
|
||||
drop(pos, stack)
|
||||
end
|
||||
end
|
||||
player_inv:set_list(list_name, {})
|
||||
end
|
||||
|
||||
meta:set_string("formspec", bones_formspec)
|
||||
meta:set_string("owner", player_name)
|
||||
|
||||
if share_bones_time ~= 0 then
|
||||
meta:set_string("infotext", S("@1's fresh bones", player_name))
|
||||
|
||||
if share_bones_time_early == 0 or not minetest.is_protected(pos, player_name) then
|
||||
meta:set_int("time", 0)
|
||||
else
|
||||
meta:set_int("time", (share_bones_time - share_bones_time_early))
|
||||
end
|
||||
|
||||
minetest.get_node_timer(pos):start(10)
|
||||
else
|
||||
meta:set_string("infotext", S("@1's bones", player_name))
|
||||
end
|
||||
end)
|
||||
|
@ -16,7 +16,4 @@ share_bones_time (Bones share time) int 1200 0
|
||||
share_bones_time_early (Earlier bones share time) int 300 0
|
||||
|
||||
# Inform player of condition and location of new bones.
|
||||
bones_position_message (Inform player about bones) bool false
|
||||
|
||||
# Add extra features
|
||||
bones_extra_features (Extra features) bool true
|
||||
bones_position_message (Inform player about bones) bool true
|
||||
|
Binary file not shown.
Before Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.8 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
Before Width: | Height: | Size: 225 B |
Binary file not shown.
Before Width: | Height: | Size: 1.4 KiB |
Loading…
x
Reference in New Issue
Block a user