From 60d34095a5108e7c5ba7139c565bbd0d391bf009 Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Thu, 4 Sep 2014 16:27:05 -0400 Subject: [PATCH] make cobwebs sit in corners when so-placed. Algorithm tries to find an X-/Z+ or X+/Z- corner first (places the cobweb using the torchlike "on-floor" mode) then an X-/Z- or X+/Z+ corner ("on-ceiling), then opposing X-/X+ walls (nodebox, not rotated), then opposing Z-/Z+ walls (nodebox, rotated 90 degrees), then falls back to plantlike (which also happens to fit places where e.g. three walls come together only 1m apart) ABM added to convert old ones. Node name has changed so if you have cobwebs in your inventory, sorry about that. --- homedecor/cobweb.lua | 118 ++++++++++++++++++ homedecor/init.lua | 2 + homedecor/misc-nodes.lua | 20 --- homedecor/textures/homedecor_cobweb.png | Bin 242 -> 236 bytes .../textures/homedecor_cobweb_plantlike.png | Bin 0 -> 242 bytes .../textures/homedecor_cobweb_torchlike.png | Bin 0 -> 243 bytes 6 files changed, 120 insertions(+), 20 deletions(-) create mode 100644 homedecor/cobweb.lua create mode 100644 homedecor/textures/homedecor_cobweb_plantlike.png create mode 100644 homedecor/textures/homedecor_cobweb_torchlike.png diff --git a/homedecor/cobweb.lua b/homedecor/cobweb.lua new file mode 100644 index 00000000..3608e6bb --- /dev/null +++ b/homedecor/cobweb.lua @@ -0,0 +1,118 @@ +minetest.register_node("homedecor:cobweb_corner", { + description = "Cobweb", + drawtype = "torchlike", + tiles = { "homedecor_cobweb_torchlike.png" }, + inventory_image = "homedecor_cobweb_inv.png", + wield_image = "homedecor_cobweb_inv.png", + paramtype = "light", + paramtype2 = "wallmounted", + sunlight_propagates = true, + walkable = false, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5} + }, + visual_scale = 1.4, + groups = { snappy = 3 }, + after_place_node = function(pos, placer, itemstack, pointed_thing) + homedecor.rotate_cobweb(pos) + end +}) + +minetest.register_node("homedecor:cobweb_centered", { + description = "Cobweb", + drawtype = "nodebox", + tiles = { "homedecor_cobweb.png" }, + inventory_image = "homedecor_cobweb_inv.png", + paramtype = "light", + paramtype2 = "facedir", + sunlight_propagates = true, + walkable = false, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5} + }, + node_box = { + type = "fixed", + fixed = { -0.5, -0.5, 0, 0.5, 0.5, 0 } + }, + groups = { snappy = 3, not_in_creative_inventory = 1 }, + drop = "homedecor:cobweb_corner" +}) + +minetest.register_node("homedecor:cobweb_plantlike", { + description = "Cobweb", + drawtype = "plantlike", + tiles = { "homedecor_cobweb_plantlike.png" }, + inventory_image = "homedecor_cobweb_inv.png", + paramtype = "light", + paramtype2 = "facedir", + sunlight_propagates = true, + walkable = false, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5} + }, + visual_scale = 1.189, + groups = { snappy = 3, not_in_creative_inventory = 1 }, + drop = "homedecor:cobweb_corner" +}) + +-- helper function to rotate the cobweb after it's placed + +function homedecor.rotate_cobweb(pos) + local wall_xm = minetest.get_node({ x=pos.x-1, y=pos.y, z=pos.z }).name + local wall_xp = minetest.get_node({ x=pos.x+1, y=pos.y, z=pos.z }).name + local wall_zm = minetest.get_node({ x=pos.x, y=pos.y, z=pos.z-1}).name + local wall_zp = minetest.get_node({ x=pos.x, y=pos.y, z=pos.z+1}).name + + local iswall_xm = (wall_xm ~= "air") + local iswall_xp = (wall_xp ~= "air") + local iswall_zm = (wall_zm ~= "air") + local iswall_zp = (wall_zp ~= "air") + + print("wall_xm: "..dump(wall_xm)) + print("wall_xp: "..dump(wall_xp)) + print("wall_zm: "..dump(wall_zm)) + print("wall_zp: "..dump(wall_zp)) + + -- only xm+zp, or only xp+zm means on-floor torchlike + + if (iswall_xm and iswall_zp and not iswall_xp and not iswall_zm) + or (iswall_xp and iswall_zm and not iswall_xm and not iswall_zp) then + minetest.set_node(pos, {name = "homedecor:cobweb_corner", param2 = 1}) + + -- only xm+zm, or only xp+zp means on-ceiling torchlike + + elseif (iswall_xm and iswall_zm and not iswall_xp and not iswall_zp) + or (iswall_xp and iswall_zp and not iswall_xm and not iswall_zm) then + minetest.set_node(pos, {name = "homedecor:cobweb_corner", param2 = 0}) + + -- only xm+xp means nodebox (not rotated, 0 degrees) + + elseif iswall_xm and iswall_xp and not iswall_zm and not iswall_zp then + minetest.set_node(pos, {name = "homedecor:cobweb_centered", param2 = 0}) + + -- only zm+zp means nodebox rotated to 90 degrees + + elseif iswall_zm and iswall_zp and not iswall_xm and not iswall_xp then + minetest.set_node(pos, {name = "homedecor:cobweb_centered", param2 = 1}) + + -- if all else fails, place the plantlike version as a fallback. + + else + minetest.set_node(pos, {name = "homedecor:cobweb_plantlike", param2 = 0}) + end + +end + +-- convert existing cobwebs + +minetest.register_abm({ + nodenames = { "homedecor:cobweb" }, + interval = 1, + chance = 1, + action = function(pos, node, active_object_count, active_object_count_wider) + homedecor_rotate_cobweb(pos) + end +}) diff --git a/homedecor/init.lua b/homedecor/init.lua index 13bf4ffc..29d65947 100644 --- a/homedecor/init.lua +++ b/homedecor/init.lua @@ -105,6 +105,8 @@ dofile(homedecor.modpath.."/furniture_bathroom.lua") dofile(homedecor.modpath.."/furniture_recipes.lua") dofile(homedecor.modpath.."/climate-control.lua") +dofile(homedecor.modpath.."/cobweb.lua") + dofile(homedecor.modpath.."/locked.lua") diff --git a/homedecor/misc-nodes.lua b/homedecor/misc-nodes.lua index afe745c4..48057b16 100644 --- a/homedecor/misc-nodes.lua +++ b/homedecor/misc-nodes.lua @@ -893,26 +893,6 @@ minetest.register_node("homedecor:trash_can", { } }) -minetest.register_node("homedecor:cobweb", { - description = "Cobweb", - drawtype = "plantlike", - tiles = { "homedecor_cobweb.png" }, - inventory_image = "homedecor_cobweb_inv.png", - paramtype = "light", - paramtype2 = "facedir", - sunlight_propagates = true, - walkable = false, - selection_box = { - type = "fixed", - fixed = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5} - }, - visual_scale = 1.189, - groups = { snappy = 3 }, - after_place_node = function(pos, placer, itemstack, pointed_thing) - minetest.add_node(pos, { name = "homedecor:cobweb", param2 = 0 }) - end -}) - minetest.register_node("homedecor:well_base", { tiles = { "homedecor_well_base_top.png", diff --git a/homedecor/textures/homedecor_cobweb.png b/homedecor/textures/homedecor_cobweb.png index 9cce2a22efd620b6d9a0808d20e48ece892768f8..2bb58a510950fe080d9dacb2abe9a9ab866249c4 100644 GIT binary patch delta 221 zcmV<303!eL0qg;g7k>~41^@s6AM^iV00029Nklrs7hm zsEAA2N&6jAU(_*sEAA2N&6jAU(_*e(e-g<8FyNf@JSHQ=iAK&($zCbZaC_tV+5WxKw4rI!H_=Pp#@m sJM5_Y?MPTvM2MMvcbs{2>mkd+FS@T=5erbrNB{r;07*qoM6N<$f?sK4?*IS* literal 0 HcmV?d00001 diff --git a/homedecor/textures/homedecor_cobweb_torchlike.png b/homedecor/textures/homedecor_cobweb_torchlike.png new file mode 100644 index 0000000000000000000000000000000000000000..4f1d12dcbf015643f22b4c86aaf10da10b612296 GIT binary patch literal 243 zcmVMzhIjmr(zu_(~A`4kyk=KVl0o)y942g&-Z)OSr-tIXcLd4ab*4U#RiCS2Z0OQRmROZ^GjOZQgmsXZOrBcRk#^X# t?zbahRS_X$jQ@@^k8V9=+sS-ad;lCeTM