Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add beds #1349

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
21 changes: 21 additions & 0 deletions mods/ctf/ctf_beds/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
Minetest Game mod: beds
=======================
See license.txt for license information.

Authors of source code
----------------------
Originally by BlockMen (MIT)
Various Minetest developers and contributors (MIT)

This mod has been modified by astro_ctf

Authors of media (textures)
---------------------------
BlockMen (CC BY-SA 3.0)
All textures unless otherwise noted

TumeniNodes (CC BY-SA 3.0)
beds_bed_under.png

This mod adds a bed to Minetest.

165 changes: 165 additions & 0 deletions mods/ctf/ctf_beds/api.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
-- Removes a node without calling on on_destruct()
-- We use this to mess with bed nodes without causing unwanted recursion.
local function remove_no_destruct(pos)
minetest.swap_node(pos, {name = "air"})
minetest.remove_node(pos) -- Now clear the meta
minetest.check_for_falling(pos)
end

local function destruct_bed(pos, n)
local node = minetest.get_node(pos)
local other

if n == 2 then
local dir = minetest.facedir_to_dir(node.param2)
other = vector.subtract(pos, dir)
elseif n == 1 then
local dir = minetest.facedir_to_dir(node.param2)
other = vector.add(pos, dir)
end
local oname = minetest.get_node(other).name
if minetest.get_item_group(oname, "bed") ~= 0 then
remove_no_destruct(other)
end
end

function beds.register_bed(name, def)
minetest.register_node(name .. "_bottom", {
description = def.description,
inventory_image = def.inventory_image,
wield_image = def.wield_image,
drawtype = "nodebox",
tiles = def.tiles.bottom,
use_texture_alpha = "clip",
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
stack_max = 1,
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 3, bed = 1},
sounds = def.sounds or default.node_sound_wood_defaults(),
node_box = {
type = "fixed",
fixed = def.nodebox.bottom,
},
selection_box = {
type = "fixed",
fixed = def.selectionbox,
},

on_place = function(itemstack, placer, pointed_thing)
local under = pointed_thing.under
local node = minetest.get_node(under)
local udef = minetest.registered_nodes[node.name]
if udef and udef.on_rightclick and
not (placer and placer:is_player() and
placer:get_player_control().sneak) then
return udef.on_rightclick(under, node, placer, itemstack,
pointed_thing) or itemstack
end

local pos
if udef and udef.buildable_to then
pos = under
else
pos = pointed_thing.above
end

local player_name = placer and placer:get_player_name() or ""



local node_def = minetest.registered_nodes[minetest.get_node(pos).name]
if not node_def or not node_def.buildable_to then
return itemstack
end

local dir = placer and placer:get_look_dir() and
minetest.dir_to_facedir(placer:get_look_dir()) or 0
local botpos = vector.add(pos, minetest.facedir_to_dir(dir))



local botdef = minetest.registered_nodes[minetest.get_node(botpos).name]
if not botdef or not botdef.buildable_to then
return itemstack
end

minetest.set_node(pos, {name = name .. "_bottom", param2 = dir})
minetest.set_node(botpos, {name = name .. "_top", param2 = dir})

if not minetest.is_creative_enabled(player_name) then
itemstack:take_item()
end
return itemstack
end,

on_destruct = function(pos)
destruct_bed(pos, 1)
end,



on_rotate = function(pos, node, user, _, new_param2)
local dir = minetest.facedir_to_dir(node.param2)
-- old position of the top node
local p = vector.add(pos, dir)
local node2 = minetest.get_node_or_nil(p)
if not node2 or minetest.get_item_group(node2.name, "bed") ~= 2 or
node.param2 ~= node2.param2 then
return false
end

if new_param2 % 32 > 3 then
return false
end
-- new position of the top node
local newp = vector.add(pos, minetest.facedir_to_dir(new_param2))
local node3 = minetest.get_node_or_nil(newp)
local node_def = node3 and minetest.registered_nodes[node3.name]
if not node_def or not node_def.buildable_to then
return false
end

node.param2 = new_param2
remove_no_destruct(p)
minetest.set_node(pos, node)
minetest.set_node(newp, {name = name .. "_top", param2 = new_param2})
return true
end,

})

minetest.register_node(name .. "_top", {
drawtype = "nodebox",
tiles = def.tiles.top,
use_texture_alpha = "clip",
paramtype = "light",
paramtype2 = "facedir",
is_ground_content = false,
pointable = false,
groups = {choppy = 2, oddly_breakable_by_hand = 2, flammable = 3, bed = 2,
not_in_creative_inventory = 1},
sounds = def.sounds or default.node_sound_wood_defaults(),
drop = name .. "_bottom",
node_box = {
type = "fixed",
fixed = def.nodebox.top,
},
on_destruct = function(pos)
destruct_bed(pos, 2)
end,
can_dig = function(pos, player)
local node = minetest.get_node(pos)
local dir = minetest.facedir_to_dir(node.param2)
local p = vector.add(pos, dir)
return beds.can_dig(p)
end,
})

