update some mods
|
@ -3,6 +3,7 @@ This Mod for Minetest adds objects that can be locked and shared.
|
|||
It is written so that other objects/mods can easily use the functions provided here.
|
||||
|
||||
Comes with modified chest, sign and xyz' xdoor2 as sample objects.
|
||||
New: Furnaces added.
|
||||
For the (unmodified) xdoors2, see http://minetest.net/forum/viewtopic.php?id=2757. Chest and sign take their textures out of default.
|
||||
The textures (lock, key and keychain) have been provided by Addi. Please consult textures/licence.txt.
|
||||
The code of the lock mod has been written by Sokomine.
|
||||
|
@ -27,6 +28,7 @@ If you do not want any of the objects chest, sign and/or door, just remove the c
|
|||
dofile(minetest.get_modpath("locks").."/shared_locked_chest.lua");
|
||||
dofile(minetest.get_modpath("locks").."/shared_locked_sign_wall.lua");
|
||||
dofile(minetest.get_modpath("locks").."/shared_locked_xdoors2.lua");
|
||||
dofile(minetest.get_modpath("locks").."/shared_locked_furnace.lua");
|
||||
|
||||
I hope this mod will be helpful.
|
||||
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
default
|
||||
pipeworks?
|
||||
|
|
|
@ -1,10 +1,52 @@
|
|||
|
||||
|
||||
|
||||
--[[
|
||||
Shared locked objects (Mod for MineTest)
|
||||
Allows to restrict usage of blocks to a certain player or a group of
|
||||
players.
|
||||
Copyright (C) 2013 Sokomine
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
--]]
|
||||
|
||||
-- Version 1.20
|
||||
|
||||
-- Changelog:
|
||||
-- 08.05.2014 * Changed animation of shared locked furnace (removed pipeworks overlay on front, changed to new animation type)
|
||||
-- 10.01.2013 * Added command to toggle for pipeworks output
|
||||
-- * Added pipeworks support for chests and furnace.
|
||||
-- 17.12.2013 * aborting input with ESC is possible again
|
||||
-- 01.09.2013 * fixed bug in input sanitization
|
||||
-- 31.08.2013 * changed receipe for key to avoid crafting conflickt with screwdriver
|
||||
-- 10.07.2013 * removed a potential bug (now uses string:gmatch)
|
||||
-- * added shared locked furnaces
|
||||
|
||||
|
||||
|
||||
locks = {};
|
||||
|
||||
minetest.register_privilege("openlocks", { description = "allows to open/use all locked objects", give_to_singleplayer = false});
|
||||
minetest.register_privilege("diglocks", { description = "allows to open/use and dig up all locked objects", give_to_singleplayer = false});
|
||||
|
||||
|
||||
locks.pipeworks_enabled = false;
|
||||
|
||||
if( minetest.get_modpath("pipeworks") ~= nil ) then
|
||||
locks.pipeworks_enabled = true;
|
||||
end
|
||||
|
||||
-- initializes a lock (that is: prepare the metadata so that it can store data)
|
||||
-- default_formspec is the formspec that will be used on right click; the input field for the commands has to exist
|
||||
-- Call this in on_construct in register_node. Excample:
|
||||
|
@ -37,6 +79,8 @@ function locks:lock_init( pos, default_formspec )
|
|||
meta:set_string("pw_user","");
|
||||
-- this formspec is presented on right-click for every user
|
||||
meta:set_string("formspec", default_formspec);
|
||||
-- by default, do not send output to pipework tubes
|
||||
meta:set_int( "allow_pipeworks", 0 );
|
||||
end
|
||||
|
||||
|
||||
|
@ -167,6 +211,15 @@ function locks:lock_allow_use( pos, player )
|
|||
local name = player:get_player_name();
|
||||
local meta = minetest.env:get_meta(pos);
|
||||
|
||||
-- pipeworks sends a special username
|
||||
if( name == ':pipeworks' ) then
|
||||
if( meta:get_int( 'allow_pipeworks' ) == 1 ) then
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
end
|
||||
end
|
||||
|
||||
-- the player has to have a key or a keychain to open his own shared locked objects
|
||||
if( name == meta:get_string("owner")) then
|
||||
|
||||
|
@ -256,6 +309,7 @@ function locks:lock_handle_input( pos, formname, fields, player )
|
|||
|
||||
-- is this input the lock is supposed to handle?
|
||||
if( not( fields.locks_sent_lock_command )
|
||||
or (fields.quit and (fields.quit==true or fields.quit=='true'))
|
||||
-- or not( fields.locks_sent_input )
|
||||
or fields.locks_sent_lock_command == "" ) then
|
||||
return;
|
||||
|
@ -271,7 +325,8 @@ function locks:lock_handle_input( pos, formname, fields, player )
|
|||
" /add <name> Player <name> can now unlock this object with any key.\n"..
|
||||
" /del <name> Player <name> can no longer use this object.\n"..
|
||||
" /list Shows a list of players who can use this object.\n"..
|
||||
" /set <password> Sets a password. Everyone who types that in can use the object.");
|
||||
" /set <password> Sets a password. Everyone who types that in can use the object.\n"..
|
||||
" /pipeworks Toggles permission for pipeworks to take inventory out of the shared locked object.\n");
|
||||
|
||||
else if( locks:lock_allow_use( pos, player )) then
|
||||
minetest.chat_send_player(name, "This locked object is owned by "..tostring( meta:get_string( "owner" ))..".\n"..
|
||||
|
@ -290,7 +345,7 @@ function locks:lock_handle_input( pos, formname, fields, player )
|
|||
end -- of /help
|
||||
|
||||
-- sanitize player input
|
||||
if( fields.locks_sent_lock_command:find("[^%a%d%s_\- \/\:]")) then
|
||||
if( fields.locks_sent_lock_command:match("[^%a%d%s_%- /%:]")) then
|
||||
minetest.chat_send_player(name, "Input contains unsupported characters. Allowed: a-z, A-Z, 0-9, _, -, :.");
|
||||
return;
|
||||
end
|
||||
|
@ -350,10 +405,33 @@ function locks:lock_handle_input( pos, formname, fields, player )
|
|||
txt = txt.."\nThe password for this lock is: \""..tostring( meta:get_string( "password" ).."\"");
|
||||
end
|
||||
|
||||
if( not( minetest.get_modpath("pipeworks") )) then
|
||||
txt = txt.."\nThe pipeworks mod is not installed. Install it if you wish support for tubes.";
|
||||
elseif( meta:get_int( "allow_pipeworks" ) == 1 ) then
|
||||
txt = txt.."\nTubes from pipeworks may be used to extract items out of/add items to this shared locked object.";
|
||||
else
|
||||
txt = txt.."\nInput from tubes is accepted, but output to them is denied (default).";
|
||||
end
|
||||
|
||||
minetest.chat_send_player(name, txt );
|
||||
return;
|
||||
end -- of /list
|
||||
|
||||
|
||||
-- toggle tube output on/off
|
||||
if( fields.locks_sent_lock_command == "/pipeworks" ) then
|
||||
|
||||
if( meta:get_int('allow_pipeworks') == 1 ) then
|
||||
meta:set_int('allow_pipeworks', 0 );
|
||||
minetest.chat_send_player( name, 'Output to pipework tubes is now DISABLED (input is still acceped).');
|
||||
return;
|
||||
else
|
||||
meta:set_int('allow_pipeworks', 1 );
|
||||
minetest.chat_send_player( name, 'Output to pipework tubes is now ENABLED. Connected tubes may insert and remove items.');
|
||||
return;
|
||||
end
|
||||
end
|
||||
|
||||
-- -- all other commands take exactly one parameter
|
||||
local help = fields.locks_sent_lock_command:split( " " );
|
||||
|
||||
|
@ -504,9 +582,8 @@ minetest.register_craftitem("locks:key", {
|
|||
minetest.register_craft({
|
||||
output = "locks:key",
|
||||
recipe = {
|
||||
{'', 'default:steel_ingot',''},
|
||||
{'', 'default:stick', ''},
|
||||
{'', '', ''},
|
||||
{'', 'default:steel_ingot',''},
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -529,5 +606,6 @@ minetest.register_craft({
|
|||
dofile(minetest.get_modpath("locks").."/shared_locked_chest.lua");
|
||||
dofile(minetest.get_modpath("locks").."/shared_locked_sign_wall.lua");
|
||||
dofile(minetest.get_modpath("locks").."/shared_locked_xdoors2.lua");
|
||||
dofile(minetest.get_modpath("locks").."/shared_locked_furnace.lua");
|
||||
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ License of locks mod for Minetest-c55
|
|||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
the Free Software Foundation; either version 2.1 of the License, or
|
||||
the Free Software Foundation; either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
|
|
|
@ -1,10 +1,46 @@
|
|||
-- 09.01.13 Added support for pipeworks.
|
||||
|
||||
|
||||
locks.chest_add = {};
|
||||
locks.chest_add.tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png",
|
||||
"default_chest_side.png", "default_chest_side.png", "default_chest_front.png"};
|
||||
locks.chest_add.groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2};
|
||||
locks.chest_add.tube = {};
|
||||
|
||||
-- additional/changed definitions for pipeworks;
|
||||
-- taken from pipeworks/compat.lua
|
||||
if( locks.pipeworks_enabled ) then
|
||||
locks.chest_add.tiles = {
|
||||
"default_chest_top.png^pipeworks_tube_connection_wooden.png",
|
||||
"default_chest_top.png^pipeworks_tube_connection_wooden.png",
|
||||
"default_chest_side.png^pipeworks_tube_connection_wooden.png",
|
||||
"default_chest_side.png^pipeworks_tube_connection_wooden.png",
|
||||
"default_chest_side.png^pipeworks_tube_connection_wooden.png"};
|
||||
locks.chest_add.groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,
|
||||
tubedevice = 1, tubedevice_receiver = 1 };
|
||||
locks.chest_add.tube = {
|
||||
insert_object = function(pos, node, stack, direction)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
return inv:add_item("main", stack)
|
||||
end,
|
||||
can_insert = function(pos, node, stack, direction)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
return inv:room_for_item("main", stack)
|
||||
end,
|
||||
input_inventory = "main",
|
||||
connect_sides = {left=1, right=1, back=1, front=1, bottom=1, top=1}
|
||||
};
|
||||
end
|
||||
|
||||
|
||||
minetest.register_node("locks:shared_locked_chest", {
|
||||
description = "Shared locked chest",
|
||||
tiles = {"default_chest_top.png", "default_chest_top.png", "default_chest_side.png",
|
||||
"default_chest_side.png", "default_chest_side.png", "default_chest_front.png"},
|
||||
tiles = locks.chest_add.tiles,
|
||||
paramtype2 = "facedir",
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2},
|
||||
groups = locks.chest_add.groups,
|
||||
tube = locks.chest_add.tube,
|
||||
legacy_facedir_simple = true,
|
||||
|
||||
on_construct = function(pos)
|
||||
|
@ -26,6 +62,11 @@ minetest.register_node("locks:shared_locked_chest", {
|
|||
end,
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
|
||||
if( locks.pipeworks_enabled ) then
|
||||
pipeworks.scan_for_tube_objects( pos );
|
||||
end
|
||||
|
||||
locks:lock_set_owner( pos, placer, "Shared locked chest" );
|
||||
end,
|
||||
|
||||
|
@ -78,6 +119,11 @@ minetest.register_node("locks:shared_locked_chest", {
|
|||
end,
|
||||
|
||||
|
||||
after_dig_node = function( pos )
|
||||
if( locks.pipeworks_enabled ) then
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
|
|
|
@ -0,0 +1,434 @@
|
|||
|
||||
-- this is a (slightly!) modified copy of minetest_game/mods/default/nodes.lua,
|
||||
-- containing only the furnace and adopted slightly for my locks mod
|
||||
|
||||
|
||||
-- 09.01.13 Added support for pipeworks.
|
||||
|
||||
|
||||
locks.furnace_add = {};
|
||||
locks.furnace_add.tiles_normal = {"default_furnace_top.png", "default_furnace_bottom.png", "default_furnace_side.png",
|
||||
"default_furnace_side.png", "default_furnace_side.png", "default_furnace_front.png"};
|
||||
locks.furnace_add.tiles_active = {"default_furnace_top.png", "default_furnace_bottom.png", "default_furnace_side.png",
|
||||
"default_furnace_side.png", "default_furnace_side.png", --"default_furnace_front_active.png"};
|
||||
{
|
||||
image = "default_furnace_front_active.png",
|
||||
backface_culling = false,
|
||||
animation = {
|
||||
type = "vertical_frames",
|
||||
aspect_w = 16,
|
||||
aspect_h = 16,
|
||||
length = 1.5
|
||||
},
|
||||
}};
|
||||
locks.furnace_add.groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2};
|
||||
locks.furnace_add.tube = {};
|
||||
|
||||
-- additional/changed definitions for pipeworks;
|
||||
-- taken from pipeworks/compat.lua
|
||||
if( locks.pipeworks_enabled ) then
|
||||
|
||||
locks.furnace_add.tiles_normal = {
|
||||
"default_furnace_top.png^pipeworks_tube_connection_stony.png",
|
||||
"default_furnace_bottom.png^pipeworks_tube_connection_stony.png",
|
||||
"default_furnace_side.png^pipeworks_tube_connection_stony.png",
|
||||
"default_furnace_side.png^pipeworks_tube_connection_stony.png",
|
||||
"default_furnace_side.png^pipeworks_tube_connection_stony.png",
|
||||
"default_furnace_front.png" };
|
||||
|
||||
|
||||
locks.furnace_add.tiles_active = {
|
||||
"default_furnace_top.png^pipeworks_tube_connection_stony.png",
|
||||
"default_furnace_bottom.png^pipeworks_tube_connection_stony.png",
|
||||
"default_furnace_side.png^pipeworks_tube_connection_stony.png",
|
||||
"default_furnace_side.png^pipeworks_tube_connection_stony.png",
|
||||
"default_furnace_side.png^pipeworks_tube_connection_stony.png",
|
||||
{
|
||||
image = "default_furnace_front_active.png",
|
||||
backface_culling = false,
|
||||
animation = {
|
||||
type = "vertical_frames",
|
||||
aspect_w = 16,
|
||||
aspect_h = 16,
|
||||
length = 1.5
|
||||
},
|
||||
}};
|
||||
-- "default_furnace_front_active.png" };
|
||||
|
||||
|
||||
locks.furnace_add.groups = {snappy=2,choppy=2,oddly_breakable_by_hand=2,
|
||||
tubedevice = 1, tubedevice_receiver = 1 };
|
||||
locks.furnace_add.tube = {
|
||||
insert_object = function(pos, node, stack, direction)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
if direction.y == 1 then
|
||||
return inv:add_item("fuel",stack)
|
||||
else
|
||||
return inv:add_item("src",stack)
|
||||
end
|
||||
end,
|
||||
can_insert = function(pos, node, stack, direction)
|
||||
local meta = minetest.env:get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
if direction.y == 1 then
|
||||
return inv:room_for_item("fuel", stack)
|
||||
else
|
||||
return inv:room_for_item("src", stack)
|
||||
end
|
||||
end,
|
||||
input_inventory = "dst",
|
||||
connect_sides = {left=1, right=1, back=1, front=1, bottom=1, top=1}
|
||||
};
|
||||
end
|
||||
|
||||
|
||||
function locks.get_furnace_active_formspec(pos, percent)
|
||||
local formspec =
|
||||
"size[8,9]"..
|
||||
"image[2,2;1,1;default_furnace_fire_bg.png^[lowpart:"..
|
||||
(100-percent)..":default_furnace_fire_fg.png]"..
|
||||
"list[current_name;fuel;2,3;1,1;]"..
|
||||
"list[current_name;src;2,1;1,1;]"..
|
||||
"list[current_name;dst;5,1;2,2;]"..
|
||||
"list[current_player;main;0,5;8,4;]"..
|
||||
|
||||
"field[0.3,4.5;6,0.7;locks_sent_lock_command;Locked furnace. Type /help for help:;]"..
|
||||
"button_exit[6.3,4;1.7,0.7;locks_sent_input;Proceed]" ;
|
||||
return formspec
|
||||
end
|
||||
|
||||
locks.furnace_inactive_formspec =
|
||||
"size[8,9]"..
|
||||
"image[2,2;1,1;default_furnace_fire_bg.png]"..
|
||||
"list[current_name;fuel;2,3;1,1;]"..
|
||||
"list[current_name;src;2,1;1,1;]"..
|
||||
"list[current_name;dst;5,1;2,2;]"..
|
||||
"list[current_player;main;0,5;8,4;]"..
|
||||
"field[0.3,4.5;6,0.7;locks_sent_lock_command;Locked furnace. Type /help for help:;]"..
|
||||
"button_exit[6.3,4;1.7,0.7;locks_sent_input;Proceed]" ;
|
||||
|
||||
minetest.register_node("locks:shared_locked_furnace", {
|
||||
description = "Shared locked furnace",
|
||||
paramtype2 = "facedir",
|
||||
groups = {cracky=2},
|
||||
legacy_facedir_simple = true,
|
||||
|
||||
tiles = locks.furnace_add.tiles_normal,
|
||||
groups = locks.furnace_add.groups,
|
||||
tube = locks.furnace_add.tube,
|
||||
|
||||
-- sounds = default.node_sound_stone_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
locks:lock_init( pos, locks.furnace_inactive_formspec)
|
||||
meta:set_string("infotext", "Shared locked furnace")
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("fuel", 1)
|
||||
inv:set_size("src", 1)
|
||||
inv:set_size("dst", 4)
|
||||
end,
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
if( locks.pipeworks_enabled ) then
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end
|
||||
locks:lock_set_owner( pos, placer, "Shared locked furnace" );
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
if( locks.pipeworks_enabled ) then
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end
|
||||
end,
|
||||
|
||||
can_dig = function(pos,player)
|
||||
if( not(locks:lock_allow_dig( pos, player ))) then
|
||||
return false;
|
||||
end
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
if not inv:is_empty("fuel") then
|
||||
return false
|
||||
elseif not inv:is_empty("dst") then
|
||||
return false
|
||||
elseif not inv:is_empty("src") then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end,
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
locks:lock_handle_input( pos, formname, fields, sender );
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
if( not( locks:lock_allow_use( pos, player ))) then
|
||||
return 0;
|
||||
end
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
if listname == "fuel" then
|
||||
if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then
|
||||
if inv:is_empty("src") then
|
||||
meta:set_string("infotext","Furnace is empty")
|
||||
end
|
||||
return stack:get_count()
|
||||
else
|
||||
return 0
|
||||
end
|
||||
elseif listname == "src" then
|
||||
return stack:get_count()
|
||||
elseif listname == "dst" then
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
if( not( locks:lock_allow_use( pos, player ))) then
|
||||
return 0;
|
||||
end
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local stack = inv:get_stack(from_list, from_index)
|
||||
if to_list == "fuel" then
|
||||
if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then
|
||||
if inv:is_empty("src") then
|
||||
meta:set_string("infotext","Furnace is empty")
|
||||
end
|
||||
return count
|
||||
else
|
||||
return 0
|
||||
end
|
||||
elseif to_list == "src" then
|
||||
return count
|
||||
elseif to_list == "dst" then
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
if( not( locks:lock_allow_use( pos, player ))) then
|
||||
return 0;
|
||||
end
|
||||
return stack:get_count()
|
||||
end,
|
||||
})
|
||||
|
||||
minetest.register_node("locks:shared_locked_furnace_active", {
|
||||
description = "Furnace",
|
||||
paramtype2 = "facedir",
|
||||
light_source = 8,
|
||||
drop = "locks:shared_locked_furnace",
|
||||
groups = {cracky=2, not_in_creative_inventory=1},
|
||||
legacy_facedir_simple = true,
|
||||
|
||||
tiles = locks.furnace_add.tiles_active,
|
||||
groups = locks.furnace_add.groups,
|
||||
tube = locks.furnace_add.tube,
|
||||
|
||||
-- sounds = default.node_sound_stone_defaults(),
|
||||
on_construct = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
locks:lock_init( pos, locks.furnace_inactive_formspec)
|
||||
meta:set_string("infotext", "Shared locked furnace");
|
||||
local inv = meta:get_inventory()
|
||||
inv:set_size("fuel", 1)
|
||||
inv:set_size("src", 1)
|
||||
inv:set_size("dst", 4)
|
||||
end,
|
||||
can_dig = function(pos,player)
|
||||
if( not(locks:lock_allow_dig( pos, player ))) then
|
||||
return false;
|
||||
end
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory()
|
||||
if not inv:is_empty("fuel") then
|
||||
return false
|
||||
elseif not inv:is_empty("dst") then
|
||||
return false
|
||||
elseif not inv:is_empty("src") then
|
||||
return false
|
||||
end
|
||||
return true
|
||||
end,
|
||||
|
||||
after_place_node = function(pos, placer)
|
||||
if( locks.pipeworks_enabled ) then
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end
|
||||
locks:lock_set_owner( pos, placer, "Shared locked furnace (active)" );
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
if( locks.pipeworks_enabled ) then
|
||||
pipeworks.scan_for_tube_objects(pos)
|
||||
end
|
||||
end,
|
||||
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
locks:lock_handle_input( pos, formname, fields, sender );
|
||||
end,
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
if( not( locks:lock_allow_use( pos, player ))) then
|
||||
return 0;
|
||||
end
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
if listname == "fuel" then
|
||||
if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then
|
||||
if inv:is_empty("src") then
|
||||
meta:set_string("infotext","Shared locked furnace (empty)")
|
||||
end
|
||||
return stack:get_count()
|
||||
else
|
||||
return 0
|
||||
end
|
||||
elseif listname == "src" then
|
||||
return stack:get_count()
|
||||
elseif listname == "dst" then
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||
if( not( locks:lock_allow_use( pos, player ))) then
|
||||
return 0;
|
||||
end
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
local stack = inv:get_stack(from_list, from_index)
|
||||
if to_list == "fuel" then
|
||||
if minetest.get_craft_result({method="fuel",width=1,items={stack}}).time ~= 0 then
|
||||
if inv:is_empty("src") then
|
||||
meta:set_string("infotext","Shared locked furnace (empty)")
|
||||
end
|
||||
return count
|
||||
else
|
||||
return 0
|
||||
end
|
||||
elseif to_list == "src" then
|
||||
return count
|
||||
elseif to_list == "dst" then
|
||||
return 0
|
||||
end
|
||||
end,
|
||||
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||
if( not( locks:lock_allow_use( pos, player ))) then
|
||||
return 0;
|
||||
end
|
||||
return stack:get_count()
|
||||
end,
|
||||
})
|
||||
|
||||
-- better make this a function specific to this mod to avoid trouble with the same function in default
|
||||
locks.hacky_swap_node = function(pos,name)
|
||||
local node = minetest.get_node(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local meta0 = meta:to_table()
|
||||
if node.name == name then
|
||||
return
|
||||
end
|
||||
node.name = name
|
||||
local meta0 = meta:to_table()
|
||||
minetest.set_node(pos,node)
|
||||
meta = minetest.get_meta(pos)
|
||||
meta:from_table(meta0)
|
||||
end
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"locks:shared_locked_furnace","locks:shared_locked_furnace_active"},
|
||||
interval = 1.0,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
local meta = minetest.get_meta(pos)
|
||||
for i, name in ipairs({
|
||||
"fuel_totaltime",
|
||||
"fuel_time",
|
||||
"src_totaltime",
|
||||
"src_time"
|
||||
}) do
|
||||
if meta:get_string(name) == "" then
|
||||
meta:set_float(name, 0.0)
|
||||
end
|
||||
end
|
||||
|
||||
local inv = meta:get_inventory()
|
||||
|
||||
local srclist = inv:get_list("src")
|
||||
local cooked = nil
|
||||
local aftercooked
|
||||
|
||||
if srclist then
|
||||
cooked, aftercooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
|
||||
end
|
||||
|
||||
local was_active = false
|
||||
|
||||
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
|
||||
was_active = true
|
||||
meta:set_float("fuel_time", meta:get_float("fuel_time") + 1)
|
||||
meta:set_float("src_time", meta:get_float("src_time") + 1)
|
||||
if cooked and cooked.item and meta:get_float("src_time") >= cooked.time then
|
||||
-- check if there's room for output in "dst" list
|
||||
if inv:room_for_item("dst",cooked.item) then
|
||||
-- Put result in "dst" list
|
||||
inv:add_item("dst", cooked.item)
|
||||
-- take stuff from "src" list
|
||||
inv:set_stack("src", 1, aftercooked.items[1])
|
||||
else
|
||||
print("Could not insert '"..cooked.item:to_string().."'")
|
||||
end
|
||||
meta:set_string("src_time", 0)
|
||||
end
|
||||
end
|
||||
|
||||
if meta:get_float("fuel_time") < meta:get_float("fuel_totaltime") then
|
||||
local percent = math.floor(meta:get_float("fuel_time") /
|
||||
meta:get_float("fuel_totaltime") * 100)
|
||||
meta:set_string("infotext","Shared locked furnace active: "..percent.."%")
|
||||
locks.hacky_swap_node(pos,"locks:shared_locked_furnace_active")
|
||||
meta:set_string("formspec",locks.get_furnace_active_formspec(pos, percent))
|
||||
return
|
||||
end
|
||||
|
||||
local fuel = nil
|
||||
local afterfuel
|
||||
local cooked = nil
|
||||
local fuellist = inv:get_list("fuel")
|
||||
local srclist = inv:get_list("src")
|
||||
|
||||
if srclist then
|
||||
cooked = minetest.get_craft_result({method = "cooking", width = 1, items = srclist})
|
||||
end
|
||||
if fuellist then
|
||||
fuel, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
|
||||
end
|
||||
|
||||
if not( fuel) or fuel.time <= 0 then
|
||||
meta:set_string("infotext","Shared locked furnace out of fuel")
|
||||
locks.hacky_swap_node(pos,"locks:shared_locked_furnace")
|
||||
meta:set_string("formspec", locks.furnace_inactive_formspec)
|
||||
return
|
||||
end
|
||||
|
||||
if cooked.item:is_empty() then
|
||||
if was_active then
|
||||
meta:set_string("infotext","Shared locked furnace is empty")
|
||||
locks.hacky_swap_node(pos,"locks:shared_locked_furnace")
|
||||
meta:set_string("formspec", locks.furnace_inactive_formspec)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
meta:set_string("fuel_totaltime", fuel.time)
|
||||
meta:set_string("fuel_time", 0)
|
||||
|
||||
inv:set_stack("fuel", 1, afterfuel.items[1])
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
output = 'locks:shared_locked_furnace',
|
||||
recipe = {
|
||||
{ 'default:furnace', 'locks:lock', '' },
|
||||
},
|
||||
})
|
||||
|
||||
print( "[Mod] locks: loading locks:shared_locked_furnace");
|
||||
|
||||
|
|
@ -1,4 +1,6 @@
|
|||
|
||||
-- allow aborting with ESC in newer Versions of MT again
|
||||
|
||||
-- a sign
|
||||
minetest.register_node("locks:shared_locked_sign_wall", {
|
||||
description = "Shared locked sign",
|
||||
|
@ -40,6 +42,11 @@ minetest.register_node("locks:shared_locked_sign_wall", {
|
|||
end,
|
||||
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
|
||||
-- abort if no input has been sent
|
||||
if( fields.quit ) then
|
||||
return;
|
||||
end
|
||||
|
||||
-- if the user already has the right to use this and did input text
|
||||
if( fields.text
|
||||
|
|
|
@ -1,62 +1,103 @@
|
|||
print("[Vines] v1.0")
|
||||
local vine_seed = 12
|
||||
|
||||
-- Nodes
|
||||
minetest.register_node("vines:rope_block", {
|
||||
description = "Rope",
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
drops = "",
|
||||
tile_images = {
|
||||
"vines_rope_block.png",
|
||||
"vines_rope_block.png",
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
"vines_rope_block.png",
|
||||
"vines_rope_block.png"
|
||||
},
|
||||
drawtype = "cube",
|
||||
groups = { snappy = 3},
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
after_place_node = function(pos)
|
||||
local c_air = minetest.get_content_id("air")
|
||||
local rope_side = "default_wood.png^vines_rope_shadow.png^vines_rope.png"
|
||||
|
||||
local p = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||
local n = minetest.env:get_node(p)
|
||||
if n.name == "air" then
|
||||
minetest.env:add_node(p, {name="vines:rope_end"})
|
||||
minetest.register_node("vines:rope_block", {
|
||||
description = "Rope",
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
drops = "",
|
||||
tiles = {
|
||||
rope_side,
|
||||
rope_side,
|
||||
"default_wood.png",
|
||||
"default_wood.png",
|
||||
rope_side,
|
||||
},
|
||||
drawtype = "cube",
|
||||
groups = { snappy = 3},
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
after_place_node = function(pos)
|
||||
local p = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||
local n = minetest.env:get_node(p)
|
||||
if n.name == "air" then
|
||||
minetest.env:add_node(p, {name="vines:rope_end"})
|
||||
end
|
||||
end,
|
||||
after_dig_node = function(pos)
|
||||
local p = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||
local n = minetest.get_node(p).name
|
||||
|
||||
if n ~= 'vines:rope'
|
||||
and n ~= 'vines:rope_end' then
|
||||
return
|
||||
end
|
||||
|
||||
local t1 = os.clock()
|
||||
local y1 = p.y
|
||||
local tab = {}
|
||||
local i = 1
|
||||
while n == 'vines:rope' do
|
||||
tab[i] = p
|
||||
i = i+1
|
||||
p.y = p.y-1
|
||||
n = minetest.get_node(p).name
|
||||
end
|
||||
if n == 'vines:rope_end' then
|
||||
tab[i] = p
|
||||
end
|
||||
local y0 = p.y
|
||||
|
||||
local manip = minetest.get_voxel_manip()
|
||||
local p1 = {x=p.x, y=y0, z=p.z}
|
||||
local p2 = {x=p.x, y=y1, z=p.z}
|
||||
local pos1, pos2 = manip:read_from_map(p1, p2)
|
||||
area = VoxelArea:new({MinEdge=pos1, MaxEdge=pos2})
|
||||
nodes = manip:get_data()
|
||||
|
||||
for i in area:iterp(p1, p2) do
|
||||
nodes[i] = c_air
|
||||
end
|
||||
|
||||
manip:set_data(nodes)
|
||||
manip:write_to_map()
|
||||
manip:update_map() -- <— this takes time
|
||||
print(string.format("[vines] rope removed at ("..pos.x.."|"..pos.y.."|"..pos.z..") after: %.2fs", os.clock() - t1))
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_node("vines:rope", {
|
||||
description = "Rope",
|
||||
walkable = false,
|
||||
climbable = true,
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
tile_images = { "vines_rope.png" },
|
||||
drawtype = "plantlike",
|
||||
groups = {},
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
description = "Rope",
|
||||
walkable = false,
|
||||
climbable = true,
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
tiles = { "vines_rope.png" },
|
||||
drawtype = "plantlike",
|
||||
groups = {},
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {-1/7, -1/2, -1/7, 1/7, 1/2, 1/7},
|
||||
},
|
||||
|
||||
|
||||
})
|
||||
|
||||
minetest.register_node("vines:rope_end", {
|
||||
description = "Rope",
|
||||
walkable = false,
|
||||
climbable = true,
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
drops = "",
|
||||
tile_images = { "vines_rope.png" },
|
||||
drawtype = "plantlike",
|
||||
groups = {},
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
after_place_node = function(pos)
|
||||
yesh = {x = pos.x, y= pos.y-1, z=pos.z}
|
||||
description = "Rope",
|
||||
walkable = false,
|
||||
climbable = true,
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
drops = "",
|
||||
tiles = { "vines_rope.png" },
|
||||
drawtype = "plantlike",
|
||||
groups = {},
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
after_place_node = function(pos)
|
||||
yesh = {x = pos.x, y= pos.y-1, z=pos.z}
|
||||
minetest.env:add_node(yesh, "vines:rope")
|
||||
end,
|
||||
selection_box = {
|
||||
|
@ -65,159 +106,197 @@ minetest.register_node("vines:rope_end", {
|
|||
},
|
||||
})
|
||||
|
||||
local function dropitem(item, pos, inv)
|
||||
if inv
|
||||
and inv:room_for_item("main", item) then
|
||||
inv:add_item("main", item)
|
||||
return
|
||||
end
|
||||
minetest.env:add_item(pos, item)
|
||||
end
|
||||
|
||||
minetest.register_node("vines:vine", {
|
||||
description = "Vine",
|
||||
walkable = false,
|
||||
climbable = true,
|
||||
drop = 'vines:vines',
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
tile_images = { "vines_vine.png" },
|
||||
drawtype = "plantlike",
|
||||
inventory_image = "vines_vine.png",
|
||||
groups = { snappy = 3,flammable=2 },
|
||||
description = "Vine",
|
||||
walkable = false,
|
||||
climbable = true,
|
||||
drop = 'vines:vines',
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
tiles = { "vines_vine.png" },
|
||||
drawtype = "plantlike",
|
||||
inventory_image = "vines_vine.png",
|
||||
groups = { snappy = 3,flammable=2 },
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
})
|
||||
|
||||
minetest.register_node("vines:vine_rotten", {
|
||||
description = "Rotten vine",
|
||||
walkable = false,
|
||||
climbable = true,
|
||||
drop = 'vines:vines',
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
tile_images = { "vines_vine_rotten.png" },
|
||||
drawtype = "plantlike",
|
||||
inventory_image = "vines_vine_rotten.png",
|
||||
groups = { snappy = 3,flammable=2 },
|
||||
description = "Rotten vine",
|
||||
walkable = false,
|
||||
climbable = true,
|
||||
drop = 'vines:vines',
|
||||
sunlight_propagates = true,
|
||||
paramtype = "light",
|
||||
tiles = { "vines_vine_rotten.png" },
|
||||
drawtype = "plantlike",
|
||||
inventory_image = "vines_vine_rotten.png",
|
||||
groups = { snappy = 3,flammable=2 },
|
||||
sounds = default.node_sound_leaves_defaults(),
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
local inv = digger:get_inventory()
|
||||
local item = 'vines:vines'
|
||||
local p = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||
local vine = oldnode.name
|
||||
while minetest.env:get_node(p).name == vine do
|
||||
minetest.env:remove_node(p)
|
||||
dropitem(item, p, inv)
|
||||
p.y = p.y-1
|
||||
end
|
||||
local about = {x=pos.x, y=pos.y+1, z=pos.z}
|
||||
if minetest.env:get_node(about).name == vine then
|
||||
minetest.env:add_node(about, {name="vines:vine"})
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
--ABM
|
||||
minetest.register_abm({
|
||||
nodenames = {"default:leaves", "growing_trees:leaves", "default:dirt_with_grass", },
|
||||
interval = 180,
|
||||
chance = 200,
|
||||
action = function(pos, node)
|
||||
|
||||
local p = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||
local n = minetest.env:get_node(p)
|
||||
|
||||
if n.name =="air" then
|
||||
minetest.env:add_node(p, {name="vines:vine"})
|
||||
end
|
||||
end
|
||||
})
|
||||
local function get_vine_random(pos)
|
||||
return PseudoRandom(math.abs(pos.x+pos.y*3+pos.z*5)+vine_seed)
|
||||
end
|
||||
|
||||
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"vines:vine"},
|
||||
interval = 5,
|
||||
chance = 4,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
|
||||
local p = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||
local n = minetest.env:get_node(p)
|
||||
|
||||
--remove if top node is removed
|
||||
if minetest.env:get_node({x=pos.x, y=pos.y+1, z=pos.z}).name == "air" then
|
||||
minetest.env:remove_node(pos)
|
||||
end
|
||||
|
||||
--the second argument in the random function represents the average height
|
||||
if math.random(0,3)<1 then
|
||||
minetest.env:add_node(pos, {name="vines:vine_rotten"})
|
||||
else
|
||||
if n.name =="air" then
|
||||
minetest.env:add_node(pos, {name="vines:vine_rotten"})
|
||||
minetest.env:add_node(p, {name="vines:vine"})
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"vines:vine_rotten"},
|
||||
interval = 60,
|
||||
chance = 4,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
|
||||
local p = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||
local n = minetest.env:get_node(p)
|
||||
|
||||
-- only remove if nothing is hangin on the bottom of it.
|
||||
if n.name ~="vines:vine" and n.name ~="vines:vine_rotten" then
|
||||
minetest.env:remove_node(pos)
|
||||
end
|
||||
|
||||
if minetest.env:get_node({x=pos.x, y=pos.y+1, z=pos.z}).name == "air" then
|
||||
minetest.env:remove_node({x=pos.x, y=pos.y+1, z=pos.z})
|
||||
end
|
||||
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"default:dirt", "default:dirt_with_grass"},
|
||||
interval = 36000,
|
||||
chance = 10,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
|
||||
local p = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||
local n = minetest.env:get_node(p)
|
||||
|
||||
--remove if top node is removed
|
||||
if n.name == "air" and is_node_in_cube ({"vines:vine"}, pos, 3) then
|
||||
minetest.env:add_node(p, {name="vines:vine"})
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"vines:rope_end"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
|
||||
local p = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||
local n = minetest.env:get_node(p)
|
||||
|
||||
--remove if top node is removed
|
||||
if n.name == "air" then
|
||||
minetest.env:remove_node(pos)
|
||||
minetest.env:add_node(pos, {name="vines:rope"})
|
||||
minetest.env:add_node(p, {name="vines:rope_end"})
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
is_node_in_cube = function(nodenames, node_pos, radius)
|
||||
for x = node_pos.x - radius, node_pos.x + radius do
|
||||
for y = node_pos.y - radius, node_pos.y + radius do
|
||||
for z = node_pos.z - radius, node_pos.z + radius do
|
||||
n = minetest.env:get_node_or_nil({x = x, y = y, z = z})
|
||||
if (n == nil)
|
||||
or (n.name == 'ignore')
|
||||
or (table_contains(nodenames, n.name) == true) then
|
||||
return true
|
||||
minetest.register_abm({ --"sumpf:leaves", "jungletree:leaves_green", "jungletree:leaves_yellow", "jungletree:leaves_red",
|
||||
nodenames = {"default:dirt_with_grass"},
|
||||
interval = 80,
|
||||
chance = 200,
|
||||
action = function(pos, node)
|
||||
|
||||
local p = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||
local n = minetest.env:get_node(p)
|
||||
|
||||
if n.name =="air" then
|
||||
minetest.env:add_node(p, {name="vines:vine"})
|
||||
print("[vines] vine grew at: ("..p.x..", "..p.y..", "..p.z..")")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
return false
|
||||
minetest.register_abm({
|
||||
nodenames = {"vines:vine"},
|
||||
interval = 5,
|
||||
chance = 4,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
|
||||
local s_pos = "("..pos.x..", "..pos.y..", "..pos.z..")"
|
||||
|
||||
--remove if top node is removed
|
||||
if minetest.env:get_node({x=pos.x, y=pos.y+1, z=pos.z}).name == "air" then
|
||||
minetest.env:remove_node(pos)
|
||||
print("[vines] vine removed at: "..s_pos)
|
||||
return
|
||||
end
|
||||
|
||||
minetest.env:add_node(pos, {name="vines:vine_rotten"})
|
||||
|
||||
local p = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||
local n = minetest.env:get_node(p)
|
||||
local pr = get_vine_random(pos)
|
||||
|
||||
--the second argument in the random function represents the average height
|
||||
if pr:next(1,4) == 1 then
|
||||
print("[vines] vine ended at: "..s_pos)
|
||||
return
|
||||
end
|
||||
|
||||
if n.name =="air" then
|
||||
minetest.env:add_node(p, {name="vines:vine"})
|
||||
print("[vines] vine got longer at: ("..p.x..", "..p.y..", "..p.z..")")
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"vines:vine_rotten"},
|
||||
interval = 60,
|
||||
chance = 4,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
|
||||
local p = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||
local n = minetest.env:get_node(p)
|
||||
local n_about = minetest.env:get_node({x=pos.x, y=pos.y+1, z=pos.z}).name
|
||||
local pr = get_vine_random(pos)
|
||||
|
||||
-- only remove if nothing is hangin on the bottom of it.
|
||||
if (
|
||||
n.name ~="vines:vine"
|
||||
and n.name ~="vines:vine_rotten"
|
||||
and n_about ~= "default:dirt"
|
||||
and n_about ~= "default:dirt_with_grass"
|
||||
and pr:next(1,4) ~= 1
|
||||
)
|
||||
or n_about == "air" then
|
||||
minetest.env:remove_node(pos)
|
||||
print("[vines] rotten vine disappeared at: ("..pos.x..", "..pos.y..", "..pos.z..")")
|
||||
end
|
||||
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"default:dirt", "default:dirt_with_grass"},
|
||||
interval = 36000,
|
||||
chance = 10,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
|
||||
local p = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||
local n = minetest.env:get_node(p)
|
||||
|
||||
--remove if top node is removed
|
||||
if n.name == "air" and is_node_in_cube ({"vines:vine"}, pos, 3) then
|
||||
minetest.env:add_node(p, {name="vines:vine"})
|
||||
print("[vines] vine grew at: ("..p.x..", "..p.y..", "..p.z..")")
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
minetest.register_abm({
|
||||
nodenames = {"vines:rope_end"},
|
||||
interval = 1,
|
||||
chance = 1,
|
||||
action = function(pos, node, active_object_count, active_object_count_wider)
|
||||
|
||||
local p = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||
local n = minetest.env:get_node(p)
|
||||
|
||||
--remove if top node is removed
|
||||
if n.name == "air" then
|
||||
minetest.env:add_node(pos, {name="vines:rope"})
|
||||
minetest.env:add_node(p, {name="vines:rope_end"})
|
||||
end
|
||||
end
|
||||
})
|
||||
|
||||
function is_node_in_cube(nodenames, pos, s)
|
||||
for i = -s, s do
|
||||
for j = -s, s do
|
||||
for k = -s, s do
|
||||
local n = minetest.get_node_or_nil({x=pos.x+i, y=pos.y+j, z=pos.z+k})
|
||||
if n == nil
|
||||
or n.name == 'ignore'
|
||||
or table_contains(nodenames, n.name) == true then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
table_contains = function(t, v)
|
||||
for _, i in ipairs(t) do
|
||||
if (i == v) then
|
||||
return true
|
||||
for _,i in ipairs(t) do
|
||||
if i == v then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return false
|
||||
return false
|
||||
end
|
||||
|
||||
-- craft rope
|
||||
|
@ -234,18 +313,4 @@ minetest.register_craftitem("vines:vines", {
|
|||
description = "Vines",
|
||||
inventory_image = "vines_vine.png",
|
||||
})
|
||||
|
||||
minetest.register_on_dignode(function (pos, node, player)
|
||||
if node.name == 'vines:rope_block' then
|
||||
local p = {x=pos.x, y=pos.y-1, z=pos.z}
|
||||
local n = minetest.env:get_node(p)
|
||||
while n.name == 'vines:rope' do
|
||||
minetest.env:remove_node(p)
|
||||
p = {x=p.x, y=p.y-1, z=p.z}
|
||||
n = minetest.env:get_node(p)
|
||||
end
|
||||
if n.name == 'vines:rope_end' then
|
||||
minetest.env:remove_node(p)
|
||||
end
|
||||
end
|
||||
end)
|
||||
print("[Vines] v1.1 loaded")
|
||||
|
|
Before Width: | Height: | Size: 244 B After Width: | Height: | Size: 172 B |
Before Width: | Height: | Size: 625 B |
After Width: | Height: | Size: 234 B |
After Width: | Height: | Size: 200 B |
Before Width: | Height: | Size: 673 B |
Before Width: | Height: | Size: 447 B After Width: | Height: | Size: 173 B |
After Width: | Height: | Size: 336 B |
Before Width: | Height: | Size: 463 B After Width: | Height: | Size: 173 B |
After Width: | Height: | Size: 331 B |