Namespacing pt. 3
This commit is contained in:
@@ -65,7 +65,7 @@ function xdecor.register(name, def)
|
||||
local inventory = def.inventory
|
||||
|
||||
|
||||
minetest.register_node("xdecor:" .. name, def)
|
||||
minetest.register_node(":xdecor:" .. name, def)
|
||||
|
||||
local workbench = minetest.settings:get_bool("enable_xdecor_workbench")
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
--local t = os.clock()
|
||||
|
||||
xdecor = {}
|
||||
local modpath = minetest.get_modpath("xdecor")
|
||||
local modpath = minetest.get_modpath("ip_xdecor")
|
||||
|
||||
dofile(modpath .. "/handlers/animations.lua")
|
||||
dofile(modpath .. "/handlers/helpers.lua")
|
||||
@@ -12,8 +12,6 @@ dofile(modpath .. "/src/nodes.lua")
|
||||
|
||||
|
||||
local subpart = {
|
||||
"cooking",
|
||||
"itemframe",
|
||||
"mailbox",
|
||||
"mechanisms",
|
||||
"rope",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
name = xdecor
|
||||
name = ip_xdecor
|
||||
description = A decoration mod meant to be simple and well-featured.
|
||||
depends = doors, stairs, xpanes
|
||||
optional_depends = fire, oresplus, moreblocks, mesecons
|
||||
|
||||
@@ -1,267 +0,0 @@
|
||||
local cauldron, sounds = {}, {}
|
||||
local S = minetest.get_translator("xdecor")
|
||||
|
||||
-- Add more ingredients here that make a soup.
|
||||
local ingredients_list = {
|
||||
"apple", "mushroom", "honey", "pumpkin", "egg", "bread", "meat",
|
||||
"chicken", "carrot", "potato", "melon", "rhubarb", "cucumber",
|
||||
"corn", "beans", "berries", "grapes", "tomato", "wheat"
|
||||
}
|
||||
|
||||
cauldron.cbox = {
|
||||
{0, 0, 0, 16, 16, 0},
|
||||
{0, 0, 16, 16, 16, 0},
|
||||
{0, 0, 0, 0, 16, 16},
|
||||
{16, 0, 0, 0, 16, 16},
|
||||
{0, 0, 0, 16, 8, 16}
|
||||
}
|
||||
|
||||
function cauldron.stop_sound(pos)
|
||||
local spos = minetest.hash_node_position(pos)
|
||||
if sounds[spos] then
|
||||
minetest.sound_stop(sounds[spos])
|
||||
end
|
||||
end
|
||||
|
||||
function cauldron.idle_construct(pos)
|
||||
local timer = minetest.get_node_timer(pos)
|
||||
timer:start(10.0)
|
||||
cauldron.stop_sound(pos)
|
||||
end
|
||||
|
||||
function cauldron.boiling_construct(pos)
|
||||
local spos = minetest.hash_node_position(pos)
|
||||
sounds[spos] = minetest.sound_play("xdecor_boiling_water", {
|
||||
pos = pos,
|
||||
max_hear_distance = 5,
|
||||
gain = 0.8,
|
||||
loop = true
|
||||
})
|
||||
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("infotext", S("Cauldron (active) - Drop foods inside to make a soup"))
|
||||
|
||||
local timer = minetest.get_node_timer(pos)
|
||||
timer:start(5.0)
|
||||
end
|
||||
|
||||
function cauldron.filling(pos, node, clicker, itemstack)
|
||||
local inv = clicker:get_inventory()
|
||||
local wield_item = clicker:get_wielded_item():get_name()
|
||||
|
||||
if wield_item:sub(1,7) == "bucket:" then
|
||||
if wield_item:sub(-6) == "_empty" and not (node.name:sub(-6) == "_empty") then
|
||||
if itemstack:get_count() > 1 then
|
||||
if inv:room_for_item("main", "bucket:bucket_water 1") then
|
||||
itemstack:take_item()
|
||||
inv:add_item("main", "bucket:bucket_water 1")
|
||||
else
|
||||
minetest.chat_send_player(clicker:get_player_name(),
|
||||
S("No room in your inventory to add a bucket of water."))
|
||||
return itemstack
|
||||
end
|
||||
else
|
||||
itemstack:replace("bucket:bucket_water")
|
||||
end
|
||||
minetest.set_node(pos, {name = "xdecor:cauldron_empty", param2 = node.param2})
|
||||
|
||||
elseif wield_item:sub(-6) == "_water" and node.name:sub(-6) == "_empty" then
|
||||
minetest.set_node(pos, {name = "xdecor:cauldron_idle", param2 = node.param2})
|
||||
itemstack:replace("bucket:bucket_empty")
|
||||
end
|
||||
|
||||
return itemstack
|
||||
end
|
||||
end
|
||||
|
||||
function cauldron.idle_timer(pos)
|
||||
local below_node = {x = pos.x, y = pos.y - 1, z = pos.z}
|
||||
if not minetest.get_node(below_node).name:find("fire") then
|
||||
return true
|
||||
end
|
||||
|
||||
local node = minetest.get_node(pos)
|
||||
minetest.set_node(pos, {name = "xdecor:cauldron_boiling", param2 = node.param2})
|
||||
return true
|
||||
end
|
||||
|
||||
-- Ugly hack to determine if an item has the function `minetest.item_eat` in its definition.
|
||||
local function eatable(itemstring)
|
||||
local item = itemstring:match("[%w_:]+")
|
||||
local on_use_def = minetest.registered_items[item].on_use
|
||||
if not on_use_def then return end
|
||||
|
||||
return string.format("%q", string.dump(on_use_def)):find("item_eat")
|
||||
end
|
||||
|
||||
function cauldron.boiling_timer(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
local objs = minetest.get_objects_inside_radius(pos, 0.5)
|
||||
|
||||
if not next(objs) then
|
||||
return true
|
||||
end
|
||||
|
||||
local ingredients = {}
|
||||
for _, obj in pairs(objs) do
|
||||
if obj and not obj:is_player() and obj:get_luaentity().itemstring then
|
||||
local itemstring = obj:get_luaentity().itemstring
|
||||
local food = itemstring:match(":([%w_]+)")
|
||||
|
||||
for _, ingredient in ipairs(ingredients_list) do
|
||||
if food and (eatable(itemstring) or food:find(ingredient)) then
|
||||
ingredients[#ingredients + 1] = food
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if #ingredients >= 2 then
|
||||
for _, obj in pairs(objs) do
|
||||
obj:remove()
|
||||
end
|
||||
|
||||
minetest.set_node(pos, {name = "xdecor:cauldron_soup", param2 = node.param2})
|
||||
end
|
||||
|
||||
local node_under = {x = pos.x, y = pos.y - 1, z = pos.z}
|
||||
|
||||
if not minetest.get_node(node_under).name:find("fire") then
|
||||
minetest.set_node(pos, {name = "xdecor:cauldron_idle", param2 = node.param2})
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function cauldron.take_soup(pos, node, clicker, itemstack)
|
||||
local inv = clicker:get_inventory()
|
||||
local wield_item = clicker:get_wielded_item()
|
||||
local item_name = wield_item:get_name()
|
||||
|
||||
if item_name == "xdecor:bowl" or item_name == "farming:bowl" then
|
||||
if wield_item:get_count() > 1 then
|
||||
if inv:room_for_item("main", "xdecor:bowl_soup 1") then
|
||||
itemstack:take_item()
|
||||
inv:add_item("main", "xdecor:bowl_soup 1")
|
||||
else
|
||||
minetest.chat_send_player(clicker:get_player_name(),
|
||||
S("No room in your inventory to add a bowl of soup."))
|
||||
return itemstack
|
||||
end
|
||||
else
|
||||
itemstack:replace("xdecor:bowl_soup 1")
|
||||
end
|
||||
|
||||
minetest.set_node(pos, {name = "xdecor:cauldron_empty", param2 = node.param2})
|
||||
end
|
||||
|
||||
return itemstack
|
||||
end
|
||||
|
||||
xdecor.register("cauldron_empty", {
|
||||
description = S("Cauldron"),
|
||||
groups = {cracky=2, oddly_breakable_by_hand=1},
|
||||
on_rotate = screwdriver.rotate_simple,
|
||||
tiles = {"xdecor_cauldron_top_empty.png", "xdecor_cauldron_sides.png"},
|
||||
infotext = S("Cauldron (empty)"),
|
||||
collision_box = xdecor.pixelbox(16, cauldron.cbox),
|
||||
on_rightclick = cauldron.filling,
|
||||
on_construct = function(pos)
|
||||
cauldron.stop_sound(pos)
|
||||
end,
|
||||
})
|
||||
|
||||
xdecor.register("cauldron_idle", {
|
||||
description = S("Cauldron (idle)"),
|
||||
groups = {cracky=2, oddly_breakable_by_hand=1, not_in_creative_inventory=1},
|
||||
on_rotate = screwdriver.rotate_simple,
|
||||
tiles = {"xdecor_cauldron_top_idle.png", "xdecor_cauldron_sides.png"},
|
||||
drop = "xdecor:cauldron_empty",
|
||||
infotext = S("Cauldron (idle)"),
|
||||
collision_box = xdecor.pixelbox(16, cauldron.cbox),
|
||||
on_rightclick = cauldron.filling,
|
||||
on_construct = cauldron.idle_construct,
|
||||
on_timer = cauldron.idle_timer,
|
||||
})
|
||||
|
||||
xdecor.register("cauldron_boiling", {
|
||||
description = S("Cauldron (active)"),
|
||||
groups = {cracky=2, oddly_breakable_by_hand=1, not_in_creative_inventory=1},
|
||||
on_rotate = screwdriver.rotate_simple,
|
||||
drop = "xdecor:cauldron_empty",
|
||||
infotext = S("Cauldron (active) - Drop foods inside to make a soup"),
|
||||
damage_per_second = 2,
|
||||
tiles = {
|
||||
{
|
||||
name = "xdecor_cauldron_top_anim_boiling_water.png",
|
||||
animation = {type = "vertical_frames", length = 3.0}
|
||||
},
|
||||
"xdecor_cauldron_sides.png"
|
||||
},
|
||||
collision_box = xdecor.pixelbox(16, cauldron.cbox),
|
||||
on_rightclick = cauldron.filling,
|
||||
on_construct = cauldron.boiling_construct,
|
||||
on_timer = cauldron.boiling_timer,
|
||||
on_destruct = function(pos)
|
||||
cauldron.stop_sound(pos)
|
||||
end,
|
||||
})
|
||||
|
||||
xdecor.register("cauldron_soup", {
|
||||
description = S("Cauldron (active)"),
|
||||
groups = {cracky = 2, oddly_breakable_by_hand = 1, not_in_creative_inventory = 1},
|
||||
on_rotate = screwdriver.rotate_simple,
|
||||
drop = "xdecor:cauldron_empty",
|
||||
infotext = S("Cauldron (active) - Use a bowl to eat the soup"),
|
||||
damage_per_second = 2,
|
||||
tiles = {
|
||||
{
|
||||
name = "xdecor_cauldron_top_anim_soup.png",
|
||||
animation = {type = "vertical_frames", length = 3.0}
|
||||
},
|
||||
"xdecor_cauldron_sides.png"
|
||||
},
|
||||
collision_box = xdecor.pixelbox(16, cauldron.cbox),
|
||||
on_rightclick = cauldron.take_soup,
|
||||
on_destruct = function(pos)
|
||||
cauldron.stop_sound(pos)
|
||||
end,
|
||||
})
|
||||
|
||||
-- Craft items
|
||||
|
||||
minetest.register_craftitem("xdecor:bowl", {
|
||||
description = S("Bowl"),
|
||||
inventory_image = "xdecor_bowl.png",
|
||||
wield_image = "xdecor_bowl.png",
|
||||
groups = {food_bowl = 1, flammable = 2},
|
||||
})
|
||||
|
||||
minetest.register_craftitem("xdecor:bowl_soup", {
|
||||
description = S("Bowl of soup"),
|
||||
inventory_image = "xdecor_bowl_soup.png",
|
||||
wield_image = "xdecor_bowl_soup.png",
|
||||
groups = {not_in_creative_inventory=1},
|
||||
stack_max = 1,
|
||||
on_use = minetest.item_eat(30, "xdecor:bowl")
|
||||
})
|
||||
|
||||
-- Recipes
|
||||
|
||||
minetest.register_craft({
|
||||
output = "xdecor:bowl 3",
|
||||
recipe = {
|
||||
{"group:wood", "", "group:wood"},
|
||||
{"", "group:wood", ""}
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "xdecor:cauldron_empty",
|
||||
recipe = {
|
||||
{"default:iron_lump", "", "default:iron_lump"},
|
||||
{"default:iron_lump", "", "default:iron_lump"},
|
||||
{"default:iron_lump", "default:iron_lump", "default:iron_lump"}
|
||||
}
|
||||
})
|
||||
@@ -1,336 +0,0 @@
|
||||
screwdriver = screwdriver or {}
|
||||
local S = minetest.get_translator("xdecor")
|
||||
local FS = function(...) return minetest.formspec_escape(S(...)) end
|
||||
local ceil, abs, random = math.ceil, math.abs, math.random
|
||||
local reg_tools = minetest.registered_tools
|
||||
|
||||
-- Cost in Mese crystal(s) for enchanting.
|
||||
local mese_cost = 1
|
||||
|
||||
-- Force of the enchantments.
|
||||
local enchanting = {
|
||||
uses = 1.2, -- Durability
|
||||
times = 0.1, -- Efficiency
|
||||
damages = 1, -- Sharpness
|
||||
}
|
||||
|
||||
local function cap(str) return
|
||||
str:gsub("^%l", string.upper)
|
||||
end
|
||||
|
||||
local function to_percent(orig_value, final_value)
|
||||
return abs(ceil(((final_value - orig_value) / orig_value) * 100))
|
||||
end
|
||||
|
||||
function enchanting:get_tooltip(enchant, orig_caps, fleshy)
|
||||
local bonus = {durable = 0, efficiency = 0, damages = 0}
|
||||
|
||||
if orig_caps then
|
||||
bonus.durable = to_percent(orig_caps.uses, orig_caps.uses * enchanting.uses)
|
||||
local sum_caps_times = 0
|
||||
for i=1, #orig_caps.times do
|
||||
sum_caps_times = sum_caps_times + orig_caps.times[i]
|
||||
end
|
||||
local average_caps_time = sum_caps_times / #orig_caps.times
|
||||
bonus.efficiency = to_percent(average_caps_time, average_caps_time -
|
||||
enchanting.times)
|
||||
end
|
||||
|
||||
if fleshy then
|
||||
bonus.damages = to_percent(fleshy, fleshy + enchanting.damages)
|
||||
end
|
||||
|
||||
local specs = { -- not finished, to complete
|
||||
durable = {"#00baff", " (+" .. bonus.durable .. "%)"},
|
||||
fast = {"#74ff49", " (+" .. bonus.efficiency .. "%)"},
|
||||
sharp = {"#ffff00", " (+" .. bonus.damages .. "%)"},
|
||||
}
|
||||
|
||||
local enchant_loc = {
|
||||
fast = S("Efficiency"),
|
||||
durable = S("Durability"),
|
||||
sharp = S("Sharpness"),
|
||||
}
|
||||
|
||||
return minetest.colorize and minetest.colorize(specs[enchant][1],
|
||||
"\n" .. enchant_loc[enchant] .. specs[enchant][2]) or
|
||||
"\n" .. enchant_loc[enchant] .. specs[enchant][2]
|
||||
end
|
||||
|
||||
local enchant_buttons = {
|
||||
"image_button[3.9,0.85;4,0.92;bg_btn.png;fast;"..FS("Efficiency").."]" ..
|
||||
"image_button[3.9,1.77;4,1.12;bg_btn.png;durable;"..FS("Durability").."]",
|
||||
"image_button[3.9,2.9;4,0.92;bg_btn.png;sharp;"..FS("Sharpness").."]",
|
||||
}
|
||||
|
||||
function enchanting.formspec(pos, num)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local formspec = [[
|
||||
size[9,8.6;]
|
||||
no_prepend[]
|
||||
bgcolor[#080808BB;true]
|
||||
listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]
|
||||
background9[0,0;9,9;ench_ui.png;6]
|
||||
list[context;tool;0.9,2.9;1,1;]
|
||||
list[context;mese;2,2.9;1,1;]
|
||||
list[current_player;main;0.55,4.5;8,4;]
|
||||
listring[current_player;main]
|
||||
listring[context;tool]
|
||||
listring[current_player;main]
|
||||
listring[context;mese]
|
||||
image[2,2.9;1,1;mese_layout.png]
|
||||
]]
|
||||
.."tooltip[sharp;"..FS("Your weapon inflicts more damages").."]"
|
||||
.."tooltip[durable;"..FS("Your tool last longer").."]"
|
||||
.."tooltip[fast;"..FS("Your tool digs faster").."]"
|
||||
..default.gui_slots .. default.get_hotbar_bg(0.55, 4.5)
|
||||
|
||||
formspec = formspec .. (enchant_buttons[num] or "")
|
||||
meta:set_string("formspec", formspec)
|
||||
end
|
||||
|
||||
function enchanting.on_put(pos, listname, _, stack)
|
||||
if listname == "tool" then
|
||||
local stackname = stack:get_name()
|
||||
local tool_groups = {
|
||||
"axe, pick, shovel",
|
||||
"sword",
|
||||
}
|
||||
|
||||
for idx, tools in ipairs(tool_groups) do
|
||||
if tools:find(stackname:match(":(%w+)")) then
|
||||
enchanting.formspec(pos, idx)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function enchanting.fields(pos, _, fields, sender)
|
||||
if not next(fields) or fields.quit then return end
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
local tool = inv:get_stack("tool", 1)
|
||||
local mese = inv:get_stack("mese", 1)
|
||||
local orig_wear = tool:get_wear()
|
||||
local mod, name = tool:get_name():match("(.*):(.*)")
|
||||
local enchanted_tool = (mod or "") .. ":enchanted_" .. (name or "") .. "_" .. next(fields)
|
||||
|
||||
if mese:get_count() >= mese_cost and reg_tools[enchanted_tool] then
|
||||
minetest.sound_play("xdecor_enchanting", {
|
||||
to_player = sender:get_player_name(),
|
||||
gain = 0.8
|
||||
})
|
||||
|
||||
tool:replace(enchanted_tool)
|
||||
tool:add_wear(orig_wear)
|
||||
mese:take_item(mese_cost)
|
||||
inv:set_stack("mese", 1, mese)
|
||||
inv:set_stack("tool", 1, tool)
|
||||
end
|
||||
end
|
||||
|
||||
function enchanting.dig(pos)
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
return inv:is_empty("tool") and inv:is_empty("mese")
|
||||
end
|
||||
|
||||
local function allowed(tool)
|
||||
if not tool then return end
|
||||
|
||||
for item in pairs(reg_tools) do
|
||||
if item:find("enchanted_" .. tool) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function enchanting.put(_, listname, _, stack)
|
||||
local stackname = stack:get_name()
|
||||
if listname == "mese" and (stackname == "default:mese_crystal" or
|
||||
stackname == "imese:industrial_mese_crystal") then
|
||||
return stack:get_count()
|
||||
elseif listname == "tool" and allowed(stackname:match("[^:]+$")) then
|
||||
return 1
|
||||
end
|
||||
|
||||
return 0
|
||||
end
|
||||
|
||||
function enchanting.on_take(pos, listname)
|
||||
if listname == "tool" then
|
||||
enchanting.formspec(pos)
|
||||
end
|
||||
end
|
||||
|
||||
function enchanting.construct(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
meta:set_string("infotext", S("Enchantment Table"))
|
||||
enchanting.formspec(pos)
|
||||
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("tool", 1)
|
||||
inv:set_size("mese", 1)
|
||||
|
||||
minetest.add_entity({x = pos.x, y = pos.y + 0.85, z = pos.z}, "xdecor:book_open")
|
||||
local timer = minetest.get_node_timer(pos)
|
||||
timer:start(0.5)
|
||||
end
|
||||
|
||||
function enchanting.destruct(pos)
|
||||
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.9)) do
|
||||
if obj and obj:get_luaentity() and
|
||||
obj:get_luaentity().name == "xdecor:book_open" then
|
||||
obj:remove()
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function enchanting.timer(pos)
|
||||
local minp = {x = pos.x - 2, y = pos.y, z = pos.z - 2}
|
||||
local maxp = {x = pos.x + 2, y = pos.y + 1, z = pos.z + 2}
|
||||
|
||||
local bookshelves = minetest.find_nodes_in_area(minp, maxp, "default:bookshelf")
|
||||
if #bookshelves == 0 then
|
||||
return true
|
||||
end
|
||||
|
||||
local bookshelf_pos = bookshelves[random(1, #bookshelves)]
|
||||
local x = pos.x - bookshelf_pos.x
|
||||
local y = bookshelf_pos.y - pos.y
|
||||
local z = pos.z - bookshelf_pos.z
|
||||
|
||||
if tostring(x .. z):find(2) then
|
||||
minetest.add_particle({
|
||||
pos = bookshelf_pos,
|
||||
velocity = {x = x, y = 2 - y, z = z},
|
||||
acceleration = {x = 0, y = -2.2, z = 0},
|
||||
expirationtime = 1,
|
||||
size = 1.5,
|
||||
glow = 5,
|
||||
texture = "xdecor_glyph" .. random(1,18) .. ".png"
|
||||
})
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
xdecor.register("enchantment_table", {
|
||||
description = S("Enchantment Table"),
|
||||
tiles = {
|
||||
"xdecor_enchantment_top.png", "xdecor_enchantment_bottom.png",
|
||||
"xdecor_enchantment_side.png", "xdecor_enchantment_side.png",
|
||||
"xdecor_enchantment_side.png", "xdecor_enchantment_side.png"
|
||||
},
|
||||
groups = {cracky = 1, level = 1},
|
||||
light_source = 6,
|
||||
sounds = default.node_sound_stone_defaults(),
|
||||
on_rotate = screwdriver.rotate_simple,
|
||||
can_dig = enchanting.dig,
|
||||
on_timer = enchanting.timer,
|
||||
on_construct = enchanting.construct,
|
||||
on_destruct = enchanting.destruct,
|
||||
on_receive_fields = enchanting.fields,
|
||||
on_metadata_inventory_put = enchanting.on_put,
|
||||
on_metadata_inventory_take = enchanting.on_take,
|
||||
allow_metadata_inventory_put = enchanting.put,
|
||||
allow_metadata_inventory_move = function()
|
||||
return 0
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_entity("xdecor:book_open", {
|
||||
visual = "sprite",
|
||||
visual_size = {x=0.75, y=0.75},
|
||||
collisionbox = {0},
|
||||
physical = false,
|
||||
textures = {"xdecor_book_open.png"},
|
||||
static_save = false,
|
||||
})
|
||||
|
||||
minetest.register_lbm({
|
||||
label = "recreate book entity",
|
||||
name = "xdecor:create_book_entity",
|
||||
nodenames = {"xdecor:enchantment_table"},
|
||||
run_at_every_load = true,
|
||||
action = function(pos, node)
|
||||
local objs = minetest.get_objects_inside_radius(pos, 0.9)
|
||||
|
||||
for _, obj in ipairs(objs) do
|
||||
local e = obj:get_luaentity()
|
||||
if e and e.name == "xdecor:book_open" then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
minetest.add_entity({x = pos.x, y = pos.y + 0.85, z = pos.z}, "xdecor:book_open")
|
||||
end,
|
||||
})
|
||||
|
||||
function enchanting:register_tools(mod, def)
|
||||
for tool in pairs(def.tools) do
|
||||
for material in def.materials:gmatch("[%w_]+") do
|
||||
for enchant in def.tools[tool].enchants:gmatch("[%w_]+") do
|
||||
local original_tool = reg_tools[mod .. ":" .. tool .. "_" .. material]
|
||||
if not original_tool then break end
|
||||
local original_toolcaps = original_tool.tool_capabilities
|
||||
|
||||
if original_toolcaps then
|
||||
local original_damage_groups = original_toolcaps.damage_groups
|
||||
local original_groupcaps = original_toolcaps.groupcaps
|
||||
local groupcaps = table.copy(original_groupcaps)
|
||||
local fleshy = original_damage_groups.fleshy
|
||||
local full_punch_interval = original_toolcaps.full_punch_interval
|
||||
local max_drop_level = original_toolcaps.max_drop_level
|
||||
local group = next(original_groupcaps)
|
||||
|
||||
if enchant == "durable" then
|
||||
groupcaps[group].uses = ceil(original_groupcaps[group].uses *
|
||||
enchanting.uses)
|
||||
elseif enchant == "fast" then
|
||||
for i, time in pairs(original_groupcaps[group].times) do
|
||||
groupcaps[group].times[i] = time - enchanting.times
|
||||
end
|
||||
elseif enchant == "sharp" then
|
||||
fleshy = fleshy + enchanting.damages
|
||||
end
|
||||
|
||||
minetest.register_tool(":" .. mod .. ":enchanted_" .. tool .. "_" .. material .. "_" .. enchant, {
|
||||
description = S("Enchanted @1 @2 @3",
|
||||
def.material_desc[material] or cap(material), def.tools[tool].desc or cap(tool),
|
||||
self:get_tooltip(enchant, original_groupcaps[group], fleshy)),
|
||||
inventory_image = original_tool.inventory_image .. "^[colorize:violet:50",
|
||||
wield_image = original_tool.wield_image,
|
||||
groups = {not_in_creative_inventory = 1},
|
||||
tool_capabilities = {
|
||||
groupcaps = groupcaps, damage_groups = {fleshy = fleshy},
|
||||
full_punch_interval = full_punch_interval,
|
||||
max_drop_level = max_drop_level
|
||||
}
|
||||
})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
enchanting:register_tools("default", {
|
||||
materials = "steel, bronze, mese, diamond",
|
||||
material_desc = {steel = S("Steel"), bronze = S("Bronze"), mese = S("Mese"), diamond = S("Diamond")},
|
||||
tools = {
|
||||
axe = {enchants = "durable, fast", desc = S("Axe")},
|
||||
pick = {enchants = "durable, fast", desc = S("Pickaxe")},
|
||||
shovel = {enchants = "durable, fast", desc = S("Shovel")},
|
||||
sword = {enchants = "sharp", desc = S("Sword")}
|
||||
},
|
||||
})
|
||||
|
||||
-- Recipes
|
||||
|
||||
minetest.register_craft({
|
||||
output = "xdecor:enchantment_table",
|
||||
recipe = {
|
||||
{"", "default:book", ""},
|
||||
{"default:diamond", "default:obsidian", "default:diamond"},
|
||||
{"default:obsidian", "default:obsidian", "default:obsidian"}
|
||||
}
|
||||
})
|
||||
@@ -1,108 +0,0 @@
|
||||
local hive = {}
|
||||
local S = minetest.get_translator("xdecor")
|
||||
local FS = function(...) return minetest.formspec_escape(S(...)) end
|
||||
local honey_max = 16
|
||||
|
||||
function hive.construct(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
|
||||
local formspec = "size[8,6;]"
|
||||
.."label[0.5,0;"..FS("Bees are busy making honey…").."]"
|
||||
..[[ image[6,1;1,1;hive_bee.png]
|
||||
image[5,1;1,1;hive_layout.png]
|
||||
list[context;honey;5,1;1,1;]
|
||||
list[current_player;main;0,2.35;8,4;]
|
||||
listring[current_player;main]
|
||||
listring[context;honey] ]] ..
|
||||
xbg .. default.get_hotbar_bg(0,2.35)
|
||||
|
||||
meta:set_string("formspec", formspec)
|
||||
meta:set_string("infotext", S("Artificial Hive"))
|
||||
inv:set_size("honey", 1)
|
||||
|
||||
local timer = minetest.get_node_timer(pos)
|
||||
timer:start(math.random(64, 128))
|
||||
end
|
||||
|
||||
function hive.timer(pos)
|
||||
local time = (minetest.get_timeofday() or 0) * 24000
|
||||
if time < 5500 or time > 18500 then
|
||||
return true
|
||||
end
|
||||
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
local honeystack = inv:get_stack("honey", 1)
|
||||
local honey = honeystack:get_count()
|
||||
|
||||
local radius = 4
|
||||
local minp = vector.add(pos, -radius)
|
||||
local maxp = vector.add(pos, radius)
|
||||
local flowers = minetest.find_nodes_in_area_under_air(minp, maxp, "group:flower")
|
||||
|
||||
if #flowers > 2 and honey < honey_max then
|
||||
inv:add_item("honey", "xdecor:honey")
|
||||
elseif honey == honey_max then
|
||||
local timer = minetest.get_node_timer(pos)
|
||||
timer:stop()
|
||||
return true
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
xdecor.register("hive", {
|
||||
description = S("Artificial Hive"),
|
||||
tiles = {"xdecor_hive_top.png", "xdecor_hive_top.png",
|
||||
"xdecor_hive_side.png", "xdecor_hive_side.png",
|
||||
"xdecor_hive_side.png", "xdecor_hive_front.png"},
|
||||
groups = {choppy=3, oddly_breakable_by_hand=2, flammable=1},
|
||||
on_construct = hive.construct,
|
||||
on_timer = hive.timer,
|
||||
|
||||
can_dig = function(pos)
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
return inv:is_empty("honey")
|
||||
end,
|
||||
|
||||
on_punch = function(_, _, puncher)
|
||||
puncher:set_hp(puncher:get_hp() - 2)
|
||||
end,
|
||||
|
||||
allow_metadata_inventory_put = function()
|
||||
return 0
|
||||
end,
|
||||
|
||||
on_metadata_inventory_take = function(pos, _, _, stack)
|
||||
if stack:get_count() == honey_max then
|
||||
local timer = minetest.get_node_timer(pos)
|
||||
timer:start(math.random(64, 128))
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
-- Craft items
|
||||
|
||||
minetest.register_craftitem("xdecor:honey", {
|
||||
description = S("Honey"),
|
||||
inventory_image = "xdecor_honey.png",
|
||||
wield_image = "xdecor_honey.png",
|
||||
on_use = minetest.item_eat(2),
|
||||
groups = {
|
||||
food_honey = 1,
|
||||
food_sugar = 1,
|
||||
flammable = 2,
|
||||
not_in_creative_inventory = 1,
|
||||
},
|
||||
})
|
||||
|
||||
-- Recipes
|
||||
|
||||
minetest.register_craft({
|
||||
output = "xdecor:hive",
|
||||
recipe = {
|
||||
{"group:stick", "group:stick", "group:stick"},
|
||||
{"default:paper", "default:paper", "default:paper"},
|
||||
{"group:stick", "group:stick", "group:stick"}
|
||||
}
|
||||
})
|
||||
@@ -1,186 +0,0 @@
|
||||
local itemframe, tmp = {}, {}
|
||||
local S = minetest.get_translator("xdecor")
|
||||
screwdriver = screwdriver or {}
|
||||
|
||||
local function remove_item(pos, node)
|
||||
local objs = minetest.get_objects_inside_radius(pos, 0.5)
|
||||
if not objs then return end
|
||||
|
||||
for _, obj in pairs(objs) do
|
||||
local ent = obj:get_luaentity()
|
||||
if obj and ent and ent.name == "xdecor:f_item" then
|
||||
obj:remove() break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local facedir = {
|
||||
[0] = {x = 0, y = 0, z = 1},
|
||||
{x = 1, y = 0, z = 0},
|
||||
{x = 0, y = 0, z = -1},
|
||||
{x = -1, y = 0, z = 0}
|
||||
}
|
||||
|
||||
local function update_item(pos, node)
|
||||
remove_item(pos, node)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local itemstring = meta:get_string("item")
|
||||
local posad = facedir[node.param2]
|
||||
if not posad or itemstring == "" then return end
|
||||
|
||||
pos = vector.add(pos, vector.multiply(posad, 6.5/16))
|
||||
tmp.nodename = node.name
|
||||
tmp.texture = ItemStack(itemstring):get_name()
|
||||
|
||||
local entity = minetest.add_entity(pos, "xdecor:f_item")
|
||||
local yaw = (math.pi * 2) - node.param2 * (math.pi / 2)
|
||||
entity:set_yaw(yaw)
|
||||
|
||||
local timer = minetest.get_node_timer(pos)
|
||||
timer:start(15.0)
|
||||
end
|
||||
|
||||
local function drop_item(pos, node)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local item = meta:get_string("item")
|
||||
if item == "" then return end
|
||||
|
||||
minetest.add_item(pos, item)
|
||||
meta:set_string("item", "")
|
||||
remove_item(pos, node)
|
||||
|
||||
local timer = minetest.get_node_timer(pos)
|
||||
timer:stop()
|
||||
end
|
||||
|
||||
function itemframe.after_place(pos, placer, itemstack)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local name = placer:get_player_name()
|
||||
meta:set_string("owner", name)
|
||||
meta:set_string("infotext", S("@1 (owned by @2)", S("Item Frame"), name))
|
||||
end
|
||||
|
||||
function itemframe.timer(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local num = #minetest.get_objects_inside_radius(pos, 0.5)
|
||||
|
||||
if num == 0 and meta:get_string("item") ~= "" then
|
||||
update_item(pos, node)
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
function itemframe.rightclick(pos, node, clicker, itemstack)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local player_name = clicker:get_player_name()
|
||||
local owner = meta:get_string("owner")
|
||||
local admin = minetest.check_player_privs(player_name, "protection_bypass")
|
||||
|
||||
if not admin and (player_name ~= owner or not itemstack) then
|
||||
return itemstack
|
||||
end
|
||||
|
||||
drop_item(pos, node)
|
||||
local itemstring = itemstack:take_item():to_string()
|
||||
meta:set_string("item", itemstring)
|
||||
update_item(pos, node)
|
||||
if itemstring == "" then
|
||||
meta:set_string("infotext", S("@1 (owned by @2)", S("Item Frame"), owner))
|
||||
else
|
||||
meta:set_string("infotext", S("@1 (owned by @2)", itemstring, owner))
|
||||
end
|
||||
return itemstack
|
||||
end
|
||||
|
||||
function itemframe.punch(pos, node, puncher)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local player_name = puncher:get_player_name()
|
||||
local owner = meta:get_string("owner")
|
||||
local admin = minetest.check_player_privs(player_name, "protection_bypass")
|
||||
|
||||
if admin and player_name == owner then
|
||||
drop_item(pos, node)
|
||||
end
|
||||
end
|
||||
|
||||
function itemframe.dig(pos, player)
|
||||
if not player then return end
|
||||
local meta = minetest.get_meta(pos)
|
||||
local player_name = player and player:get_player_name()
|
||||
local owner = meta:get_string("owner")
|
||||
local admin = minetest.check_player_privs(player_name, "protection_bypass")
|
||||
|
||||
return admin or player_name == owner
|
||||
end
|
||||
|
||||
xdecor.register("itemframe", {
|
||||
description = S("Item Frame"),
|
||||
groups = {choppy = 3, oddly_breakable_by_hand = 2, flammable = 3},
|
||||
sounds = default.node_sound_wood_defaults(),
|
||||
on_rotate = screwdriver.disallow,
|
||||
sunlight_propagates = true,
|
||||
inventory_image = "xdecor_itemframe.png",
|
||||
node_box = xdecor.nodebox.slab_z(0.9375),
|
||||
tiles = {
|
||||
"xdecor_wood.png", "xdecor_wood.png", "xdecor_wood.png",
|
||||
"xdecor_wood.png", "xdecor_wood.png", "xdecor_itemframe.png"
|
||||
},
|
||||
after_place_node = itemframe.after_place,
|
||||
on_timer = itemframe.timer,
|
||||
on_rightclick = itemframe.rightclick,
|
||||
on_punch = itemframe.punch,
|
||||
can_dig = itemframe.dig,
|
||||
after_destruct = remove_item
|
||||
})
|
||||
|
||||
minetest.register_entity("xdecor:f_item", {
|
||||
visual = "wielditem",
|
||||
visual_size = {x = 0.33, y = 0.33},
|
||||
collisionbox = {0},
|
||||
physical = false,
|
||||
textures = {"air"},
|
||||
on_activate = function(self, staticdata)
|
||||
local pos = self.object:get_pos()
|
||||
if minetest.get_node(pos).name ~= "xdecor:itemframe" then
|
||||
self.object:remove()
|
||||
end
|
||||
|
||||
if tmp.nodename and tmp.texture then
|
||||
self.nodename = tmp.nodename
|
||||
tmp.nodename = nil
|
||||
self.texture = tmp.texture
|
||||
tmp.texture = nil
|
||||
elseif staticdata and staticdata ~= "" then
|
||||
local data = staticdata:split(";")
|
||||
if data and data[1] and data[2] then
|
||||
self.nodename = data[1]
|
||||
self.texture = data[2]
|
||||
end
|
||||
end
|
||||
if self.texture then
|
||||
self.object:set_properties({
|
||||
textures = {self.texture}
|
||||
})
|
||||
end
|
||||
end,
|
||||
get_staticdata = function(self)
|
||||
if self.nodename and self.texture then
|
||||
return self.nodename .. ";" .. self.texture
|
||||
end
|
||||
|
||||
return ""
|
||||
end
|
||||
})
|
||||
|
||||
-- Recipes
|
||||
|
||||
minetest.register_craft({
|
||||
output = "xdecor:itemframe",
|
||||
recipe = {
|
||||
{"group:stick", "group:stick", "group:stick"},
|
||||
{"group:stick", "default:paper", "group:stick"},
|
||||
{"group:stick", "group:stick", "group:stick"}
|
||||
}
|
||||
})
|
||||
@@ -705,7 +705,7 @@ xdecor.register("woodframed_glass", {
|
||||
sounds = default.node_sound_glass_defaults()
|
||||
})
|
||||
|
||||
minetest.register_node("xdecor:toilet", {
|
||||
minetest.register_node(":xdecor:toilet", {
|
||||
description = "Toilet",
|
||||
tiles = {
|
||||
"soviet_machine.png",
|
||||
|
||||
Reference in New Issue
Block a user