minetest.register_alias(name, name .. "_bottom")

minetest.register_craft({
output = name,
recipe = def.recipe
})
end
106 changes: 106 additions & 0 deletions mods/ctf/ctf_beds/beds.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
-- beds/beds.lua

-- support for MT game translation.
local S = beds.get_translator

-- Fancy shaped bed

beds.register_bed("beds:fancy_bed", {
description = S("Fancy Bed"),
inventory_image = "beds_bed_fancy.png",
wield_image = "beds_bed_fancy.png",
tiles = {
bottom = {
"beds_bed_top1.png",
"beds_bed_under.png",
"beds_bed_side1.png",
"beds_bed_side1.png^[transformFX",
"beds_bed_foot.png",
"beds_bed_foot.png",
},
top = {
"beds_bed_top2.png",
"beds_bed_under.png",
"beds_bed_side2.png",
"beds_bed_side2.png^[transformFX",
"beds_bed_head.png",
"beds_bed_head.png",
}
},
nodebox = {
bottom = {
{-0.5, -0.5, -0.5, -0.375, -0.065, -0.4375},
{0.375, -0.5, -0.5, 0.5, -0.065, -0.4375},
{-0.5, -0.375, -0.5, 0.5, -0.125, -0.4375},
{-0.5, -0.375, -0.5, -0.4375, -0.125, 0.5},
{0.4375, -0.375, -0.5, 0.5, -0.125, 0.5},
{-0.4375, -0.3125, -0.4375, 0.4375, -0.0625, 0.5},
},
top = {
{-0.5, -0.5, 0.4375, -0.375, 0.1875, 0.5},
{0.375, -0.5, 0.4375, 0.5, 0.1875, 0.5},
{-0.5, 0, 0.4375, 0.5, 0.125, 0.5},
{-0.5, -0.375, 0.4375, 0.5, -0.125, 0.5},
{-0.5, -0.375, -0.5, -0.4375, -0.125, 0.5},
{0.4375, -0.375, -0.5, 0.5, -0.125, 0.5},
{-0.4375, -0.3125, -0.5, 0.4375, -0.0625, 0.4375},
}
},
selectionbox = {-0.5, -0.5, -0.5, 0.5, 0.06, 1.5},
recipe = {
{"", "", "group:stick"},
{"wool:white", "wool:white", "wool:white"},
{"group:wood", "group:wood", "group:wood"},
},
})

-- Simple shaped bed

beds.register_bed("beds:bed", {
description = S("Simple Bed"),
inventory_image = "beds_bed.png",
wield_image = "beds_bed.png",
tiles = {
bottom = {
"beds_bed_top_bottom.png^[transformR90",
"beds_bed_under.png",
"beds_bed_side_bottom_r.png",
"beds_bed_side_bottom_r.png^[transformFX",
"blank.png",
"beds_bed_side_bottom.png"
},
top = {
"beds_bed_top_top.png^[transformR90",
"beds_bed_under.png",
"beds_bed_side_top_r.png",
"beds_bed_side_top_r.png^[transformFX",
"beds_bed_side_top.png",
"blank.png",
}
},
nodebox = {
bottom = {-0.5, -0.5, -0.5, 0.5, 0.0625, 0.5},
top = {-0.5, -0.5, -0.5, 0.5, 0.0625, 0.5},
},
selectionbox = {-0.5, -0.5, -0.5, 0.5, 0.0625, 1.5},
recipe = {
{"wool:white", "wool:white", "wool:white"},
{"group:wood", "group:wood", "group:wood"}
},
})



-- Fuel

minetest.register_craft({
type = "fuel",
recipe = "beds:fancy_bed_bottom",
burntime = 13,
})

minetest.register_craft({
type = "fuel",
recipe = "beds:bed_bottom",
burntime = 12,
})
29 changes: 29 additions & 0 deletions mods/ctf/ctf_beds/functions.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
local pi = math.pi


-- support for MT game translation.
local S = beds.get_translator

-- Helper functions

local function get_look_yaw(pos)
local rotation = minetest.get_node(pos).param2
if rotation > 3 then
rotation = rotation % 4 -- Mask colorfacedir values
end
if rotation == 1 then
return pi / 2, rotation
elseif rotation == 3 then
return -pi / 2, rotation
elseif rotation == 0 then
return pi, rotation
else
return 0, rotation
end
end






19 changes: 19 additions & 0 deletions mods/ctf/ctf_beds/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
-- beds/init.lua

-- Load support for MT game translation.
local S = minetest.get_translator("beds")

beds = {}
beds.bed_position = {}
beds.pos = {}
beds.get_translator = S



local modpath = minetest.get_modpath("beds")

-- Load files

dofile(modpath .. "/functions.lua")
dofile(modpath .. "/api.lua")
dofile(modpath .. "/beds.lua")
Loading