From a62926d974dd4172cff23f22cc98384baf1b719f Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Sat, 19 Jul 2014 05:59:01 -0400 Subject: [PATCH] imported Blockmen's beds mod --- beds/README.txt | 26 +++ beds/depends.txt | 3 + beds/init.lua | 261 +++++++++++++++++++++++ beds/textures/beds_bed.png | Bin 0 -> 1035 bytes beds/textures/beds_bed_leer.png | Bin 0 -> 143 bytes beds/textures/beds_bed_side_bottom.png | Bin 0 -> 372 bytes beds/textures/beds_bed_side_bottom_r.png | Bin 0 -> 333 bytes beds/textures/beds_bed_side_top.png | Bin 0 -> 406 bytes beds/textures/beds_bed_side_top_r.png | Bin 0 -> 385 bytes beds/textures/beds_bed_top_bottom.png | Bin 0 -> 307 bytes beds/textures/beds_bed_top_top.png | Bin 0 -> 655 bytes 11 files changed, 290 insertions(+) create mode 100644 beds/README.txt create mode 100644 beds/depends.txt create mode 100644 beds/init.lua create mode 100644 beds/textures/beds_bed.png create mode 100644 beds/textures/beds_bed_leer.png create mode 100644 beds/textures/beds_bed_side_bottom.png create mode 100644 beds/textures/beds_bed_side_bottom_r.png create mode 100644 beds/textures/beds_bed_side_top.png create mode 100644 beds/textures/beds_bed_side_top_r.png create mode 100644 beds/textures/beds_bed_top_bottom.png create mode 100644 beds/textures/beds_bed_top_top.png diff --git a/beds/README.txt b/beds/README.txt new file mode 100644 index 00000000..380239c5 --- /dev/null +++ b/beds/README.txt @@ -0,0 +1,26 @@ +Minetest mod "Beds" +======================= +version: 1.1 + + +License of source code: WTFPL +----------------------------- +author: BlockMen (2013) +original author: PilzAdam + +This program is free software. It comes without any warranty, to +the extent permitted by applicable law. You can redistribute it +and/or modify it under the terms of the Do What The Fuck You Want +To Public License, Version 2, as published by Sam Hocevar. See +http://sam.zoy.org/wtfpl/COPYING for more details. + + +--USING the mod-- +------------------ + +This mods implements Beds like known from Minecraft. You can use them to sleep at night to skip the time or to prevent attacks by evil mobs. + + +To sleep you have to "rightclick" on your bed. You can only sleep at night and get noticed when it is too early. + +After dying the player will respawn at the last bed he has slept. \ No newline at end of file diff --git a/beds/depends.txt b/beds/depends.txt new file mode 100644 index 00000000..f098279c --- /dev/null +++ b/beds/depends.txt @@ -0,0 +1,3 @@ +default + +wool diff --git a/beds/init.lua b/beds/init.lua new file mode 100644 index 00000000..bbd8b823 --- /dev/null +++ b/beds/init.lua @@ -0,0 +1,261 @@ +local player_in_bed = 0 +local guy +local hand +local old_yaw = 0 + +local function get_dir(pos) + local btop = "beds:bed_top" + if minetest.env:get_node({x=pos.x+1,y=pos.y,z=pos.z}).name == btop then + return 7.9 + elseif minetest.env:get_node({x=pos.x-1,y=pos.y,z=pos.z}).name == btop then + return 4.75 + elseif minetest.env:get_node({x=pos.x,y=pos.y,z=pos.z+1}).name == btop then + return 3.15 + elseif minetest.env:get_node({x=pos.x,y=pos.y,z=pos.z-1}).name == btop then + return 6.28 + end +end + +function plock(start, max, tick, player, yaw) + if start+tick < max then + player:set_look_pitch(-1.2) + player:set_look_yaw(yaw) + minetest.after(tick, plock, start+tick, max, tick, player, yaw) + else + player:set_look_pitch(0) + if old_yaw ~= 0 then minetest.after(0.1+tick, function() player:set_look_yaw(old_yaw) end) end + end +end + +function exit(pos) + local npos = minetest.env:find_node_near(pos, 1, "beds:bed_bottom") + if npos ~= nil then pos = npos end + if minetest.env:get_node({x=pos.x+1,y=pos.y,z=pos.z}).name == "air" then + return {x=pos.x+1,y=pos.y,z=pos.z} + elseif minetest.env:get_node({x=pos.x-1,y=pos.y,z=pos.z}).name == "air" then + return {x=pos.x-1,y=pos.y,z=pos.z} + elseif minetest.env:get_node({x=pos.x,y=pos.y,z=pos.z+1}).name == "air" then + return {x=pos.x,y=pos.y,z=pos.z+1} + elseif minetest.env:get_node({x=pos.x,y=pos.y,z=pos.z-1}).name == "air" then + return {x=pos.x,y=pos.y,z=pos.z-1} + else + return {x=pos.x,y=pos.y,z=pos.z} + end +end + +minetest.register_node("beds:bed_bottom", { + description = "Bed", + inventory_image = "beds_bed.png", + wield_image = "beds_bed.png", + wield_scale = {x=0.8,y=2.5,z=1.3}, + drawtype = "nodebox", + tiles = {"beds_bed_top_bottom.png^[transformR90", "default_wood.png", "beds_bed_side_bottom_r.png", "beds_bed_side_bottom_r.png^[transformfx", "beds_bed_leer.png", "beds_bed_side_bottom.png"}, + paramtype = "light", + paramtype2 = "facedir", + stack_max = 1, + groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3}, + sounds = default.node_sound_wood_defaults(), + node_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.06, 0.5}, + }, + selection_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.06, 1.5}, + + }, + + after_place_node = function(pos, placer, itemstack) + local node = minetest.env:get_node(pos) + local param2 = node.param2 + local npos = {x=pos.x, y=pos.y, z=pos.z} + if param2 == 0 then + npos.z = npos.z+1 + elseif param2 == 1 then + npos.x = npos.x+1 + elseif param2 == 2 then + npos.z = npos.z-1 + elseif param2 == 3 then + npos.x = npos.x-1 + end + if minetest.registered_nodes[minetest.env:get_node(npos).name].buildable_to == true and minetest.env:get_node({x=npos.x, y=npos.y-1, z=npos.z}).name ~= "air" then + minetest.env:set_node(npos, {name="beds:bed_top", param2 = param2}) + else + minetest.env:dig_node(pos) + return true + end + end, + + on_destruct = function(pos) + pos = minetest.env:find_node_near(pos, 1, "beds:bed_top") + if pos ~= nil then minetest.env:remove_node(pos) end + end, + + on_rightclick = function(pos, node, clicker, itemstack) + if not clicker:is_player() then + return + end + + if minetest.env:get_timeofday() > 0.2 and minetest.env:get_timeofday() < 0.805 then + minetest.chat_send_all("You can only sleep at night") + return + else + clicker:set_physics_override(0,0,0) + old_yaw = clicker:get_look_yaw() + guy = clicker + clicker:set_look_yaw(get_dir(pos)) + minetest.chat_send_all("Good night") + plock(0,2,0.1,clicker, get_dir(pos)) + end + + if not clicker:get_player_control().sneak then + local meta = minetest.env:get_meta(pos) + local param2 = node.param2 + if param2 == 0 then + pos.z = pos.z+1 + elseif param2 == 1 then + pos.x = pos.x+1 + elseif param2 == 2 then + pos.z = pos.z-1 + elseif param2 == 3 then + pos.x = pos.x-1 + end + if clicker:get_player_name() == meta:get_string("player") then + if param2 == 0 then + pos.x = pos.x-1 + elseif param2 == 1 then + pos.z = pos.z+1 + elseif param2 == 2 then + pos.x = pos.x+1 + elseif param2 == 3 then + pos.z = pos.z-1 + end + pos.y = pos.y-0.5 + clicker:setpos(pos) + meta:set_string("player", "") + player_in_bed = player_in_bed-1 + elseif meta:get_string("player") == "" then + pos.y = pos.y-0.5 + clicker:setpos(pos) + meta:set_string("player", clicker:get_player_name()) + player_in_bed = player_in_bed+1 + end + end + end +}) + +minetest.register_node("beds:bed_top", { + drawtype = "nodebox", + tiles = {"beds_bed_top_top.png^[transformR90", "beds_bed_leer.png", "beds_bed_side_top_r.png", "beds_bed_side_top_r.png^[transformfx", "beds_bed_side_top.png", "beds_bed_leer.png"}, + paramtype = "light", + paramtype2 = "facedir", + groups = {snappy=1,choppy=2,oddly_breakable_by_hand=2,flammable=3}, + sounds = default.node_sound_wood_defaults(), + node_box = { + type = "fixed", + fixed = {-0.5, -0.5, -0.5, 0.5, 0.06, 0.5}, + }, + selection_box = { + type = "fixed", + fixed = {0, 0, 0, 0, 0, 0}, + }, +}) + +minetest.register_alias("beds:bed", "beds:bed_bottom") + +minetest.register_craft({ + output = "beds:bed", + recipe = { + {"group:wool", "group:wool", "group:wool", }, + {"group:wood", "group:wood", "group:wood", } + } +}) + +beds_player_spawns = {} +local file = io.open(minetest.get_worldpath().."/beds_player_spawns", "r") +if file then + beds_player_spawns = minetest.deserialize(file:read("*all")) + file:close() +end + +local timer = 0 +local wait = false +minetest.register_globalstep(function(dtime) + if timer<2 then + timer = timer+dtime + return + end + timer = 0 + + local players = #minetest.get_connected_players() + if players == player_in_bed and players ~= 0 then + if minetest.env:get_timeofday() < 0.2 or minetest.env:get_timeofday() > 0.805 then + if not wait then + minetest.after(2, function() + minetest.env:set_timeofday(0.23) + wait = false + guy:set_physics_override(1,1,1) + guy:setpos(exit(guy:getpos())) + + end) + wait = true + for _,player in ipairs(minetest.get_connected_players()) do + beds_player_spawns[player:get_player_name()] = player:getpos() + end + local file = io.open(minetest.get_worldpath().."/beds_player_spawns", "w") + if file then + file:write(minetest.serialize(beds_player_spawns)) + file:close() + end + end + end + end +end) + +minetest.register_on_respawnplayer(function(player) + local name = player:get_player_name() + if beds_player_spawns[name] then + player:setpos(beds_player_spawns[name]) + return true + end +end) + +minetest.register_abm({ + nodenames = {"beds:bed_bottom"}, + interval = 1, + chance = 1, + action = function(pos, node) + local meta = minetest.env:get_meta(pos) + if meta:get_string("player") ~= "" then + local param2 = node.param2 + if param2 == 0 then + pos.z = pos.z+1 + elseif param2 == 1 then + pos.x = pos.x+1 + elseif param2 == 2 then + pos.z = pos.z-1 + elseif param2 == 3 then + pos.x = pos.x-1 + end + local player = minetest.env:get_player_by_name(meta:get_string("player")) + if player == nil then + meta:set_string("player", "") + player_in_bed = player_in_bed-1 + return + end + local player_pos = player:getpos() + player_pos.x = math.floor(0.5+player_pos.x) + player_pos.y = math.floor(0.5+player_pos.y) + player_pos.z = math.floor(0.5+player_pos.z) + if pos.x ~= player_pos.x or pos.y ~= player_pos.y or pos.z ~= player_pos.z then + meta:set_string("player", "") + player_in_bed = player_in_bed-1 + return + end + end + end +}) + +if minetest.setting_get("log_mods") then + minetest.log("action", "beds loaded") +end diff --git a/beds/textures/beds_bed.png b/beds/textures/beds_bed.png new file mode 100644 index 0000000000000000000000000000000000000000..e8d0e5c4397df19eeaf237614ea9dd7bbc18ae8b GIT binary patch literal 1035 zcmV+m1oZofP)2ArZz!2#Vkr zVdzK}w{I=5xcDSFV6-})P{#JVoizkR46xaR@rVdvbwoiCd?NIVpdHO-Vc{Wnzgzw* z!2j-BjH!wG!gC2NjvC5{n==3s!@VLn6(Cqq&BDSDY+l0t3wd}m((s9JO|>hm7BMbv zgc!>>rnh}kgi#R!BDhqrOCiE7mx=n?wg8ez;^vmQ{UGl1DeN3O{6v6f0JNTMPaCJ6pz6~99g+$%8 zTYx3gyaa6}xQeoIW~8GTLJ~1Ls81#L+FwtAdU~?&> zt!D|;6ft1VMmv<66w@z4j{;l~q08{OmXSulT8Ojp(z2)k>rR~Kwf>bi7_j;aE*`V$Pb zoFUj+&S13}_i+<_sVVfRU0+oIhX@13#|X5P)6r10qwqLD)Lo0Cu5jClEp2aL9s;j1#Ect1P61r%ytm^_}jtXoQxr}#I z;QqAajl*{Z&}*{4mcZ4s*gni<(qpA_2N&*N1jl5q^6aef5PzJT-d*?EAms1Hk_t@CO;LDeXY029*E+002ovPDHLk FV1m|M>A3&^ literal 0 HcmV?d00001 diff --git a/beds/textures/beds_bed_leer.png b/beds/textures/beds_bed_leer.png new file mode 100644 index 0000000000000000000000000000000000000000..2dc0e3dc6e85a0ed7b1ad4b899ad82b5b6b0e8e6 GIT binary patch literal 143 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9GGLLkg|>2BR0prEv; zi(^Q|oa7(>|JyUG&QLnLn5{?3AnQPa5d*`~wSVP9epPk@l}VMjMwB>~mSp4?F@)x% kCZ;F^R~DC~<`(NHc;+SRos_jJ1FB;1boFyt=akR{04v}rR{#J2 literal 0 HcmV?d00001 diff --git a/beds/textures/beds_bed_side_bottom.png b/beds/textures/beds_bed_side_bottom.png new file mode 100644 index 0000000000000000000000000000000000000000..7b20f03465266d70c6739d70ee1230eadd4fa0c3 GIT binary patch literal 372 zcmV-)0gL{LP)H`2`Oh}07V5`oXvL!34~z`(d{ahB)seF8`vV#)u3Wd)Q7Mud(CPZ8-X93_G% z5gtV7itrqf?!sAKAl8MiQ4OmL3{;MZE;7XQ}%cS`~+e@1V;Ls+>ZX94_4iftR6qkfu>t=VpHe`*_5#UF52i zM84mv3~sXo-YOfvV~N7d9usPpU@wjQe4a5d9@kzXa$r6^#cCIGm_lZ+Cw%BUEq^Wg zf?2BR0px{kU z7srr_Id9K9`W*@oX??hvchR;T48lPIw>pFt@R{%wFzjLwzF(bt!Q;^Zi*`OAU5UHQ zoyWHBY@Ba;!>Hr~@B8`1tSh>_j{k3rWnFW`=TYFJl`N5+JCAHW;?236Go&hUa=%8J zBDeU4DvpzPIbWM7?dCq=)BI@PSu5ViS!&(487O_wXnvPjYQOg1sdaYi zPUNU=t-#(*N76w(vpn)B8JeM)Wj5p;L75X c)ZAhn1<$->y_2$bWk6L7p00i_>zopr01dl@od5s; literal 0 HcmV?d00001 diff --git a/beds/textures/beds_bed_side_top.png b/beds/textures/beds_bed_side_top.png new file mode 100644 index 0000000000000000000000000000000000000000..a7b4009a7dae602e0cce5d69b6d1e211a77f5c3d GIT binary patch literal 406 zcmV;H0crk;P)jqSY#pq_1V+=Zv@s z+6NVe>4YJ5f(jQA9ijsiv?u~6QPT8FW~*-lZM@- z)$UBJ+jHpl99r!T4ZF$9>l?!UYT`IQ^!tN}4F)5|<6nlu5$(?RoPe1x)UVdCGAbu2 zKUH&ys;Od`3g>BsQp!*DP{lGePLn>0IUkmxP%#5s7Q$?665{cCgR=u4>4=P>d)beA zNa_n@BNB%0A)&e1)g&?znar}xj_Ts(C`Q=~vKR6o>Xmg$=>VIW#PhK&rs=L2!!i`M zG#BEj7N=~6NQB)}0}r)0<-AHx_abgDRQ+acAWo>gTAW3dxF3BA}b^rhX07*qoM6N<$g62BR0px}N_ z7srr_IjIx9`C1$}T;%UoT-y1cHBBU~Q6NBknb7O*UyZENVmbj44*O(P91}!u6dYh{ zo!cX{=2+QY2QNMk8lXmjdch_8` z)_aL>5b)4GjUx%cA+m$)!vc^ zdPSmdKI;Vst03qOX A8vpN31JCKFiU=qf-*5KVQeE?vb@`} zENiS~lsb9P2vp>u-=@#>%)KoKBJ7LsU4&f`K8x^CgdGt+i15&8(&^f`0}pRF!X0>Y zx;77uCbxHW6)A^jm!e=_4<9b7^R=WUPif}2yg$U;c zbZ8)-L}+(jn9k;`*CCro5pE*pizS^Gy8v8^Q0mHnPDD5`PwLuze1C;fia1VC+n8Xz z#&JFF>kZ^agi_Zg&AAB2B776U?l}ZONRlL^X-bl$D5aQ8XFN8aiUhxnZYn8$its}O z#~HBMM5Jkk)*7ufaU8Q;`n1{|v}{=k!2Zqo};xUNm7DfP1o)tHFN9x ze>gP>yy2KAQfRHo^PD`-Nz;rl4Cy(}8=%x>1#lq3Xgoow67ZKi&&jfkFx=2{+_y27 zfZBh6DN1c$6KJhT)3iv?uK-HbD*I4PkY&XuW?GXZ39D7Wi`{<%)Qo54+7?kC9XH5X|;+?thRCAY~P+Se-WY8?$UQ$hNB6i(HO@a@bui_ zzTPOh@YNiAud>#E9xbd^o2TavR;x{;X}y|n@9O*mzV?^nCS1+D0000QbVXQnL3MO! pZ*l-tY-M3&AX9mBbY*RGEFej4V=l=ZK6U^A002ovPDHLkV1kBhCXfIC literal 0 HcmV?d00001