1
0
mirror of https://github.com/mt-mods/homedecor_modpack.git synced 2024-11-18 08:00:40 +01:00

use unified dyes auto-colorization feature

also fixed some bugs in bed handling
also got rid of the old, obsolete "placeholder" node, aliased it to air.
This commit is contained in:
Vanessa Ezekowitz 2017-03-18 05:51:46 -04:00
parent 27eae09d93
commit 1eb1e87f08
11 changed files with 100 additions and 41 deletions

View File

@ -16,6 +16,7 @@ minetest.register_node("homedecor:bathroom_tiles_dark", {
groups = {cracky=3, ud_param2_colorable = 1},
sounds = default.node_sound_stone_defaults(),
on_construct = unifieddyes.on_construct,
after_place_node = unifieddyes.recolor_on_place,
after_dig_node = unifieddyes.after_dig_node
})
@ -34,6 +35,7 @@ minetest.register_node("homedecor:bathroom_tiles_medium", {
groups = {cracky=3, ud_param2_colorable = 1},
sounds = default.node_sound_stone_defaults(),
on_construct = unifieddyes.on_construct,
after_place_node = unifieddyes.recolor_on_place,
after_dig_node = unifieddyes.after_dig_node
})
@ -52,6 +54,7 @@ minetest.register_node("homedecor:bathroom_tiles_light", {
groups = {cracky=3, ud_param2_colorable = 1},
sounds = default.node_sound_stone_defaults(),
on_construct = unifieddyes.on_construct,
after_place_node = unifieddyes.recolor_on_place,
after_dig_node = unifieddyes.after_dig_node
})

View File

