Added support for painting the wallpapers and plaster, tools sounds API
This commit is contained in:
parent
2bc793c3df
commit
c75ca9eb94
@ -3,23 +3,6 @@ local S = minetest.get_translator(minetest.get_current_modname())
|
||||
|
||||
dofile(modpath .. "/ores.lua")
|
||||
|
||||
-- Maps a tool name to its sound playing on crafting
|
||||
local craft_tools = {
|
||||
["saw"] = "multidecor_saw",
|
||||
["steel_scissors"] = "multidecor_steel_scissors",
|
||||
["hammer"] = "multidecor_hammer"
|
||||
}
|
||||
|
||||
-- Durabilities of each craft sound in seconds
|
||||
local craft_sounds_durabilities = {
|
||||
["multidecor_saw"] = 3,
|
||||
["multidecor_steel_scissors"] = 2,
|
||||
["multidecor_hammer"] = 1
|
||||
}
|
||||
|
||||
-- Maps a playername to the current playing action sound
|
||||
multidecor.players_actions_sounds = {}
|
||||
|
||||
local woods = {"", "jungle", "aspen", "pine"}
|
||||
|
||||
if minetest.get_modpath("ethereal") then
|
||||
@ -650,51 +633,3 @@ minetest.register_craft({
|
||||
{"", "", ""}
|
||||
}
|
||||
})
|
||||
|
||||
minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv)
|
||||
local contains_tool_with_name = ""
|
||||
|
||||
local function check_for_item(itemname)
|
||||
for name, _ in pairs(craft_tools) do
|
||||
if "multidecor:" .. name == itemname then
|
||||
contains_tool_with_name = name
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for _, stack in ipairs(old_craft_grid) do
|
||||
check_for_item(stack:get_name())
|
||||
if contains_tool_with_name ~= "" then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
local playername = player:get_player_name()
|
||||
if contains_tool_with_name ~= "" and not multidecor.players_actions_sounds[playername] then
|
||||
multidecor.players_actions_sounds[playername] = {
|
||||
name = craft_tools[contains_tool_with_name],
|
||||
cur_time = 0.0,
|
||||
durability = craft_sounds_durabilities[craft_tools[contains_tool_with_name]]
|
||||
}
|
||||
|
||||
minetest.sound_play(craft_tools[contains_tool_with_name], {to_player=playername})
|
||||
end
|
||||
|
||||
return
|
||||
end)
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
local playername = player:get_player_name()
|
||||
local sound = multidecor.players_actions_sounds[playername]
|
||||
|
||||
if sound then
|
||||
sound.cur_time = sound.cur_time + dtime
|
||||
|
||||
if sound.cur_time >= sound.durability then
|
||||
multidecor.players_actions_sounds[playername] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
@ -34,3 +34,4 @@ dofile(modpath .. "/seat.lua")
|
||||
dofile(modpath .. "/shelves.lua")
|
||||
dofile(modpath .. "/table.lua")
|
||||
dofile(modpath .. "/tap.lua")
|
||||
dofile(modpath .. "/tools_sounds.lua")
|
||||
|
@ -131,15 +131,7 @@ function multidecor.register.on_punch(pos, node, puncher)
|
||||
wielded_item:set_wear(wielded_item:get_wear()+math.modf(65535/50))
|
||||
puncher:set_wielded_item(wielded_item)
|
||||
|
||||
if not multidecor.players_actions_sounds[playername] then
|
||||
multidecor.players_actions_sounds[playername] = {
|
||||
name = "multidecor_scraping",
|
||||
cur_time = 0.0,
|
||||
durability = 4.0
|
||||
}
|
||||
|
||||
minetest.sound_play("multidecor_scraping", {to_player=playername})
|
||||
end
|
||||
multidecor.tools_sounds.play(playername, 4)
|
||||
end
|
||||
|
||||
--[[def:
|
||||
|
75
decor_api/tools_sounds.lua
Normal file
75
decor_api/tools_sounds.lua
Normal file
@ -0,0 +1,75 @@
|
||||
multidecor.tools_sounds = {}
|
||||
|
||||
-- Predefined sounds for these tools
|
||||
multidecor.tools_sounds.sounds = {
|
||||
{name="saw", durability=3},
|
||||
{name="steel_scissors", durability=2},
|
||||
{name="hammer", durability=1},
|
||||
{name="scraping", durability=4}
|
||||
}
|
||||
|
||||
-- Maps a playername to the current playing tool sound
|
||||
multidecor.tools_sounds.current_sounds = {}
|
||||
|
||||
-- Plays some locationless sound having 'sound_index' in 'multidecor.tools_sounds.sounds' table
|
||||
-- for player 'playername'
|
||||
function multidecor.tools_sounds.play(playername, sound_index)
|
||||
if multidecor.tools_sounds.current_sounds[playername] then
|
||||
return
|
||||
end
|
||||
|
||||
if not multidecor.tools_sounds.sounds[sound_index] then
|
||||
return
|
||||
end
|
||||
|
||||
local sound = multidecor.tools_sounds.sounds[sound_index]
|
||||
multidecor.tools_sounds.current_sounds[playername] = {
|
||||
name = sound.name,
|
||||
cur_time = 0.0,
|
||||
durability = sound.durability
|
||||
}
|
||||
|
||||
minetest.sound_play("multidecor_" .. sound.name, {to_player=playername})
|
||||
end
|
||||
|
||||
minetest.register_on_craft(function(itemstack, player, old_craft_grid, craft_inv)
|
||||
local sound_index
|
||||
|
||||
local function check_for_item(itemname)
|
||||
for i, sound in pairs(multidecor.tools_sounds.sounds) do
|
||||
if "multidecor:" .. sound.name == itemname then
|
||||
sound_index = i
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for _, stack in ipairs(old_craft_grid) do
|
||||
check_for_item(stack:get_name())
|
||||
if sound_index ~= nil then
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if sound_index ~= nil then
|
||||
multidecor.tools_sounds.play(player:get_player_name(), sound_index)
|
||||
end
|
||||
|
||||
return
|
||||
end)
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
local playername = player:get_player_name()
|
||||
local cur_sound = multidecor.tools_sounds.current_sounds[playername]
|
||||
|
||||
if cur_sound then
|
||||
cur_sound.cur_time = cur_sound.cur_time + dtime
|
||||
|
||||
if cur_sound.cur_time >= cur_sound.durability then
|
||||
multidecor.tools_sounds.current_sounds[playername] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
@ -1,19 +1,47 @@
|
||||
local wallpapers = {
|
||||
"white",
|
||||
"cyan_patterned",
|
||||
"yellow_patterned",
|
||||
"white_patterned",
|
||||
}
|
||||
|
||||
local wallpapers_crafts = {
|
||||
{"dye:white"},
|
||||
{"dye:cyan", "dye:blue"},
|
||||
{"dye:yellow", "dye:white"},
|
||||
{"dye:white", "dye:grey"}
|
||||
{name="white", colorable=true, recipe={"dye:white"}},
|
||||
{name="cyan_patterned", colorable=false, recipe={"dye:cyan", "dye:blue"}},
|
||||
{name="yellow_patterned", colorable=false, recipe={"dye:yellow", "dye:white"}},
|
||||
{name="white_patterned", colorable=true, recipe={"dye:white", "dye:grey"}}
|
||||
}
|
||||
|
||||
local cover_sbox = {-0.5, -0.5, -0.05, 0.5, 0.5, 0.05}
|
||||
|
||||
local function wallpaper_colorable(name)
|
||||
for _, wallpaper_sort in ipairs(wallpapers) do
|
||||
if wallpaper_sort.name .. "_wallpaper" == name and wallpaper_sort.colorable then
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
end
|
||||
|
||||
local function check_for_dye_in_inv(player)
|
||||
local inv = player:get_inventory()
|
||||
local dye_index = player:get_wield_index() + 1
|
||||
local dye = inv:get_stack("main", dye_index)
|
||||
local next_itemname = dye:get_name()
|
||||
|
||||
if not dye or dye:is_empty() or
|
||||
minetest.get_item_group(next_itemname, "dye") ~= 1 then -- no any dye next to the brush or the slot is empty
|
||||
return
|
||||
end
|
||||
|
||||
local index
|
||||
|
||||
-- Checks if the color of the given dye is supported for painting
|
||||
for colorindex, colorname in ipairs(multidecor.colors) do
|
||||
if minetest.get_item_group(next_itemname, "color_" .. colorname) == 1 then
|
||||
index = colorindex - 1
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
return index
|
||||
end
|
||||
|
||||
minetest.register_entity(":multidecor:cover", {
|
||||
visual = "upright_sprite",
|
||||
physical = false,
|
||||
@ -36,15 +64,55 @@ minetest.register_entity(":multidecor:cover", {
|
||||
|
||||
self.cover_name = data.cover_name
|
||||
self.box = data.box
|
||||
self.color = data.color
|
||||
|
||||
local texture = "multidecor_" .. self.cover_name .. ".png"
|
||||
|
||||
if self.color then
|
||||
texture = texture .. "^[multiply:" .. self.color
|
||||
end
|
||||
|
||||
self.object:set_properties({
|
||||
textures = {texture},
|
||||
selectionbox = self.box
|
||||
})
|
||||
self.object:set_armor_groups({immortal=1})
|
||||
end,
|
||||
on_rightclick = function(self, clicker)
|
||||
local paint_brush = clicker:get_wielded_item()
|
||||
|
||||
if paint_brush:get_name() ~= "multidecor:paint_brush" then
|
||||
return
|
||||
end
|
||||
|
||||
local color_index = check_for_dye_in_inv(clicker)
|
||||
|
||||
if not color_index then
|
||||
return
|
||||
end
|
||||
|
||||
if self.cover_name ~= "plaster" and not wallpaper_colorable(self.cover_name) then
|
||||
return
|
||||
end
|
||||
|
||||
if minetest.is_protected(pos, clicker:get_player_name()) then
|
||||
return
|
||||
end
|
||||
|
||||
local color = multidecor.colors[color_index+1]
|
||||
|
||||
self.color = color
|
||||
|
||||
self.object:set_properties({
|
||||
textures = {"multidecor_" .. self.cover_name .. ".png^[multiply:" .. self.color}
|
||||
})
|
||||
|
||||
local dye_index = clicker:get_wield_index() + 1
|
||||
local inv = clicker:get_inventory()
|
||||
local dye = inv:get_stack("main", dye_index)
|
||||
dye:take_item()
|
||||
inv:set_stack("main", dye_index, dye)
|
||||
end,
|
||||
on_punch = function(self, puncher)
|
||||
local wielded_item = puncher:get_wielded_item()
|
||||
|
||||
@ -61,19 +129,10 @@ minetest.register_entity(":multidecor:cover", {
|
||||
wielded_item:set_wear(wielded_item:get_wear()+math.modf(65535/50))
|
||||
puncher:set_wielded_item(wielded_item)
|
||||
|
||||
local playername = puncher:get_player_name()
|
||||
if not multidecor.players_actions_sounds[playername] then
|
||||
multidecor.players_actions_sounds[playername] = {
|
||||
name = "multidecor_scraping",
|
||||
cur_time = 0.0,
|
||||
durability = 4.0
|
||||
}
|
||||
|
||||
minetest.sound_play("multidecor_scraping", {to_player=playername})
|
||||
end
|
||||
multidecor.tools_sounds.play(puncher:get_player_name(), 4)
|
||||
end,
|
||||
get_staticdata = function(self)
|
||||
return minetest.serialize({cover_name=self.cover_name, box=self.box})
|
||||
return minetest.serialize({cover_name=self.cover_name, box=self.box, color=self.color})
|
||||
end
|
||||
})
|
||||
|
||||
@ -107,8 +166,8 @@ local function on_place_cover(pointed_thing, cover_stack, cover_name, placer)
|
||||
return cover_stack
|
||||
end
|
||||
|
||||
for i, wallpaper_sort in ipairs(wallpapers) do
|
||||
local itemname = wallpaper_sort .. "_wallpaper"
|
||||
for _, wallpaper_sort in ipairs(wallpapers) do
|
||||
local itemname = wallpaper_sort.name .. "_wallpaper"
|
||||
minetest.register_craftitem(":multidecor:" .. itemname, {
|
||||
description = modern.S(hlpfuncs.upper_first_letters(itemname)),
|
||||
inventory_image = "multidecor_" .. itemname .. ".png",
|
||||
@ -117,7 +176,7 @@ for i, wallpaper_sort in ipairs(wallpapers) do
|
||||
end
|
||||
})
|
||||
|
||||
local recipe = table.copy(wallpapers_crafts[i])
|
||||
local recipe = table.copy(wallpaper_sort.recipe)
|
||||
table.insert(recipe, "default:paper")
|
||||
table.insert(recipe, "multidecor:paint_brush")
|
||||
|
||||
@ -173,38 +232,24 @@ minetest.register_tool(":multidecor:paint_brush", {
|
||||
return
|
||||
end
|
||||
|
||||
local inv = placer:get_inventory()
|
||||
local dye_index = placer:get_wield_index()
|
||||
local next_itemstack = inv:get_stack("main", dye_index+1)
|
||||
local next_itemname = next_itemstack:get_name()
|
||||
local color_index = check_for_dye_in_inv(placer)
|
||||
|
||||
if not next_itemstack or next_itemstack:is_empty() or
|
||||
minetest.get_item_group(next_itemname, "dye") ~= 1 then -- no any dye next to the brush or the slot is empty
|
||||
if not color_index then
|
||||
return
|
||||
end
|
||||
|
||||
local index, dye_color
|
||||
|
||||
for colorindex, colorname in ipairs(multidecor.colors) do
|
||||
if minetest.get_item_group(next_itemname, "color_" .. colorname) == 1 then
|
||||
index = colorindex - 1
|
||||
dye_color = colorname
|
||||
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if not dye_color then return end -- not supported color
|
||||
|
||||
if minetest.is_protected(pos, placer:get_player_name()) then
|
||||
return
|
||||
end
|
||||
|
||||
local rot = node.param2 % mul
|
||||
minetest.swap_node(pos, {name=node.name, param2=index*mul+rot})
|
||||
minetest.swap_node(pos, {name=node.name, param2=color_index*mul+rot})
|
||||
|
||||
next_itemstack:take_item()
|
||||
inv:set_stack("main", dye_index+1, next_itemstack)
|
||||
local dye_index = placer:get_wield_index() + 1
|
||||
local inv = placer:get_inventory()
|
||||
local dye = inv:get_stack("main", dye_index)
|
||||
dye:take_item()
|
||||
inv:set_stack("main", dye_index, dye)
|
||||
end
|
||||
})
|
||||
|
||||
@ -223,16 +268,16 @@ minetest.register_tool(":multidecor:spatula", {
|
||||
inventory_image = "multidecor_spatula.png",
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
local inv = placer:get_inventory()
|
||||
local spatula_index = placer:get_wield_index()
|
||||
local next_itemstack = inv:get_stack("main", spatula_index+1)
|
||||
local plaster_index = placer:get_wield_index() + 1
|
||||
local plaster = inv:get_stack("main", plaster_index)
|
||||
|
||||
if not next_itemstack or next_itemstack:is_empty() or
|
||||
next_itemstack:get_name() ~= "multidecor:plaster_lump" then
|
||||
if not plaster or plaster:is_empty() or
|
||||
plaster:get_name() ~= "multidecor:plaster_lump" then
|
||||
return
|
||||
end
|
||||
|
||||
next_itemstack = on_place_cover(pointed_thing, next_itemstack, "plaster", placer)
|
||||
inv:set_stack("main", spatula_index+1, next_itemstack)
|
||||
plaster = on_place_cover(pointed_thing, plaster, "plaster", placer)
|
||||
inv:set_stack("main", plaster_index, plaster)
|
||||
end
|
||||
})
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user