From f6a40ffb78c31551a208a28fd469eead5d0573f6 Mon Sep 17 00:00:00 2001 From: Elias Fleckenstein Date: Thu, 26 May 2022 07:29:28 +0200 Subject: [PATCH] Run tools/strip_trailing_whitespace.sh --- mods/CORE/mcl_util/init.lua | 2 +- mods/ENTITIES/mcl_mobs/api.lua | 8 +- mods/ENTITIES/mobs_mc/villager.lua | 8 +- mods/ENVIRONMENT/mcl_weather/nether_dust.lua | 4 +- mods/ENVIRONMENT/mcl_weather/rain.lua | 2 +- mods/HELP/mcl_item_id/init.lua | 4 +- mods/HUD/mcl_inventory/creative.lua | 4 +- mods/HUD/mcl_inventory/init.lua | 470 ++++---- mods/ITEMS/REDSTONE/mcl_dispensers/init.lua | 2 +- mods/ITEMS/mcl_beds/respawn_anchor.lua | 8 +- mods/ITEMS/mcl_buckets/init.lua | 2 +- mods/ITEMS/mcl_cake/init.lua | 312 ++--- mods/ITEMS/mcl_crafting_table/init.lua | 140 +-- mods/ITEMS/mcl_doors/api_doors.lua | 1118 +++++++++--------- mods/ITEMS/mcl_doors/api_trapdoors.lua | 462 ++++---- mods/ITEMS/mcl_doors/init.lua | 18 +- mods/ITEMS/mcl_farming/hoes.lua | 550 ++++----- mods/ITEMS/mcl_fences/init.lua | 612 +++++----- mods/ITEMS/mcl_loom/init.lua | 4 +- mods/ITEMS/mcl_mobitems/init.lua | 894 +++++++------- mods/ITEMS/mcl_shields/init.lua | 6 +- mods/ITEMS/mcl_totems/init.lua | 2 +- mods/MAPGEN/mcl_mapgen_core/init.lua | 2 +- mods/MAPGEN/mcl_villages/buildings.lua | 6 +- mods/MISC/mcl_privs/init.lua | 2 +- mods/PLAYER/mcl_death_drop/init.lua | 114 +- mods/PLAYER/mcl_spawn/init.lua | 4 +- 27 files changed, 2380 insertions(+), 2380 deletions(-) diff --git a/mods/CORE/mcl_util/init.lua b/mods/CORE/mcl_util/init.lua index 30d63fd32..a179d53e6 100644 --- a/mods/CORE/mcl_util/init.lua +++ b/mods/CORE/mcl_util/init.lua @@ -603,7 +603,7 @@ function mcl_util.get_pointed_thing(player, liquid) local look_dir = vector.multiply(player:get_look_dir(), 5) local pos2 = vector.add(pos, look_dir) local ray = minetest.raycast(pos, pos2, false, liquid) - + if ray then for pointed_thing in ray do return pointed_thing diff --git a/mods/ENTITIES/mcl_mobs/api.lua b/mods/ENTITIES/mcl_mobs/api.lua index 3c5616c2f..dc87926a9 100644 --- a/mods/ENTITIES/mcl_mobs/api.lua +++ b/mods/ENTITIES/mcl_mobs/api.lua @@ -1402,7 +1402,7 @@ end -- should mob follow what I'm holding ? local follow_holding = function(self, clicker) if self.nofollow then return false end - + if mcl_mobs.invis[clicker:get_player_name()] then return false end @@ -2307,7 +2307,7 @@ local function check_doors(self) else if closed then def.on_rightclick(d,n,self) end end - + end end end @@ -2316,7 +2316,7 @@ end -- returns true if mob has died local do_states = function(self, dtime) if self.can_open_doors then check_doors(self) end - + local yaw = self.object:get_yaw() or 0 if self.state == "stand" then @@ -2386,7 +2386,7 @@ local do_states = function(self, dtime) elseif self.current_target then go_to_pos(self,self.current_target) end - + if self.current_target and not minetest.line_of_sight(self.object:get_pos(),self.current_target) then self.waypoints=minetest.find_path(p,self._target,150,1,4) self.current_target = nil diff --git a/mods/ENTITIES/mobs_mc/villager.lua b/mods/ENTITIES/mobs_mc/villager.lua index 303eb3053..dbbdf9949 100644 --- a/mods/ENTITIES/mobs_mc/villager.lua +++ b/mods/ENTITIES/mobs_mc/villager.lua @@ -293,7 +293,7 @@ local professions = { }, { { { "mcl_core:emerald", 7, 7}, { "mcl_itemframes:item_frame", 1, 1 }}, - + { { "mcl_core:emerald", 7, 7}, { "mcl_banners:banner_item_white", 1, 1 }}, { { "mcl_core:emerald", 7, 7}, { "mcl_banners:banner_item_grey", 1, 1 }}, { { "mcl_core:emerald", 7, 7}, { "mcl_banners:banner_item_silver", 1, 1 }}, @@ -578,7 +578,7 @@ local function go_home(entity) local b=entity._bed if not b then return end mcl_mobs:gopath(entity,b,function(entity,b) - if vector.distance(entity.object:get_pos(),b) < 2 then + if vector.distance(entity.object:get_pos(),b) < 2 then entity.state = "stand" set_velocity(entity,0) entity.object:set_pos(b) @@ -589,7 +589,7 @@ local function go_home(entity) end return true end - end) + end) end ----- JOBSITE LOGIC @@ -1315,7 +1315,7 @@ mcl_mobs:register_mob("mobs_mc:villager", { if not self._player_scan_timer then self._player_scan_timer = 0 end - + self._player_scan_timer = self._player_scan_timer + dtime -- Check infrequently to keep CPU load low if self._player_scan_timer > PLAYER_SCAN_INTERVAL then diff --git a/mods/ENVIRONMENT/mcl_weather/nether_dust.lua b/mods/ENVIRONMENT/mcl_weather/nether_dust.lua index 22cc2b483..a90c8e96e 100644 --- a/mods/ENVIRONMENT/mcl_weather/nether_dust.lua +++ b/mods/ENVIRONMENT/mcl_weather/nether_dust.lua @@ -24,7 +24,7 @@ local function check_player(player) local name=player:get_player_name() if mcl_worlds.has_dust(player:get_pos()) and not mcl_weather.nether_dust.particlespawners[name] then return true - end + end end mcl_weather.nether_dust.add_particlespawners = function(player) @@ -45,7 +45,7 @@ mcl_weather.nether_dust.delete_particlespawners = function(player) for i=1,3 do minetest.delete_particlespawner(mcl_weather.nether_dust.particlespawners[name][i]) end - mcl_weather.nether_dust.particlespawners[name]=nil + mcl_weather.nether_dust.particlespawners[name]=nil end end diff --git a/mods/ENVIRONMENT/mcl_weather/rain.lua b/mods/ENVIRONMENT/mcl_weather/rain.lua index 0caef5c6f..f85b91369 100644 --- a/mods/ENVIRONMENT/mcl_weather/rain.lua +++ b/mods/ENVIRONMENT/mcl_weather/rain.lua @@ -165,7 +165,7 @@ function mcl_weather.rain.clear() mcl_weather.rain.remove_sound(player) mcl_weather.rain.remove_player(player) mcl_weather.remove_spawners_player(player) - end + end end minetest.register_globalstep(function(dtime) diff --git a/mods/HELP/mcl_item_id/init.lua b/mods/HELP/mcl_item_id/init.lua index f3e6d2735..0e029932b 100644 --- a/mods/HELP/mcl_item_id/init.lua +++ b/mods/HELP/mcl_item_id/init.lua @@ -26,8 +26,8 @@ local same_id = { walls = { "andesite", "brick", "cobble", "diorite", "endbricks", "granite", "mossycobble", "netherbrick", "prismarine", - "rednetherbrick", "redsandstone", "sandstone", - "stonebrick", "stonebrickmossy", + "rednetherbrick", "redsandstone", "sandstone", + "stonebrick", "stonebrickmossy", }, wool = { "black", "blue", "brown", "cyan", "green", diff --git a/mods/HUD/mcl_inventory/creative.lua b/mods/HUD/mcl_inventory/creative.lua index 1c85c125e..4c2faaef6 100644 --- a/mods/HUD/mcl_inventory/creative.lua +++ b/mods/HUD/mcl_inventory/creative.lua @@ -360,7 +360,7 @@ function mcl_inventory.set_creative_formspec(player, start_i, pagenum, inv_size, end local stack_size = get_stack_size(player) - + -- Survival inventory slots main_list = "list[current_player;main;0,3.75;9,3;9]".. mcl_formspec.get_itemslot_bg(0,3.75,9,3).. @@ -394,7 +394,7 @@ function mcl_inventory.set_creative_formspec(player, start_i, pagenum, inv_size, -- switch stack size button "image_button[9,5;1,1;default_apple.png;__switch_stack;]".. "label[9.4,5.4;".. F(C("#FFFFFF", stack_size ~= 1 and stack_size or "")) .."]".. - "tooltip[__switch_stack;"..F(S("Switch stack size")).."]" + "tooltip[__switch_stack;"..F(S("Switch stack size")).."]" -- For shortcuts listrings = listrings .. diff --git a/mods/HUD/mcl_inventory/init.lua b/mods/HUD/mcl_inventory/init.lua index d47478c9e..eb6b4c7b1 100644 --- a/mods/HUD/mcl_inventory/init.lua +++ b/mods/HUD/mcl_inventory/init.lua @@ -1,236 +1,236 @@ -local S = minetest.get_translator(minetest.get_current_modname()) -local F = minetest.formspec_escape - -mcl_inventory = {} - ---local mod_player = minetest.get_modpath("mcl_player") ---local mod_craftguide = minetest.get_modpath("mcl_craftguide") - --- Returns a single itemstack in the given inventory to the main inventory, or drop it when there's no space left -function return_item(itemstack, dropper, pos, inv) - if dropper:is_player() then - -- Return to main inventory - if inv:room_for_item("main", itemstack) then - inv:add_item("main", itemstack) - else - -- Drop item on the ground - local v = dropper:get_look_dir() - local p = {x=pos.x, y=pos.y+1.2, z=pos.z} - p.x = p.x+(math.random(1,3)*0.2) - p.z = p.z+(math.random(1,3)*0.2) - local obj = minetest.add_item(p, itemstack) - if obj then - v.x = v.x*4 - v.y = v.y*4 + 2 - v.z = v.z*4 - obj:set_velocity(v) - obj:get_luaentity()._insta_collect = false - end - end - else - -- Fallback for unexpected cases - minetest.add_item(pos, itemstack) - end - return itemstack -end - --- Return items in the given inventory list (name) to the main inventory, or drop them if there is no space left -function return_fields(player, name) - local inv = player:get_inventory() - local list = inv:get_list(name) - if not list then return end - for i,stack in ipairs(list) do - return_item(stack, player, player:get_pos(), inv) - stack:clear() - inv:set_stack(name, i, stack) - end -end - -local function set_inventory(player, armor_change_only) - if minetest.is_creative_enabled(player:get_player_name()) then - if armor_change_only then - -- Stay on survival inventory plage if only the armor has been changed - mcl_inventory.set_creative_formspec(player, 0, 0, nil, nil, "inv") - else - mcl_inventory.set_creative_formspec(player, 0, 1) - end - return - end - local inv = player:get_inventory() - inv:set_width("craft", 2) - inv:set_size("craft", 4) - - local armor_slots = {"helmet", "chestplate", "leggings", "boots"} - local armor_slot_imgs = "" - for a=1,4 do - if inv:get_stack("armor", a+1):is_empty() then - armor_slot_imgs = armor_slot_imgs .. "image[0,"..(a-1)..";1,1;mcl_inventory_empty_armor_slot_"..armor_slots[a]..".png]" - end - end - - if inv:get_stack("offhand", 1):is_empty() then - armor_slot_imgs = armor_slot_imgs .. "image[3,2;1,1;mcl_inventory_empty_armor_slot_shield.png]" - end - - local form = "size[9,8.75]".. - "background[-0.19,-0.25;9.41,9.49;crafting_formspec_bg.png]".. - mcl_player.get_player_formspec_model(player, 1.0, 0.0, 2.25, 4.5, "").. - --armor - "list[current_player;armor;0,0;1,1;1]".. - "list[current_player;armor;0,1;1,1;2]".. - "list[current_player;armor;0,2;1,1;3]".. - "list[current_player;armor;0,3;1,1;4]".. - mcl_formspec.get_itemslot_bg(0,0,1,1).. - mcl_formspec.get_itemslot_bg(0,1,1,1).. - mcl_formspec.get_itemslot_bg(0,2,1,1).. - mcl_formspec.get_itemslot_bg(0,3,1,1).. - "list[current_player;offhand;3,2;1,1]".. - mcl_formspec.get_itemslot_bg(3,2,1,1).. - armor_slot_imgs.. - -- craft and inventory - "label[0,4;"..F(minetest.colorize("#313131", S("Inventory"))).."]".. - "list[current_player;main;0,4.5;9,3;9]".. - "list[current_player;main;0,7.74;9,1;]".. - "label[4,0.5;"..F(minetest.colorize("#313131", S("Crafting"))).."]".. - "list[current_player;craft;4,1;2,2]".. - "list[current_player;craftpreview;7,1.5;1,1;]".. - mcl_formspec.get_itemslot_bg(0,4.5,9,3).. - mcl_formspec.get_itemslot_bg(0,7.74,9,1).. - mcl_formspec.get_itemslot_bg(4,1,2,2).. - mcl_formspec.get_itemslot_bg(7,1.5,1,1).. - -- crafting guide button - "image_button[4.5,3;1,1;craftguide_book.png;__mcl_craftguide;]".. - "tooltip[__mcl_craftguide;"..F(S("Recipe book")).."]".. - -- help button - "image_button[8,3;1,1;doc_button_icon_lores.png;__mcl_doc;]".. - "tooltip[__mcl_doc;"..F(S("Help")).."]".. - -- skins button - "image_button[3,3;1,1;mcl_skins_button.png;__mcl_skins;]".. - "tooltip[__mcl_skins;"..F(S("Select player skin")).."]".. - -- achievements button - "image_button[7,3;1,1;mcl_achievements_button.png;__mcl_achievements;]".. - "tooltip[__mcl_achievements;"..F(S("Achievements")).."]".. - -- for shortcuts - "listring[current_player;main]".. - "listring[current_player;armor]".. - "listring[current_player;main]" .. - "listring[current_player;craft]" .. - "listring[current_player;main]" - player:set_inventory_formspec(form) -end - --- Drop items in craft grid and reset inventory on closing -minetest.register_on_player_receive_fields(function(player, formname, fields) - if fields.quit then - return_fields(player,"craft") - return_fields(player,"enchanting_lapis") - return_fields(player,"enchanting_item") - if not minetest.is_creative_enabled(player:get_player_name()) and (formname == "" or formname == "main") then - set_inventory(player) - end - end -end) - -if not minetest.is_creative_enabled("") then - function mcl_inventory.update_inventory_formspec(player) - set_inventory(player) - end -end - --- Drop crafting grid items on leaving -minetest.register_on_leaveplayer(function(player) - return_fields(player, "craft") - return_fields(player, "enchanting_lapis") - return_fields(player, "enchanting_item") -end) - -minetest.register_on_joinplayer(function(player) - --init inventory - local inv = player:get_inventory() - inv:set_width("main", 9) - inv:set_size("main", 36) - inv:set_size("offhand", 1) - - --set hotbar size - player:hud_set_hotbar_itemcount(9) - --add hotbar images - player:hud_set_hotbar_image("mcl_inventory_hotbar.png") - player:hud_set_hotbar_selected_image("mcl_inventory_hotbar_selected.png") - - local old_update_player = mcl_armor.update_player - function mcl_armor.update_player(player, info) - old_update_player(player, info) - set_inventory(player, true) - end - - -- In Creative Mode, the initial inventory setup is handled in creative.lua - if not minetest.is_creative_enabled(player:get_player_name()) then - set_inventory(player) - end - - --[[ Make sure the crafting grid is empty. Why? Because the player might have - items remaining in the crafting grid from the previous join; this is likely - when the server has been shutdown and the server didn't clean up the player - inventories. ]] - return_fields(player, "craft") - return_fields(player, "enchanting_item") - return_fields(player, "enchanting_lapis") -end) - - -dofile(minetest.get_modpath(minetest.get_current_modname()).."/creative.lua") - -local mt_is_creative_enabled = minetest.is_creative_enabled - -function minetest.is_creative_enabled(name) - if mt_is_creative_enabled(name) then return true end - local p = minetest.get_player_by_name(name) - if p then - return p:get_meta():get_string("gamemode") == "creative" - end - return false -end - -local function in_table(n,h) - for k,v in pairs(h) do - if v == n then return true end - end - return false -end - -local gamemodes = { - "survival", - "creative" -} - -function mcl_inventory.player_set_gamemode(p,g) - local m = p:get_meta() - m:set_string("gamemode",g) - set_inventory(p) -end - -minetest.register_chatcommand("gamemode",{ - params = S("[] []"), - description = S("Change gamemode (survival/creative) for yourself or player"), - privs = { server = true }, - func = function(n,param) - -- Full input validation ( just for @erlehmann <3 ) - local p = minetest.get_player_by_name(n) - local args = param:split(" ") - if args[2] ~= nil then - p = minetest.get_player_by_name(args[2]) - end - if not p then - return false, S("Player not online") - end - if args[1] ~= nil and not in_table(args[1],gamemodes) then - return false, S("Gamemode " .. args[1] .. " does not exist.") - elseif args[1] ~= nil then - mcl_inventory.player_set_gamemode(p,args[1]) - end - --Result message - show effective game mode - local gm = p:get_meta():get_string("gamemode") - if gm == "" then gm = gamemodes[1] end - return true, S("Gamemode for player ")..n..S(": "..gm) +local S = minetest.get_translator(minetest.get_current_modname()) +local F = minetest.formspec_escape + +mcl_inventory = {} + +--local mod_player = minetest.get_modpath("mcl_player") +--local mod_craftguide = minetest.get_modpath("mcl_craftguide") + +-- Returns a single itemstack in the given inventory to the main inventory, or drop it when there's no space left +function return_item(itemstack, dropper, pos, inv) + if dropper:is_player() then + -- Return to main inventory + if inv:room_for_item("main", itemstack) then + inv:add_item("main", itemstack) + else + -- Drop item on the ground + local v = dropper:get_look_dir() + local p = {x=pos.x, y=pos.y+1.2, z=pos.z} + p.x = p.x+(math.random(1,3)*0.2) + p.z = p.z+(math.random(1,3)*0.2) + local obj = minetest.add_item(p, itemstack) + if obj then + v.x = v.x*4 + v.y = v.y*4 + 2 + v.z = v.z*4 + obj:set_velocity(v) + obj:get_luaentity()._insta_collect = false + end + end + else + -- Fallback for unexpected cases + minetest.add_item(pos, itemstack) end -}) + return itemstack +end + +-- Return items in the given inventory list (name) to the main inventory, or drop them if there is no space left +function return_fields(player, name) + local inv = player:get_inventory() + local list = inv:get_list(name) + if not list then return end + for i,stack in ipairs(list) do + return_item(stack, player, player:get_pos(), inv) + stack:clear() + inv:set_stack(name, i, stack) + end +end + +local function set_inventory(player, armor_change_only) + if minetest.is_creative_enabled(player:get_player_name()) then + if armor_change_only then + -- Stay on survival inventory plage if only the armor has been changed + mcl_inventory.set_creative_formspec(player, 0, 0, nil, nil, "inv") + else + mcl_inventory.set_creative_formspec(player, 0, 1) + end + return + end + local inv = player:get_inventory() + inv:set_width("craft", 2) + inv:set_size("craft", 4) + + local armor_slots = {"helmet", "chestplate", "leggings", "boots"} + local armor_slot_imgs = "" + for a=1,4 do + if inv:get_stack("armor", a+1):is_empty() then + armor_slot_imgs = armor_slot_imgs .. "image[0,"..(a-1)..";1,1;mcl_inventory_empty_armor_slot_"..armor_slots[a]..".png]" + end + end + + if inv:get_stack("offhand", 1):is_empty() then + armor_slot_imgs = armor_slot_imgs .. "image[3,2;1,1;mcl_inventory_empty_armor_slot_shield.png]" + end + + local form = "size[9,8.75]".. + "background[-0.19,-0.25;9.41,9.49;crafting_formspec_bg.png]".. + mcl_player.get_player_formspec_model(player, 1.0, 0.0, 2.25, 4.5, "").. + --armor + "list[current_player;armor;0,0;1,1;1]".. + "list[current_player;armor;0,1;1,1;2]".. + "list[current_player;armor;0,2;1,1;3]".. + "list[current_player;armor;0,3;1,1;4]".. + mcl_formspec.get_itemslot_bg(0,0,1,1).. + mcl_formspec.get_itemslot_bg(0,1,1,1).. + mcl_formspec.get_itemslot_bg(0,2,1,1).. + mcl_formspec.get_itemslot_bg(0,3,1,1).. + "list[current_player;offhand;3,2;1,1]".. + mcl_formspec.get_itemslot_bg(3,2,1,1).. + armor_slot_imgs.. + -- craft and inventory + "label[0,4;"..F(minetest.colorize("#313131", S("Inventory"))).."]".. + "list[current_player;main;0,4.5;9,3;9]".. + "list[current_player;main;0,7.74;9,1;]".. + "label[4,0.5;"..F(minetest.colorize("#313131", S("Crafting"))).."]".. + "list[current_player;craft;4,1;2,2]".. + "list[current_player;craftpreview;7,1.5;1,1;]".. + mcl_formspec.get_itemslot_bg(0,4.5,9,3).. + mcl_formspec.get_itemslot_bg(0,7.74,9,1).. + mcl_formspec.get_itemslot_bg(4,1,2,2).. + mcl_formspec.get_itemslot_bg(7,1.5,1,1).. + -- crafting guide button + "image_button[4.5,3;1,1;craftguide_book.png;__mcl_craftguide;]".. + "tooltip[__mcl_craftguide;"..F(S("Recipe book")).."]".. + -- help button + "image_button[8,3;1,1;doc_button_icon_lores.png;__mcl_doc;]".. + "tooltip[__mcl_doc;"..F(S("Help")).."]".. + -- skins button + "image_button[3,3;1,1;mcl_skins_button.png;__mcl_skins;]".. + "tooltip[__mcl_skins;"..F(S("Select player skin")).."]".. + -- achievements button + "image_button[7,3;1,1;mcl_achievements_button.png;__mcl_achievements;]".. + "tooltip[__mcl_achievements;"..F(S("Achievements")).."]".. + -- for shortcuts + "listring[current_player;main]".. + "listring[current_player;armor]".. + "listring[current_player;main]" .. + "listring[current_player;craft]" .. + "listring[current_player;main]" + player:set_inventory_formspec(form) +end + +-- Drop items in craft grid and reset inventory on closing +minetest.register_on_player_receive_fields(function(player, formname, fields) + if fields.quit then + return_fields(player,"craft") + return_fields(player,"enchanting_lapis") + return_fields(player,"enchanting_item") + if not minetest.is_creative_enabled(player:get_player_name()) and (formname == "" or formname == "main") then + set_inventory(player) + end + end +end) + +if not minetest.is_creative_enabled("") then + function mcl_inventory.update_inventory_formspec(player) + set_inventory(player) + end +end + +-- Drop crafting grid items on leaving +minetest.register_on_leaveplayer(function(player) + return_fields(player, "craft") + return_fields(player, "enchanting_lapis") + return_fields(player, "enchanting_item") +end) + +minetest.register_on_joinplayer(function(player) + --init inventory + local inv = player:get_inventory() + inv:set_width("main", 9) + inv:set_size("main", 36) + inv:set_size("offhand", 1) + + --set hotbar size + player:hud_set_hotbar_itemcount(9) + --add hotbar images + player:hud_set_hotbar_image("mcl_inventory_hotbar.png") + player:hud_set_hotbar_selected_image("mcl_inventory_hotbar_selected.png") + + local old_update_player = mcl_armor.update_player + function mcl_armor.update_player(player, info) + old_update_player(player, info) + set_inventory(player, true) + end + + -- In Creative Mode, the initial inventory setup is handled in creative.lua + if not minetest.is_creative_enabled(player:get_player_name()) then + set_inventory(player) + end + + --[[ Make sure the crafting grid is empty. Why? Because the player might have + items remaining in the crafting grid from the previous join; this is likely + when the server has been shutdown and the server didn't clean up the player + inventories. ]] + return_fields(player, "craft") + return_fields(player, "enchanting_item") + return_fields(player, "enchanting_lapis") +end) + + +dofile(minetest.get_modpath(minetest.get_current_modname()).."/creative.lua") + +local mt_is_creative_enabled = minetest.is_creative_enabled + +function minetest.is_creative_enabled(name) + if mt_is_creative_enabled(name) then return true end + local p = minetest.get_player_by_name(name) + if p then + return p:get_meta():get_string("gamemode") == "creative" + end + return false +end + +local function in_table(n,h) + for k,v in pairs(h) do + if v == n then return true end + end + return false +end + +local gamemodes = { + "survival", + "creative" +} + +function mcl_inventory.player_set_gamemode(p,g) + local m = p:get_meta() + m:set_string("gamemode",g) + set_inventory(p) +end + +minetest.register_chatcommand("gamemode",{ + params = S("[] []"), + description = S("Change gamemode (survival/creative) for yourself or player"), + privs = { server = true }, + func = function(n,param) + -- Full input validation ( just for @erlehmann <3 ) + local p = minetest.get_player_by_name(n) + local args = param:split(" ") + if args[2] ~= nil then + p = minetest.get_player_by_name(args[2]) + end + if not p then + return false, S("Player not online") + end + if args[1] ~= nil and not in_table(args[1],gamemodes) then + return false, S("Gamemode " .. args[1] .. " does not exist.") + elseif args[1] ~= nil then + mcl_inventory.player_set_gamemode(p,args[1]) + end + --Result message - show effective game mode + local gm = p:get_meta():get_string("gamemode") + if gm == "" then gm = gamemodes[1] end + return true, S("Gamemode for player ")..n..S(": "..gm) + end +}) diff --git a/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua b/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua index 0cd0608c4..0d677318f 100644 --- a/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua +++ b/mods/ITEMS/REDSTONE/mcl_dispensers/init.lua @@ -133,7 +133,7 @@ local dispenserdef = { if not stackdef then return end - + local iname = stack:get_name() local igroups = stackdef.groups diff --git a/mods/ITEMS/mcl_beds/respawn_anchor.lua b/mods/ITEMS/mcl_beds/respawn_anchor.lua index f3dd0453f..469a8ba4f 100644 --- a/mods/ITEMS/mcl_beds/respawn_anchor.lua +++ b/mods/ITEMS/mcl_beds/respawn_anchor.lua @@ -90,9 +90,9 @@ for i=0,4 do minetest.register_craft({ --TODO: Please change this crafting recipe once crying obsidian is implemented! output = "mcl_beds:respawn_anchor", - recipe = { + recipe = { {"mcl_core:obsidian", "mcl_core:obsidian", "mcl_core:obsidian"}, {"mcl_nether:glowstone", "mcl_nether:glowstone", "mcl_nether:glowstone"}, - {"mcl_core:obsidian", "mcl_core:obsidian", "mcl_core:obsidian"} - } - }) + {"mcl_core:obsidian", "mcl_core:obsidian", "mcl_core:obsidian"} + } + }) diff --git a/mods/ITEMS/mcl_buckets/init.lua b/mods/ITEMS/mcl_buckets/init.lua index ff0b866da..85215caaf 100644 --- a/mods/ITEMS/mcl_buckets/init.lua +++ b/mods/ITEMS/mcl_buckets/init.lua @@ -314,7 +314,7 @@ controls.register_on_press(function(player, key) end wielded_item = on_place_bucket(wielded_item, player, pointed_thing, def) end - + player:set_wielded_item(wielded_item) end) diff --git a/mods/ITEMS/mcl_cake/init.lua b/mods/ITEMS/mcl_cake/init.lua index f3a69f413..1b0824e77 100644 --- a/mods/ITEMS/mcl_cake/init.lua +++ b/mods/ITEMS/mcl_cake/init.lua @@ -1,156 +1,156 @@ ---[[ -#!#!#!#Cake mod created by Jordan4ibanez#!#!# -#!#!#!#Released under CC Attribution-ShareAlike 3.0 Unported #!#!# -]]-- - -local CAKE_HUNGER_POINTS = 2 - -local S = minetest.get_translator(minetest.get_current_modname()) - -local cake_texture = {"cake_top.png","cake_bottom.png","cake_inner.png","cake_side.png","cake_side.png","cake_side.png"} -local slice_1 = { -7/16, -8/16, -7/16, -5/16, 0/16, 7/16} -local slice_2 = { -7/16, -8/16, -7/16, -3/16, 0/16, 7/16} -local slice_3 = { -7/16, -8/16, -7/16, -1/16, 0/16, 7/16} -local slice_4 = { -7/16, -8/16, -7/16, 1/16, 0/16, 7/16} -local slice_5 = { -7/16, -8/16, -7/16, 3/16, 0/16, 7/16} -local slice_6 = { -7/16, -8/16, -7/16, 5/16, 0/16, 7/16} - -local full_cake = { -7/16, -8/16, -7/16, 7/16, 0/16, 7/16} - -minetest.register_craft({ - output = "mcl_cake:cake", - recipe = { - {"mcl_mobitems:milk_bucket", "mcl_mobitems:milk_bucket", "mcl_mobitems:milk_bucket"}, - {"mcl_core:sugar", "mcl_throwing:egg", "mcl_core:sugar"}, - {"mcl_farming:wheat_item", "mcl_farming:wheat_item", "mcl_farming:wheat_item"}, - }, - replacements = { - {"mcl_mobitems:milk_bucket", "mcl_buckets:bucket_empty"}, - {"mcl_mobitems:milk_bucket", "mcl_buckets:bucket_empty"}, - {"mcl_mobitems:milk_bucket", "mcl_buckets:bucket_empty"}, - }, -}) - -minetest.register_node("mcl_cake:cake", { - description = S("Cake"), - _tt_help = S("With 7 tasty slices!").."\n"..S("Hunger points: +@1 per slice", CAKE_HUNGER_POINTS), - _doc_items_longdesc = S("Cakes can be placed and eaten to restore hunger points. A cake has 7 slices. Each slice restores 2 hunger points and 0.4 saturation points. Cakes will be destroyed when dug or when the block below them is broken."), - _doc_items_usagehelp = S("Place the cake anywhere, then rightclick it to eat a single slice. You can't eat from the cake when your hunger bar is full."), - tiles = {"cake_top.png","cake_bottom.png","cake_side.png","cake_side.png","cake_side.png","cake_side.png"}, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "opaque" or false, - inventory_image = "cake.png", - wield_image = "cake.png", - paramtype = "light", - is_ground_content = false, - drawtype = "nodebox", - selection_box = { - type = "fixed", - fixed = full_cake - }, - node_box = { - type = "fixed", - fixed = full_cake - }, - stack_max = 1, - groups = { - handy = 1, attached_node = 1, dig_by_piston = 1, comparator_signal = 14, - cake = 7, food = 2, no_eat_delay = 1, compostability = 100 - }, - drop = "", - on_rightclick = function(pos, node, clicker, itemstack) - -- Cake is subject to protection - local name = clicker:get_player_name() - if minetest.is_protected(pos, name) then - minetest.record_protection_violation(pos, name) - return - end - local newcake = minetest.do_item_eat(2, ItemStack("mcl_cake:cake_6"), ItemStack("mcl_cake:cake"), clicker, {type="nothing"}) - -- Check if we were allowed to eat - if newcake:get_name() ~= "mcl_cake:cake" or minetest.is_creative_enabled(clicker:get_player_name()) then - minetest.add_node(pos,{type="node",name="mcl_cake:cake_6",param2=0}) - end - end, - sounds = mcl_sounds.node_sound_leaves_defaults(), - - _food_particles = false, - _mcl_saturation = 0.4, - _mcl_blast_resistance = 0.5, - _mcl_hardness = 0.5, -}) - -local register_slice = function(level, nodebox, desc) - local this = "mcl_cake:cake_"..level - local after_eat = "mcl_cake:cake_"..(level-1) - local on_rightclick - if level > 1 then - on_rightclick = function(pos, node, clicker, itemstack) - local name = clicker:get_player_name() - if minetest.is_protected(pos, name) then - minetest.record_protection_violation(pos, name) - return - end - local newcake = minetest.do_item_eat(CAKE_HUNGER_POINTS, ItemStack(after_eat), ItemStack(this), clicker, {type="nothing"}) - -- Check if we were allowed to eat - if newcake:get_name() ~= this or minetest.is_creative_enabled(clicker:get_player_name()) then - minetest.add_node(pos,{type="node",name=after_eat,param2=0}) - end - end - else - -- Last slice - on_rightclick = function(pos, node, clicker, itemstack) - local name = clicker:get_player_name() - if minetest.is_protected(pos, name) then - minetest.record_protection_violation(pos, name) - return - end - local newcake = minetest.do_item_eat(CAKE_HUNGER_POINTS, ItemStack("mcl:cake:cake 0"), ItemStack("mcl_cake:cake_1"), clicker, {type="nothing"}) - -- Check if we were allowed to eat - if newcake:get_name() ~= this or minetest.is_creative_enabled(clicker:get_player_name()) then - minetest.remove_node(pos) - minetest.check_for_falling(pos) - end - end - end - - minetest.register_node(this, { - description = desc, - _doc_items_create_entry = false, - tiles = cake_texture, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "opaque" or false, - paramtype = "light", - is_ground_content = false, - drawtype = "nodebox", - selection_box = { - type = "fixed", - fixed = nodebox, - }, - node_box = { - type = "fixed", - fixed = nodebox, - }, - groups = { - handy = 1, attached_node = 1, not_in_creative_inventory = 1, - dig_by_piston = 1, cake = level, comparator_signal = level * 2, - food = 2, no_eat_delay = 1 - }, - drop = "", - on_rightclick = on_rightclick, - sounds = mcl_sounds.node_sound_leaves_defaults(), - - _food_particles = false, - _mcl_saturation = 0.4, - _mcl_blast_resistance = 0.5, - _mcl_hardness = 0.5, - }) - - if minetest.get_modpath("doc") then - doc.add_entry_alias("nodes", "mcl_cake:cake", "nodes", "mcl_cake:cake_"..level) - end -end - -register_slice(6, slice_6, S("Cake (6 Slices Left)")) -register_slice(5, slice_5, S("Cake (5 Slices Left)")) -register_slice(4, slice_4, S("Cake (4 Slices Left)")) -register_slice(3, slice_3, S("Cake (3 Slices Left)")) -register_slice(2, slice_2, S("Cake (2 Slices Left)")) -register_slice(1, slice_1, S("Cake (1 Slice Left)")) +--[[ +#!#!#!#Cake mod created by Jordan4ibanez#!#!# +#!#!#!#Released under CC Attribution-ShareAlike 3.0 Unported #!#!# +]]-- + +local CAKE_HUNGER_POINTS = 2 + +local S = minetest.get_translator(minetest.get_current_modname()) + +local cake_texture = {"cake_top.png","cake_bottom.png","cake_inner.png","cake_side.png","cake_side.png","cake_side.png"} +local slice_1 = { -7/16, -8/16, -7/16, -5/16, 0/16, 7/16} +local slice_2 = { -7/16, -8/16, -7/16, -3/16, 0/16, 7/16} +local slice_3 = { -7/16, -8/16, -7/16, -1/16, 0/16, 7/16} +local slice_4 = { -7/16, -8/16, -7/16, 1/16, 0/16, 7/16} +local slice_5 = { -7/16, -8/16, -7/16, 3/16, 0/16, 7/16} +local slice_6 = { -7/16, -8/16, -7/16, 5/16, 0/16, 7/16} + +local full_cake = { -7/16, -8/16, -7/16, 7/16, 0/16, 7/16} + +minetest.register_craft({ + output = "mcl_cake:cake", + recipe = { + {"mcl_mobitems:milk_bucket", "mcl_mobitems:milk_bucket", "mcl_mobitems:milk_bucket"}, + {"mcl_core:sugar", "mcl_throwing:egg", "mcl_core:sugar"}, + {"mcl_farming:wheat_item", "mcl_farming:wheat_item", "mcl_farming:wheat_item"}, + }, + replacements = { + {"mcl_mobitems:milk_bucket", "mcl_buckets:bucket_empty"}, + {"mcl_mobitems:milk_bucket", "mcl_buckets:bucket_empty"}, + {"mcl_mobitems:milk_bucket", "mcl_buckets:bucket_empty"}, + }, +}) + +minetest.register_node("mcl_cake:cake", { + description = S("Cake"), + _tt_help = S("With 7 tasty slices!").."\n"..S("Hunger points: +@1 per slice", CAKE_HUNGER_POINTS), + _doc_items_longdesc = S("Cakes can be placed and eaten to restore hunger points. A cake has 7 slices. Each slice restores 2 hunger points and 0.4 saturation points. Cakes will be destroyed when dug or when the block below them is broken."), + _doc_items_usagehelp = S("Place the cake anywhere, then rightclick it to eat a single slice. You can't eat from the cake when your hunger bar is full."), + tiles = {"cake_top.png","cake_bottom.png","cake_side.png","cake_side.png","cake_side.png","cake_side.png"}, + use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "opaque" or false, + inventory_image = "cake.png", + wield_image = "cake.png", + paramtype = "light", + is_ground_content = false, + drawtype = "nodebox", + selection_box = { + type = "fixed", + fixed = full_cake + }, + node_box = { + type = "fixed", + fixed = full_cake + }, + stack_max = 1, + groups = { + handy = 1, attached_node = 1, dig_by_piston = 1, comparator_signal = 14, + cake = 7, food = 2, no_eat_delay = 1, compostability = 100 + }, + drop = "", + on_rightclick = function(pos, node, clicker, itemstack) + -- Cake is subject to protection + local name = clicker:get_player_name() + if minetest.is_protected(pos, name) then + minetest.record_protection_violation(pos, name) + return + end + local newcake = minetest.do_item_eat(2, ItemStack("mcl_cake:cake_6"), ItemStack("mcl_cake:cake"), clicker, {type="nothing"}) + -- Check if we were allowed to eat + if newcake:get_name() ~= "mcl_cake:cake" or minetest.is_creative_enabled(clicker:get_player_name()) then + minetest.add_node(pos,{type="node",name="mcl_cake:cake_6",param2=0}) + end + end, + sounds = mcl_sounds.node_sound_leaves_defaults(), + + _food_particles = false, + _mcl_saturation = 0.4, + _mcl_blast_resistance = 0.5, + _mcl_hardness = 0.5, +}) + +local register_slice = function(level, nodebox, desc) + local this = "mcl_cake:cake_"..level + local after_eat = "mcl_cake:cake_"..(level-1) + local on_rightclick + if level > 1 then + on_rightclick = function(pos, node, clicker, itemstack) + local name = clicker:get_player_name() + if minetest.is_protected(pos, name) then + minetest.record_protection_violation(pos, name) + return + end + local newcake = minetest.do_item_eat(CAKE_HUNGER_POINTS, ItemStack(after_eat), ItemStack(this), clicker, {type="nothing"}) + -- Check if we were allowed to eat + if newcake:get_name() ~= this or minetest.is_creative_enabled(clicker:get_player_name()) then + minetest.add_node(pos,{type="node",name=after_eat,param2=0}) + end + end + else + -- Last slice + on_rightclick = function(pos, node, clicker, itemstack) + local name = clicker:get_player_name() + if minetest.is_protected(pos, name) then + minetest.record_protection_violation(pos, name) + return + end + local newcake = minetest.do_item_eat(CAKE_HUNGER_POINTS, ItemStack("mcl:cake:cake 0"), ItemStack("mcl_cake:cake_1"), clicker, {type="nothing"}) + -- Check if we were allowed to eat + if newcake:get_name() ~= this or minetest.is_creative_enabled(clicker:get_player_name()) then + minetest.remove_node(pos) + minetest.check_for_falling(pos) + end + end + end + + minetest.register_node(this, { + description = desc, + _doc_items_create_entry = false, + tiles = cake_texture, + use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "opaque" or false, + paramtype = "light", + is_ground_content = false, + drawtype = "nodebox", + selection_box = { + type = "fixed", + fixed = nodebox, + }, + node_box = { + type = "fixed", + fixed = nodebox, + }, + groups = { + handy = 1, attached_node = 1, not_in_creative_inventory = 1, + dig_by_piston = 1, cake = level, comparator_signal = level * 2, + food = 2, no_eat_delay = 1 + }, + drop = "", + on_rightclick = on_rightclick, + sounds = mcl_sounds.node_sound_leaves_defaults(), + + _food_particles = false, + _mcl_saturation = 0.4, + _mcl_blast_resistance = 0.5, + _mcl_hardness = 0.5, + }) + + if minetest.get_modpath("doc") then + doc.add_entry_alias("nodes", "mcl_cake:cake", "nodes", "mcl_cake:cake_"..level) + end +end + +register_slice(6, slice_6, S("Cake (6 Slices Left)")) +register_slice(5, slice_5, S("Cake (5 Slices Left)")) +register_slice(4, slice_4, S("Cake (4 Slices Left)")) +register_slice(3, slice_3, S("Cake (3 Slices Left)")) +register_slice(2, slice_2, S("Cake (2 Slices Left)")) +register_slice(1, slice_1, S("Cake (1 Slice Left)")) diff --git a/mods/ITEMS/mcl_crafting_table/init.lua b/mods/ITEMS/mcl_crafting_table/init.lua index eae503eeb..7f6b9ccc5 100644 --- a/mods/ITEMS/mcl_crafting_table/init.lua +++ b/mods/ITEMS/mcl_crafting_table/init.lua @@ -1,70 +1,70 @@ -local S = minetest.get_translator(minetest.get_current_modname()) -local formspec_escape = minetest.formspec_escape -local show_formspec = minetest.show_formspec -local C = minetest.colorize -local text_color = "#313131" -local itemslot_bg = mcl_formspec.get_itemslot_bg - -mcl_crafting_table = {} - -function mcl_crafting_table.show_crafting_form(player) - player:get_inventory():set_width("craft", 3) - player:get_inventory():set_size("craft", 9) - - show_formspec(player:get_player_name(), "main", - "size[9,8.75]".. - "image[4.7,1.5;1.5,1;gui_crafting_arrow.png]".. - "label[0,4;"..formspec_escape(C(text_color, S("Inventory"))).."]".. - "list[current_player;main;0,4.5;9,3;9]".. - itemslot_bg(0,4.5,9,3).. - "list[current_player;main;0,7.74;9,1;]".. - itemslot_bg(0,7.74,9,1).. - "label[1.75,0;"..formspec_escape(C(text_color, S("Crafting"))).."]".. - "list[current_player;craft;1.75,0.5;3,3;]".. - itemslot_bg(1.75,0.5,3,3).. - "list[current_player;craftpreview;6.1,1.5;1,1;]".. - itemslot_bg(6.1,1.5,1,1).. - "image_button[0.75,1.5;1,1;craftguide_book.png;__mcl_craftguide;]".. - "tooltip[__mcl_craftguide;"..formspec_escape(S("Recipe book")).."]".. - "listring[current_player;main]".. - "listring[current_player;craft]" - ) -end - -minetest.register_node("mcl_crafting_table:crafting_table", { - description = S("Crafting Table"), - _tt_help = S("3×3 crafting grid"), - _doc_items_longdesc = S("A crafting table is a block which grants you access to a 3×3 crafting grid which allows you to perform advanced crafts."), - _doc_items_usagehelp = S("Rightclick the crafting table to access the 3×3 crafting grid."), - _doc_items_hidden = false, - is_ground_content = false, - tiles = {"crafting_workbench_top.png", "default_wood.png", "crafting_workbench_side.png", - "crafting_workbench_side.png", "crafting_workbench_front.png", "crafting_workbench_front.png"}, - paramtype2 = "facedir", - groups = {handy=1,axey=1, deco_block=1, material_wood=1,flammable=-1}, - on_rightclick = function(pos, node, player, itemstack) - if not player:get_player_control().sneak then - mcl_crafting_table.show_crafting_form(player) - end - end, - sounds = mcl_sounds.node_sound_wood_defaults(), - _mcl_blast_resistance = 2.5, - _mcl_hardness = 2.5, -}) - -minetest.register_craft({ - output = "mcl_crafting_table:crafting_table", - recipe = { - {"group:wood", "group:wood"}, - {"group:wood", "group:wood"} - } -}) - -minetest.register_craft({ - type = "fuel", - recipe = "mcl_crafting_table:crafting_table", - burntime = 15, -}) - -minetest.register_alias("crafting:workbench", "mcl_crafting_table:crafting_table") -minetest.register_alias("mcl_inventory:workbench", "mcl_crafting_table:crafting_table") +local S = minetest.get_translator(minetest.get_current_modname()) +local formspec_escape = minetest.formspec_escape +local show_formspec = minetest.show_formspec +local C = minetest.colorize +local text_color = "#313131" +local itemslot_bg = mcl_formspec.get_itemslot_bg + +mcl_crafting_table = {} + +function mcl_crafting_table.show_crafting_form(player) + player:get_inventory():set_width("craft", 3) + player:get_inventory():set_size("craft", 9) + + show_formspec(player:get_player_name(), "main", + "size[9,8.75]".. + "image[4.7,1.5;1.5,1;gui_crafting_arrow.png]".. + "label[0,4;"..formspec_escape(C(text_color, S("Inventory"))).."]".. + "list[current_player;main;0,4.5;9,3;9]".. + itemslot_bg(0,4.5,9,3).. + "list[current_player;main;0,7.74;9,1;]".. + itemslot_bg(0,7.74,9,1).. + "label[1.75,0;"..formspec_escape(C(text_color, S("Crafting"))).."]".. + "list[current_player;craft;1.75,0.5;3,3;]".. + itemslot_bg(1.75,0.5,3,3).. + "list[current_player;craftpreview;6.1,1.5;1,1;]".. + itemslot_bg(6.1,1.5,1,1).. + "image_button[0.75,1.5;1,1;craftguide_book.png;__mcl_craftguide;]".. + "tooltip[__mcl_craftguide;"..formspec_escape(S("Recipe book")).."]".. + "listring[current_player;main]".. + "listring[current_player;craft]" + ) +end + +minetest.register_node("mcl_crafting_table:crafting_table", { + description = S("Crafting Table"), + _tt_help = S("3×3 crafting grid"), + _doc_items_longdesc = S("A crafting table is a block which grants you access to a 3×3 crafting grid which allows you to perform advanced crafts."), + _doc_items_usagehelp = S("Rightclick the crafting table to access the 3×3 crafting grid."), + _doc_items_hidden = false, + is_ground_content = false, + tiles = {"crafting_workbench_top.png", "default_wood.png", "crafting_workbench_side.png", + "crafting_workbench_side.png", "crafting_workbench_front.png", "crafting_workbench_front.png"}, + paramtype2 = "facedir", + groups = {handy=1,axey=1, deco_block=1, material_wood=1,flammable=-1}, + on_rightclick = function(pos, node, player, itemstack) + if not player:get_player_control().sneak then + mcl_crafting_table.show_crafting_form(player) + end + end, + sounds = mcl_sounds.node_sound_wood_defaults(), + _mcl_blast_resistance = 2.5, + _mcl_hardness = 2.5, +}) + +minetest.register_craft({ + output = "mcl_crafting_table:crafting_table", + recipe = { + {"group:wood", "group:wood"}, + {"group:wood", "group:wood"} + } +}) + +minetest.register_craft({ + type = "fuel", + recipe = "mcl_crafting_table:crafting_table", + burntime = 15, +}) + +minetest.register_alias("crafting:workbench", "mcl_crafting_table:crafting_table") +minetest.register_alias("mcl_inventory:workbench", "mcl_crafting_table:crafting_table") diff --git a/mods/ITEMS/mcl_doors/api_doors.lua b/mods/ITEMS/mcl_doors/api_doors.lua index 7d00c4c69..c2fc7c377 100644 --- a/mods/ITEMS/mcl_doors/api_doors.lua +++ b/mods/ITEMS/mcl_doors/api_doors.lua @@ -1,559 +1,559 @@ -local S = minetest.get_translator(minetest.get_current_modname()) -local minetest_get_meta = minetest.get_meta - --- This helper function calls on_place_node callbacks. -local function on_place_node(place_to, newnode, - placer, oldnode, itemstack, pointed_thing) - -- Run script hook - for _, callback in pairs(minetest.registered_on_placenodes) do - -- Deep-copy pos, node and pointed_thing because callback can modify them - local place_to_copy = {x = place_to.x, y = place_to.y, z = place_to.z} - local newnode_copy = - {name = newnode.name, param1 = newnode.param1, param2 = newnode.param2} - local oldnode_copy = - {name = oldnode.name, param1 = oldnode.param1, param2 = oldnode.param2} - local pointed_thing_copy = { - type = pointed_thing.type, - above = vector.new(pointed_thing.above), - under = vector.new(pointed_thing.under), - ref = pointed_thing.ref, - } - callback(place_to_copy, newnode_copy, placer, - oldnode_copy, itemstack, pointed_thing_copy) - end -end - --- Registers a door --- name: The name of the door --- def: a table with the folowing fields: --- description --- inventory_image --- groups --- tiles_bottom: the tiles of the bottom part of the door {front, side} --- tiles_top: the tiles of the bottom part of the door {front, side} --- If the following fields are not defined the default values are used --- node_box_bottom --- node_box_top --- selection_box_bottom --- selection_box_top --- only_placer_can_open: if true only the player who placed the door can --- open it --- only_redstone_can_open: if true, the door can only be opened by redstone, --- not by rightclicking it - -function mcl_doors:register_door(name, def) - def.groups.not_in_creative_inventory = 1 - def.groups.dig_by_piston = 1 - def.groups.door = 1 - def.groups.mesecon_ignore_opaque_dig = 1 - - if not def.sound_open then - def.sound_open = "doors_door_open" - end - if not def.sound_close then - def.sound_close = "doors_door_close" - end - - local box = {{-8/16, -8/16, -8/16, 8/16, 8/16, -5/16}} - - if not def.node_box_bottom then - def.node_box_bottom = box - end - if not def.node_box_top then - def.node_box_top = box - end - if not def.selection_box_bottom then - def.selection_box_bottom= box - end - if not def.selection_box_top then - def.selection_box_top = box - end - - local longdesc, usagehelp, tt_help - tt_help = def._tt_help - longdesc = def._doc_items_longdesc - if not longdesc then - if def.only_redstone_can_open then - longdesc = S("This door is a 2-block high barrier which can be opened or closed by hand or by redstone power.") - else - longdesc = S("This door is a 2-block high barrier which can only be opened by redstone power, not by hand.") - end - end - usagehelp = def._doc_items_usagehelp - if not usagehelp then - if def.only_redstone_can_open then - usagehelp = S("To open or close this door, send a redstone signal to its bottom half.") - else - usagehelp = S("To open or close this door, rightclick it or send a redstone signal to its bottom half.") - end - end - if not tt_help then - if def.only_redstone_can_open then - tt_help = S("Openable by redstone power") - else - tt_help = S("Openable by players and redstone power") - end - end - - local craftitem_groups = { mesecon_conductor_craftable = 1, deco_block = 1 } - if def.groups and def.groups.flammable then - craftitem_groups.flammable = def.groups.flammable - end - - minetest.register_craftitem(name, { - description = def.description, - _tt_help = tt_help, - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usagehelp, - inventory_image = def.inventory_image, - stack_max = 64, - groups = craftitem_groups, - on_place = function(itemstack, placer, pointed_thing) - if not pointed_thing.type == "node" or not placer or not placer:is_player() then - return itemstack - end - local pn = placer:get_player_name() - if minetest.is_protected(pointed_thing.above, pn) and minetest.is_protected(pointed_thing.under, pn) then - return itemstack - end - local ptu = pointed_thing.under - local nu = minetest.get_node(ptu) - -- Pointed thing's rightclick action takes precedence, unless player holds down the sneak key - if minetest.registered_nodes[nu.name] and minetest.registered_nodes[nu.name].on_rightclick and not placer:get_player_control().sneak then - return minetest.registered_nodes[nu.name].on_rightclick(ptu, nu, placer, itemstack) - end - - local pt - if minetest.registered_nodes[nu.name] and minetest.registered_nodes[nu.name].buildable_to then - pt = pointed_thing.under - else - pt = pointed_thing.above - end - local pt2 = {x=pt.x, y=pt.y, z=pt.z} - pt2.y = pt2.y+1 - local ptname = minetest.get_node(pt).name - local pt2name = minetest.get_node(pt2).name - if - (minetest.registered_nodes[ptname] and not minetest.registered_nodes[ptname].buildable_to) or - (minetest.registered_nodes[pt2name] and not minetest.registered_nodes[pt2name].buildable_to) - then - return itemstack - end - - -- get left coordinate for checking if another door is there - local pt_left = {x=pt.x, y=pt.y, z=pt.z} - local p2 = minetest.dir_to_facedir(placer:get_look_dir()) - - if p2 == 0 then - pt_left.x = pt_left.x-1 - elseif p2 == 1 then - pt_left.z = pt_left.z+1 - elseif p2 == 2 then - pt_left.x = pt_left.x+1 - elseif p2 == 3 then - pt_left.z = pt_left.z-1 - end - - local left_node = minetest.get_node(pt_left) - - -- Set door nodes - minetest.set_node(pt, {name=name.."_b_1", param2=p2}) - minetest.set_node(pt2, {name=name.."_t_1", param2=p2}) - - if def.sounds and def.sounds.place then - minetest.sound_play(def.sounds.place, {pos=pt}, true) - end - - if def.only_placer_can_open then - local meta = minetest_get_meta(pt) - meta:set_string("doors_owner", "") - meta = minetest_get_meta(pt2) - meta:set_string("doors_owner", "") - end - - local meta1 = minetest_get_meta(pt) - local meta2 = minetest_get_meta(pt2) - -- save mirror state for the correct door - if left_node.name:sub(1, #name) == name then - meta1:set_int("is_mirrored", 1) - meta2:set_int("is_mirrored", 1) - end - - -- Save open state. 1 = open. 0 = closed - meta1:set_int("is_open", 0) - meta2:set_int("is_open", 0) - - - if not minetest.is_creative_enabled(pn) then - itemstack:take_item() - end - - on_place_node(pt, minetest.get_node(pt), placer, nu, itemstack, pointed_thing) - on_place_node(pt2, minetest.get_node(pt2), placer, minetest.get_node({x=ptu.x,y=ptu.y+1,z=ptu.z}), itemstack, pointed_thing) - - return itemstack - end, - }) - - local tt = def.tiles_top - local tb = def.tiles_bottom - - local function on_open_close(pos, dir, check_name, replace, replace_dir) - local meta1 = minetest_get_meta(pos) - pos.y = pos.y+dir - local meta2 = minetest_get_meta(pos) - - -- if name of other door is not the same as check_name -> return - if not minetest.get_node(pos).name == check_name then - return - end - - -- swap directions if mirrored - local params = {3,0,1,2} - if meta1:get_int("is_open") == 0 and meta2:get_int("is_mirrored") == 0 or meta1:get_int("is_open") == 1 and meta2:get_int("is_mirrored") == 1 then - params = {1,2,3,0} - end - - local p2 = minetest.get_node(pos).param2 - local np2 = params[p2+1] - - minetest.swap_node(pos, {name=replace_dir, param2=np2}) - pos.y = pos.y-dir - minetest.swap_node(pos, {name=replace, param2=np2}) - - local door_switching_sound - if meta1:get_int("is_open") == 1 then - door_switching_sound = def.sound_close - meta1:set_int("is_open", 0) - meta2:set_int("is_open", 0) - else - door_switching_sound = def.sound_open - meta1:set_int("is_open", 1) - meta2:set_int("is_open", 1) - end - minetest.sound_play(door_switching_sound, {pos = pos, gain = 0.5, max_hear_distance = 16}, true) - end - - local function on_mesecons_signal_open(pos, node) - on_open_close(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2") - end - local function on_mesecons_signal_close(pos, node) - if not mesecon.is_powered({x=pos.x,y=pos.y+1,z=pos.z}) then - on_open_close(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1") - end - end - local function on_mesecons_signal_open_top(pos, node) - on_mesecons_signal_open({x=pos.x, y=pos.y-1, z=pos.z}, node) - end - local function on_mesecons_signal_close_top(pos, node) - if not mesecon.is_powered({x=pos.x,y=pos.y-1,z=pos.z}) then - on_mesecons_signal_close({x=pos.x, y=pos.y-1, z=pos.z}, node) - end - end - - local function check_player_priv(pos, player) - if not def.only_placer_can_open then - return true - end - local meta = minetest_get_meta(pos) - local pn = player:get_player_name() - return meta:get_string("doors_owner") == pn - end - - local on_rightclick - -- Disable on_rightclick if this is a redstone-only door - if not def.only_redstone_can_open then - on_rightclick = function(pos, node, clicker) - if check_player_priv(pos, clicker) then - on_open_close(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2") - end - end - end - - minetest.register_node(name.."_b_1", { - tiles = {"blank.png", tt[2].."^[transformFXR90", tb[2], tb[2].."^[transformFX", tb[1], tb[1].."^[transformFX"}, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, - paramtype = "light", - paramtype2 = "facedir", - sunlight_propagates = true, - is_ground_content = false, - drop = "", - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = def.node_box_bottom - }, - selection_box = { - type = "fixed", - fixed = def.selection_box_bottom - }, - groups = def.groups, - _mcl_hardness = def._mcl_hardness, - _mcl_blast_resistance = def._mcl_blast_resistance, - sounds = def.sounds, - - after_destruct = function(bottom, oldnode) - local meta_bottom = minetest_get_meta(bottom) - if meta_bottom:get_int("rotation") == 1 then - meta_bottom:set_int("rotation", 0) - else - minetest.add_item(bottom, name) - local top = { x = bottom.x, y = bottom.y + 1, z = bottom.z } - if minetest.get_node(bottom).name ~= name.."_b_2" and minetest.get_node(top).name == name.."_t_1" then - minetest.remove_node(top) - end - end - end, - - on_rightclick = on_rightclick, - - mesecons = { effector = { - action_on = on_mesecons_signal_open, - }}, - - on_rotate = function(bottom, node, user, mode, param2) - if mode == screwdriver.ROTATE_FACE then - local meta_bottom = minetest_get_meta(bottom) - meta_bottom:set_int("rotation", 1) - node.param2 = screwdriver.rotate.facedir(bottom, node, mode) - minetest.swap_node(bottom, node) - - local top = {x=bottom.x,y=bottom.y+1,z=bottom.z} - local meta_top = minetest_get_meta(top) - meta_top:set_int("rotation", 1) - node.name = name .."_t_1" - minetest.swap_node(top, node) - - return true - end - return false - end, - - can_dig = check_player_priv, - }) - - if def.only_redstone_can_open then - on_rightclick = nil - else - on_rightclick = function(pos, node, clicker) - if check_player_priv(pos, clicker) then - on_open_close(pos, -1, name.."_b_1", name.."_t_2", name.."_b_2") - end - end - end - - minetest.register_node(name.."_t_1", { - tiles = {tt[2].."^[transformR90", "blank.png", tt[2], tt[2].."^[transformFX", tt[1], tt[1].."^[transformFX"}, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, - paramtype = "light", - paramtype2 = "facedir", - sunlight_propagates = true, - is_ground_content = false, - drop = "", - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = def.node_box_top - }, - selection_box = { - type = "fixed", - fixed = def.selection_box_top - }, - groups = def.groups, - _mcl_hardness = def._mcl_hardness, - _mcl_blast_resistance = def._mcl_blast_resistance, - sounds = def.sounds, - - after_destruct = function(top, oldnode) - local meta_top = minetest_get_meta(top) - if meta_top:get_int("rotation") == 1 then - meta_top:set_int("rotation", 0) - else - local bottom = { x = top.x, y = top.y - 1, z = top.z } - if minetest.get_node(top).name ~= name.."_t_2" and minetest.get_node(bottom).name == name.."_b_1" and oldnode.name == name.."_t_1" then - minetest.dig_node(bottom) - end - end - end, - - on_rightclick = on_rightclick, - - mesecons = { effector = { - action_on = on_mesecons_signal_open_top, - rules = mesecon.rules.flat, - }}, - - on_rotate = function(top, node, user, mode, param2) - if mode == screwdriver.ROTATE_FACE then - local meta_top = minetest_get_meta(top) - meta_top:set_int("rotation", 1) - node.param2 = screwdriver.rotate.facedir(top, node, mode) - minetest.swap_node(top, node) - - local bottom = {x=top.x,y=top.y-1,z=top.z} - local meta_bottom = minetest_get_meta(bottom) - meta_bottom:set_int("rotation", 1) - node.name = name .."_b_1" - minetest.swap_node(bottom, node) - - return true - end - return false - end, - - can_dig = check_player_priv, - }) - - if def.only_redstone_can_open then - on_rightclick = nil - else - on_rightclick = function(pos, node, clicker) - if check_player_priv(pos, clicker) then - on_open_close(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1") - end - end - end - - minetest.register_node(name.."_b_2", { - tiles = {"blank.png", tt[2].."^[transformFXR90", tb[2].."^[transformI", tb[2].."^[transformFX", tb[1].."^[transformFX", tb[1]}, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, - paramtype = "light", - paramtype2 = "facedir", - sunlight_propagates = true, - is_ground_content = false, - drop = "", - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = def.node_box_bottom - }, - selection_box = { - type = "fixed", - fixed = def.selection_box_bottom - }, - groups = def.groups, - _mcl_hardness = def._mcl_hardness, - _mcl_blast_resistance = def._mcl_blast_resistance, - sounds = def.sounds, - - after_destruct = function(bottom, oldnode) - local meta_bottom = minetest_get_meta(bottom) - if meta_bottom:get_int("rotation") == 1 then - meta_bottom:set_int("rotation", 0) - else - local top = { x = bottom.x, y = bottom.y + 1, z = bottom.z } - minetest.add_item(bottom, name) - if minetest.get_node(bottom).name ~= name.."_b_1" and minetest.get_node(top).name == name.."_t_2" then - minetest.remove_node(top) - end - end - end, - - on_rightclick = on_rightclick, - - mesecons = { effector = { - action_off = on_mesecons_signal_close, - }}, - - on_rotate = function(bottom, node, user, mode, param2) - if mode == screwdriver.ROTATE_FACE then - local meta_bottom = minetest_get_meta(bottom) - meta_bottom:set_int("rotation", 1) - node.param2 = screwdriver.rotate.facedir(bottom, node, mode) - minetest.swap_node(bottom, node) - - local top = {x=bottom.x,y=bottom.y+1,z=bottom.z} - local meta_top = minetest_get_meta(top) - meta_top:set_int("rotation", 1) - node.name = name .."_t_2" - minetest.swap_node(top, node) - - return true - end - return false - end, - - can_dig = check_player_priv, - }) - - if def.only_redstone_can_open then - on_rightclick = nil - else - on_rightclick = function(pos, node, clicker) - if check_player_priv(pos, clicker) then - on_open_close(pos, -1, name.."_b_2", name.."_t_1", name.."_b_1") - end - end - end - - minetest.register_node(name.."_t_2", { - tiles = {tt[2].."^[transformR90", "blank.png", tt[2].."^[transformI", tt[2].."^[transformFX", tt[1].."^[transformFX", tt[1]}, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, - paramtype = "light", - paramtype2 = "facedir", - sunlight_propagates = true, - is_ground_content = false, - drop = "", - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = def.node_box_top - }, - selection_box = { - type = "fixed", - fixed = def.selection_box_top - }, - groups = def.groups, - _mcl_hardness = def._mcl_hardness, - _mcl_blast_resistance = def._mcl_blast_resistance, - sounds = def.sounds, - - after_destruct = function(top, oldnode) - local meta_top = minetest_get_meta(top) - if meta_top:get_int("rotation") == 1 then - meta_top:set_int("rotation", 0) - else - local bottom = { x = top.x, y = top.y - 1, z = top.z } - if minetest.get_node(top).name ~= name.."_t_1" and minetest.get_node(bottom).name == name.."_b_2" and oldnode.name == name.."_t_2" then - minetest.dig_node(bottom) - end - end - end, - - on_rightclick = on_rightclick, - - mesecons = { effector = { - action_off = on_mesecons_signal_close_top, - rules = mesecon.rules.flat, - }}, - - on_rotate = function(top, node, user, mode, param2) - if mode == screwdriver.ROTATE_FACE then - local meta_top = minetest_get_meta(top) - meta_top:set_int("rotation", 1) - node.param2 = screwdriver.rotate.facedir(top, node, mode) - minetest.swap_node(top, node) - - local bottom = {x=top.x,y=top.y-1,z=top.z} - local meta_bottom = minetest_get_meta(bottom) - meta_bottom:set_int("rotation", 1) - node.name = name .."_b_2" - minetest.swap_node(bottom, node) - - return true - end - return false - end, - - can_dig = check_player_priv, - }) - - -- Add entry aliases for the Help - if minetest.get_modpath("doc") then - doc.add_entry_alias("craftitems", name, "nodes", name.."_b_1") - doc.add_entry_alias("craftitems", name, "nodes", name.."_b_2") - doc.add_entry_alias("craftitems", name, "nodes", name.."_t_1") - doc.add_entry_alias("craftitems", name, "nodes", name.."_t_2") - end - -end +local S = minetest.get_translator(minetest.get_current_modname()) +local minetest_get_meta = minetest.get_meta + +-- This helper function calls on_place_node callbacks. +local function on_place_node(place_to, newnode, + placer, oldnode, itemstack, pointed_thing) + -- Run script hook + for _, callback in pairs(minetest.registered_on_placenodes) do + -- Deep-copy pos, node and pointed_thing because callback can modify them + local place_to_copy = {x = place_to.x, y = place_to.y, z = place_to.z} + local newnode_copy = + {name = newnode.name, param1 = newnode.param1, param2 = newnode.param2} + local oldnode_copy = + {name = oldnode.name, param1 = oldnode.param1, param2 = oldnode.param2} + local pointed_thing_copy = { + type = pointed_thing.type, + above = vector.new(pointed_thing.above), + under = vector.new(pointed_thing.under), + ref = pointed_thing.ref, + } + callback(place_to_copy, newnode_copy, placer, + oldnode_copy, itemstack, pointed_thing_copy) + end +end + +-- Registers a door +-- name: The name of the door +-- def: a table with the folowing fields: +-- description +-- inventory_image +-- groups +-- tiles_bottom: the tiles of the bottom part of the door {front, side} +-- tiles_top: the tiles of the bottom part of the door {front, side} +-- If the following fields are not defined the default values are used +-- node_box_bottom +-- node_box_top +-- selection_box_bottom +-- selection_box_top +-- only_placer_can_open: if true only the player who placed the door can +-- open it +-- only_redstone_can_open: if true, the door can only be opened by redstone, +-- not by rightclicking it + +function mcl_doors:register_door(name, def) + def.groups.not_in_creative_inventory = 1 + def.groups.dig_by_piston = 1 + def.groups.door = 1 + def.groups.mesecon_ignore_opaque_dig = 1 + + if not def.sound_open then + def.sound_open = "doors_door_open" + end + if not def.sound_close then + def.sound_close = "doors_door_close" + end + + local box = {{-8/16, -8/16, -8/16, 8/16, 8/16, -5/16}} + + if not def.node_box_bottom then + def.node_box_bottom = box + end + if not def.node_box_top then + def.node_box_top = box + end + if not def.selection_box_bottom then + def.selection_box_bottom= box + end + if not def.selection_box_top then + def.selection_box_top = box + end + + local longdesc, usagehelp, tt_help + tt_help = def._tt_help + longdesc = def._doc_items_longdesc + if not longdesc then + if def.only_redstone_can_open then + longdesc = S("This door is a 2-block high barrier which can be opened or closed by hand or by redstone power.") + else + longdesc = S("This door is a 2-block high barrier which can only be opened by redstone power, not by hand.") + end + end + usagehelp = def._doc_items_usagehelp + if not usagehelp then + if def.only_redstone_can_open then + usagehelp = S("To open or close this door, send a redstone signal to its bottom half.") + else + usagehelp = S("To open or close this door, rightclick it or send a redstone signal to its bottom half.") + end + end + if not tt_help then + if def.only_redstone_can_open then + tt_help = S("Openable by redstone power") + else + tt_help = S("Openable by players and redstone power") + end + end + + local craftitem_groups = { mesecon_conductor_craftable = 1, deco_block = 1 } + if def.groups and def.groups.flammable then + craftitem_groups.flammable = def.groups.flammable + end + + minetest.register_craftitem(name, { + description = def.description, + _tt_help = tt_help, + _doc_items_longdesc = longdesc, + _doc_items_usagehelp = usagehelp, + inventory_image = def.inventory_image, + stack_max = 64, + groups = craftitem_groups, + on_place = function(itemstack, placer, pointed_thing) + if not pointed_thing.type == "node" or not placer or not placer:is_player() then + return itemstack + end + local pn = placer:get_player_name() + if minetest.is_protected(pointed_thing.above, pn) and minetest.is_protected(pointed_thing.under, pn) then + return itemstack + end + local ptu = pointed_thing.under + local nu = minetest.get_node(ptu) + -- Pointed thing's rightclick action takes precedence, unless player holds down the sneak key + if minetest.registered_nodes[nu.name] and minetest.registered_nodes[nu.name].on_rightclick and not placer:get_player_control().sneak then + return minetest.registered_nodes[nu.name].on_rightclick(ptu, nu, placer, itemstack) + end + + local pt + if minetest.registered_nodes[nu.name] and minetest.registered_nodes[nu.name].buildable_to then + pt = pointed_thing.under + else + pt = pointed_thing.above + end + local pt2 = {x=pt.x, y=pt.y, z=pt.z} + pt2.y = pt2.y+1 + local ptname = minetest.get_node(pt).name + local pt2name = minetest.get_node(pt2).name + if + (minetest.registered_nodes[ptname] and not minetest.registered_nodes[ptname].buildable_to) or + (minetest.registered_nodes[pt2name] and not minetest.registered_nodes[pt2name].buildable_to) + then + return itemstack + end + + -- get left coordinate for checking if another door is there + local pt_left = {x=pt.x, y=pt.y, z=pt.z} + local p2 = minetest.dir_to_facedir(placer:get_look_dir()) + + if p2 == 0 then + pt_left.x = pt_left.x-1 + elseif p2 == 1 then + pt_left.z = pt_left.z+1 + elseif p2 == 2 then + pt_left.x = pt_left.x+1 + elseif p2 == 3 then + pt_left.z = pt_left.z-1 + end + + local left_node = minetest.get_node(pt_left) + + -- Set door nodes + minetest.set_node(pt, {name=name.."_b_1", param2=p2}) + minetest.set_node(pt2, {name=name.."_t_1", param2=p2}) + + if def.sounds and def.sounds.place then + minetest.sound_play(def.sounds.place, {pos=pt}, true) + end + + if def.only_placer_can_open then + local meta = minetest_get_meta(pt) + meta:set_string("doors_owner", "") + meta = minetest_get_meta(pt2) + meta:set_string("doors_owner", "") + end + + local meta1 = minetest_get_meta(pt) + local meta2 = minetest_get_meta(pt2) + -- save mirror state for the correct door + if left_node.name:sub(1, #name) == name then + meta1:set_int("is_mirrored", 1) + meta2:set_int("is_mirrored", 1) + end + + -- Save open state. 1 = open. 0 = closed + meta1:set_int("is_open", 0) + meta2:set_int("is_open", 0) + + + if not minetest.is_creative_enabled(pn) then + itemstack:take_item() + end + + on_place_node(pt, minetest.get_node(pt), placer, nu, itemstack, pointed_thing) + on_place_node(pt2, minetest.get_node(pt2), placer, minetest.get_node({x=ptu.x,y=ptu.y+1,z=ptu.z}), itemstack, pointed_thing) + + return itemstack + end, + }) + + local tt = def.tiles_top + local tb = def.tiles_bottom + + local function on_open_close(pos, dir, check_name, replace, replace_dir) + local meta1 = minetest_get_meta(pos) + pos.y = pos.y+dir + local meta2 = minetest_get_meta(pos) + + -- if name of other door is not the same as check_name -> return + if not minetest.get_node(pos).name == check_name then + return + end + + -- swap directions if mirrored + local params = {3,0,1,2} + if meta1:get_int("is_open") == 0 and meta2:get_int("is_mirrored") == 0 or meta1:get_int("is_open") == 1 and meta2:get_int("is_mirrored") == 1 then + params = {1,2,3,0} + end + + local p2 = minetest.get_node(pos).param2 + local np2 = params[p2+1] + + minetest.swap_node(pos, {name=replace_dir, param2=np2}) + pos.y = pos.y-dir + minetest.swap_node(pos, {name=replace, param2=np2}) + + local door_switching_sound + if meta1:get_int("is_open") == 1 then + door_switching_sound = def.sound_close + meta1:set_int("is_open", 0) + meta2:set_int("is_open", 0) + else + door_switching_sound = def.sound_open + meta1:set_int("is_open", 1) + meta2:set_int("is_open", 1) + end + minetest.sound_play(door_switching_sound, {pos = pos, gain = 0.5, max_hear_distance = 16}, true) + end + + local function on_mesecons_signal_open(pos, node) + on_open_close(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2") + end + local function on_mesecons_signal_close(pos, node) + if not mesecon.is_powered({x=pos.x,y=pos.y+1,z=pos.z}) then + on_open_close(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1") + end + end + local function on_mesecons_signal_open_top(pos, node) + on_mesecons_signal_open({x=pos.x, y=pos.y-1, z=pos.z}, node) + end + local function on_mesecons_signal_close_top(pos, node) + if not mesecon.is_powered({x=pos.x,y=pos.y-1,z=pos.z}) then + on_mesecons_signal_close({x=pos.x, y=pos.y-1, z=pos.z}, node) + end + end + + local function check_player_priv(pos, player) + if not def.only_placer_can_open then + return true + end + local meta = minetest_get_meta(pos) + local pn = player:get_player_name() + return meta:get_string("doors_owner") == pn + end + + local on_rightclick + -- Disable on_rightclick if this is a redstone-only door + if not def.only_redstone_can_open then + on_rightclick = function(pos, node, clicker) + if check_player_priv(pos, clicker) then + on_open_close(pos, 1, name.."_t_1", name.."_b_2", name.."_t_2") + end + end + end + + minetest.register_node(name.."_b_1", { + tiles = {"blank.png", tt[2].."^[transformFXR90", tb[2], tb[2].."^[transformFX", tb[1], tb[1].."^[transformFX"}, + use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, + paramtype = "light", + paramtype2 = "facedir", + sunlight_propagates = true, + is_ground_content = false, + drop = "", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = def.node_box_bottom + }, + selection_box = { + type = "fixed", + fixed = def.selection_box_bottom + }, + groups = def.groups, + _mcl_hardness = def._mcl_hardness, + _mcl_blast_resistance = def._mcl_blast_resistance, + sounds = def.sounds, + + after_destruct = function(bottom, oldnode) + local meta_bottom = minetest_get_meta(bottom) + if meta_bottom:get_int("rotation") == 1 then + meta_bottom:set_int("rotation", 0) + else + minetest.add_item(bottom, name) + local top = { x = bottom.x, y = bottom.y + 1, z = bottom.z } + if minetest.get_node(bottom).name ~= name.."_b_2" and minetest.get_node(top).name == name.."_t_1" then + minetest.remove_node(top) + end + end + end, + + on_rightclick = on_rightclick, + + mesecons = { effector = { + action_on = on_mesecons_signal_open, + }}, + + on_rotate = function(bottom, node, user, mode, param2) + if mode == screwdriver.ROTATE_FACE then + local meta_bottom = minetest_get_meta(bottom) + meta_bottom:set_int("rotation", 1) + node.param2 = screwdriver.rotate.facedir(bottom, node, mode) + minetest.swap_node(bottom, node) + + local top = {x=bottom.x,y=bottom.y+1,z=bottom.z} + local meta_top = minetest_get_meta(top) + meta_top:set_int("rotation", 1) + node.name = name .."_t_1" + minetest.swap_node(top, node) + + return true + end + return false + end, + + can_dig = check_player_priv, + }) + + if def.only_redstone_can_open then + on_rightclick = nil + else + on_rightclick = function(pos, node, clicker) + if check_player_priv(pos, clicker) then + on_open_close(pos, -1, name.."_b_1", name.."_t_2", name.."_b_2") + end + end + end + + minetest.register_node(name.."_t_1", { + tiles = {tt[2].."^[transformR90", "blank.png", tt[2], tt[2].."^[transformFX", tt[1], tt[1].."^[transformFX"}, + use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, + paramtype = "light", + paramtype2 = "facedir", + sunlight_propagates = true, + is_ground_content = false, + drop = "", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = def.node_box_top + }, + selection_box = { + type = "fixed", + fixed = def.selection_box_top + }, + groups = def.groups, + _mcl_hardness = def._mcl_hardness, + _mcl_blast_resistance = def._mcl_blast_resistance, + sounds = def.sounds, + + after_destruct = function(top, oldnode) + local meta_top = minetest_get_meta(top) + if meta_top:get_int("rotation") == 1 then + meta_top:set_int("rotation", 0) + else + local bottom = { x = top.x, y = top.y - 1, z = top.z } + if minetest.get_node(top).name ~= name.."_t_2" and minetest.get_node(bottom).name == name.."_b_1" and oldnode.name == name.."_t_1" then + minetest.dig_node(bottom) + end + end + end, + + on_rightclick = on_rightclick, + + mesecons = { effector = { + action_on = on_mesecons_signal_open_top, + rules = mesecon.rules.flat, + }}, + + on_rotate = function(top, node, user, mode, param2) + if mode == screwdriver.ROTATE_FACE then + local meta_top = minetest_get_meta(top) + meta_top:set_int("rotation", 1) + node.param2 = screwdriver.rotate.facedir(top, node, mode) + minetest.swap_node(top, node) + + local bottom = {x=top.x,y=top.y-1,z=top.z} + local meta_bottom = minetest_get_meta(bottom) + meta_bottom:set_int("rotation", 1) + node.name = name .."_b_1" + minetest.swap_node(bottom, node) + + return true + end + return false + end, + + can_dig = check_player_priv, + }) + + if def.only_redstone_can_open then + on_rightclick = nil + else + on_rightclick = function(pos, node, clicker) + if check_player_priv(pos, clicker) then + on_open_close(pos, 1, name.."_t_2", name.."_b_1", name.."_t_1") + end + end + end + + minetest.register_node(name.."_b_2", { + tiles = {"blank.png", tt[2].."^[transformFXR90", tb[2].."^[transformI", tb[2].."^[transformFX", tb[1].."^[transformFX", tb[1]}, + use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, + paramtype = "light", + paramtype2 = "facedir", + sunlight_propagates = true, + is_ground_content = false, + drop = "", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = def.node_box_bottom + }, + selection_box = { + type = "fixed", + fixed = def.selection_box_bottom + }, + groups = def.groups, + _mcl_hardness = def._mcl_hardness, + _mcl_blast_resistance = def._mcl_blast_resistance, + sounds = def.sounds, + + after_destruct = function(bottom, oldnode) + local meta_bottom = minetest_get_meta(bottom) + if meta_bottom:get_int("rotation") == 1 then + meta_bottom:set_int("rotation", 0) + else + local top = { x = bottom.x, y = bottom.y + 1, z = bottom.z } + minetest.add_item(bottom, name) + if minetest.get_node(bottom).name ~= name.."_b_1" and minetest.get_node(top).name == name.."_t_2" then + minetest.remove_node(top) + end + end + end, + + on_rightclick = on_rightclick, + + mesecons = { effector = { + action_off = on_mesecons_signal_close, + }}, + + on_rotate = function(bottom, node, user, mode, param2) + if mode == screwdriver.ROTATE_FACE then + local meta_bottom = minetest_get_meta(bottom) + meta_bottom:set_int("rotation", 1) + node.param2 = screwdriver.rotate.facedir(bottom, node, mode) + minetest.swap_node(bottom, node) + + local top = {x=bottom.x,y=bottom.y+1,z=bottom.z} + local meta_top = minetest_get_meta(top) + meta_top:set_int("rotation", 1) + node.name = name .."_t_2" + minetest.swap_node(top, node) + + return true + end + return false + end, + + can_dig = check_player_priv, + }) + + if def.only_redstone_can_open then + on_rightclick = nil + else + on_rightclick = function(pos, node, clicker) + if check_player_priv(pos, clicker) then + on_open_close(pos, -1, name.."_b_2", name.."_t_1", name.."_b_1") + end + end + end + + minetest.register_node(name.."_t_2", { + tiles = {tt[2].."^[transformR90", "blank.png", tt[2].."^[transformI", tt[2].."^[transformFX", tt[1].."^[transformFX", tt[1]}, + use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, + paramtype = "light", + paramtype2 = "facedir", + sunlight_propagates = true, + is_ground_content = false, + drop = "", + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = def.node_box_top + }, + selection_box = { + type = "fixed", + fixed = def.selection_box_top + }, + groups = def.groups, + _mcl_hardness = def._mcl_hardness, + _mcl_blast_resistance = def._mcl_blast_resistance, + sounds = def.sounds, + + after_destruct = function(top, oldnode) + local meta_top = minetest_get_meta(top) + if meta_top:get_int("rotation") == 1 then + meta_top:set_int("rotation", 0) + else + local bottom = { x = top.x, y = top.y - 1, z = top.z } + if minetest.get_node(top).name ~= name.."_t_1" and minetest.get_node(bottom).name == name.."_b_2" and oldnode.name == name.."_t_2" then + minetest.dig_node(bottom) + end + end + end, + + on_rightclick = on_rightclick, + + mesecons = { effector = { + action_off = on_mesecons_signal_close_top, + rules = mesecon.rules.flat, + }}, + + on_rotate = function(top, node, user, mode, param2) + if mode == screwdriver.ROTATE_FACE then + local meta_top = minetest_get_meta(top) + meta_top:set_int("rotation", 1) + node.param2 = screwdriver.rotate.facedir(top, node, mode) + minetest.swap_node(top, node) + + local bottom = {x=top.x,y=top.y-1,z=top.z} + local meta_bottom = minetest_get_meta(bottom) + meta_bottom:set_int("rotation", 1) + node.name = name .."_b_2" + minetest.swap_node(bottom, node) + + return true + end + return false + end, + + can_dig = check_player_priv, + }) + + -- Add entry aliases for the Help + if minetest.get_modpath("doc") then + doc.add_entry_alias("craftitems", name, "nodes", name.."_b_1") + doc.add_entry_alias("craftitems", name, "nodes", name.."_b_2") + doc.add_entry_alias("craftitems", name, "nodes", name.."_t_1") + doc.add_entry_alias("craftitems", name, "nodes", name.."_t_2") + end + +end diff --git a/mods/ITEMS/mcl_doors/api_trapdoors.lua b/mods/ITEMS/mcl_doors/api_trapdoors.lua index 3d2a8e891..5b7a0e5d0 100644 --- a/mods/ITEMS/mcl_doors/api_trapdoors.lua +++ b/mods/ITEMS/mcl_doors/api_trapdoors.lua @@ -1,231 +1,231 @@ -local S = minetest.get_translator(minetest.get_current_modname()) - --- Wrapper around mintest.pointed_thing_to_face_pos. -local function get_fpos(placer, pointed_thing) - local fpos - -- Workaround: minetest.pointed_thing_to_face_pos crashes in MT 0.4.16 if - -- pointed_thing.under and pointed_thing.above are equal - -- FIXME: Remove this when MT got fixed. - if not vector.equals(pointed_thing.under, pointed_thing.above) then - -- The happy case: Everything is normal - local finepos = minetest.pointed_thing_to_face_pos(placer, pointed_thing) - fpos = finepos.y % 1 - else - -- Fallback if both above and under are equal - fpos = 0 - end - return fpos -end - ----- Trapdoor ---- - -local on_rotate -if minetest.get_modpath("screwdriver") then - on_rotate = function(pos, node, user, mode, param2) - -- Flip trapdoor vertically - if mode == screwdriver.ROTATE_AXIS then - local minor = node.param2 - if node.param2 >= 20 then - minor = node.param2 - 20 - if minor == 3 then - minor = 1 - elseif minor == 1 then - minor = 3 - end - node.param2 = minor - else - if minor == 3 then - minor = 1 - elseif minor == 1 then - minor = 3 - end - node.param2 = minor - node.param2 = node.param2 + 20 - end - minetest.set_node(pos, node) - return true - end - end -end - -function mcl_doors:register_trapdoor(name, def) - local groups = table.copy(def.groups) - if groups == nil then - groups = {} - end - groups.mesecon_ignore_opaque_dig = 1 - - if not def.sound_open then - def.sound_open = "doors_door_open" - end - if not def.sound_close then - def.sound_close = "doors_door_close" - end - - local function punch(pos) - local me = minetest.get_node(pos) - local tmp_node - -- Close - if minetest.get_item_group(me.name, "trapdoor") == 2 then - minetest.sound_play(def.sound_close, {pos = pos, gain = 0.3, max_hear_distance = 16}, true) - tmp_node = {name=name, param1=me.param1, param2=me.param2} - -- Open - else - minetest.sound_play(def.sound_open, {pos = pos, gain = 0.3, max_hear_distance = 16}, true) - tmp_node = {name=name.."_open", param1=me.param1, param2=me.param2} - end - minetest.set_node(pos, tmp_node) - end - - local on_rightclick - if not def.only_redstone_can_open then - on_rightclick = function(pos, node, clicker) - punch(pos) - end - end - - -- Default help texts - local longdesc, usagehelp, tt_help - longdesc = def._doc_items_longdesc - if not longdesc then - if def.only_redstone_can_open then - longdesc = S("Trapdoors are horizontal barriers which can be opened or closed and climbed like a ladder when open. They occupy the upper or lower part of a block, depending on how they have been placed. This trapdoor can only be opened or closed by redstone power.") - else - longdesc = S("Trapdoors are horizontal barriers which can be opened or closed and climbed like a ladder when open. They occupy the upper or lower part of a block, depending on how they have been placed. This trapdoor can be opened or closed by hand or redstone power.") - end - end - usagehelp = def._doc_items_usagehelp - if not usagehelp and not def.only_redstone_can_open then - usagehelp = S("To open or close this trapdoor, rightclick it or send a redstone signal to it.") - end - if def.only_redstone_can_open then - tt_help = S("Openable by redstone power") - else - tt_help = S("Openable by players and redstone power") - end - - -- Closed trapdoor - - local tile_front = def.tile_front - local tile_side = def.tile_side - if not tile_side then - tile_side = tile_front - end - local tiles_closed = { - tile_front, - tile_front .. "^[transformFY", - tile_side, tile_side, - tile_side, tile_side, - } - - local groups_closed = groups - groups_closed.trapdoor = 1 - groups_closed.deco_block = 1 - minetest.register_node(name, { - description = def.description, - _tt_help = tt_help, - _doc_items_longdesc = longdesc, - _doc_items_usagehelp = usagehelp, - drawtype = "nodebox", - tiles = tiles_closed, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, - inventory_image = def.inventory_image, - wield_image = def.wield_image, - is_ground_content = false, - paramtype = "light", - stack_max = 64, - paramtype2 = "facedir", - sunlight_propagates = true, - groups = groups_closed, - _mcl_hardness = def._mcl_hardness, - _mcl_blast_resistance = def._mcl_blast_resistance, - sounds = def.sounds, - node_box = { - type = "fixed", - fixed = { - {-8/16, -8/16, -8/16, 8/16, -5/16, 8/16},}, - }, - mesecons = {effector = { - action_on = (function(pos, node) - punch(pos) - end), - }}, - on_place = function(itemstack, placer, pointed_thing) - local p0 = pointed_thing.under - local p1 = pointed_thing.above - local param2 = 0 - - local placer_pos = placer:get_pos() - if placer_pos then - param2 = minetest.dir_to_facedir(vector.subtract(p1, placer_pos)) - end - - local fpos = get_fpos(placer, pointed_thing) - - --local origname = itemstack:get_name() - if p0.y - 1 == p1.y or (fpos > 0 and fpos < 0.5) - or (fpos < -0.5 and fpos > -0.999999999) then - param2 = param2 + 20 - if param2 == 21 then - param2 = 23 - elseif param2 == 23 then - param2 = 21 - end - end - return minetest.item_place(itemstack, placer, pointed_thing, param2) - end, - on_rightclick = on_rightclick, - on_rotate = on_rotate, - }) - - -- Open trapdoor - - local groups_open = table.copy(groups) - - local tiles_open = { - tile_side, - tile_side .. "^[transformR180", - tile_side .. "^[transformR270", - tile_side .. "^[transformR90", - tile_front .. "^[transform46", - tile_front .. "^[transformFY", - } - - groups_open.trapdoor = 2 - groups_open.not_in_creative_inventory = 1 - minetest.register_node(name.."_open", { - drawtype = "nodebox", - tiles = tiles_open, - use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, - is_ground_content = false, - paramtype = "light", - paramtype2 = "facedir", - -- TODO: Implement Minecraft behaviour: Climbable if directly above - -- ladder w/ matching orientation. - -- Current behavour: Always climbable - climbable = true, - sunlight_propagates = true, - pointable = true, - groups = groups_open, - _mcl_hardness = def._mcl_hardness, - _mcl_blast_resistance = def._mcl_blast_resistance, - sounds = def.sounds, - drop = name, - node_box = { - type = "fixed", - fixed = {-0.5, -0.5, 5/16, 0.5, 0.5, 0.5} - }, - on_rightclick = on_rightclick, - mesecons = {effector = { - action_off = (function(pos, node) - punch(pos) - end), - }}, - on_rotate = on_rotate, - }) - - if minetest.get_modpath("doc") then - doc.add_entry_alias("nodes", name, "nodes", name.."_open") - end - -end +local S = minetest.get_translator(minetest.get_current_modname()) + +-- Wrapper around mintest.pointed_thing_to_face_pos. +local function get_fpos(placer, pointed_thing) + local fpos + -- Workaround: minetest.pointed_thing_to_face_pos crashes in MT 0.4.16 if + -- pointed_thing.under and pointed_thing.above are equal + -- FIXME: Remove this when MT got fixed. + if not vector.equals(pointed_thing.under, pointed_thing.above) then + -- The happy case: Everything is normal + local finepos = minetest.pointed_thing_to_face_pos(placer, pointed_thing) + fpos = finepos.y % 1 + else + -- Fallback if both above and under are equal + fpos = 0 + end + return fpos +end + +---- Trapdoor ---- + +local on_rotate +if minetest.get_modpath("screwdriver") then + on_rotate = function(pos, node, user, mode, param2) + -- Flip trapdoor vertically + if mode == screwdriver.ROTATE_AXIS then + local minor = node.param2 + if node.param2 >= 20 then + minor = node.param2 - 20 + if minor == 3 then + minor = 1 + elseif minor == 1 then + minor = 3 + end + node.param2 = minor + else + if minor == 3 then + minor = 1 + elseif minor == 1 then + minor = 3 + end + node.param2 = minor + node.param2 = node.param2 + 20 + end + minetest.set_node(pos, node) + return true + end + end +end + +function mcl_doors:register_trapdoor(name, def) + local groups = table.copy(def.groups) + if groups == nil then + groups = {} + end + groups.mesecon_ignore_opaque_dig = 1 + + if not def.sound_open then + def.sound_open = "doors_door_open" + end + if not def.sound_close then + def.sound_close = "doors_door_close" + end + + local function punch(pos) + local me = minetest.get_node(pos) + local tmp_node + -- Close + if minetest.get_item_group(me.name, "trapdoor") == 2 then + minetest.sound_play(def.sound_close, {pos = pos, gain = 0.3, max_hear_distance = 16}, true) + tmp_node = {name=name, param1=me.param1, param2=me.param2} + -- Open + else + minetest.sound_play(def.sound_open, {pos = pos, gain = 0.3, max_hear_distance = 16}, true) + tmp_node = {name=name.."_open", param1=me.param1, param2=me.param2} + end + minetest.set_node(pos, tmp_node) + end + + local on_rightclick + if not def.only_redstone_can_open then + on_rightclick = function(pos, node, clicker) + punch(pos) + end + end + + -- Default help texts + local longdesc, usagehelp, tt_help + longdesc = def._doc_items_longdesc + if not longdesc then + if def.only_redstone_can_open then + longdesc = S("Trapdoors are horizontal barriers which can be opened or closed and climbed like a ladder when open. They occupy the upper or lower part of a block, depending on how they have been placed. This trapdoor can only be opened or closed by redstone power.") + else + longdesc = S("Trapdoors are horizontal barriers which can be opened or closed and climbed like a ladder when open. They occupy the upper or lower part of a block, depending on how they have been placed. This trapdoor can be opened or closed by hand or redstone power.") + end + end + usagehelp = def._doc_items_usagehelp + if not usagehelp and not def.only_redstone_can_open then + usagehelp = S("To open or close this trapdoor, rightclick it or send a redstone signal to it.") + end + if def.only_redstone_can_open then + tt_help = S("Openable by redstone power") + else + tt_help = S("Openable by players and redstone power") + end + + -- Closed trapdoor + + local tile_front = def.tile_front + local tile_side = def.tile_side + if not tile_side then + tile_side = tile_front + end + local tiles_closed = { + tile_front, + tile_front .. "^[transformFY", + tile_side, tile_side, + tile_side, tile_side, + } + + local groups_closed = groups + groups_closed.trapdoor = 1 + groups_closed.deco_block = 1 + minetest.register_node(name, { + description = def.description, + _tt_help = tt_help, + _doc_items_longdesc = longdesc, + _doc_items_usagehelp = usagehelp, + drawtype = "nodebox", + tiles = tiles_closed, + use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, + inventory_image = def.inventory_image, + wield_image = def.wield_image, + is_ground_content = false, + paramtype = "light", + stack_max = 64, + paramtype2 = "facedir", + sunlight_propagates = true, + groups = groups_closed, + _mcl_hardness = def._mcl_hardness, + _mcl_blast_resistance = def._mcl_blast_resistance, + sounds = def.sounds, + node_box = { + type = "fixed", + fixed = { + {-8/16, -8/16, -8/16, 8/16, -5/16, 8/16},}, + }, + mesecons = {effector = { + action_on = (function(pos, node) + punch(pos) + end), + }}, + on_place = function(itemstack, placer, pointed_thing) + local p0 = pointed_thing.under + local p1 = pointed_thing.above + local param2 = 0 + + local placer_pos = placer:get_pos() + if placer_pos then + param2 = minetest.dir_to_facedir(vector.subtract(p1, placer_pos)) + end + + local fpos = get_fpos(placer, pointed_thing) + + --local origname = itemstack:get_name() + if p0.y - 1 == p1.y or (fpos > 0 and fpos < 0.5) + or (fpos < -0.5 and fpos > -0.999999999) then + param2 = param2 + 20 + if param2 == 21 then + param2 = 23 + elseif param2 == 23 then + param2 = 21 + end + end + return minetest.item_place(itemstack, placer, pointed_thing, param2) + end, + on_rightclick = on_rightclick, + on_rotate = on_rotate, + }) + + -- Open trapdoor + + local groups_open = table.copy(groups) + + local tiles_open = { + tile_side, + tile_side .. "^[transformR180", + tile_side .. "^[transformR270", + tile_side .. "^[transformR90", + tile_front .. "^[transform46", + tile_front .. "^[transformFY", + } + + groups_open.trapdoor = 2 + groups_open.not_in_creative_inventory = 1 + minetest.register_node(name.."_open", { + drawtype = "nodebox", + tiles = tiles_open, + use_texture_alpha = minetest.features.use_texture_alpha_string_modes and "clip" or true, + is_ground_content = false, + paramtype = "light", + paramtype2 = "facedir", + -- TODO: Implement Minecraft behaviour: Climbable if directly above + -- ladder w/ matching orientation. + -- Current behavour: Always climbable + climbable = true, + sunlight_propagates = true, + pointable = true, + groups = groups_open, + _mcl_hardness = def._mcl_hardness, + _mcl_blast_resistance = def._mcl_blast_resistance, + sounds = def.sounds, + drop = name, + node_box = { + type = "fixed", + fixed = {-0.5, -0.5, 5/16, 0.5, 0.5, 0.5} + }, + on_rightclick = on_rightclick, + mesecons = {effector = { + action_off = (function(pos, node) + punch(pos) + end), + }}, + on_rotate = on_rotate, + }) + + if minetest.get_modpath("doc") then + doc.add_entry_alias("nodes", name, "nodes", name.."_open") + end + +end diff --git a/mods/ITEMS/mcl_doors/init.lua b/mods/ITEMS/mcl_doors/init.lua index 9e06b513f..a39b33c5e 100644 --- a/mods/ITEMS/mcl_doors/init.lua +++ b/mods/ITEMS/mcl_doors/init.lua @@ -1,9 +1,9 @@ -mcl_doors = {} - -local this = minetest.get_current_modname() -local path = minetest.get_modpath(this) - -dofile(path.."/api_doors.lua") -- Doors API -dofile(path.."/api_trapdoors.lua") -- Trapdoors API -dofile(path.."/register.lua") -- Register builtin doors and trapdoors -dofile(path.."/alias.lua") -- Legacy aliases +mcl_doors = {} + +local this = minetest.get_current_modname() +local path = minetest.get_modpath(this) + +dofile(path.."/api_doors.lua") -- Doors API +dofile(path.."/api_trapdoors.lua") -- Trapdoors API +dofile(path.."/register.lua") -- Register builtin doors and trapdoors +dofile(path.."/alias.lua") -- Legacy aliases diff --git a/mods/ITEMS/mcl_farming/hoes.lua b/mods/ITEMS/mcl_farming/hoes.lua index d94ea6f8e..d2250eb70 100644 --- a/mods/ITEMS/mcl_farming/hoes.lua +++ b/mods/ITEMS/mcl_farming/hoes.lua @@ -1,275 +1,275 @@ -local S = minetest.get_translator(minetest.get_current_modname()) - -local function create_soil(pos, inv) - if pos == nil then - return false - end - local node = minetest.get_node(pos) - local name = node.name - local above = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}) - if minetest.get_item_group(name, "cultivatable") == 2 then - if above.name == "air" then - node.name = "mcl_farming:soil" - minetest.set_node(pos, node) - minetest.sound_play("default_dig_crumbly", { pos = pos, gain = 0.5 }, true) - return true - end - elseif minetest.get_item_group(name, "cultivatable") == 1 then - if above.name == "air" then - node.name = "mcl_core:dirt" - minetest.set_node(pos, node) - minetest.sound_play("default_dig_crumbly", { pos = pos, gain = 0.6 }, true) - return true - end - end - return false -end - -local hoe_on_place_function = function(wear_divisor) - return function(itemstack, user, pointed_thing) - -- Call on_rightclick if the pointed node defines it - local node = minetest.get_node(pointed_thing.under) - if user and not user:get_player_control().sneak then - if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then - return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, user, itemstack) or itemstack - end - end - - if minetest.is_protected(pointed_thing.under, user:get_player_name()) then - minetest.record_protection_violation(pointed_thing.under, user:get_player_name()) - return itemstack - end - - if create_soil(pointed_thing.under, user:get_inventory()) then - if not minetest.is_creative_enabled(user:get_player_name()) then - itemstack:add_wear(65535/wear_divisor) - end - return itemstack - end - end -end - -local uses = { - wood = 60, - stone = 132, - iron = 251, - gold = 33, - diamond = 1562, -} - -local hoe_tt = S("Turns block into farmland") -local hoe_longdesc = S("Hoes are essential tools for growing crops. They are used to create farmland in order to plant seeds on it. Hoes can also be used as very weak weapons in a pinch.") -local hoe_usagehelp = S("Use the hoe on a cultivatable block (by rightclicking it) to turn it into farmland. Dirt, grass blocks and grass paths are cultivatable blocks. Using a hoe on coarse dirt turns it into dirt.") - -minetest.register_tool("mcl_farming:hoe_wood", { - description = S("Wood Hoe"), - _tt_help = hoe_tt.."\n"..S("Uses: @1", uses.wood), - _doc_items_longdesc = hoe_longdesc, - _doc_items_usagehelp = hoe_usagehelp, - _doc_items_hidden = false, - inventory_image = "farming_tool_woodhoe.png", - wield_scale = mcl_vars.tool_wield_scale, - on_place = hoe_on_place_function(uses.wood), - groups = { tool=1, hoe=1, enchantability=15 }, - tool_capabilities = { - full_punch_interval = 1, - damage_groups = { fleshy = 1, }, - punch_attack_uses = uses.wood, - }, - _repair_material = "group:wood", - _mcl_toollike_wield = true, - _mcl_diggroups = { - hoey = { speed = 2, level = 1, uses = 60 } - }, -}) - -minetest.register_craft({ - output = "mcl_farming:hoe_wood", - recipe = { - {"group:wood", "group:wood"}, - {"", "mcl_core:stick"}, - {"", "mcl_core:stick"} - } -}) -minetest.register_craft({ - output = "mcl_farming:hoe_wood", - recipe = { - {"group:wood", "group:wood"}, - {"mcl_core:stick", ""}, - {"mcl_core:stick", ""} - } -}) -minetest.register_craft({ - type = "fuel", - recipe = "mcl_farming:hoe_wood", - burntime = 10, -}) - -minetest.register_tool("mcl_farming:hoe_stone", { - description = S("Stone Hoe"), - _tt_help = hoe_tt.."\n"..S("Uses: @1", uses.stone), - _doc_items_longdesc = hoe_longdesc, - _doc_items_usagehelp = hoe_usagehelp, - inventory_image = "farming_tool_stonehoe.png", - wield_scale = mcl_vars.tool_wield_scale, - on_place = hoe_on_place_function(uses.stone), - groups = { tool=1, hoe=1, enchantability=5 }, - tool_capabilities = { - full_punch_interval = 0.5, - damage_groups = { fleshy = 1, }, - punch_attack_uses = uses.stone, - }, - _repair_material = "group:cobble", - _mcl_toollike_wield = true, - _mcl_diggroups = { - hoey = { speed = 4, level = 3, uses = 132 } - }, -}) - -minetest.register_craft({ - output = "mcl_farming:hoe_stone", - recipe = { - {"group:cobble", "group:cobble"}, - {"", "mcl_core:stick"}, - {"", "mcl_core:stick"} - } -}) -minetest.register_craft({ - output = "mcl_farming:hoe_stone", - recipe = { - {"group:cobble", "group:cobble"}, - {"mcl_core:stick", ""}, - {"mcl_core:stick", ""} - } -}) - -minetest.register_tool("mcl_farming:hoe_iron", { - description = S("Iron Hoe"), - _tt_help = hoe_tt.."\n"..S("Uses: @1", uses.iron), - _doc_items_longdesc = hoe_longdesc, - _doc_items_usagehelp = hoe_usagehelp, - inventory_image = "farming_tool_steelhoe.png", - wield_scale = mcl_vars.tool_wield_scale, - on_place = hoe_on_place_function(uses.iron), - groups = { tool=1, hoe=1, enchantability=14 }, - tool_capabilities = { - -- 1/3 - full_punch_interval = 0.33333333, - damage_groups = { fleshy = 1, }, - punch_attack_uses = uses.iron, - }, - _repair_material = "mcl_core:iron_ingot", - _mcl_toollike_wield = true, - _mcl_diggroups = { - hoey = { speed = 6, level = 4, uses = 251 } - }, -}) - -minetest.register_craft({ - output = "mcl_farming:hoe_iron", - recipe = { - {"mcl_core:iron_ingot", "mcl_core:iron_ingot"}, - {"", "mcl_core:stick"}, - {"", "mcl_core:stick"} - } -}) -minetest.register_craft({ - output = "mcl_farming:hoe_iron", - recipe = { - {"mcl_core:iron_ingot", "mcl_core:iron_ingot"}, - {"mcl_core:stick", ""}, - {"mcl_core:stick", ""} - } -}) - -minetest.register_craft({ - type = "cooking", - output = "mcl_core:iron_nugget", - recipe = "mcl_farming:hoe_iron", - cooktime = 10, -}) - -minetest.register_tool("mcl_farming:hoe_gold", { - description = S("Golden Hoe"), - _tt_help = hoe_tt.."\n"..S("Uses: @1", uses.gold), - _doc_items_longdesc = hoe_longdesc, - _doc_items_usagehelp = hoe_usagehelp, - inventory_image = "farming_tool_goldhoe.png", - wield_scale = mcl_vars.tool_wield_scale, - on_place = hoe_on_place_function(uses.gold), - groups = { tool=1, hoe=1, enchantability=22 }, - tool_capabilities = { - full_punch_interval = 1, - damage_groups = { fleshy = 1, }, - punch_attack_uses = uses.gold, - }, - _repair_material = "mcl_core:gold_ingot", - _mcl_toollike_wield = true, - _mcl_diggroups = { - hoey = { speed = 12, level = 2, uses = 33 } - }, -}) - -minetest.register_craft({ - output = "mcl_farming:hoe_gold", - recipe = { - {"mcl_core:gold_ingot", "mcl_core:gold_ingot"}, - {"", "mcl_core:stick"}, - {"", "mcl_core:stick"} - } -}) -minetest.register_craft({ - output = "mcl_farming:hoe_gold", - recipe = { - {"mcl_core:gold_ingot", "mcl_core:gold_ingot"}, - {"mcl_core:stick", ""}, - {"mcl_core:stick", ""} - } -}) - - - -minetest.register_craft({ - type = "cooking", - output = "mcl_core:gold_nugget", - recipe = "mcl_farming:hoe_gold", - cooktime = 10, -}) - -minetest.register_tool("mcl_farming:hoe_diamond", { - description = S("Diamond Hoe"), - _tt_help = hoe_tt.."\n"..S("Uses: @1", uses.diamond), - _doc_items_longdesc = hoe_longdesc, - _doc_items_usagehelp = hoe_usagehelp, - inventory_image = "farming_tool_diamondhoe.png", - wield_scale = mcl_vars.tool_wield_scale, - on_place = hoe_on_place_function(uses.diamond), - groups = { tool=1, hoe=1, enchantability=10 }, - tool_capabilities = { - full_punch_interval = 0.25, - damage_groups = { fleshy = 1, }, - punch_attack_uses = uses.diamond, - }, - _repair_material = "mcl_core:diamond", - _mcl_toollike_wield = true, - _mcl_diggroups = { - hoey = { speed = 8, level = 5, uses = 1562 } - }, -}) - -minetest.register_craft({ - output = "mcl_farming:hoe_diamond", - recipe = { - {"mcl_core:diamond", "mcl_core:diamond"}, - {"", "mcl_core:stick"}, - {"", "mcl_core:stick"} - } -}) -minetest.register_craft({ - output = "mcl_farming:hoe_diamond", - recipe = { - {"mcl_core:diamond", "mcl_core:diamond"}, - {"mcl_core:stick", ""}, - {"mcl_core:stick", ""} - } -}) +local S = minetest.get_translator(minetest.get_current_modname()) + +local function create_soil(pos, inv) + if pos == nil then + return false + end + local node = minetest.get_node(pos) + local name = node.name + local above = minetest.get_node({x=pos.x, y=pos.y+1, z=pos.z}) + if minetest.get_item_group(name, "cultivatable") == 2 then + if above.name == "air" then + node.name = "mcl_farming:soil" + minetest.set_node(pos, node) + minetest.sound_play("default_dig_crumbly", { pos = pos, gain = 0.5 }, true) + return true + end + elseif minetest.get_item_group(name, "cultivatable") == 1 then + if above.name == "air" then + node.name = "mcl_core:dirt" + minetest.set_node(pos, node) + minetest.sound_play("default_dig_crumbly", { pos = pos, gain = 0.6 }, true) + return true + end + end + return false +end + +local hoe_on_place_function = function(wear_divisor) + return function(itemstack, user, pointed_thing) + -- Call on_rightclick if the pointed node defines it + local node = minetest.get_node(pointed_thing.under) + if user and not user:get_player_control().sneak then + if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then + return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, user, itemstack) or itemstack + end + end + + if minetest.is_protected(pointed_thing.under, user:get_player_name()) then + minetest.record_protection_violation(pointed_thing.under, user:get_player_name()) + return itemstack + end + + if create_soil(pointed_thing.under, user:get_inventory()) then + if not minetest.is_creative_enabled(user:get_player_name()) then + itemstack:add_wear(65535/wear_divisor) + end + return itemstack + end + end +end + +local uses = { + wood = 60, + stone = 132, + iron = 251, + gold = 33, + diamond = 1562, +} + +local hoe_tt = S("Turns block into farmland") +local hoe_longdesc = S("Hoes are essential tools for growing crops. They are used to create farmland in order to plant seeds on it. Hoes can also be used as very weak weapons in a pinch.") +local hoe_usagehelp = S("Use the hoe on a cultivatable block (by rightclicking it) to turn it into farmland. Dirt, grass blocks and grass paths are cultivatable blocks. Using a hoe on coarse dirt turns it into dirt.") + +minetest.register_tool("mcl_farming:hoe_wood", { + description = S("Wood Hoe"), + _tt_help = hoe_tt.."\n"..S("Uses: @1", uses.wood), + _doc_items_longdesc = hoe_longdesc, + _doc_items_usagehelp = hoe_usagehelp, + _doc_items_hidden = false, + inventory_image = "farming_tool_woodhoe.png", + wield_scale = mcl_vars.tool_wield_scale, + on_place = hoe_on_place_function(uses.wood), + groups = { tool=1, hoe=1, enchantability=15 }, + tool_capabilities = { + full_punch_interval = 1, + damage_groups = { fleshy = 1, }, + punch_attack_uses = uses.wood, + }, + _repair_material = "group:wood", + _mcl_toollike_wield = true, + _mcl_diggroups = { + hoey = { speed = 2, level = 1, uses = 60 } + }, +}) + +minetest.register_craft({ + output = "mcl_farming:hoe_wood", + recipe = { + {"group:wood", "group:wood"}, + {"", "mcl_core:stick"}, + {"", "mcl_core:stick"} + } +}) +minetest.register_craft({ + output = "mcl_farming:hoe_wood", + recipe = { + {"group:wood", "group:wood"}, + {"mcl_core:stick", ""}, + {"mcl_core:stick", ""} + } +}) +minetest.register_craft({ + type = "fuel", + recipe = "mcl_farming:hoe_wood", + burntime = 10, +}) + +minetest.register_tool("mcl_farming:hoe_stone", { + description = S("Stone Hoe"), + _tt_help = hoe_tt.."\n"..S("Uses: @1", uses.stone), + _doc_items_longdesc = hoe_longdesc, + _doc_items_usagehelp = hoe_usagehelp, + inventory_image = "farming_tool_stonehoe.png", + wield_scale = mcl_vars.tool_wield_scale, + on_place = hoe_on_place_function(uses.stone), + groups = { tool=1, hoe=1, enchantability=5 }, + tool_capabilities = { + full_punch_interval = 0.5, + damage_groups = { fleshy = 1, }, + punch_attack_uses = uses.stone, + }, + _repair_material = "group:cobble", + _mcl_toollike_wield = true, + _mcl_diggroups = { + hoey = { speed = 4, level = 3, uses = 132 } + }, +}) + +minetest.register_craft({ + output = "mcl_farming:hoe_stone", + recipe = { + {"group:cobble", "group:cobble"}, + {"", "mcl_core:stick"}, + {"", "mcl_core:stick"} + } +}) +minetest.register_craft({ + output = "mcl_farming:hoe_stone", + recipe = { + {"group:cobble", "group:cobble"}, + {"mcl_core:stick", ""}, + {"mcl_core:stick", ""} + } +}) + +minetest.register_tool("mcl_farming:hoe_iron", { + description = S("Iron Hoe"), + _tt_help = hoe_tt.."\n"..S("Uses: @1", uses.iron), + _doc_items_longdesc = hoe_longdesc, + _doc_items_usagehelp = hoe_usagehelp, + inventory_image = "farming_tool_steelhoe.png", + wield_scale = mcl_vars.tool_wield_scale, + on_place = hoe_on_place_function(uses.iron), + groups = { tool=1, hoe=1, enchantability=14 }, + tool_capabilities = { + -- 1/3 + full_punch_interval = 0.33333333, + damage_groups = { fleshy = 1, }, + punch_attack_uses = uses.iron, + }, + _repair_material = "mcl_core:iron_ingot", + _mcl_toollike_wield = true, + _mcl_diggroups = { + hoey = { speed = 6, level = 4, uses = 251 } + }, +}) + +minetest.register_craft({ + output = "mcl_farming:hoe_iron", + recipe = { + {"mcl_core:iron_ingot", "mcl_core:iron_ingot"}, + {"", "mcl_core:stick"}, + {"", "mcl_core:stick"} + } +}) +minetest.register_craft({ + output = "mcl_farming:hoe_iron", + recipe = { + {"mcl_core:iron_ingot", "mcl_core:iron_ingot"}, + {"mcl_core:stick", ""}, + {"mcl_core:stick", ""} + } +}) + +minetest.register_craft({ + type = "cooking", + output = "mcl_core:iron_nugget", + recipe = "mcl_farming:hoe_iron", + cooktime = 10, +}) + +minetest.register_tool("mcl_farming:hoe_gold", { + description = S("Golden Hoe"), + _tt_help = hoe_tt.."\n"..S("Uses: @1", uses.gold), + _doc_items_longdesc = hoe_longdesc, + _doc_items_usagehelp = hoe_usagehelp, + inventory_image = "farming_tool_goldhoe.png", + wield_scale = mcl_vars.tool_wield_scale, + on_place = hoe_on_place_function(uses.gold), + groups = { tool=1, hoe=1, enchantability=22 }, + tool_capabilities = { + full_punch_interval = 1, + damage_groups = { fleshy = 1, }, + punch_attack_uses = uses.gold, + }, + _repair_material = "mcl_core:gold_ingot", + _mcl_toollike_wield = true, + _mcl_diggroups = { + hoey = { speed = 12, level = 2, uses = 33 } + }, +}) + +minetest.register_craft({ + output = "mcl_farming:hoe_gold", + recipe = { + {"mcl_core:gold_ingot", "mcl_core:gold_ingot"}, + {"", "mcl_core:stick"}, + {"", "mcl_core:stick"} + } +}) +minetest.register_craft({ + output = "mcl_farming:hoe_gold", + recipe = { + {"mcl_core:gold_ingot", "mcl_core:gold_ingot"}, + {"mcl_core:stick", ""}, + {"mcl_core:stick", ""} + } +}) + + + +minetest.register_craft({ + type = "cooking", + output = "mcl_core:gold_nugget", + recipe = "mcl_farming:hoe_gold", + cooktime = 10, +}) + +minetest.register_tool("mcl_farming:hoe_diamond", { + description = S("Diamond Hoe"), + _tt_help = hoe_tt.."\n"..S("Uses: @1", uses.diamond), + _doc_items_longdesc = hoe_longdesc, + _doc_items_usagehelp = hoe_usagehelp, + inventory_image = "farming_tool_diamondhoe.png", + wield_scale = mcl_vars.tool_wield_scale, + on_place = hoe_on_place_function(uses.diamond), + groups = { tool=1, hoe=1, enchantability=10 }, + tool_capabilities = { + full_punch_interval = 0.25, + damage_groups = { fleshy = 1, }, + punch_attack_uses = uses.diamond, + }, + _repair_material = "mcl_core:diamond", + _mcl_toollike_wield = true, + _mcl_diggroups = { + hoey = { speed = 8, level = 5, uses = 1562 } + }, +}) + +minetest.register_craft({ + output = "mcl_farming:hoe_diamond", + recipe = { + {"mcl_core:diamond", "mcl_core:diamond"}, + {"", "mcl_core:stick"}, + {"", "mcl_core:stick"} + } +}) +minetest.register_craft({ + output = "mcl_farming:hoe_diamond", + recipe = { + {"mcl_core:diamond", "mcl_core:diamond"}, + {"mcl_core:stick", ""}, + {"mcl_core:stick", ""} + } +}) diff --git a/mods/ITEMS/mcl_fences/init.lua b/mods/ITEMS/mcl_fences/init.lua index 243cc2219..b14d103d2 100644 --- a/mods/ITEMS/mcl_fences/init.lua +++ b/mods/ITEMS/mcl_fences/init.lua @@ -1,306 +1,306 @@ -local S = minetest.get_translator(minetest.get_current_modname()) - --- Node box -local p = {-2/16, -0.5, -2/16, 2/16, 0.5, 2/16} -local x1 = {-0.5, 4/16, -1/16, -2/16, 7/16, 1/16} --oben(quer) -x -local x12 = {-0.5, -2/16, -1/16, -2/16, 1/16, 1/16} --unten(quer) -x -local x2 = {2/16, 4/16, -1/16, 0.5, 7/16, 1/16} --oben(quer) x -local x22 = {2/16, -2/16, -1/16, 0.5, 1/16, 1/16} --unten(quer) x -local z1 = {-1/16, 4/16, -0.5, 1/16, 7/16, -2/16} --oben(quer) -z -local z12 = {-1/16, -2/16, -0.5, 1/16, 1/16, -2/16} --unten(quer) -z -local z2 = {-1/16, 4/16, 2/16, 1/16, 7/16, 0.5} --oben(quer) z -local z22 = {-1/16, -2/16, 2/16, 1/16, 1/16, 0.5} --unten(quer) z - --- Collision box -local cp = {-2/16, -0.5, -2/16, 2/16, 1.01, 2/16} -local cx1 = {-0.5, -0.5, -2/16, -2/16, 1.01, 2/16} --unten(quer) -x -local cx2 = {2/16, -0.5, -2/16, 0.5, 1.01, 2/16} --unten(quer) x -local cz1 = {-2/16, -0.5, -0.5, 2/16, 1.01, -2/16} --unten(quer) -z -local cz2 = {-2/16, -0.5, 2/16, 2/16, 1.01, 0.5} --unten(quer) z - -mcl_fences = {} - -function mcl_fences.register_fence(id, fence_name, texture, groups, hardness, blast_resistance, connects_to, sounds) - local cgroups = table.copy(groups) - if cgroups == nil then cgroups = {} end - cgroups.fence = 1 - cgroups.deco_block = 1 - if connects_to == nil then - connects_to = {} - else - connects_to = table.copy(connects_to) - end - local fence_id = minetest.get_current_modname()..":"..id - table.insert(connects_to, "group:solid") - table.insert(connects_to, "group:fence_gate") - table.insert(connects_to, fence_id) - minetest.register_node(fence_id, { - description = fence_name, - _doc_items_longdesc = S("Fences are structures which block the way. Fences will connect to each other and solid blocks. They cannot be jumped over with a simple jump."), - tiles = {texture}, - inventory_image = "mcl_fences_fence_mask.png^" .. texture .. "^mcl_fences_fence_mask.png^[makealpha:255,126,126", - wield_image = "mcl_fences_fence_mask.png^" .. texture .. "^mcl_fences_fence_mask.png^[makealpha:255,126,126", - paramtype = "light", - is_ground_content = false, - groups = cgroups, - stack_max = 64, - sunlight_propagates = true, - drawtype = "nodebox", - connect_sides = { "front", "back", "left", "right" }, - connects_to = connects_to, - node_box = { - type = "connected", - fixed = {p}, - connect_front = {z1,z12}, - connect_back = {z2,z22,}, - connect_left = {x1,x12}, - connect_right = {x2,x22}, - }, - collision_box = { - type = "connected", - fixed = {cp}, - connect_front = {cz1}, - connect_back = {cz2,}, - connect_left = {cx1}, - connect_right = {cx2}, - }, - sounds = sounds, - _mcl_blast_resistance = blast_resistance, - _mcl_hardness = hardness, - }) - - return fence_id -end - -function mcl_fences.register_fence_gate(id, fence_gate_name, texture, groups, hardness, blast_resistance, sounds, sound_open, sound_close, sound_gain_open, sound_gain_close) - local meta2 - local state2 = 0 - - local function update_gate(pos, node) - minetest.set_node(pos, node) - end - - local gate_id = minetest.get_current_modname()..":"..id.."_gate" - local open_gate_id = gate_id .. "_open" - if not sound_open then - sound_open = "doors_fencegate_open" - end - if not sound_close then - sound_close = "doors_fencegate_close" - end - if not sound_gain_open then - sound_gain_open = 0.3 - end - if not sound_gain_close then - sound_gain_close = 0.3 - end - local function punch_gate(pos, node) - meta2 = minetest.get_meta(pos) - state2 = meta2:get_int("state") - local tmp_node2 - if state2 == 1 then - state2 = 0 - minetest.sound_play(sound_close, {gain = sound_gain_close, max_hear_distance = 10, pos = pos}, true) - tmp_node2 = {name=gate_id, param1=node.param1, param2=node.param2} - else - state2 = 1 - minetest.sound_play(sound_open, {gain = sound_gain_open, max_hear_distance = 10, pos = pos}, true) - tmp_node2 = {name=open_gate_id, param1=node.param1, param2=node.param2} - end - update_gate(pos, tmp_node2) - meta2:set_int("state", state2) - end - - local on_rotate - if minetest.get_modpath("screwdriver") then - on_rotate = screwdriver.rotate_simple - end - - local cgroups = table.copy(groups) - if cgroups == nil then cgroups = {} end - cgroups.fence_gate = 1 - cgroups.deco_block = 1 - - cgroups.mesecon_ignore_opaque_dig = 1 - cgroups.mesecon_effector_on = 1 - cgroups.fence_gate = 1 - minetest.register_node(open_gate_id, { - tiles = {texture}, - paramtype = "light", - paramtype2 = "facedir", - is_ground_content = false, - sunlight_propagates = true, - walkable = false, - groups = cgroups, - drop = gate_id, - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - {-0.5, -3/16, -1/16, -6/16, 0.5, 1/16}, --links abschluss - {6/16, -3/16, -1/16, 0.5, 0.5, 1/16}, --rechts abschluss - {-0.5, 4/16, 1/16, -6/16, 7/16, 6/16}, --oben-links(quer) x - {-0.5, -2/16, 1/16, -6/16, 1/16, 6/16}, --unten-links(quer) x - {6/16, 4/16, 1/16, 0.5, 7/16, 0.5}, --oben-rechts(quer) x - {6/16, -2/16, 1/16, 0.5, 1/16, 0.5}, --unten-rechts(quer) x - {-0.5, -2/16, 6/16, -6/16, 7/16, 0.5}, --mitte links - {6/16, 1/16, 0.5, 0.5, 4/16, 6/16}, --mitte rechts - } - }, - selection_box = { - type = "fixed", - fixed = { - {-0.5, -3/16, -1/16, 0.5, 0.5, 1/16}, --gate - } - }, - on_rightclick = function(pos, node, clicker) - punch_gate(pos, node) - end, - mesecons = {effector = { - action_off = (function(pos, node) - punch_gate(pos, node) - end), - }}, - on_rotate = on_rotate, - sounds = sounds, - _mcl_blast_resistance = blast_resistance, - _mcl_hardness = hardness, - }) - - local cgroups_closed = table.copy(cgroups) - cgroups_closed.mesecon_effector_on = nil - cgroups_closed.mesecon_effector_off = nil - minetest.register_node(gate_id, { - description = fence_gate_name, - _tt_help = S("Openable by players and redstone power"), - _doc_items_longdesc = S("Fence gates can be opened or closed and can't be jumped over. Fences will connect nicely to fence gates."), - _doc_items_usagehelp = S("Right-click the fence gate to open or close it."), - tiles = {texture}, - inventory_image = "mcl_fences_fence_gate_mask.png^" .. texture .. "^mcl_fences_fence_gate_mask.png^[makealpha:255,126,126", - wield_image = "mcl_fences_fence_gate_mask.png^" .. texture .. "^mcl_fences_fence_gate_mask.png^[makealpha:255,126,126", - paramtype = "light", - is_ground_content = false, - stack_max = 64, - paramtype2 = "facedir", - sunlight_propagates = true, - walkable = true, - groups = cgroups_closed, - drawtype = "nodebox", - node_box = { - type = "fixed", - fixed = { - {-0.5, -3/16, -1/16, -6/16, 0.5, 1/16}, --links abschluss - {6/16, -3/16, -1/16, 0.5, 0.5, 1/16}, --rechts abschluss - {-2/16, -2/16, -1/16, 0, 7/16, 1/16}, --mitte links - {0, -2/16, -1/16, 2/16, 7/16, 1/16}, --mitte rechts - {-0.5, 4/16, -1/16, -2/16, 7/16, 1/16}, --oben(quer) -z - {-0.5, -2/16, -1/16, -2/16, 1/16, 1/16}, --unten(quer) -z - {2/16, 4/16, -1/16, 0.5, 7/16, 1/16}, --oben(quer) z - {2/16, -2/16, -1/16, 0.5, 1/16, 1/16}, --unten(quer) z - } - }, - collision_box = { - type = "fixed", - fixed = { - {-0.5, -3/16, -2/16, 0.5, 1, 2/16}, --gate - } - }, - selection_box = { - type = "fixed", - fixed = { - {-0.5, -3/16, -1/16, 0.5, 0.5, 1/16}, --gate - } - }, - on_construct = function(pos) - meta2 = minetest.get_meta(pos) - meta2:set_int("state", 0) - state2 = 0 - end, - mesecons = {effector = { - action_on = (function(pos, node) - punch_gate(pos, node) - end), - }}, - on_rotate = on_rotate, - on_rightclick = function(pos, node, clicker) - punch_gate(pos, node) - end, - sounds = sounds, - _mcl_blast_resistance = blast_resistance, - _mcl_hardness = hardness, - }) - - if minetest.get_modpath("doc") then - doc.add_entry_alias("nodes", gate_id, "nodes", open_gate_id) - end - - return gate_id, open_gate_id -end - -function mcl_fences.register_fence_and_fence_gate(id, fence_name, fence_gate_name, texture_fence, groups, hardness, blast_resistance, connects_to, sounds, sound_open, sound_close, sound_gain_open, sound_gain_close, texture_fence_gate) - if texture_fence_gate == nil then - texture_fence_gate = texture_fence - end - local fence_id = mcl_fences.register_fence(id, fence_name, texture_fence, groups, hardness, blast_resistance, connects_to, sounds) - local gate_id, open_gate_id = mcl_fences.register_fence_gate(id, fence_gate_name, texture_fence_gate, groups, hardness, blast_resistance, sounds, sound_open, sound_close, sound_gain_open, sound_gain_close) - return fence_id, gate_id, open_gate_id -end - -local wood_groups = {handy=1,axey=1, flammable=2,fence_wood=1, fire_encouragement=5, fire_flammability=20} -local wood_connect = {"group:fence_wood"} -local wood_sounds = mcl_sounds.node_sound_wood_defaults() - -local woods = { - {"", S("Oak Fence"), S("Oak Fence Gate"), "mcl_fences_fence_oak.png", "mcl_fences_fence_gate_oak.png", "mcl_core:wood"}, - {"spruce", S("Spruce Fence"), S("Spruce Fence Gate"), "mcl_fences_fence_spruce.png", "mcl_fences_fence_gate_spruce.png", "mcl_core:sprucewood"}, - {"birch", S("Birch Fence"), S("Birch Fence Gate"), "mcl_fences_fence_birch.png", "mcl_fences_fence_gate_birch.png", "mcl_core:birchwood"}, - {"jungle", S("Jungle Fence"), S("Jungle Fence Gate"), "mcl_fences_fence_jungle.png", "mcl_fences_fence_gate_jungle.png", "mcl_core:junglewood"}, - {"dark_oak", S("Dark Oak Fence"), S("Dark Oak Fence Gate"), "mcl_fences_fence_big_oak.png", "mcl_fences_fence_gate_big_oak.png", "mcl_core:darkwood"}, - {"acacia", S("Acacia Fence"), S("Acacia Fence Gate"), "mcl_fences_fence_acacia.png", "mcl_fences_fence_gate_acacia.png", "mcl_core:acaciawood"}, -} - -for w=1, #woods do - local wood = woods[w] - local id, id_gate - if wood[1] == "" then - id = "fence" - id_gate = "fence_gate" - else - id = wood[1].."_fence" - id_gate = wood[1].."_fence_gate" - end - mcl_fences.register_fence_and_fence_gate(id, wood[2], wood[3], wood[4], wood_groups, 2, 15, wood_connect, wood_sounds) - - minetest.register_craft({ - output = "mcl_fences:"..id.." 3", - recipe = { - {wood[6], "mcl_core:stick", wood[6]}, - {wood[6], "mcl_core:stick", wood[6]}, - } - }) - minetest.register_craft({ - output = "mcl_fences:"..id_gate, - recipe = { - {"mcl_core:stick", wood[6], "mcl_core:stick"}, - {"mcl_core:stick", wood[6], "mcl_core:stick"}, - } - }) -end - - --- Nether Brick Fence (without fence gate!) -mcl_fences.register_fence("nether_brick_fence", S("Nether Brick Fence"), "mcl_fences_fence_nether_brick.png", {pickaxey=1, deco_block=1, fence_nether_brick=1}, 2, 30, {"group:fence_nether_brick"}, mcl_sounds.node_sound_stone_defaults()) - -minetest.register_craft({ - output = "mcl_fences:nether_brick_fence 6", - recipe = { - {"mcl_nether:nether_brick", "mcl_nether:netherbrick", "mcl_nether:nether_brick"}, - {"mcl_nether:nether_brick", "mcl_nether:netherbrick", "mcl_nether:nether_brick"}, - } -}) - -minetest.register_craft({ - type = "fuel", - recipe = "group:fence_wood", - burntime = 15, -}) +local S = minetest.get_translator(minetest.get_current_modname()) + +-- Node box +local p = {-2/16, -0.5, -2/16, 2/16, 0.5, 2/16} +local x1 = {-0.5, 4/16, -1/16, -2/16, 7/16, 1/16} --oben(quer) -x +local x12 = {-0.5, -2/16, -1/16, -2/16, 1/16, 1/16} --unten(quer) -x +local x2 = {2/16, 4/16, -1/16, 0.5, 7/16, 1/16} --oben(quer) x +local x22 = {2/16, -2/16, -1/16, 0.5, 1/16, 1/16} --unten(quer) x +local z1 = {-1/16, 4/16, -0.5, 1/16, 7/16, -2/16} --oben(quer) -z +local z12 = {-1/16, -2/16, -0.5, 1/16, 1/16, -2/16} --unten(quer) -z +local z2 = {-1/16, 4/16, 2/16, 1/16, 7/16, 0.5} --oben(quer) z +local z22 = {-1/16, -2/16, 2/16, 1/16, 1/16, 0.5} --unten(quer) z + +-- Collision box +local cp = {-2/16, -0.5, -2/16, 2/16, 1.01, 2/16} +local cx1 = {-0.5, -0.5, -2/16, -2/16, 1.01, 2/16} --unten(quer) -x +local cx2 = {2/16, -0.5, -2/16, 0.5, 1.01, 2/16} --unten(quer) x +local cz1 = {-2/16, -0.5, -0.5, 2/16, 1.01, -2/16} --unten(quer) -z +local cz2 = {-2/16, -0.5, 2/16, 2/16, 1.01, 0.5} --unten(quer) z + +mcl_fences = {} + +function mcl_fences.register_fence(id, fence_name, texture, groups, hardness, blast_resistance, connects_to, sounds) + local cgroups = table.copy(groups) + if cgroups == nil then cgroups = {} end + cgroups.fence = 1 + cgroups.deco_block = 1 + if connects_to == nil then + connects_to = {} + else + connects_to = table.copy(connects_to) + end + local fence_id = minetest.get_current_modname()..":"..id + table.insert(connects_to, "group:solid") + table.insert(connects_to, "group:fence_gate") + table.insert(connects_to, fence_id) + minetest.register_node(fence_id, { + description = fence_name, + _doc_items_longdesc = S("Fences are structures which block the way. Fences will connect to each other and solid blocks. They cannot be jumped over with a simple jump."), + tiles = {texture}, + inventory_image = "mcl_fences_fence_mask.png^" .. texture .. "^mcl_fences_fence_mask.png^[makealpha:255,126,126", + wield_image = "mcl_fences_fence_mask.png^" .. texture .. "^mcl_fences_fence_mask.png^[makealpha:255,126,126", + paramtype = "light", + is_ground_content = false, + groups = cgroups, + stack_max = 64, + sunlight_propagates = true, + drawtype = "nodebox", + connect_sides = { "front", "back", "left", "right" }, + connects_to = connects_to, + node_box = { + type = "connected", + fixed = {p}, + connect_front = {z1,z12}, + connect_back = {z2,z22,}, + connect_left = {x1,x12}, + connect_right = {x2,x22}, + }, + collision_box = { + type = "connected", + fixed = {cp}, + connect_front = {cz1}, + connect_back = {cz2,}, + connect_left = {cx1}, + connect_right = {cx2}, + }, + sounds = sounds, + _mcl_blast_resistance = blast_resistance, + _mcl_hardness = hardness, + }) + + return fence_id +end + +function mcl_fences.register_fence_gate(id, fence_gate_name, texture, groups, hardness, blast_resistance, sounds, sound_open, sound_close, sound_gain_open, sound_gain_close) + local meta2 + local state2 = 0 + + local function update_gate(pos, node) + minetest.set_node(pos, node) + end + + local gate_id = minetest.get_current_modname()..":"..id.."_gate" + local open_gate_id = gate_id .. "_open" + if not sound_open then + sound_open = "doors_fencegate_open" + end + if not sound_close then + sound_close = "doors_fencegate_close" + end + if not sound_gain_open then + sound_gain_open = 0.3 + end + if not sound_gain_close then + sound_gain_close = 0.3 + end + local function punch_gate(pos, node) + meta2 = minetest.get_meta(pos) + state2 = meta2:get_int("state") + local tmp_node2 + if state2 == 1 then + state2 = 0 + minetest.sound_play(sound_close, {gain = sound_gain_close, max_hear_distance = 10, pos = pos}, true) + tmp_node2 = {name=gate_id, param1=node.param1, param2=node.param2} + else + state2 = 1 + minetest.sound_play(sound_open, {gain = sound_gain_open, max_hear_distance = 10, pos = pos}, true) + tmp_node2 = {name=open_gate_id, param1=node.param1, param2=node.param2} + end + update_gate(pos, tmp_node2) + meta2:set_int("state", state2) + end + + local on_rotate + if minetest.get_modpath("screwdriver") then + on_rotate = screwdriver.rotate_simple + end + + local cgroups = table.copy(groups) + if cgroups == nil then cgroups = {} end + cgroups.fence_gate = 1 + cgroups.deco_block = 1 + + cgroups.mesecon_ignore_opaque_dig = 1 + cgroups.mesecon_effector_on = 1 + cgroups.fence_gate = 1 + minetest.register_node(open_gate_id, { + tiles = {texture}, + paramtype = "light", + paramtype2 = "facedir", + is_ground_content = false, + sunlight_propagates = true, + walkable = false, + groups = cgroups, + drop = gate_id, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-0.5, -3/16, -1/16, -6/16, 0.5, 1/16}, --links abschluss + {6/16, -3/16, -1/16, 0.5, 0.5, 1/16}, --rechts abschluss + {-0.5, 4/16, 1/16, -6/16, 7/16, 6/16}, --oben-links(quer) x + {-0.5, -2/16, 1/16, -6/16, 1/16, 6/16}, --unten-links(quer) x + {6/16, 4/16, 1/16, 0.5, 7/16, 0.5}, --oben-rechts(quer) x + {6/16, -2/16, 1/16, 0.5, 1/16, 0.5}, --unten-rechts(quer) x + {-0.5, -2/16, 6/16, -6/16, 7/16, 0.5}, --mitte links + {6/16, 1/16, 0.5, 0.5, 4/16, 6/16}, --mitte rechts + } + }, + selection_box = { + type = "fixed", + fixed = { + {-0.5, -3/16, -1/16, 0.5, 0.5, 1/16}, --gate + } + }, + on_rightclick = function(pos, node, clicker) + punch_gate(pos, node) + end, + mesecons = {effector = { + action_off = (function(pos, node) + punch_gate(pos, node) + end), + }}, + on_rotate = on_rotate, + sounds = sounds, + _mcl_blast_resistance = blast_resistance, + _mcl_hardness = hardness, + }) + + local cgroups_closed = table.copy(cgroups) + cgroups_closed.mesecon_effector_on = nil + cgroups_closed.mesecon_effector_off = nil + minetest.register_node(gate_id, { + description = fence_gate_name, + _tt_help = S("Openable by players and redstone power"), + _doc_items_longdesc = S("Fence gates can be opened or closed and can't be jumped over. Fences will connect nicely to fence gates."), + _doc_items_usagehelp = S("Right-click the fence gate to open or close it."), + tiles = {texture}, + inventory_image = "mcl_fences_fence_gate_mask.png^" .. texture .. "^mcl_fences_fence_gate_mask.png^[makealpha:255,126,126", + wield_image = "mcl_fences_fence_gate_mask.png^" .. texture .. "^mcl_fences_fence_gate_mask.png^[makealpha:255,126,126", + paramtype = "light", + is_ground_content = false, + stack_max = 64, + paramtype2 = "facedir", + sunlight_propagates = true, + walkable = true, + groups = cgroups_closed, + drawtype = "nodebox", + node_box = { + type = "fixed", + fixed = { + {-0.5, -3/16, -1/16, -6/16, 0.5, 1/16}, --links abschluss + {6/16, -3/16, -1/16, 0.5, 0.5, 1/16}, --rechts abschluss + {-2/16, -2/16, -1/16, 0, 7/16, 1/16}, --mitte links + {0, -2/16, -1/16, 2/16, 7/16, 1/16}, --mitte rechts + {-0.5, 4/16, -1/16, -2/16, 7/16, 1/16}, --oben(quer) -z + {-0.5, -2/16, -1/16, -2/16, 1/16, 1/16}, --unten(quer) -z + {2/16, 4/16, -1/16, 0.5, 7/16, 1/16}, --oben(quer) z + {2/16, -2/16, -1/16, 0.5, 1/16, 1/16}, --unten(quer) z + } + }, + collision_box = { + type = "fixed", + fixed = { + {-0.5, -3/16, -2/16, 0.5, 1, 2/16}, --gate + } + }, + selection_box = { + type = "fixed", + fixed = { + {-0.5, -3/16, -1/16, 0.5, 0.5, 1/16}, --gate + } + }, + on_construct = function(pos) + meta2 = minetest.get_meta(pos) + meta2:set_int("state", 0) + state2 = 0 + end, + mesecons = {effector = { + action_on = (function(pos, node) + punch_gate(pos, node) + end), + }}, + on_rotate = on_rotate, + on_rightclick = function(pos, node, clicker) + punch_gate(pos, node) + end, + sounds = sounds, + _mcl_blast_resistance = blast_resistance, + _mcl_hardness = hardness, + }) + + if minetest.get_modpath("doc") then + doc.add_entry_alias("nodes", gate_id, "nodes", open_gate_id) + end + + return gate_id, open_gate_id +end + +function mcl_fences.register_fence_and_fence_gate(id, fence_name, fence_gate_name, texture_fence, groups, hardness, blast_resistance, connects_to, sounds, sound_open, sound_close, sound_gain_open, sound_gain_close, texture_fence_gate) + if texture_fence_gate == nil then + texture_fence_gate = texture_fence + end + local fence_id = mcl_fences.register_fence(id, fence_name, texture_fence, groups, hardness, blast_resistance, connects_to, sounds) + local gate_id, open_gate_id = mcl_fences.register_fence_gate(id, fence_gate_name, texture_fence_gate, groups, hardness, blast_resistance, sounds, sound_open, sound_close, sound_gain_open, sound_gain_close) + return fence_id, gate_id, open_gate_id +end + +local wood_groups = {handy=1,axey=1, flammable=2,fence_wood=1, fire_encouragement=5, fire_flammability=20} +local wood_connect = {"group:fence_wood"} +local wood_sounds = mcl_sounds.node_sound_wood_defaults() + +local woods = { + {"", S("Oak Fence"), S("Oak Fence Gate"), "mcl_fences_fence_oak.png", "mcl_fences_fence_gate_oak.png", "mcl_core:wood"}, + {"spruce", S("Spruce Fence"), S("Spruce Fence Gate"), "mcl_fences_fence_spruce.png", "mcl_fences_fence_gate_spruce.png", "mcl_core:sprucewood"}, + {"birch", S("Birch Fence"), S("Birch Fence Gate"), "mcl_fences_fence_birch.png", "mcl_fences_fence_gate_birch.png", "mcl_core:birchwood"}, + {"jungle", S("Jungle Fence"), S("Jungle Fence Gate"), "mcl_fences_fence_jungle.png", "mcl_fences_fence_gate_jungle.png", "mcl_core:junglewood"}, + {"dark_oak", S("Dark Oak Fence"), S("Dark Oak Fence Gate"), "mcl_fences_fence_big_oak.png", "mcl_fences_fence_gate_big_oak.png", "mcl_core:darkwood"}, + {"acacia", S("Acacia Fence"), S("Acacia Fence Gate"), "mcl_fences_fence_acacia.png", "mcl_fences_fence_gate_acacia.png", "mcl_core:acaciawood"}, +} + +for w=1, #woods do + local wood = woods[w] + local id, id_gate + if wood[1] == "" then + id = "fence" + id_gate = "fence_gate" + else + id = wood[1].."_fence" + id_gate = wood[1].."_fence_gate" + end + mcl_fences.register_fence_and_fence_gate(id, wood[2], wood[3], wood[4], wood_groups, 2, 15, wood_connect, wood_sounds) + + minetest.register_craft({ + output = "mcl_fences:"..id.." 3", + recipe = { + {wood[6], "mcl_core:stick", wood[6]}, + {wood[6], "mcl_core:stick", wood[6]}, + } + }) + minetest.register_craft({ + output = "mcl_fences:"..id_gate, + recipe = { + {"mcl_core:stick", wood[6], "mcl_core:stick"}, + {"mcl_core:stick", wood[6], "mcl_core:stick"}, + } + }) +end + + +-- Nether Brick Fence (without fence gate!) +mcl_fences.register_fence("nether_brick_fence", S("Nether Brick Fence"), "mcl_fences_fence_nether_brick.png", {pickaxey=1, deco_block=1, fence_nether_brick=1}, 2, 30, {"group:fence_nether_brick"}, mcl_sounds.node_sound_stone_defaults()) + +minetest.register_craft({ + output = "mcl_fences:nether_brick_fence 6", + recipe = { + {"mcl_nether:nether_brick", "mcl_nether:netherbrick", "mcl_nether:nether_brick"}, + {"mcl_nether:nether_brick", "mcl_nether:netherbrick", "mcl_nether:nether_brick"}, + } +}) + +minetest.register_craft({ + type = "fuel", + recipe = "group:fence_wood", + burntime = 15, +}) diff --git a/mods/ITEMS/mcl_loom/init.lua b/mods/ITEMS/mcl_loom/init.lua index 750ecc758..6126a5d39 100644 --- a/mods/ITEMS/mcl_loom/init.lua +++ b/mods/ITEMS/mcl_loom/init.lua @@ -1,6 +1,6 @@ local S = minetest.get_translator(minetest.get_current_modname()) -- Loom Code. Used to craft banner designs easier. Still needs a GUI. https://minecraft.fandom.com/wiki/Loom - + minetest.register_node("mcl_loom:loom", { description = S("Loom"), _tt_help = S("Used to create banner designs"), @@ -13,7 +13,7 @@ minetest.register_node("mcl_loom:loom", { paramtype2 = "facedir", groups = {choppy=1, deco_block=1, material_wood=1, flammable=1} }) - + minetest.register_craft({ output = "mcl_loom:loom", diff --git a/mods/ITEMS/mcl_mobitems/init.lua b/mods/ITEMS/mcl_mobitems/init.lua index 2fe30b09d..85907b95b 100644 --- a/mods/ITEMS/mcl_mobitems/init.lua +++ b/mods/ITEMS/mcl_mobitems/init.lua @@ -1,447 +1,447 @@ -local S = minetest.get_translator(minetest.get_current_modname()) - -minetest.register_craftitem("mcl_mobitems:rotten_flesh", { - description = S("Rotten Flesh"), - _tt_help = minetest.colorize(mcl_colors.YELLOW, S("80% chance of food poisoning")), - _doc_items_longdesc = S("Yuck! This piece of flesh clearly has seen better days. If you're really desperate, you can eat it to restore a few hunger points, but there's a 80% chance it causes food poisoning, which increases your hunger for a while."), - inventory_image = "mcl_mobitems_rotten_flesh.png", - wield_image = "mcl_mobitems_rotten_flesh.png", - on_place = minetest.item_eat(4), - on_secondary_use = minetest.item_eat(4), - groups = { food = 2, eatable = 4 }, - _mcl_saturation = 0.8, - stack_max = 64, -}) - -minetest.register_craftitem("mcl_mobitems:mutton", { - description = S("Raw Mutton"), - _doc_items_longdesc = S("Raw mutton is the flesh from a sheep and can be eaten safely. Cooking it will greatly increase its nutritional value."), - inventory_image = "mcl_mobitems_mutton_raw.png", - wield_image = "mcl_mobitems_mutton_raw.png", - on_place = minetest.item_eat(2), - on_secondary_use = minetest.item_eat(2), - groups = { food = 2, eatable = 2, smoker_cookable = 1 }, - _mcl_saturation = 1.2, - stack_max = 64, -}) - -minetest.register_craftitem("mcl_mobitems:cooked_mutton", { - description = S("Cooked Mutton"), - _doc_items_longdesc = S("Cooked mutton is the cooked flesh from a sheep and is used as food."), - inventory_image = "mcl_mobitems_mutton_cooked.png", - wield_image = "mcl_mobitems_mutton_cooked.png", - on_place = minetest.item_eat(6), - on_secondary_use = minetest.item_eat(6), - groups = { food = 2, eatable = 6 }, - _mcl_saturation = 9.6, - stack_max = 64, -}) - -minetest.register_craftitem("mcl_mobitems:beef", { - description = S("Raw Beef"), - _doc_items_longdesc = S("Raw beef is the flesh from cows and can be eaten safely. Cooking it will greatly increase its nutritional value."), - inventory_image = "mcl_mobitems_beef_raw.png", - wield_image = "mcl_mobitems_beef_raw.png", - on_place = minetest.item_eat(3), - on_secondary_use = minetest.item_eat(3), - groups = { food = 2, eatable = 3, smoker_cookable = 1 }, - _mcl_saturation = 1.8, - stack_max = 64, -}) - -minetest.register_craftitem("mcl_mobitems:cooked_beef", { - description = S("Steak"), - _doc_items_longdesc = S("Steak is cooked beef from cows and can be eaten."), - inventory_image = "mcl_mobitems_beef_cooked.png", - wield_image = "mcl_mobitems_beef_cooked.png", - on_place = minetest.item_eat(8), - on_secondary_use = minetest.item_eat(8), - groups = { food = 2, eatable = 8 }, - _mcl_saturation = 12.8, - stack_max = 64, -}) - -minetest.register_craftitem("mcl_mobitems:chicken", { - description = S("Raw Chicken"), - _tt_help = minetest.colorize(mcl_colors.YELLOW, S("30% chance of food poisoning")), - _doc_items_longdesc = S("Raw chicken is a food item which is not safe to consume. You can eat it to restore a few hunger points, but there's a 30% chance to suffer from food poisoning, which increases your hunger rate for a while. Cooking raw chicken will make it safe to eat and increases its nutritional value."), - inventory_image = "mcl_mobitems_chicken_raw.png", - wield_image = "mcl_mobitems_chicken_raw.png", - on_place = minetest.item_eat(2), - on_secondary_use = minetest.item_eat(2), - groups = { food = 2, eatable = 2, smoker_cookable = 1 }, - _mcl_saturation = 1.2, - stack_max = 64, -}) - -minetest.register_craftitem("mcl_mobitems:cooked_chicken", { - description = S("Cooked Chicken"), - _doc_items_longdesc = S("A cooked chicken is a healthy food item which can be eaten."), - inventory_image = "mcl_mobitems_chicken_cooked.png", - wield_image = "mcl_mobitems_chicken_cooked.png", - on_place = minetest.item_eat(6), - on_secondary_use = minetest.item_eat(6), - groups = { food = 2, eatable = 6 }, - _mcl_saturation = 7.2, - stack_max = 64, -}) - -minetest.register_craftitem("mcl_mobitems:porkchop", { - description = S("Raw Porkchop"), - _doc_items_longdesc = S("A raw porkchop is the flesh from a pig and can be eaten safely. Cooking it will greatly increase its nutritional value."), - inventory_image = "mcl_mobitems_porkchop_raw.png", - wield_image = "mcl_mobitems_porkchop_raw.png", - on_place = minetest.item_eat(3), - on_secondary_use = minetest.item_eat(3), - groups = { food = 2, eatable = 3, smoker_cookable = 1 }, - _mcl_saturation = 1.8, - stack_max = 64, -}) - -minetest.register_craftitem("mcl_mobitems:cooked_porkchop", { - description = S("Cooked Porkchop"), - _doc_items_longdesc = S("Cooked porkchop is the cooked flesh of a pig and is used as food."), - inventory_image = "mcl_mobitems_porkchop_cooked.png", - wield_image = "mcl_mobitems_porkchop_cooked.png", - on_place = minetest.item_eat(8), - on_secondary_use = minetest.item_eat(8), - groups = { food = 2, eatable = 8 }, - _mcl_saturation = 12.8, - stack_max = 64, -}) - -minetest.register_craftitem("mcl_mobitems:rabbit", { - description = S("Raw Rabbit"), - _doc_items_longdesc = S("Raw rabbit is a food item from a dead rabbit. It can be eaten safely. Cooking it will increase its nutritional value."), - inventory_image = "mcl_mobitems_rabbit_raw.png", - wield_image = "mcl_mobitems_rabbit_raw.png", - on_place = minetest.item_eat(3), - on_secondary_use = minetest.item_eat(3), - groups = { food = 2, eatable = 3, smoker_cookable = 1 }, - _mcl_saturation = 1.8, - stack_max = 64, -}) - -minetest.register_craftitem("mcl_mobitems:cooked_rabbit", { - description = S("Cooked Rabbit"), - _doc_items_longdesc = S("This is a food item which can be eaten."), - inventory_image = "mcl_mobitems_rabbit_cooked.png", - wield_image = "mcl_mobitems_rabbit_cooked.png", - on_place = minetest.item_eat(5), - on_secondary_use = minetest.item_eat(5), - groups = { food = 2, eatable = 5 }, - _mcl_saturation = 6.0, - stack_max = 64, -}) - --- Reset food poisoning and status effects -local function drink_milk(itemstack, player, pointed_thing) - local bucket = minetest.do_item_eat(0, "mcl_buckets:bucket_empty", itemstack, player, pointed_thing) - -- Check if we were allowed to drink this (eat delay check) - if mcl_hunger.active and (bucket:get_name() ~= "mcl_mobitems:milk_bucket" or minetest.is_creative_enabled(player:get_player_name())) then - mcl_hunger.stop_poison(player) - end - mcl_potions._reset_player_effects(player) - return bucket -end - -minetest.register_craftitem("mcl_mobitems:milk_bucket", { - description = S("Milk"), - _tt_help = minetest.colorize(mcl_colors.GREEN, S("Removes all status effects")), - _doc_items_longdesc = S("Milk is very refreshing and can be obtained by using a bucket on a cow. Drinking it will remove all status effects, but restores no hunger points."), - _doc_items_usagehelp = S("Use the placement key to drink the milk."), - inventory_image = "mcl_mobitems_bucket_milk.png", - wield_image = "mcl_mobitems_bucket_milk.png", - on_place = drink_milk, - on_secondary_use = drink_milk, - stack_max = 1, - groups = { food = 3, can_eat_when_full = 1 }, -}) - -minetest.register_craftitem("mcl_mobitems:spider_eye", { - description = S("Spider Eye"), - _tt_help = minetest.colorize(mcl_colors.YELLOW, S("Poisonous")), - _doc_items_longdesc = S("Spider eyes are used mainly in crafting. If you're really desperate, you can eat a spider eye, but it will poison you briefly."), - inventory_image = "mcl_mobitems_spider_eye.png", - wield_image = "mcl_mobitems_spider_eye.png", - on_place = minetest.item_eat(2), - on_secondary_use = minetest.item_eat(2), - groups = { food = 2, eatable = 2, brewitem = 1 }, - _mcl_saturation = 3.2, - stack_max = 64, -}) - -minetest.register_craftitem("mcl_mobitems:bone", { - description = S("Bone"), - _doc_items_longdesc = S("Bones can be used to tame wolves so they will protect you. They are also useful as a crafting ingredient."), - _doc_items_usagehelp = S("Wield the bone near wolves to attract them. Use the “Place” key on the wolf to give it a bone and tame it. You can then give commands to the tamed wolf by using the “Place” key on it."), - inventory_image = "mcl_mobitems_bone.png", - stack_max = 64, - groups = { craftitem=1 }, - _mcl_toollike_wield = true, -}) - -minetest.register_craftitem("mcl_mobitems:string",{ - description = S("String"), - _doc_items_longdesc = S("Strings are used in crafting."), - inventory_image = "mcl_mobitems_string.png", - stack_max = 64, - groups = { craftitem = 1 }, -}) - -minetest.register_craftitem("mcl_mobitems:blaze_rod", { - description = S("Blaze Rod"), - _doc_items_longdesc = S("This is a crafting component dropped from dead blazes."), - wield_image = "mcl_mobitems_blaze_rod.png", - inventory_image = "mcl_mobitems_blaze_rod.png", - groups = { craftitem = 1 }, - stack_max = 64, -}) - -minetest.register_craftitem("mcl_mobitems:blaze_powder", { - description = S("Blaze Powder"), - _doc_items_longdesc = S("This item is mainly used for crafting."), - wield_image = "mcl_mobitems_blaze_powder.png", - inventory_image = "mcl_mobitems_blaze_powder.png", - groups = { craftitem = 1, brewitem = 1 }, - stack_max = 64, -}) - -minetest.register_craftitem("mcl_mobitems:magma_cream", { - description = S("Magma Cream"), - _doc_items_longdesc = S("Magma cream is a crafting component."), - wield_image = "mcl_mobitems_magma_cream.png", - inventory_image = "mcl_mobitems_magma_cream.png", - groups = { craftitem = 1, brewitem = 1 }, - stack_max = 64, -}) - -minetest.register_craftitem("mcl_mobitems:ghast_tear", { - description = S("Ghast Tear"), - _doc_items_longdesc = S("Place this item in an item frame as decoration."), - wield_image = "mcl_mobitems_ghast_tear.png", - inventory_image = "mcl_mobitems_ghast_tear.png", - groups = { brewitem = 1 }, - stack_max = 64, -}) - -minetest.register_craftitem("mcl_mobitems:nether_star", { - description = S("Nether Star"), - _doc_items_longdesc = S("A nether star is dropped when the Wither dies. Place it in an item frame to show the world how hardcore you are! Or just as decoration."), - wield_image = "mcl_mobitems_nether_star.png", - inventory_image = "mcl_mobitems_nether_star.png", - -- TODO: Reveal item when it's useful - groups = { craftitem = 1, not_in_creative_inventory = 1 }, - stack_max = 64, -}) - -minetest.register_craftitem("mcl_mobitems:leather", { - description = S("Leather"), - _doc_items_longdesc = S("Leather is a versatile crafting component."), - wield_image = "mcl_mobitems_leather.png", - inventory_image = "mcl_mobitems_leather.png", - groups = { craftitem = 1 }, - stack_max = 64, -}) - -minetest.register_craftitem("mcl_mobitems:feather", { - description = S("Feather"), - _doc_items_longdesc = S("Feathers are used in crafting and are dropped from chickens."), - wield_image = "mcl_mobitems_feather.png", - inventory_image = "mcl_mobitems_feather.png", - groups = { craftitem = 1 }, - stack_max = 64, -}) - -minetest.register_craftitem("mcl_mobitems:rabbit_hide", { - description = S("Rabbit Hide"), - _doc_items_longdesc = S("Rabbit hide is used to create leather."), - wield_image = "mcl_mobitems_rabbit_hide.png", - inventory_image = "mcl_mobitems_rabbit_hide.png", - groups = { craftitem = 1 }, - stack_max = 64, -}) - -minetest.register_craftitem("mcl_mobitems:rabbit_foot", { - description = S("Rabbit's Foot"), - _doc_items_longdesc = S("Must be your lucky day! Place this item in an item frame for decoration."), - wield_image = "mcl_mobitems_rabbit_foot.png", - inventory_image = "mcl_mobitems_rabbit_foot.png", - groups = { brewitem = 1 }, - stack_max = 64, -}) - -minetest.register_craftitem("mcl_mobitems:saddle", { - description = S("Saddle"), - _tt_help = S("Can be placed on animals to ride them"), - _doc_items_longdesc = S("Saddles can be put on some animals in order to mount them."), - _doc_items_usagehelp = S("Use the placement key with the saddle in your hand to try to put on the saddle. Saddles fit on horses, mules, donkeys and pigs. Horses, mules and donkeys need to be tamed first, otherwise they'll reject the saddle. Saddled animals can be mounted by using the placement key on them again."), - wield_image = "mcl_mobitems_saddle.png", - inventory_image = "mcl_mobitems_saddle.png", - groups = { transport = 1 }, - stack_max = 1, -}) - -minetest.register_craftitem("mcl_mobitems:rabbit_stew", { - description = S("Rabbit Stew"), - _doc_items_longdesc = S("Rabbit stew is a very nutricious food item."), - wield_image = "mcl_mobitems_rabbit_stew.png", - inventory_image = "mcl_mobitems_rabbit_stew.png", - stack_max = 1, - on_place = minetest.item_eat(10, "mcl_core:bowl"), - on_secondary_use = minetest.item_eat(10, "mcl_core:bowl"), - groups = { food = 3, eatable = 10 }, - _mcl_saturation = 12.0, -}) - -minetest.register_craftitem("mcl_mobitems:shulker_shell", { - description = S("Shulker Shell"), - _doc_items_longdesc = S("Shulker shells are used in crafting. They are dropped from dead shulkers."), - inventory_image = "mcl_mobitems_shulker_shell.png", - groups = { craftitem = 1 }, -}) - -minetest.register_craftitem("mcl_mobitems:slimeball", { - description = S("Slimeball"), - _doc_items_longdesc = S("Slimeballs are used in crafting. They are dropped from slimes."), - inventory_image = "mcl_mobitems_slimeball.png", - groups = { craftitem = 1 }, -}) - -minetest.register_craftitem("mcl_mobitems:gunpowder", { - description = S("Gunpowder"), - _doc_items_longdesc = doc.sub.items.temp.craftitem, - inventory_image = "default_gunpowder.png", - stack_max = 64, - groups = { craftitem=1, brewitem = 1 }, -}) - -minetest.register_tool("mcl_mobitems:carrot_on_a_stick", { - description = S("Carrot on a Stick"), - _tt_help = S("Lets you ride a saddled pig"), - _doc_items_longdesc = S("A carrot on a stick can be used on saddled pigs to ride them."), - _doc_items_usagehelp = S("Place it on a saddled pig to mount it. You can now ride the pig like a horse. Pigs will also walk towards you when you just wield the carrot on a stick."), - wield_image = "mcl_mobitems_carrot_on_a_stick.png", - inventory_image = "mcl_mobitems_carrot_on_a_stick.png", - groups = { transport = 1 }, - _mcl_toollike_wield = true, -}) - ------------ --- Crafting ------------ - -minetest.register_craft({ - output = "mcl_mobitems:leather", - recipe = { - { "mcl_mobitems:rabbit_hide", "mcl_mobitems:rabbit_hide" }, - { "mcl_mobitems:rabbit_hide", "mcl_mobitems:rabbit_hide" }, - } -}) - -minetest.register_craft({ - output = "mcl_mobitems:blaze_powder 2", - recipe = {{"mcl_mobitems:blaze_rod"}}, -}) - -minetest.register_craft({ - output = "mcl_mobitems:rabbit_stew", - recipe = { - { "", "mcl_mobitems:cooked_rabbit", "", }, - { "group:mushroom", "mcl_farming:potato_item_baked", "mcl_farming:carrot_item", }, - { "", "mcl_core:bowl", "", }, - }, -}) - -minetest.register_craft({ - output = "mcl_mobitems:rabbit_stew", - recipe = { - { "", "mcl_mobitems:cooked_rabbit", "", }, - { "mcl_farming:carrot_item", "mcl_farming:potato_item_baked", "group:mushroom", }, - { "", "mcl_core:bowl", "", }, - }, -}) - -minetest.register_craft({ - output = "mcl_mobitems:carrot_on_a_stick", - recipe = { - { "mcl_fishing:fishing_rod", "", }, - { "", "mcl_farming:carrot_item" }, - }, -}) - -minetest.register_craft({ - output = "mcl_mobitems:carrot_on_a_stick", - recipe = { - { "", "mcl_fishing:fishing_rod", }, - { "mcl_farming:carrot_item", "" }, - }, -}) - -minetest.register_craft({ - type = "shapeless", - output = "mcl_mobitems:magma_cream", - recipe = {"mcl_mobitems:blaze_powder", "mcl_mobitems:slimeball"}, -}) - -minetest.register_craft({ - type = "cooking", - output = "mcl_mobitems:cooked_mutton", - recipe = "mcl_mobitems:mutton", - cooktime = 10, -}) - -minetest.register_craft({ - type = "cooking", - output = "mcl_mobitems:cooked_rabbit", - recipe = "mcl_mobitems:rabbit", - cooktime = 10, -}) - -minetest.register_craft({ - type = "cooking", - output = "mcl_mobitems:cooked_chicken", - recipe = "mcl_mobitems:chicken", - cooktime = 10, -}) - -minetest.register_craft({ - type = "cooking", - output = "mcl_mobitems:cooked_beef", - recipe = "mcl_mobitems:beef", - cooktime = 10, -}) - -minetest.register_craft({ - type = "cooking", - output = "mcl_mobitems:cooked_porkchop", - recipe = "mcl_mobitems:porkchop", - cooktime = 10, -}) - -minetest.register_craft({ - type = "fuel", - recipe = "mcl_mobitems:blaze_rod", - burntime = 120, -}) - -minetest.register_craft({ - output = "mcl_mobitems:slimeball 9", - recipe = {{"mcl_core:slimeblock"}}, -}) - -minetest.register_craft({ - output = "mcl_core:slimeblock", - recipe = {{"mcl_mobitems:slimeball","mcl_mobitems:slimeball","mcl_mobitems:slimeball",}, - {"mcl_mobitems:slimeball","mcl_mobitems:slimeball","mcl_mobitems:slimeball",}, - {"mcl_mobitems:slimeball","mcl_mobitems:slimeball","mcl_mobitems:slimeball",}}, -}) - -minetest.register_on_item_eat(function (hp_change, replace_with_item, itemstack, user, pointed_thing) - - -- poisoning with spider eye - if itemstack:get_name() == "mcl_mobitems:spider_eye" then - mcl_potions.poison_func(user, 1, 4) - end - -end ) +local S = minetest.get_translator(minetest.get_current_modname()) + +minetest.register_craftitem("mcl_mobitems:rotten_flesh", { + description = S("Rotten Flesh"), + _tt_help = minetest.colorize(mcl_colors.YELLOW, S("80% chance of food poisoning")), + _doc_items_longdesc = S("Yuck! This piece of flesh clearly has seen better days. If you're really desperate, you can eat it to restore a few hunger points, but there's a 80% chance it causes food poisoning, which increases your hunger for a while."), + inventory_image = "mcl_mobitems_rotten_flesh.png", + wield_image = "mcl_mobitems_rotten_flesh.png", + on_place = minetest.item_eat(4), + on_secondary_use = minetest.item_eat(4), + groups = { food = 2, eatable = 4 }, + _mcl_saturation = 0.8, + stack_max = 64, +}) + +minetest.register_craftitem("mcl_mobitems:mutton", { + description = S("Raw Mutton"), + _doc_items_longdesc = S("Raw mutton is the flesh from a sheep and can be eaten safely. Cooking it will greatly increase its nutritional value."), + inventory_image = "mcl_mobitems_mutton_raw.png", + wield_image = "mcl_mobitems_mutton_raw.png", + on_place = minetest.item_eat(2), + on_secondary_use = minetest.item_eat(2), + groups = { food = 2, eatable = 2, smoker_cookable = 1 }, + _mcl_saturation = 1.2, + stack_max = 64, +}) + +minetest.register_craftitem("mcl_mobitems:cooked_mutton", { + description = S("Cooked Mutton"), + _doc_items_longdesc = S("Cooked mutton is the cooked flesh from a sheep and is used as food."), + inventory_image = "mcl_mobitems_mutton_cooked.png", + wield_image = "mcl_mobitems_mutton_cooked.png", + on_place = minetest.item_eat(6), + on_secondary_use = minetest.item_eat(6), + groups = { food = 2, eatable = 6 }, + _mcl_saturation = 9.6, + stack_max = 64, +}) + +minetest.register_craftitem("mcl_mobitems:beef", { + description = S("Raw Beef"), + _doc_items_longdesc = S("Raw beef is the flesh from cows and can be eaten safely. Cooking it will greatly increase its nutritional value."), + inventory_image = "mcl_mobitems_beef_raw.png", + wield_image = "mcl_mobitems_beef_raw.png", + on_place = minetest.item_eat(3), + on_secondary_use = minetest.item_eat(3), + groups = { food = 2, eatable = 3, smoker_cookable = 1 }, + _mcl_saturation = 1.8, + stack_max = 64, +}) + +minetest.register_craftitem("mcl_mobitems:cooked_beef", { + description = S("Steak"), + _doc_items_longdesc = S("Steak is cooked beef from cows and can be eaten."), + inventory_image = "mcl_mobitems_beef_cooked.png", + wield_image = "mcl_mobitems_beef_cooked.png", + on_place = minetest.item_eat(8), + on_secondary_use = minetest.item_eat(8), + groups = { food = 2, eatable = 8 }, + _mcl_saturation = 12.8, + stack_max = 64, +}) + +minetest.register_craftitem("mcl_mobitems:chicken", { + description = S("Raw Chicken"), + _tt_help = minetest.colorize(mcl_colors.YELLOW, S("30% chance of food poisoning")), + _doc_items_longdesc = S("Raw chicken is a food item which is not safe to consume. You can eat it to restore a few hunger points, but there's a 30% chance to suffer from food poisoning, which increases your hunger rate for a while. Cooking raw chicken will make it safe to eat and increases its nutritional value."), + inventory_image = "mcl_mobitems_chicken_raw.png", + wield_image = "mcl_mobitems_chicken_raw.png", + on_place = minetest.item_eat(2), + on_secondary_use = minetest.item_eat(2), + groups = { food = 2, eatable = 2, smoker_cookable = 1 }, + _mcl_saturation = 1.2, + stack_max = 64, +}) + +minetest.register_craftitem("mcl_mobitems:cooked_chicken", { + description = S("Cooked Chicken"), + _doc_items_longdesc = S("A cooked chicken is a healthy food item which can be eaten."), + inventory_image = "mcl_mobitems_chicken_cooked.png", + wield_image = "mcl_mobitems_chicken_cooked.png", + on_place = minetest.item_eat(6), + on_secondary_use = minetest.item_eat(6), + groups = { food = 2, eatable = 6 }, + _mcl_saturation = 7.2, + stack_max = 64, +}) + +minetest.register_craftitem("mcl_mobitems:porkchop", { + description = S("Raw Porkchop"), + _doc_items_longdesc = S("A raw porkchop is the flesh from a pig and can be eaten safely. Cooking it will greatly increase its nutritional value."), + inventory_image = "mcl_mobitems_porkchop_raw.png", + wield_image = "mcl_mobitems_porkchop_raw.png", + on_place = minetest.item_eat(3), + on_secondary_use = minetest.item_eat(3), + groups = { food = 2, eatable = 3, smoker_cookable = 1 }, + _mcl_saturation = 1.8, + stack_max = 64, +}) + +minetest.register_craftitem("mcl_mobitems:cooked_porkchop", { + description = S("Cooked Porkchop"), + _doc_items_longdesc = S("Cooked porkchop is the cooked flesh of a pig and is used as food."), + inventory_image = "mcl_mobitems_porkchop_cooked.png", + wield_image = "mcl_mobitems_porkchop_cooked.png", + on_place = minetest.item_eat(8), + on_secondary_use = minetest.item_eat(8), + groups = { food = 2, eatable = 8 }, + _mcl_saturation = 12.8, + stack_max = 64, +}) + +minetest.register_craftitem("mcl_mobitems:rabbit", { + description = S("Raw Rabbit"), + _doc_items_longdesc = S("Raw rabbit is a food item from a dead rabbit. It can be eaten safely. Cooking it will increase its nutritional value."), + inventory_image = "mcl_mobitems_rabbit_raw.png", + wield_image = "mcl_mobitems_rabbit_raw.png", + on_place = minetest.item_eat(3), + on_secondary_use = minetest.item_eat(3), + groups = { food = 2, eatable = 3, smoker_cookable = 1 }, + _mcl_saturation = 1.8, + stack_max = 64, +}) + +minetest.register_craftitem("mcl_mobitems:cooked_rabbit", { + description = S("Cooked Rabbit"), + _doc_items_longdesc = S("This is a food item which can be eaten."), + inventory_image = "mcl_mobitems_rabbit_cooked.png", + wield_image = "mcl_mobitems_rabbit_cooked.png", + on_place = minetest.item_eat(5), + on_secondary_use = minetest.item_eat(5), + groups = { food = 2, eatable = 5 }, + _mcl_saturation = 6.0, + stack_max = 64, +}) + +-- Reset food poisoning and status effects +local function drink_milk(itemstack, player, pointed_thing) + local bucket = minetest.do_item_eat(0, "mcl_buckets:bucket_empty", itemstack, player, pointed_thing) + -- Check if we were allowed to drink this (eat delay check) + if mcl_hunger.active and (bucket:get_name() ~= "mcl_mobitems:milk_bucket" or minetest.is_creative_enabled(player:get_player_name())) then + mcl_hunger.stop_poison(player) + end + mcl_potions._reset_player_effects(player) + return bucket +end + +minetest.register_craftitem("mcl_mobitems:milk_bucket", { + description = S("Milk"), + _tt_help = minetest.colorize(mcl_colors.GREEN, S("Removes all status effects")), + _doc_items_longdesc = S("Milk is very refreshing and can be obtained by using a bucket on a cow. Drinking it will remove all status effects, but restores no hunger points."), + _doc_items_usagehelp = S("Use the placement key to drink the milk."), + inventory_image = "mcl_mobitems_bucket_milk.png", + wield_image = "mcl_mobitems_bucket_milk.png", + on_place = drink_milk, + on_secondary_use = drink_milk, + stack_max = 1, + groups = { food = 3, can_eat_when_full = 1 }, +}) + +minetest.register_craftitem("mcl_mobitems:spider_eye", { + description = S("Spider Eye"), + _tt_help = minetest.colorize(mcl_colors.YELLOW, S("Poisonous")), + _doc_items_longdesc = S("Spider eyes are used mainly in crafting. If you're really desperate, you can eat a spider eye, but it will poison you briefly."), + inventory_image = "mcl_mobitems_spider_eye.png", + wield_image = "mcl_mobitems_spider_eye.png", + on_place = minetest.item_eat(2), + on_secondary_use = minetest.item_eat(2), + groups = { food = 2, eatable = 2, brewitem = 1 }, + _mcl_saturation = 3.2, + stack_max = 64, +}) + +minetest.register_craftitem("mcl_mobitems:bone", { + description = S("Bone"), + _doc_items_longdesc = S("Bones can be used to tame wolves so they will protect you. They are also useful as a crafting ingredient."), + _doc_items_usagehelp = S("Wield the bone near wolves to attract them. Use the “Place” key on the wolf to give it a bone and tame it. You can then give commands to the tamed wolf by using the “Place” key on it."), + inventory_image = "mcl_mobitems_bone.png", + stack_max = 64, + groups = { craftitem=1 }, + _mcl_toollike_wield = true, +}) + +minetest.register_craftitem("mcl_mobitems:string",{ + description = S("String"), + _doc_items_longdesc = S("Strings are used in crafting."), + inventory_image = "mcl_mobitems_string.png", + stack_max = 64, + groups = { craftitem = 1 }, +}) + +minetest.register_craftitem("mcl_mobitems:blaze_rod", { + description = S("Blaze Rod"), + _doc_items_longdesc = S("This is a crafting component dropped from dead blazes."), + wield_image = "mcl_mobitems_blaze_rod.png", + inventory_image = "mcl_mobitems_blaze_rod.png", + groups = { craftitem = 1 }, + stack_max = 64, +}) + +minetest.register_craftitem("mcl_mobitems:blaze_powder", { + description = S("Blaze Powder"), + _doc_items_longdesc = S("This item is mainly used for crafting."), + wield_image = "mcl_mobitems_blaze_powder.png", + inventory_image = "mcl_mobitems_blaze_powder.png", + groups = { craftitem = 1, brewitem = 1 }, + stack_max = 64, +}) + +minetest.register_craftitem("mcl_mobitems:magma_cream", { + description = S("Magma Cream"), + _doc_items_longdesc = S("Magma cream is a crafting component."), + wield_image = "mcl_mobitems_magma_cream.png", + inventory_image = "mcl_mobitems_magma_cream.png", + groups = { craftitem = 1, brewitem = 1 }, + stack_max = 64, +}) + +minetest.register_craftitem("mcl_mobitems:ghast_tear", { + description = S("Ghast Tear"), + _doc_items_longdesc = S("Place this item in an item frame as decoration."), + wield_image = "mcl_mobitems_ghast_tear.png", + inventory_image = "mcl_mobitems_ghast_tear.png", + groups = { brewitem = 1 }, + stack_max = 64, +}) + +minetest.register_craftitem("mcl_mobitems:nether_star", { + description = S("Nether Star"), + _doc_items_longdesc = S("A nether star is dropped when the Wither dies. Place it in an item frame to show the world how hardcore you are! Or just as decoration."), + wield_image = "mcl_mobitems_nether_star.png", + inventory_image = "mcl_mobitems_nether_star.png", + -- TODO: Reveal item when it's useful + groups = { craftitem = 1, not_in_creative_inventory = 1 }, + stack_max = 64, +}) + +minetest.register_craftitem("mcl_mobitems:leather", { + description = S("Leather"), + _doc_items_longdesc = S("Leather is a versatile crafting component."), + wield_image = "mcl_mobitems_leather.png", + inventory_image = "mcl_mobitems_leather.png", + groups = { craftitem = 1 }, + stack_max = 64, +}) + +minetest.register_craftitem("mcl_mobitems:feather", { + description = S("Feather"), + _doc_items_longdesc = S("Feathers are used in crafting and are dropped from chickens."), + wield_image = "mcl_mobitems_feather.png", + inventory_image = "mcl_mobitems_feather.png", + groups = { craftitem = 1 }, + stack_max = 64, +}) + +minetest.register_craftitem("mcl_mobitems:rabbit_hide", { + description = S("Rabbit Hide"), + _doc_items_longdesc = S("Rabbit hide is used to create leather."), + wield_image = "mcl_mobitems_rabbit_hide.png", + inventory_image = "mcl_mobitems_rabbit_hide.png", + groups = { craftitem = 1 }, + stack_max = 64, +}) + +minetest.register_craftitem("mcl_mobitems:rabbit_foot", { + description = S("Rabbit's Foot"), + _doc_items_longdesc = S("Must be your lucky day! Place this item in an item frame for decoration."), + wield_image = "mcl_mobitems_rabbit_foot.png", + inventory_image = "mcl_mobitems_rabbit_foot.png", + groups = { brewitem = 1 }, + stack_max = 64, +}) + +minetest.register_craftitem("mcl_mobitems:saddle", { + description = S("Saddle"), + _tt_help = S("Can be placed on animals to ride them"), + _doc_items_longdesc = S("Saddles can be put on some animals in order to mount them."), + _doc_items_usagehelp = S("Use the placement key with the saddle in your hand to try to put on the saddle. Saddles fit on horses, mules, donkeys and pigs. Horses, mules and donkeys need to be tamed first, otherwise they'll reject the saddle. Saddled animals can be mounted by using the placement key on them again."), + wield_image = "mcl_mobitems_saddle.png", + inventory_image = "mcl_mobitems_saddle.png", + groups = { transport = 1 }, + stack_max = 1, +}) + +minetest.register_craftitem("mcl_mobitems:rabbit_stew", { + description = S("Rabbit Stew"), + _doc_items_longdesc = S("Rabbit stew is a very nutricious food item."), + wield_image = "mcl_mobitems_rabbit_stew.png", + inventory_image = "mcl_mobitems_rabbit_stew.png", + stack_max = 1, + on_place = minetest.item_eat(10, "mcl_core:bowl"), + on_secondary_use = minetest.item_eat(10, "mcl_core:bowl"), + groups = { food = 3, eatable = 10 }, + _mcl_saturation = 12.0, +}) + +minetest.register_craftitem("mcl_mobitems:shulker_shell", { + description = S("Shulker Shell"), + _doc_items_longdesc = S("Shulker shells are used in crafting. They are dropped from dead shulkers."), + inventory_image = "mcl_mobitems_shulker_shell.png", + groups = { craftitem = 1 }, +}) + +minetest.register_craftitem("mcl_mobitems:slimeball", { + description = S("Slimeball"), + _doc_items_longdesc = S("Slimeballs are used in crafting. They are dropped from slimes."), + inventory_image = "mcl_mobitems_slimeball.png", + groups = { craftitem = 1 }, +}) + +minetest.register_craftitem("mcl_mobitems:gunpowder", { + description = S("Gunpowder"), + _doc_items_longdesc = doc.sub.items.temp.craftitem, + inventory_image = "default_gunpowder.png", + stack_max = 64, + groups = { craftitem=1, brewitem = 1 }, +}) + +minetest.register_tool("mcl_mobitems:carrot_on_a_stick", { + description = S("Carrot on a Stick"), + _tt_help = S("Lets you ride a saddled pig"), + _doc_items_longdesc = S("A carrot on a stick can be used on saddled pigs to ride them."), + _doc_items_usagehelp = S("Place it on a saddled pig to mount it. You can now ride the pig like a horse. Pigs will also walk towards you when you just wield the carrot on a stick."), + wield_image = "mcl_mobitems_carrot_on_a_stick.png", + inventory_image = "mcl_mobitems_carrot_on_a_stick.png", + groups = { transport = 1 }, + _mcl_toollike_wield = true, +}) + +----------- +-- Crafting +----------- + +minetest.register_craft({ + output = "mcl_mobitems:leather", + recipe = { + { "mcl_mobitems:rabbit_hide", "mcl_mobitems:rabbit_hide" }, + { "mcl_mobitems:rabbit_hide", "mcl_mobitems:rabbit_hide" }, + } +}) + +minetest.register_craft({ + output = "mcl_mobitems:blaze_powder 2", + recipe = {{"mcl_mobitems:blaze_rod"}}, +}) + +minetest.register_craft({ + output = "mcl_mobitems:rabbit_stew", + recipe = { + { "", "mcl_mobitems:cooked_rabbit", "", }, + { "group:mushroom", "mcl_farming:potato_item_baked", "mcl_farming:carrot_item", }, + { "", "mcl_core:bowl", "", }, + }, +}) + +minetest.register_craft({ + output = "mcl_mobitems:rabbit_stew", + recipe = { + { "", "mcl_mobitems:cooked_rabbit", "", }, + { "mcl_farming:carrot_item", "mcl_farming:potato_item_baked", "group:mushroom", }, + { "", "mcl_core:bowl", "", }, + }, +}) + +minetest.register_craft({ + output = "mcl_mobitems:carrot_on_a_stick", + recipe = { + { "mcl_fishing:fishing_rod", "", }, + { "", "mcl_farming:carrot_item" }, + }, +}) + +minetest.register_craft({ + output = "mcl_mobitems:carrot_on_a_stick", + recipe = { + { "", "mcl_fishing:fishing_rod", }, + { "mcl_farming:carrot_item", "" }, + }, +}) + +minetest.register_craft({ + type = "shapeless", + output = "mcl_mobitems:magma_cream", + recipe = {"mcl_mobitems:blaze_powder", "mcl_mobitems:slimeball"}, +}) + +minetest.register_craft({ + type = "cooking", + output = "mcl_mobitems:cooked_mutton", + recipe = "mcl_mobitems:mutton", + cooktime = 10, +}) + +minetest.register_craft({ + type = "cooking", + output = "mcl_mobitems:cooked_rabbit", + recipe = "mcl_mobitems:rabbit", + cooktime = 10, +}) + +minetest.register_craft({ + type = "cooking", + output = "mcl_mobitems:cooked_chicken", + recipe = "mcl_mobitems:chicken", + cooktime = 10, +}) + +minetest.register_craft({ + type = "cooking", + output = "mcl_mobitems:cooked_beef", + recipe = "mcl_mobitems:beef", + cooktime = 10, +}) + +minetest.register_craft({ + type = "cooking", + output = "mcl_mobitems:cooked_porkchop", + recipe = "mcl_mobitems:porkchop", + cooktime = 10, +}) + +minetest.register_craft({ + type = "fuel", + recipe = "mcl_mobitems:blaze_rod", + burntime = 120, +}) + +minetest.register_craft({ + output = "mcl_mobitems:slimeball 9", + recipe = {{"mcl_core:slimeblock"}}, +}) + +minetest.register_craft({ + output = "mcl_core:slimeblock", + recipe = {{"mcl_mobitems:slimeball","mcl_mobitems:slimeball","mcl_mobitems:slimeball",}, + {"mcl_mobitems:slimeball","mcl_mobitems:slimeball","mcl_mobitems:slimeball",}, + {"mcl_mobitems:slimeball","mcl_mobitems:slimeball","mcl_mobitems:slimeball",}}, +}) + +minetest.register_on_item_eat(function (hp_change, replace_with_item, itemstack, user, pointed_thing) + + -- poisoning with spider eye + if itemstack:get_name() == "mcl_mobitems:spider_eye" then + mcl_potions.poison_func(user, 1, 4) + end + +end ) diff --git a/mods/ITEMS/mcl_shields/init.lua b/mods/ITEMS/mcl_shields/init.lua index a1be310e7..038ffc0f3 100644 --- a/mods/ITEMS/mcl_shields/init.lua +++ b/mods/ITEMS/mcl_shields/init.lua @@ -90,7 +90,7 @@ minetest.register_entity("mcl_shields:shield_entity", { local color = minetest.registered_items[item]._shield_color if color then shield_texture = "mcl_shield_base_nopattern.png^(mcl_shield_pattern_base.png^[colorize:" .. color .. ")" - end + end end end @@ -128,7 +128,7 @@ mcl_damage.register_modifier(function(obj, damage, reason) local type = reason.type local damager = reason.direct local blocking, shieldstack = mcl_shields.is_blocking(obj) - + if not (obj:is_player() and blocking and mcl_shields.types[type] and damager) then return end @@ -275,7 +275,7 @@ local function handle_blocking(player) player_shield.blocking = 2 end elseif shield_in_offhand then - local offhand_can_block = (wielded_item(player) == "" or not mcl_util.get_pointed_thing(player, true)) + local offhand_can_block = (wielded_item(player) == "" or not mcl_util.get_pointed_thing(player, true)) and (minetest.get_item_group(wielded_item(player), "bow") ~= 1 and minetest.get_item_group(wielded_item(player), "crossbow") ~= 1) if not offhand_can_block then diff --git a/mods/ITEMS/mcl_totems/init.lua b/mods/ITEMS/mcl_totems/init.lua index 7a45ea58f..2ea4f0c6b 100644 --- a/mods/ITEMS/mcl_totems/init.lua +++ b/mods/ITEMS/mcl_totems/init.lua @@ -46,7 +46,7 @@ mcl_damage.register_modifier(function(obj, damage, reason) -- Effects minetest.sound_play({name = "mcl_totems_totem", gain = 1}, {pos=ppos, max_hear_distance = 16}, true) - + for i = 1, 4 do for c = 1, #particle_colors do minetest.add_particlespawner({ diff --git a/mods/MAPGEN/mcl_mapgen_core/init.lua b/mods/MAPGEN/mcl_mapgen_core/init.lua index 69132927c..d9494d18b 100644 --- a/mods/MAPGEN/mcl_mapgen_core/init.lua +++ b/mods/MAPGEN/mcl_mapgen_core/init.lua @@ -2096,7 +2096,7 @@ local function basic(vm, data, data2, emin, emax, area, minp, maxp, blockseed) lvm_used = true end end - + -- Set param2 (=color) of sugar cane nodes = minetest.find_nodes_in_area(minp, maxp, {"mcl_core:reeds"}) for n=1, #nodes do diff --git a/mods/MAPGEN/mcl_villages/buildings.lua b/mods/MAPGEN/mcl_villages/buildings.lua index 9038769fd..67a0785ce 100644 --- a/mods/MAPGEN/mcl_villages/buildings.lua +++ b/mods/MAPGEN/mcl_villages/buildings.lua @@ -234,7 +234,7 @@ end function settlements.place_schematics(settlement_info, pr) local building_all_info - + --attempt to place one belltower in the center of the village - this doesn't always work out great but it's a lot better than doing it first or last. local belltower = table.remove(settlement_info,math.floor(#settlement_info/2)) if belltower then @@ -251,10 +251,10 @@ function settlements.place_schematics(settlement_info, pr) pr ) end - + for i, built_house in ipairs(settlement_info) do local is_last = i == #settlement_info - + for j, schem in ipairs(settlements.schematic_table) do if settlement_info[i]["name"] == schem["name"] then building_all_info = schem diff --git a/mods/MISC/mcl_privs/init.lua b/mods/MISC/mcl_privs/init.lua index dc3aa0f69..ddca9f946 100644 --- a/mods/MISC/mcl_privs/init.lua +++ b/mods/MISC/mcl_privs/init.lua @@ -26,7 +26,7 @@ for _, action in pairs({"grant", "revoke"}) do end local meta = player:get_meta() - + if priv == "fly" then meta:set_int("mcl_privs:fly_changed", 1) end diff --git a/mods/PLAYER/mcl_death_drop/init.lua b/mods/PLAYER/mcl_death_drop/init.lua index 665393ca5..5ea548ecc 100644 --- a/mods/PLAYER/mcl_death_drop/init.lua +++ b/mods/PLAYER/mcl_death_drop/init.lua @@ -1,57 +1,57 @@ -local random = math.random - -local ipairs = ipairs - -mcl_death_drop = {} - -mcl_death_drop.registered_dropped_lists = {} - -function mcl_death_drop.register_dropped_list(inv, listname, drop) - table.insert(mcl_death_drop.registered_dropped_lists, {inv = inv, listname = listname, drop = drop}) -end - -mcl_death_drop.register_dropped_list("PLAYER", "main", true) -mcl_death_drop.register_dropped_list("PLAYER", "craft", true) -mcl_death_drop.register_dropped_list("PLAYER", "armor", true) -mcl_death_drop.register_dropped_list("PLAYER", "offhand", true) - -minetest.register_on_dieplayer(function(player) - local keep = minetest.settings:get_bool("mcl_keepInventory", false) - if keep == false then - -- Drop inventory, crafting grid and armor - local playerinv = player:get_inventory() - local pos = player:get_pos() - -- No item drop if in deep void - local _, void_deadly = mcl_worlds.is_in_void(pos) - - for l=1,#mcl_death_drop.registered_dropped_lists do - local inv = mcl_death_drop.registered_dropped_lists[l].inv - if inv == "PLAYER" then - inv = playerinv - elseif type(inv) == "function" then - inv = inv(player) - end - local listname = mcl_death_drop.registered_dropped_lists[l].listname - local drop = mcl_death_drop.registered_dropped_lists[l].drop - if inv then - for i, stack in ipairs(inv:get_list(listname)) do - local x = random(0, 9)/3 - local z = random(0, 9)/3 - pos.x = pos.x + x - pos.z = pos.z + z - if not void_deadly and drop and not mcl_enchanting.has_enchantment(stack, "curse_of_vanishing") then - local def = minetest.registered_items[stack:get_name()] - if def and def.on_drop then - stack = def.on_drop(stack, player, pos) - end - minetest.add_item(pos, stack) - end - pos.x = pos.x - x - pos.z = pos.z - z - end - inv:set_list(listname, {}) - end - end - mcl_armor.update(player) - end -end) +local random = math.random + +local ipairs = ipairs + +mcl_death_drop = {} + +mcl_death_drop.registered_dropped_lists = {} + +function mcl_death_drop.register_dropped_list(inv, listname, drop) + table.insert(mcl_death_drop.registered_dropped_lists, {inv = inv, listname = listname, drop = drop}) +end + +mcl_death_drop.register_dropped_list("PLAYER", "main", true) +mcl_death_drop.register_dropped_list("PLAYER", "craft", true) +mcl_death_drop.register_dropped_list("PLAYER", "armor", true) +mcl_death_drop.register_dropped_list("PLAYER", "offhand", true) + +minetest.register_on_dieplayer(function(player) + local keep = minetest.settings:get_bool("mcl_keepInventory", false) + if keep == false then + -- Drop inventory, crafting grid and armor + local playerinv = player:get_inventory() + local pos = player:get_pos() + -- No item drop if in deep void + local _, void_deadly = mcl_worlds.is_in_void(pos) + + for l=1,#mcl_death_drop.registered_dropped_lists do + local inv = mcl_death_drop.registered_dropped_lists[l].inv + if inv == "PLAYER" then + inv = playerinv + elseif type(inv) == "function" then + inv = inv(player) + end + local listname = mcl_death_drop.registered_dropped_lists[l].listname + local drop = mcl_death_drop.registered_dropped_lists[l].drop + if inv then + for i, stack in ipairs(inv:get_list(listname)) do + local x = random(0, 9)/3 + local z = random(0, 9)/3 + pos.x = pos.x + x + pos.z = pos.z + z + if not void_deadly and drop and not mcl_enchanting.has_enchantment(stack, "curse_of_vanishing") then + local def = minetest.registered_items[stack:get_name()] + if def and def.on_drop then + stack = def.on_drop(stack, player, pos) + end + minetest.add_item(pos, stack) + end + pos.x = pos.x - x + pos.z = pos.z - z + end + inv:set_list(listname, {}) + end + end + mcl_armor.update(player) + end +end) diff --git a/mods/PLAYER/mcl_spawn/init.lua b/mods/PLAYER/mcl_spawn/init.lua index 9d11df705..9022dfc25 100644 --- a/mods/PLAYER/mcl_spawn/init.lua +++ b/mods/PLAYER/mcl_spawn/init.lua @@ -473,10 +473,10 @@ function mcl_spawn.get_player_spawn_pos(player) player:get_meta():set_string("mcl_beds:spawn", "") minetest.chat_send_player(player:get_player_name(), S("Your spawn bed was missing or blocked, and you had no charged respawn anchor!")) return mcl_spawn.get_world_spawn_pos(), false - end + end end end - + -- Find spawning position on/near the bed free of solid or damaging blocks iterating a square spiral 15x15: