From ba1feda0d838e4f9bb65c3595f40259d209fd357 Mon Sep 17 00:00:00 2001 From: MoNTE48 Date: Sat, 22 Jun 2019 18:37:36 +0200 Subject: [PATCH] Add furniture mod by @Thomas--S --- .../files/bluestone/mesecons_doors/init.lua | 31 +++ games/default/files/ts_furniture/LICENSE | 21 ++ games/default/files/ts_furniture/README.md | 12 ++ games/default/files/ts_furniture/depends.txt | 1 + games/default/files/ts_furniture/init.lua | 182 ++++++++++++++++++ 5 files changed, 247 insertions(+) create mode 100644 games/default/files/ts_furniture/LICENSE create mode 100644 games/default/files/ts_furniture/README.md create mode 100644 games/default/files/ts_furniture/depends.txt create mode 100644 games/default/files/ts_furniture/init.lua diff --git a/games/default/files/bluestone/mesecons_doors/init.lua b/games/default/files/bluestone/mesecons_doors/init.lua index 8b0099ae8..52d6c177a 100644 --- a/games/default/files/bluestone/mesecons_doors/init.lua +++ b/games/default/files/bluestone/mesecons_doors/init.lua @@ -74,6 +74,21 @@ meseconify_door("doors:door_steel") meseconify_door("doors:door_glass") meseconify_door("doors:door_obsidian_glass") +-- Trapdoor +local function trapdoor_switch(pos, node) + local state = minetest.get_meta(pos):get_int("state") + + if state == 1 then + minetest.sound_play("doors_door_close", {pos = pos, gain = 0.3, max_hear_distance = 10}) + minetest.set_node(pos, {name="doors:trapdoor", param2 = node.param2}) + else + minetest.sound_play("doors_door_open", {pos = pos, gain = 0.3, max_hear_distance = 10}) + minetest.set_node(pos, {name="doors:trapdoor_open", param2 = node.param2}) + end + + minetest.get_meta(pos):set_int("state", state == 1 and 0 or 1) +end + if doors and doors.get then local override = { mesecons = {effector = { @@ -95,4 +110,20 @@ if doors and doors.get then minetest.override_item("doors:trapdoor_open", override) minetest.override_item("doors:trapdoor_steel", override) minetest.override_item("doors:trapdoor_steel_open", override) +else + if minetest.registered_nodes["doors:trapdoor"] then + minetest.override_item("doors:trapdoor", { + mesecons = {effector = { + action_on = trapdoor_switch, + action_off = trapdoor_switch + }}, + }) + + minetest.override_item("doors:trapdoor_open", { + mesecons = {effector = { + action_on = trapdoor_switch, + action_off = trapdoor_switch + }}, + }) + end end diff --git a/games/default/files/ts_furniture/LICENSE b/games/default/files/ts_furniture/LICENSE new file mode 100644 index 000000000..2e317385b --- /dev/null +++ b/games/default/files/ts_furniture/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Thomas S. + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/games/default/files/ts_furniture/README.md b/games/default/files/ts_furniture/README.md new file mode 100644 index 000000000..55395bc03 --- /dev/null +++ b/games/default/files/ts_furniture/README.md @@ -0,0 +1,12 @@ +MultiCraft Game mod: ts_furniture +================================= + +https://github.com/minetest-mods/ts_furniture + +This mod adds basic furniture (Chairs, Tables, Small Tables, Tiny Tables, Benches). + +It was made by Thomas-S. + +It is published under the MIT license. + +Code from "Get Comfortable [cozy]" (by everamzah; published under WTFPL) was used and modified. diff --git a/games/default/files/ts_furniture/depends.txt b/games/default/files/ts_furniture/depends.txt new file mode 100644 index 000000000..4ad96d515 --- /dev/null +++ b/games/default/files/ts_furniture/depends.txt @@ -0,0 +1 @@ +default diff --git a/games/default/files/ts_furniture/init.lua b/games/default/files/ts_furniture/init.lua new file mode 100644 index 000000000..7081ecd56 --- /dev/null +++ b/games/default/files/ts_furniture/init.lua @@ -0,0 +1,182 @@ +ts_furniture = {} + +-- If true, you can sit on chairs and benches, when right-click them. +ts_furniture.enable_sitting = false + +-- The following code is from "Get Comfortable [cozy]" (by everamzah; published under WTFPL). +-- Thomas S. modified it, so that it can be used in this mod +--[[minetest.register_globalstep(function(dtime) + local players = minetest.get_connected_players() + for i = 1, #players do + local name = players[i]:get_player_name() + if default.player_attached[name] and not players[i]:get_attach() and + (players[i]:get_player_control().up == true or + players[i]:get_player_control().down == true or + players[i]:get_player_control().left == true or + players[i]:get_player_control().right == true or + players[i]:get_player_control().jump == true) then + players[i]:set_eye_offset({ x = 0, y = 0, z = 0 }, { x = 0, y = 0, z = 0 }) + players[i]:set_physics_override(1, 1, 1) + default.player_attached[name] = false + player_api.set_animation(players[i], "stand", 30) + end + end +end) + +ts_furniture.sit = function(name, pos) + local player = minetest.get_player_by_name(name) + if default.player_attached[name] then + player:set_eye_offset({ x = 0, y = 0, z = 0 }, { x = 0, y = 0, z = 0 }) + player:set_physics_override(1, 1, 1) + default.player_attached[name] = false + player_api.set_animation(player, "stand", 30) + else + player:moveto(pos) + player:set_eye_offset({ x = 0, y = -7, z = 2 }, { x = 0, y = 0, z = 0 }) + player:set_physics_override(0, 0, 0) + default.player_attached[name] = true + player_api.set_animation(player, "sit", 30) + end +end]] +-- end of cozy-code + +local furnitures = { + ["chair"] = { + description = "Chair", + sitting = true, + nodebox = { + { -0.3, -0.5, 0.2, -0.2, 0.5, 0.3 }, -- foot 1 + { 0.2, -0.5, 0.2, 0.3, 0.5, 0.3 }, -- foot 2 + { 0.2, -0.5, -0.3, 0.3, -0.1, -0.2 }, -- foot 3 + { -0.3, -0.5, -0.3, -0.2, -0.1, -0.2 }, -- foot 4 + { -0.3, -0.1, -0.3, 0.3, 0, 0.2 }, -- seating + { -0.2, 0.1, 0.25, 0.2, 0.4, 0.26 } -- conector 1-2 + }, + craft = function(recipe) + return { + { "", "group:stick" }, + { recipe, recipe }, + { "group:stick", "group:stick" } + } + end + }, + ["table"] = { + description = "Table", + nodebox = { + { -0.4, -0.5, -0.4, -0.3, 0.4, -0.3 }, -- foot 1 + { 0.3, -0.5, -0.4, 0.4, 0.4, -0.3 }, -- foot 2 + { -0.4, -0.5, 0.3, -0.3, 0.4, 0.4 }, -- foot 3 + { 0.3, -0.5, 0.3, 0.4, 0.4, 0.4 }, -- foot 4 + { -0.5, 0.4, -0.5, 0.5, 0.5, 0.5 }, -- table top + }, + craft = function(recipe) + return { + { recipe, recipe, recipe }, + { "group:stick", "", "group:stick" }, + { "group:stick", "", "group:stick" } + } + end + }, + ["small_table"] = { + description = "Small Table", + nodebox = { + { -0.4, -0.5, -0.4, -0.3, 0.1, -0.3 }, -- foot 1 + { 0.3, -0.5, -0.4, 0.4, 0.1, -0.3 }, -- foot 2 + { -0.4, -0.5, 0.3, -0.3, 0.1, 0.4 }, -- foot 3 + { 0.3, -0.5, 0.3, 0.4, 0.1, 0.4 }, -- foot 4 + { -0.5, 0.1, -0.5, 0.5, 0.2, 0.5 }, -- table top + }, + craft = function(recipe) + return { + { recipe, recipe, recipe }, + { "group:stick", "", "group:stick" } + } + end + }, + ["tiny_table"] = { + description = "Tiny Table", + nodebox = { + { -0.5, -0.1, -0.5, 0.5, 0, 0.5 }, -- table top + { -0.4, -0.5, -0.5, -0.3, -0.1, 0.5 }, -- foot 1 + { 0.3, -0.5, -0.5, 0.4, -0.1, 0.5 }, -- foot 2 + }, + craft = function(recipe) + local bench_name = "ts_furniture:" .. recipe:gsub(":", "_") .. "_bench" + return { + { bench_name, bench_name } + } + end + }, + ["bench"] = { + description = "Bench", + sitting = true, + nodebox = { + { -0.5, -0.1, 0, 0.5, 0, 0.5 }, -- seating + { -0.4, -0.5, 0, -0.3, -0.1, 0.5 }, -- foot 1 + { 0.3, -0.5, 0, 0.4, -0.1, 0.5 }, -- foot 2 + }, + craft = function(recipe) + return { + { recipe, recipe }, + { "group:stick", "group:stick" } + } + end + }, +} + +local ignore_groups = { + ["wood"] = true, + ["stone"] = true, +} + +function ts_furniture.register_furniture(recipe, description, texture) + local recipe_def = minetest.registered_items[recipe] + if not recipe_def then + return + end + + local groups = {} + for k, v in pairs(recipe_def.groups) do + if not ignore_groups[k] then + groups[k] = v + end + end + + for furniture, def in pairs(furnitures) do + local node_name = "ts_furniture:" .. recipe:gsub(":", "_") .. "_" .. furniture + + def.on_rightclick = nil + + if def.sitting and ts_furniture.enable_sitting then + def.on_rightclick = function(pos, node, player, itemstack, pointed_thing) + ts_furniture.sit(player:get_player_name(), pos) + end + end + + minetest.register_node(":" .. node_name, { + description = description .. " " .. def.description, + drawtype = "nodebox", + paramtype = "light", + paramtype2 = "facedir", + sunlight_propagates = true, + tiles = { texture }, + groups = groups, + node_box = { + type = "fixed", + fixed = def.nodebox + }, + on_rightclick = def.on_rightclick + }) + + minetest.register_craft({ + output = node_name, + recipe = def.craft(recipe) + }) + end +end + +--ts_furniture.register_furniture("default:aspen_wood", "Aspen", "default_aspen_wood.png") +ts_furniture.register_furniture("default:pine_wood", "Pine", "default_pine_wood.png") +ts_furniture.register_furniture("default:acacia_wood", "Acacia", "default_acacia_wood.png") +ts_furniture.register_furniture("default:wood", "Wooden", "default_wood.png") +ts_furniture.register_furniture("default:junglewood", "Jungle Wood", "default_junglewood.png")