@ -52,11 +52,13 @@ homedecor.register("bed_regular", {
on_rotate = screwdriver.disallow,
after_place_node = function(pos, placer, itemstack, pointed_thing)
unifieddyes.fix_rotation_nsew(pos, placer, itemstack, pointed_thing)
unifieddyes.recolor_on_place(pos, placer, itemstack, pointed_thing)
if not placer:get_player_control().sneak then
return homedecor.bed_expansion(pos, placer, itemstack, pointed_thing)
end
end,
after_dig_node = function(pos)
after_dig_node = function(pos, oldnode, oldmetadata, digger)
unifieddyes.after_dig_node(pos, oldnode, oldmetadata, digger)
homedecor.unextend_bed(pos)
end,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
@ -91,7 +93,9 @@ homedecor.register("bed_extended", {
sounds = default.node_sound_wood_defaults(),
expand = { forward = "air" },
on_rotate = screwdriver.disallow,
after_dig_node = function(pos)
after_place_node = unifieddyes.recolor_on_place,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
unifieddyes.after_dig_node(pos, oldnode, oldmetadata, digger)
homedecor.unextend_bed(pos)
end,
-- on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
@ -123,10 +127,14 @@ homedecor.register("bed_kingsize", {
node_box = kbed_cbox,
sounds = default.node_sound_wood_defaults(),
on_rotate = screwdriver.disallow,
after_place_node = unifieddyes.fix_rotation_nsew,
after_place_node = function(pos, placer, itemstack, pointed_thing)
unifieddyes.fix_rotation_nsew(pos, placer, itemstack, pointed_thing)
unifieddyes.recolor_on_place(pos, placer, itemstack, pointed_thing)
end,
after_dig_node = function(pos, oldnode, oldmetadata, digger)
unifieddyes.after_dig_node(pos, oldnode, oldmetadata, digger)
local inv = digger:get_inventory()
if digger:get_player_control().sneak and inv:room_for_item("main", "bed_regular 1") then
if digger:get_player_control().sneak and inv:room_for_item("main", "homedecor:bed_regular 2") then
inv:remove_item("main", "homedecor:bed_kingsize 1")
inv:add_item("main", "homedecor:bed_regular 2")
end

View File

@ -81,7 +81,10 @@ homedecor.register("kitchen_chair_padded", {
collision_box = kc_cbox,
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2, ud_param2_colorable = 1},
sounds = default.node_sound_wood_defaults(),
after_place_node = unifieddyes.fix_rotation_nsew,
after_place_node = function(pos, placer, itemstack, pointed_thing)
unifieddyes.fix_rotation_nsew(pos, placer, itemstack, pointed_thing)
unifieddyes.recolor_on_place(pos, placer, itemstack, pointed_thing)
end,
after_dig_node = unifieddyes.after_dig_node,
on_rotate = unifieddyes.fix_after_screwdriver_nsew,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
@ -105,7 +108,10 @@ homedecor.register("armchair", {
groups = {snappy=3, ud_param2_colorable = 1},
sounds = default.node_sound_wood_defaults(),
node_box = ac_cbox,
after_place_node = unifieddyes.fix_rotation_nsew,
after_place_node = function(pos, placer, itemstack, pointed_thing)
unifieddyes.fix_rotation_nsew(pos, placer, itemstack, pointed_thing)
unifieddyes.recolor_on_place(pos, placer, itemstack, pointed_thing)
end,
after_dig_node = unifieddyes.after_dig_node,
on_rotate = unifieddyes.fix_after_screwdriver_nsew,
})

View File

@ -53,18 +53,8 @@ homedecor.wall_fdir_to_fwd = {
{ -1, 0 },
}
local placeholder_node = "homedecor:expansion_placeholder"
minetest.register_node(placeholder_node, {
description = S("Expansion placeholder (you hacker you!)"),
groups = { not_in_creative_inventory=1 },
drawtype = "airlike",
paramtype = "light",
walkable = false,
selection_box = { type = "fixed", fixed = { 0, 0, 0, 0, 0, 0 } },
is_ground_content = false,
sunlight_propagates = true,
buildable_to = false,
})
local placeholder_node = "air"
minetest.register_alias("homedecor:expansion_placeholder", "air")
--- select which node was pointed at based on it being known, not ignored, buildable_to
-- returns nil if no node could be selected
@ -94,7 +84,7 @@ local function is_buildable_to(placer_name, ...)
end
-- place one or two nodes if and only if both can be placed
local function stack(itemstack, placer, fdir, pos, def, pos2, node1, node2)
local function stack(itemstack, placer, fdir, pos, def, pos2, node1, node2, pointed_thing)
local placer_name = placer:get_player_name() or ""
if is_buildable_to(placer_name, pos, pos2) then
local lfdir = fdir or minetest.dir_to_facedir(placer:get_look_dir())
@ -111,7 +101,7 @@ local function stack(itemstack, placer, fdir, pos, def, pos2, node1, node2)
-- call after_place_node of the placed node if available
local ctrl_node_def = minetest.registered_nodes[node1]
if ctrl_node_def and ctrl_node_def.after_place_node then
ctrl_node_def.after_place_node(pos, placer)
ctrl_node_def.after_place_node(pos, placer, itemstack, pointed_thing)
end
if not homedecor.expect_infinite_stacks then
@ -140,7 +130,7 @@ function homedecor.stack_vertically(itemstack, placer, pointed_thing, node1, nod
local top_pos = { x=pos.x, y=pos.y+1, z=pos.z }
return stack(itemstack, placer, nil, pos, def, top_pos, node1, node2)
return stack(itemstack, placer, nil, pos, def, top_pos, node1, node2, pointed_thing)
end
-- Stack one door node above another
@ -162,7 +152,7 @@ function homedecor.stack_wing(itemstack, placer, pointed_thing, node1, node2, no
end
local top_pos = { x=pos.x, y=pos.y+1, z=pos.z }
return stack(itemstack, placer, fdir, pos, def, top_pos, node1, node2)
return stack(itemstack, placer, fdir, pos, def, top_pos, node1, node2, pointed_thing)
end
function homedecor.stack_sideways(itemstack, placer, pointed_thing, node1, node2, dir)
@ -177,13 +167,14 @@ function homedecor.stack_sideways(itemstack, placer, pointed_thing, node1, node2
local pos2 = { x = pos.x + fdir_transform[fdir+1][1], y=pos.y, z = pos.z + fdir_transform[fdir+1][2] }
return stack(itemstack, placer, fdir, pos, def, pos2, node1, node2)
return stack(itemstack, placer, fdir, pos, def, pos2, node1, node2, pointed_thing)
end
function homedecor.bed_expansion(pos, placer, itemstack, pointed_thing, trybunks)
local thisnode = minetest.get_node(pos)
local fdir = thisnode.param2
local param2 = thisnode.param2
local fdir = param2 % 8
local fxd = homedecor.wall_fdir_to_fwd[fdir+1][1]
local fzd = homedecor.wall_fdir_to_fwd[fdir+1][2]
@ -219,14 +210,23 @@ function homedecor.bed_expansion(pos, placer, itemstack, pointed_thing, trybunks
local rightpos = {x=pos.x+rxd, y=pos.y, z=pos.z+rzd}
local rightnode = minetest.get_node(rightpos)
local inv = placer:get_inventory()
local lastdye = unifieddyes.last_used_dye[placer_name]
if leftnode.name == "homedecor:bed_regular" then
local newname = string.gsub(thisnode.name, "_regular", "_kingsize")
local meta = minetest.get_meta(leftpos)
minetest.set_node(pos, {name = "air"})
minetest.set_node(leftpos, { name = newname, param2 = fdir})
minetest.set_node(leftpos, { name = newname, param2 = param2})
meta:set_string("dye", lastdye)
inv:add_item("main", lastdye)
elseif rightnode.name == "homedecor:bed_regular" then
local newname = string.gsub(thisnode.name, "_regular", "_kingsize")
local meta = minetest.get_meta(rightpos)
minetest.set_node(rightpos, {name = "air"})
minetest.set_node(pos, { name = newname, param2 = fdir})
minetest.set_node(pos, { name = newname, param2 = param2})
meta:set_string("dye", lastdye)
inv:add_item("main", lastdye)
end
local toppos = {x=pos.x, y=pos.y+1.0, z=pos.z}
@ -234,18 +234,26 @@ function homedecor.bed_expansion(pos, placer, itemstack, pointed_thing, trybunks
if trybunks and is_buildable_to(placer_name, toppos, topposfwd) then
local newname = string.gsub(thisnode.name, "_regular", "_extended")
minetest.set_node(toppos, { name = thisnode.name, param2 = fdir})
minetest.set_node(pos, { name = newname, param2 = fdir})
local newparam2 = param2 % 8
if inv:contains_item("main", lastdye) then
minetest.set_node(toppos, { name = thisnode.name, param2 = param2})
inv:remove_item("main", lastdye.." 1")
else
minetest.set_node(toppos, { name = thisnode.name, param2 = newparam2})
minetest.chat_send_player(placer_name, "Ran out of "..lastdye..", using neutral color.")
unifieddyes.last_used_dye[placer_name] = nil
end
minetest.swap_node(pos, { name = newname, param2 = param2})
itemstack:take_item()
end
end
function homedecor.unextend_bed(pos)
local bottomnode = minetest.get_node({x=pos.x, y=pos.y-1.0, z=pos.z})
local fdir = bottomnode.param2
local param2 = bottomnode.param2
if bottomnode.name == "homedecor:bed_extended" then
local newname = string.gsub(bottomnode.name, "_extended", "_regular")
minetest.set_node({x=pos.x, y=pos.y-1.0, z=pos.z}, { name = newname, param2 = fdir})
minetest.swap_node({x=pos.x, y=pos.y-1.0, z=pos.z}, { name = newname, param2 = param2})
end
end

View File

@ -35,7 +35,10 @@ minetest.register_node("homedecor:glowlight_half", {
groups = { snappy = 3, ud_param2_colorable = 1 },
light_source = default.LIGHT_MAX,
sounds = default.node_sound_glass_defaults(),
after_place_node = unifieddyes.fix_rotation,
after_place_node = function(pos, placer, itemstack, pointed_thing)
unifieddyes.fix_rotation(pos, placer, itemstack, pointed_thing)
unifieddyes.recolor_on_place(pos, placer, itemstack, pointed_thing)
end,
after_dig_node = unifieddyes.after_dig_node
})
@ -63,7 +66,10 @@ minetest.register_node("homedecor:glowlight_quarter", {
groups = { snappy = 3, ud_param2_colorable = 1 },
light_source = default.LIGHT_MAX-1,
sounds = default.node_sound_glass_defaults(),
after_place_node = unifieddyes.fix_rotation,
after_place_node = function(pos, placer, itemstack, pointed_thing)
unifieddyes.fix_rotation(pos, placer, itemstack, pointed_thing)
unifieddyes.recolor_on_place(pos, placer, itemstack, pointed_thing)
end,
after_dig_node = unifieddyes.after_dig_node
})
@ -91,7 +97,10 @@ minetest.register_node("homedecor:glowlight_small_cube", {
groups = { snappy = 3, ud_param2_colorable = 1 },
light_source = default.LIGHT_MAX-1,
sounds = default.node_sound_glass_defaults(),
after_place_node = unifieddyes.fix_rotation,
after_place_node = function(pos, placer, itemstack, pointed_thing)
unifieddyes.fix_rotation(pos, placer, itemstack, pointed_thing)
unifieddyes.recolor_on_place(pos, placer, itemstack, pointed_thing)
end,
after_dig_node = unifieddyes.after_dig_node
})
@ -429,6 +438,7 @@ local function reg_lamp(suffix, nxt, light, brightness)
minetest.set_node(pos, node)
end,
on_construct = unifieddyes.on_construct,
after_place_node = unifieddyes.recolor_on_place,
after_dig_node = unifieddyes.after_dig_node
})
@ -459,8 +469,9 @@ local function reg_lamp(suffix, nxt, light, brightness)
minetest.set_node(pos, node)
end,
on_construct = unifieddyes.on_construct,
after_place_node = unifieddyes.recolor_on_place,
after_dig_node = unifieddyes.after_dig_node,
expand = { top="placeholder" },
expand = { top="air" },
})
-- for old maps that had the original 3dforniture mod
@ -497,7 +508,10 @@ homedecor.register("desk_lamp", {
node_box = dlamp_cbox,
walkable = false,
groups = {snappy=3, ud_param2_colorable = 1},
after_place_node = unifieddyes.fix_rotation_nsew,
after_place_node = function(pos, placer, itemstack, pointed_thing)
unifieddyes.fix_rotation_nsew(pos, placer, itemstack, pointed_thing)
unifieddyes.recolor_on_place(pos, placer, itemstack, pointed_thing)
end,
after_dig_node = unifieddyes.after_dig_node,
on_rotate = unifieddyes.fix_after_screwdriver_nsew
})

View File

@ -32,13 +32,17 @@ homedecor.register("shutter", {
description = S("Wooden Shutter"),
inventory_image = inv,
wield_image = inv,
paramtype2 = "wallmounted",
paramtype2 = "colorwallmounted",
palette = "unifieddyes_palette_colorwallmounted.png",
ud_replacement_node = "homedecor:shutter_colored",
groups = { snappy = 3, ud_param2_colorable = 1 },
sounds = default.node_sound_wood_defaults(),
selection_box = shutter_cbox,
node_box = shutter_cbox,
after_place_node = unifieddyes.fix_rotation,
after_place_node = function(pos, placer, itemstack, pointed_thing)
unifieddyes.fix_rotation(pos, placer, itemstack, pointed_thing)
unifieddyes.recolor_on_place(pos, placer, itemstack, pointed_thing)
end,
after_dig_node = unifieddyes.after_dig_node
})
@ -54,7 +58,10 @@ homedecor.register("shutter_colored", {
sounds = default.node_sound_wood_defaults(),
selection_box = shutter_cbox,
node_box = shutter_cbox,
after_place_node = unifieddyes.fix_rotation,
after_place_node = function(pos, placer, itemstack, pointed_thing)
unifieddyes.fix_rotation(pos, placer, itemstack, pointed_thing)
unifieddyes.recolor_on_place(pos, placer, itemstack, pointed_thing)
end,
after_dig_node = unifieddyes.after_dig_node,
drop = "homedecor:shutter"
})

View File

@ -113,7 +113,10 @@ minetest.register_node("homedecor:curtain_closed", {
palette = "unifieddyes_palette_colorwallmounted.png",
selection_box = { type = "wallmounted" },
after_dig_node = unifieddyes.after_dig_node,
after_place_node = unifieddyes.fix_rotation,
after_place_node = function(pos, placer, itemstack, pointed_thing)
unifieddyes.fix_rotation(pos, placer, itemstack, pointed_thing)
unifieddyes.recolor_on_place(pos, placer, itemstack, pointed_thing)
end,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
local topnode = minetest.get_node({x=pos.x, y=pos.y+1.0, z=pos.z})
if string.find(topnode.name, "homedecor:curtainrod") then
@ -139,7 +142,10 @@ minetest.register_node("homedecor:curtain_open", {
palette = "unifieddyes_palette_colorwallmounted.png",
selection_box = { type = "wallmounted" },
after_dig_node = unifieddyes.after_dig_node,
after_place_node = unifieddyes.fix_rotation,
after_place_node = function(pos, placer, itemstack, pointed_thing)
unifieddyes.fix_rotation(pos, placer, itemstack, pointed_thing)
unifieddyes.recolor_on_place(pos, placer, itemstack, pointed_thing)
end,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
local topnode = minetest.get_node({x=pos.x, y=pos.y+1.0, z=pos.z})
if string.find(topnode.name, "homedecor:curtainrod") then

View File

@ -34,6 +34,7 @@ minetest.register_node("lavalamp:lavalamp", {
groups = {snappy=2,cracky=3,oddly_breakable_by_hand=3, ud_param2_colorable = 1},
sounds = default.node_sound_glass_defaults(),
on_construct = unifieddyes.on_construct,
after_place_node = unifieddyes.recolor_on_place,
after_dig_node = unifieddyes.after_dig_node,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
node.name = "lavalamp:lavalamp_off"
@ -64,6 +65,7 @@ minetest.register_node("lavalamp:lavalamp_off", {
sounds = default.node_sound_glass_defaults(),
drop = "lavalamp:lavalamp",
on_construct = unifieddyes.on_construct,
after_place_node = unifieddyes.recolor_on_place,
after_dig_node = unifieddyes.after_dig_node,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
node.name = "lavalamp:lavalamp"

View File

@ -23,7 +23,10 @@ minetest.register_node("lrfurn:armchair", {
groups = {snappy=3, ud_param2_colorable = 1},
sounds = default.node_sound_wood_defaults(),
node_box = armchair_cbox,
after_place_node = unifieddyes.fix_rotation_nsew,
after_place_node = function(pos, placer, itemstack, pointed_thing)
unifieddyes.fix_rotation_nsew(pos, placer, itemstack, pointed_thing)
unifieddyes.recolor_on_place(pos, placer, itemstack, pointed_thing)
end,
after_dig_node = unifieddyes.after_dig_node,
on_rotate = unifieddyes.fix_after_screwdriver_nsew,
on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)

View File

@ -26,6 +26,7 @@ minetest.register_node("lrfurn:longsofa", {
on_rotate = screwdriver.disallow,
after_place_node = function(pos, placer, itemstack, pointed_thing)
lrfurn.fix_sofa_rotation_nsew(pos, placer, itemstack, pointed_thing)
unifieddyes.recolor_on_place(pos, placer, itemstack, pointed_thing)
local playername = placer:get_player_name()
if minetest.is_protected(pos, placer:get_player_name()) then return true end

View File

@ -26,6 +26,7 @@ minetest.register_node("lrfurn:sofa", {
on_rotate = screwdriver.disallow,
after_place_node = function(pos, placer, itemstack, pointed_thing)
lrfurn.fix_sofa_rotation_nsew(pos, placer, itemstack, pointed_thing)
unifieddyes.recolor_on_place(pos, placer, itemstack, pointed_thing)
local playername = placer:get_player_name()
if minetest.is_protected(pos, placer:get_player_name()) then return true end