diff --git a/basic_machines/README b/basic_machines/README
deleted file mode 100644
index c46ca2a..0000000
--- a/basic_machines/README
+++ /dev/null
@@ -1,24 +0,0 @@
-BASIC_MACHINES: lightweight automation mod for minetest
-minetest 0.4.14+
-(c) 2015-2016 rnd
-textures by rnd, new textures by SaKeL (2016) and Jozet (2017)
-
-
-MANUAL:
- 1.WIKI PAGES: https://github.com/ac-minetest/basic_machines/wiki
- 2.ingame help: right click mover/detector/keypad.. and click help button
-
----------------------------------------------------------------------
-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 .
-----------------------------------------------------------------------
\ No newline at end of file
diff --git a/basic_machines/autocrafter.lua b/basic_machines/autocrafter.lua
deleted file mode 100644
index 20053fe..0000000
--- a/basic_machines/autocrafter.lua
+++ /dev/null
@@ -1,354 +0,0 @@
--- modified and adapted from pipeworks mod by VanessaE
--- by rnd
--- disabled timers and on/off button, now autocrafter is only activated by signal
-
-local autocrafterCache = {} -- caches some recipe data to avoid to call the slow function minetest.get_craft_result() every second
-
-local craft_time = 1
-
-local function count_index(invlist)
- local index = {}
- for _, stack in pairs(invlist) do
- if not stack:is_empty() then
- local stack_name = stack:get_name()
- index[stack_name] = (index[stack_name] or 0) + stack:get_count()
- end
- end
- return index
-end
-
-local function get_item_info(stack)
- local name = stack:get_name()
- local def = minetest.registered_items[name]
- local description = def and def.description or "Unknown item"
- return description, name
-end
-
-local function get_craft(pos, inventory, hash)
- local hash = hash or minetest.hash_node_position(pos)
- local craft = autocrafterCache[hash]
- if not craft then
- local recipe = inventory:get_list("recipe")
- local output, decremented_input = minetest.get_craft_result({method = "normal", width = 3, items = recipe})
- craft = {recipe = recipe, consumption=count_index(recipe), output = output, decremented_input = decremented_input}
- autocrafterCache[hash] = craft
- end
- return craft
-end
-
-local function autocraft(inventory, craft)
- if not craft then return false end
- local output_item = craft.output.item
-
- -- check if we have enough room in dst
- if not inventory:room_for_item("dst", output_item) then return false end
- local consumption = craft.consumption
- local inv_index = count_index(inventory:get_list("src"))
- -- check if we have enough material available
- for itemname, number in pairs(consumption) do
- if (not inv_index[itemname]) or inv_index[itemname] < number then return false end
- end
- -- consume material
- for itemname, number in pairs(consumption) do
- for i = 1, number do -- We have to do that since remove_item does not work if count > stack_max
- inventory:remove_item("src", ItemStack(itemname))
- end
- end
-
- -- craft the result into the dst inventory and add any "replacements" as well
- inventory:add_item("dst", output_item)
- for i = 1, 9 do
- inventory:add_item("dst", craft.decremented_input.items[i])
- end
- return true
-end
-
--- returns false to stop the timer, true to continue running
--- is started only from start_autocrafter(pos) after sanity checks and cached recipe
-local function run_autocrafter(pos, elapsed)
- local meta = minetest.get_meta(pos)
- local inventory = meta:get_inventory()
- local craft = get_craft(pos, inventory)
- local output_item = craft.output.item
- -- only use crafts that have an actual result
- if output_item:is_empty() then
- meta:set_string("infotext", "unconfigured Autocrafter: unknown recipe")
- return false
- end
-
- for step = 1, math.floor(elapsed/craft_time) do
- local continue = autocraft(inventory, craft)
- if not continue then return false end
- end
- return true
-end
-
-local function start_crafter(pos) -- rnd we dont need timer anymore
- -- local meta = minetest.get_meta(pos)
- -- if meta:get_int("enabled") == 1 then
- -- local timer = minetest.get_node_timer(pos)
- -- if not timer:is_started() then
- -- timer:start(craft_time)
- -- end
- -- end
-end
-
-local function after_inventory_change(pos)
- start_crafter(pos)
-end
-
--- note, that this function assumes allready being updated to virtual items
--- and doesn't handle recipes with stacksizes > 1
-local function after_recipe_change(pos, inventory)
- local meta = minetest.get_meta(pos)
- -- if we emptied the grid, there's no point in keeping it running or cached
- if inventory:is_empty("recipe") then
- --minetest.get_node_timer(pos):stop()
- autocrafterCache[minetest.hash_node_position(pos)] = nil
- meta:set_string("infotext", "unconfigured Autocrafter")
- return
- end
- local recipe_changed = false
- local recipe = inventory:get_list("recipe")
-
- local hash = minetest.hash_node_position(pos)
- local craft = autocrafterCache[hash]
-
- if craft then
- -- check if it changed
- local cached_recipe = craft.recipe
- for i = 1, 9 do
- if recipe[i]:get_name() ~= cached_recipe[i]:get_name() then
- autocrafterCache[hash] = nil -- invalidate recipe
- craft = nil
- break
- end
- end
- end
-
- craft = craft or get_craft(pos, inventory, hash)
- local output_item = craft.output.item
- local description, name = get_item_info(output_item)
- meta:set_string("infotext", string.format("'%s' Autocrafter (%s)", description, name))
- inventory:set_stack("output", 1, output_item)
-
- after_inventory_change(pos)
-end
-
--- clean out unknown items and groups, which would be handled like unknown items in the crafting grid
--- if minetest supports query by group one day, this might replace them
--- with a canonical version instead
-local function normalize(item_list)
- for i = 1, #item_list do
- local name = item_list[i]
- if not minetest.registered_items[name] then
- item_list[i] = ""
- end
- end
- return item_list
-end
-
-local function on_output_change(pos, inventory, stack)
- if not stack then
- inventory:set_list("output", {})
- inventory:set_list("recipe", {})
- else
- local input = minetest.get_craft_recipe(stack:get_name())
- if not input.items or input.type ~= "normal" then return end
- local items, width = normalize(input.items), input.width
- local item_idx, width_idx = 1, 1
- for i = 1, 9 do
- if width_idx <= width then
- inventory:set_stack("recipe", i, items[item_idx])
- item_idx = item_idx + 1
- else
- inventory:set_stack("recipe", i, ItemStack(""))
- end
- width_idx = (width_idx < 3) and (width_idx + 1) or 1
- end
- -- we'll set the output slot in after_recipe_change to the actual result of the new recipe
- end
- after_recipe_change(pos, inventory)
-end
-
--- returns false if we shouldn't bother attempting to start the timer again after this
-local function update_meta(meta, enabled)
- --local state = enabled and "on" or "off"
- --meta:set_int("enabled", enabled and 1 or 0)
- meta:set_string("formspec",
- "size[8,11]"..
- "list[context;recipe;0,0;3,3;]"..
- "image[3,1;1,1;gui_hb_bg.png^[colorize:#141318:255]"..
- "list[context;output;3,1;1,1;]"..
- --"image_button[3,2;1,1;pipeworks_button_" .. state .. ".png;" .. state .. ";;;false;pipeworks_button_interm.png]" .. -- rnd disable button
- "list[context;src;0,3.5;8,3;]"..
- "list[context;dst;4,0;4,3;]"..
- default.gui_bg..
- default.gui_bg_img..
- default.gui_slots..
- default.get_hotbar_bg(0,7)..
- "list[current_player;main;0,7;8,4;]"..
- "listring[context;dst]"..
- "listring[current_player;main]"..
- "listring[context;src]"..
- "listring[current_player;main]"..
- "listring[context;recipe]"..
- "listring[current_player;main]"
- )
-
- -- toggling the button doesn't quite call for running a recipe change check
- -- so instead we run a minimal version for infotext setting only
- -- this might be more written code, but actually executes less
- local output = meta:get_inventory():get_stack("output", 1)
- if output:is_empty() then -- doesn't matter if paused or not
- meta:set_string("infotext", "unconfigured Autocrafter: Place items for recipe top left. To operate place required items in bottom space (src inventory) and activated with keypad signal. Obtain crafted item from top right (dst inventory).")
- return false
- end
-
- local description, name = get_item_info(output)
- local infotext = enabled and string.format("'%s' Autocrafter (%s)", description, name)
- or string.format("paused '%s' Autocrafter", description)
-
- meta:set_string("infotext", infotext)
- return enabled
-end
-
--- 1st version of the autocrafter had actual items in the crafting grid
--- the 2nd replaced these with virtual items, dropped the content on update and set "virtual_items" to string "1"
--- the third added an output inventory, changed the formspec and added a button for enabling/disabling
--- so we work out way backwards on this history and update each single case to the newest version
-local function upgrade_autocrafter(pos, meta)
- local meta = meta or minetest.get_meta(pos)
- local inv = meta:get_inventory()
-
- if inv:get_size("output") == 0 then -- we are version 2 or 1
- inv:set_size("output", 1)
- -- migrate the old autocrafters into an "enabled" state
- update_meta(meta, true)
-
- if meta:get_string("virtual_items") == "1" then -- we are version 2
- -- we allready dropped stuff, so lets remove the metadatasetting (we are not being called again for this node)
- meta:set_string("virtual_items", "")
- else -- we are version 1
- local recipe = inv:get_list("recipe")
- if not recipe then return end
- for idx, stack in ipairs(recipe) do
- if not stack:is_empty() then
- minetest.item_drop(stack, "", pos)
- stack:set_count(1)
- stack:set_wear(0)
- inv:set_stack("recipe", idx, stack)
- end
- end
- end
-
- -- update the recipe, cache, and start the crafter
- autocrafterCache[minetest.hash_node_position(pos)] = nil
- after_recipe_change(pos, inv)
- end
-end
-
-minetest.register_node("basic_machines:autocrafter", {
- description = "Autocrafter",
- drawtype = "normal",
- tiles = {"pipeworks_autocrafter.png"},
- groups = {cracky=3, mesecon_effector_on = 1},
- on_construct = function(pos)
- local meta = minetest.get_meta(pos)
- local inv = meta:get_inventory()
- inv:set_size("src", 3*8)
- inv:set_size("recipe", 3*3)
- inv:set_size("dst", 4*3)
- inv:set_size("output", 1)
- update_meta(meta, false)
- end,
- on_receive_fields = function(pos, formname, fields, sender)
- --if not pipeworks.may_configure(pos, sender) then return end
- local meta = minetest.get_meta(pos)
- if fields.on then
- update_meta(meta, false)
- --minetest.get_node_timer(pos):stop()
- elseif fields.off then
- if update_meta(meta, true) then
- start_crafter(pos)
- end
- end
- end,
- can_dig = function(pos, player)
- upgrade_autocrafter(pos)
- local meta = minetest.get_meta(pos)
- local inv = meta:get_inventory()
- return (inv:is_empty("src") and inv:is_empty("dst"))
- end,
- after_place_node = function(pos, placer) -- rnd : set owner
- local meta = minetest.get_meta(pos);
- meta:set_string("owner", placer:get_player_name());
- end,
- --after_place_node = pipeworks.scan_for_tube_objects,
- --after_dig_node = function(pos)
- --pipeworks.scan_for_tube_objects(pos)
- --end,
- on_destruct = function(pos)
- autocrafterCache[minetest.hash_node_position(pos)] = nil
- end,
- allow_metadata_inventory_put = function(pos, listname, index, stack, player)
- --if not pipeworks.may_configure(pos, player) then return 0 end
- local meta = minetest.get_meta(pos);if meta:get_string("owner")~=player:get_player_name() then return 0 end -- rnd
-
- upgrade_autocrafter(pos)
- local inv = minetest.get_meta(pos):get_inventory()
- if listname == "recipe" then
- stack:set_count(1)
- inv:set_stack(listname, index, stack)
- after_recipe_change(pos, inv)
- return 0
- elseif listname == "output" then
- on_output_change(pos, inv, stack)
- return 0
- end
- after_inventory_change(pos)
- return stack:get_count()
- end,
- allow_metadata_inventory_take = function(pos, listname, index, stack, player)
- --if not pipeworks.may_configure(pos, player) then
- -- minetest.log("action", string.format("%s attempted to take from autocrafter at %s", player:get_player_name(), minetest.pos_to_string(pos)))
- -- return 0
- -- end
- local meta = minetest.get_meta(pos);if meta:get_string("owner")~=player:get_player_name() then return 0 end -- rnd
-
- upgrade_autocrafter(pos)
- local inv = minetest.get_meta(pos):get_inventory()
- if listname == "recipe" then
- inv:set_stack(listname, index, ItemStack(""))
- after_recipe_change(pos, inv)
- return 0
- elseif listname == "output" then
- on_output_change(pos, inv, nil)
- return 0
- end
- after_inventory_change(pos)
- return stack:get_count()
- end,
- allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
- return 0; -- no internal inventory moves!
- end,
-
- mesecons = {effector = { -- rnd: run machine when activated by signal
- action_on = function (pos, node,ttl)
- if type(ttl)~="number" then ttl = 1 end
- if ttl<0 then return end -- machines_TTL prevents infinite recursion
- run_autocrafter(pos, craft_time);
- end
- }
- }
- --on_timer = run_autocrafter -- rnd
-})
-
--- minetest.register_craft( {
- -- output = "basic_machines:autocrafter",
- -- recipe = {
- -- { "default:steel_ingot", "default:mese_crystal", "default:steel_ingot" },
- -- { "default:diamondblock", "default:steel_ingot", "default:diamondblock" },
- -- { "default:steel_ingot", "default:mese_crystal", "default:steel_ingot" }
- -- },
--- })
\ No newline at end of file
diff --git a/basic_machines/ball.lua b/basic_machines/ball.lua
deleted file mode 100644
index 844ecbe..0000000
--- a/basic_machines/ball.lua
+++ /dev/null
@@ -1,669 +0,0 @@
--- BALL: energy ball that flies around, can bounce and activate stuff
--- rnd 2016:
-
--- TO DO: move mode: ball just rolling around on ground without hopping, also if inside slope it would "roll down", just increased velocity in slope direction
-
--- SETTINGS
-
-basic_machines.ball = {};
-basic_machines.ball.maxdamage = 10; -- player health 20
-basic_machines.ball.bounce_materials = { -- to be used with bounce setting 2 in ball spawner: 1: bounce in x direction, 2: bounce in z direction, otherwise it bounces in y direction
-["default:wood"]=1,
-["xpanes:bar_2"]=1,
-["xpanes:bar_10"]=1,
-["darkage:iron_bars"]=1,
-["default:glass"] = 2,
-};
-
--- END OF SETTINGS
-
-local ballcount = {};
-local function round(x)
- if x < 0 then
- return -math.floor(-x+0.5);
- else
- return math.floor(x+0.5);
- end
-end
-
-
-local ball_spawner_update_form = function (pos)
-
- local meta = minetest.get_meta(pos);
- local x0,y0,z0;
- x0=meta:get_int("x0");y0=meta:get_int("y0");z0=meta:get_int("z0"); -- direction of velocity
-
- local energy,bounce,g,puncheable, gravity,hp,hurt,solid;
- local speed = meta:get_float("speed"); -- if positive sets initial ball speed
- energy = meta:get_float("energy"); -- if positive activates, negative deactivates, 0 does nothing
- bounce = meta:get_int("bounce"); -- if nonzero bounces when hit obstacle, 0 gets absorbed
- gravity = meta:get_float("gravity"); -- gravity
- hp = meta:get_float("hp");
- hurt = meta:get_float("hurt");
- puncheable = meta:get_int("puncheable"); -- if 1 can be punched by players in protection, if 2 can be punched by anyone
- solid = meta:get_int("solid"); -- if 1 then entity is solid - cant be walked on
-
- local texture = meta:get_string("texture") or "basic_machines_ball.png";
- local visual = meta:get_string("visual") or "sprite";
- local scale = meta:get_int("scale");
-
- local form =
- "size[4.25,4.75]" .. -- width, height
- "field[0.25,0.5;1,1;x0;target;"..x0.."] field[1.25,0.5;1,1;y0;;"..y0.."] field[2.25,0.5;1,1;z0;;"..z0.."]"..
- "field[3.25,0.5;1,1;speed;speed;"..speed.."]"..
- --speed, jump, gravity,sneak
- "field[0.25,1.5;1,1;energy;energy;"..energy.."]"..
- "field[1.25,1.5;1,1;bounce;bounce;".. bounce.."]"..
- "field[2.25,1.5;1,1;gravity;gravity;"..gravity.."]"..
- "field[3.25,1.5;1,1;puncheable;puncheable;"..puncheable.."]"..
- "field[3.25,2.5;1,1;solid;solid;"..solid.."]"..
- "field[0.25,2.5;1,1;hp;hp;"..hp.."]".."field[1.25,2.5;1,1;hurt;hurt;"..hurt.."]"..
- "field[0.25,3.5;4,1;texture;texture;"..minetest.formspec_escape(texture).."]"..
- "field[0.25,4.5;1,1;scale;scale;"..scale.."]".."field[1.25,4.5;1,1;visual;visual;"..visual.."]"..
- "button_exit[3.25,4.25;1,1;OK;OK]";
-
-
-
- if meta:get_int("admin")==1 then
- local lifetime = meta:get_int("lifetime");
- if lifetime <= 0 then lifetime = 20 end
- form = form .. "field[2.25,2.5;1,1;lifetime;lifetime;"..lifetime.."]"
- end
-
- meta:set_string("formspec",form);
-
-end
-
-
-
-minetest.register_entity("basic_machines:ball",{
- timer = 0,
- lifetime = 20, -- how long it exists before disappearing
- energy = 0, -- if negative it will deactivate stuff, positive will activate, 0 wont do anything
- puncheable = 1, -- can be punched by players in protection
- bounce = 0, -- 0: absorbs in block, 1 = proper bounce=lag buggy, -- to do: 2 = line of sight bounce
- gravity = 0,
- speed = 5, -- velocity when punched
- hurt = 0, -- how much damage it does to target entity, if 0 damage disabled
- owner = "",
- state = false,
- origin = {x=0,y=0,z=0},
- lastpos = {x=0,y=0,z=0}, -- last not-colliding position
- hp_max = 100,
- elasticity = 0.9, -- speed gets multiplied by this after bounce
- visual="sprite",
- visual_size={x=.6,y=.6},
- collisionbox = {-0.5,-0.5,-0.5, 0.5,0.5,0.5},
- physical=false,
-
- --textures={"basic_machines_ball"},
-
- on_activate = function(self, staticdata)
- self.object:set_properties({textures={"basic_machines_ball.png"}})
- self.object:set_properties({visual_size = {x=1, y=1}});
- self.timer = 0;self.owner = "";
- self.origin = self.object:getpos();
- self.lifetime = 20;
- end,
-
- get_staticdata = function(self) -- this gets called before object put in world and before it hides
- if not self.state then return nil end
- self.object:remove();
- return nil
- end,
-
-
- on_punch = function (self, puncher, time_from_last_punch, tool_capabilities, dir)
- if self.puncheable == 0 then return end
- if self.puncheable == 1 then -- only those in protection
- local name = puncher:get_player_name();
- local pos = self.object:getpos();
- if minetest.is_protected(pos,name) then return end
- end
- --minetest.chat_send_all(minetest.pos_to_string(dir))
- if time_from_last_punch<0.5 then return end
- local v = self.speed or 1;
-
- local velocity = dir;
- velocity.x = velocity.x*v;velocity.y = velocity.y*v;velocity.z = velocity.z*v;
- self.object:setvelocity(velocity)
- end,
-
- on_step = function(self, dtime)
- self.timer=self.timer+dtime
- if self.timer>self.lifetime then
- local count = ballcount[self.owner] or 1; count=count-1; ballcount[self.owner] = count;
- self.object:remove()
- return
- end
-
- if not self.state then self.state = true end
- local pos=self.object:getpos()
-
- local origin = self.origin;
-
- local r = 30;-- maximal distance when balls disappear
- local dist = math.max(math.abs(pos.x-origin.x), math.abs(pos.y-origin.y), math.abs(pos.z-origin.z));
- if dist>r then -- remove if it goes too far
- local count = ballcount[self.owner] or 1; count=count-1; ballcount[self.owner] = count;
- self.object:remove()
- return
- end
-
- local nodename = minetest.get_node(pos).name;
- local walkable = false;
- if nodename ~= "air" then
- walkable = minetest.registered_nodes[nodename].walkable;
- if nodename == "basic_machines:ball_spawner" and dist>0.5 then walkable = true end -- ball can activate spawner, just not originating one
- end
- if not walkable then
- self.lastpos = pos
- if self.hurt~=0 then -- check for coliding nearby objects
- local objects = minetest.get_objects_inside_radius(pos,2);
- if #objects>1 then
- for _, obj in pairs(objects) do
- local p = obj:getpos();
- local d = math.sqrt((p.x-pos.x)^2+(p.y-pos.y)^2+(p.z-pos.z)^2);
- if d>0 then
-
- --if minetest.is_protected(p,self.owner) then return end
- if math.abs(p.x)<32 and math.abs(p.y)<32 and math.abs(p.z)<32 then return end -- no damage around spawn
-
- if obj:is_player() then --player
- if obj:get_player_name()==self.owner then break end -- dont hurt owner
-
- local hp = obj:get_hp()
- local newhp = hp-self.hurt;
- if newhp<=0 and boneworld and boneworld.killxp then
- local killxp = boneworld.killxp[self.owner];
- if killxp then
- boneworld.killxp[self.owner] = killxp + 0.01;
- end
- end
- obj:set_hp(newhp)
- else -- non player
- local lua_entity = obj:get_luaentity();
- if lua_entity and lua_entity.itemstring then
- local entname = lua_entity.itemstring;
- if entname == "robot" then
- self.object:remove()
- return;
- end
- end
- local hp = obj:get_hp()
- local newhp = hp-self.hurt;
- minetest.chat_send_player(self.owner,"#ball: target hp " .. newhp)
- if newhp<=0 then obj:remove() else obj:set_hp(newhp) end
- end
-
-
-
-
- local count = ballcount[self.owner] or 1; count=count-1; ballcount[self.owner] = count;
- self.object:remove();
- return
- end
- end
- end
- end
- end
-
-
- if walkable then -- we hit a node
- --minetest.chat_send_all(" hit node at " .. minetest.pos_to_string(pos))
-
-
- local node = minetest.get_node(pos);
- local table = minetest.registered_nodes[node.name];
- if table and table.mesecons and table.mesecons.effector then -- activate target
-
- local energy = self.energy;
- if energy~=0 then
- if minetest.is_protected(pos,self.owner) then return end
- end
- local effector = table.mesecons.effector;
-
- self.object:remove();
-
- if energy>0 then
- if not effector.action_on then return end
- effector.action_on(pos,node,16);
- elseif energy<0 then
- if not effector.action_off then return end
- effector.action_off(pos,node,16);
- end
-
-
- else -- bounce ( copyright rnd, 2016 )
- local bounce = self.bounce;
- if self.bounce == 0 then
- local count = ballcount[self.owner] or 1; count=count-1; ballcount[self.owner] = count;
- self.object:remove()
- return end
-
- local n = {x=0,y=0,z=0}; -- this will be bounce normal
- local v = self.object:getvelocity();
- local opos = {x=round(pos.x),y=round(pos.y), z=round(pos.z)}; -- obstacle
- local bpos ={ x=(pos.x-opos.x),y=(pos.y-opos.y),z=(pos.z-opos.z)}; -- boundary position on cube, approximate
-
- if bounce == 2 then -- uses special blocks for non buggy lag proof bouncing: by default it bounces in y direction
- local bounce_direction = basic_machines.ball.bounce_materials[node.name] or 0;
-
- if bounce_direction == 0 then
- if v.y>=0 then n.y = -1 else n.y = 1 end
- elseif bounce_direction == 1 then
- if v.x>=0 then n.x = -1 else n.x = 1 end
- n.y = 0;
- elseif bounce_direction == 2 then
- if v.z>=0 then n.z = -1 else n.z = 1 end
- n.y = 0;
- end
-
- else -- algorithm to determine bounce direction - problem: with lag its impossible to determine reliable which node was hit and which face ..
-
- if v.x<=0 then n.x = 1 else n.x = -1 end -- possible bounce directions
- if v.y<=0 then n.y = 1 else n.y = -1 end
- if v.z<=0 then n.z = 1 else n.z = -1 end
-
- local dpos = {};
-
- dpos.x = 0.5*n.x; dpos.y = 0; dpos.z = 0; -- calculate distance to bounding surface midpoints
-
- local d1 = (bpos.x-dpos.x)^2 + (bpos.y)^2 + (bpos.z)^2;
- dpos.x = 0; dpos.y = 0.5*n.y; dpos.z = 0;
- local d2 = (bpos.x)^2 + (bpos.y-dpos.y)^2 + (bpos.z)^2;
- dpos.x = 0; dpos.y = 0; dpos.z = 0.5*n.z;
- local d3 = (bpos.x)^2 + (bpos.y)^2 + (bpos.z-dpos.z)^2;
- local d = math.min(d1,d2,d3); -- we obtain bounce direction from minimal distance
-
- if d1==d then --x
- n.y=0;n.z=0
- elseif d2==d then --y
- n.x=0;n.z=0
- elseif d3==d then --z
- n.x=0;n.y=0
- end
-
-
- nodename=minetest.get_node({x=opos.x+n.x,y=opos.y+n.y,z=opos.z+n.z}).name -- verify normal
- walkable = nodename ~= "air";
- if walkable then -- problem, nonempty node - incorrect normal, fix it
- if n.x ~=0 then -- x direction is wrong, try something else
- n.x=0;
- if v.y>=0 then n.y = -1 else n.y = 1 end -- try y
- nodename=minetest.get_node({x=opos.x+n.x,y=opos.y+n.y,z=opos.z+n.z}).name -- verify normal
- walkable = nodename ~= "air";
- if walkable then -- still problem, only remaining is z
- n.y=0;
- if v.z>=0 then n.z = -1 else n.z = 1 end
- nodename=minetest.get_node({x=opos.x+n.x,y=opos.y+n.y,z=opos.z+n.z}).name -- verify normal
- walkable = nodename ~= "air";
- if walkable then -- messed up, just remove the ball
- self.object:remove()
- return
- end
-
- end
-
- end
- end
-
- end
-
- local elasticity = self.elasticity;
-
- -- bounce
- if n.x~=0 then
- v.x=-elasticity*v.x
- elseif n.y~=0 then
- v.y=-elasticity*v.y
- elseif n.z~=0 then
- v.z=-elasticity*v.z
- end
-
- local r = 0.2
- bpos = {x=pos.x+n.x*r,y=pos.y+n.y*r,z=pos.z+n.z*r}; -- point placed a bit further away from box
- self.object:setpos(bpos) -- place object at last known outside point
-
- self.object:setvelocity(v);
-
- minetest.sound_play("default_dig_cracky", {pos=pos,gain=1.0,max_hear_distance = 8,})
-
- end
- end
- return
- end,
-})
-
-
-minetest.register_node("basic_machines:ball_spawner", {
- description = "Spawns energy ball one block above",
- tiles = {"basic_machines_ball.png"},
- groups = {cracky=3, mesecon_effector_on = 1},
- drawtype = "allfaces",
- paramtype = "light",
- param1=1,
- walkable = false,
- alpha = 150,
- sounds = default.node_sound_wood_defaults(),
- after_place_node = function(pos, placer)
- local meta = minetest.env:get_meta(pos)
- meta:set_string("owner", placer:get_player_name());
- local privs = minetest.get_player_privs(placer:get_player_name()); if privs.privs then meta:set_int("admin",1) end
-
- if privs.machines then meta:set_int("machines",1) end
-
- meta:set_float("hurt",0);
- meta:set_string("texture", "basic_machines_ball.png");
- meta:set_float("hp",100);
- meta:set_float("speed",5); -- if positive sets initial ball speed
- meta:set_float("energy",1); -- if positive activates, negative deactivates, 0 does nothing
- meta:set_int("bounce",0); -- if nonzero bounces when hit obstacle, 0 gets absorbed
- meta:set_float("gravity",0); -- gravity
- meta:set_int("puncheable",0); -- if 0 not puncheable, if 1 can be punched by players in protection, if 2 can be punched by anyone
- meta:set_int("scale",100);
- meta:set_string("visual","sprite");
- ball_spawner_update_form(pos);
-
- end,
-
- mesecons = {effector = {
- action_on = function (pos, node,ttl)
- if type(ttl)~="number" then ttl = 1 end
- if ttl<0 then return end
-
- local meta = minetest.get_meta(pos);
- local t0 = meta:get_int("t");
- local t1 = minetest.get_gametime();
- local T = meta:get_int("T"); -- temperature
-
- if t0>t1-2 then -- activated before natural time
- T=T+1;
- else
- if T>0 then
- T=T-1
- if t1-t0>5 then T = 0 end
- end
- end
- meta:set_int("T",T);
- meta:set_int("t",t1); -- update last activation time
-
- if T > 2 then -- overheat
- minetest.sound_play("default_cool_lava",{pos = pos, max_hear_distance = 16, gain = 0.25})
- meta:set_string("infotext","overheat: temperature ".. T)
- return
- end
-
- if meta:get_int("machines")~=1 then -- no machines priv, limit ball count
- local owner = meta:get_string("owner");
- local count = ballcount[owner];
- if not count or count<0 then count = 0 end
-
- if count>=2 then
- if t1-t0>20 then count = 0
- else return
- end
- end
-
- count = count + 1;
- ballcount[owner]=count;
- --minetest.chat_send_all("count " .. count);
- end
-
- pos.x = round(pos.x);pos.y = round(pos.y);pos.z = round(pos.z);
- local obj = minetest.add_entity({x=pos.x,y=pos.y,z=pos.z}, "basic_machines:ball");
- local luaent = obj:get_luaentity();
- local meta = minetest.get_meta(pos);
-
- local speed,energy,bounce,gravity,puncheable,solid;
- speed = meta:get_float("speed");
- energy = meta:get_float("energy"); -- if positive activates, negative deactivates, 0 does nothing
- bounce = meta:get_int("bounce"); -- if nonzero bounces when hit obstacle, 0 gets absorbed
- gravity = meta:get_float("gravity"); -- gravity
- puncheable = meta:get_int("puncheable"); -- if 1 can be punched by players in protection, if 2 can be punched by anyone
- solid = meta:get_int("solid");
-
- if energy<0 then
- obj:set_properties({textures={"basic_machines_ball.png^[colorize:blue:120"}})
- end
-
- luaent.bounce = bounce;
- luaent.energy = energy;
- if gravity>0 then
- obj:setacceleration({x=0,y=-gravity,z=0});
- end
- luaent.puncheable = puncheable;
- luaent.owner = meta:get_string("owner");
- luaent.hurt = meta:get_float("hurt");
- if solid==1 then
- luaent.physical = true
- end
-
- obj:set_hp( meta:get_float("hp") );
-
- local x0,y0,z0;
- if speed>0 then luaent.speed = speed end
-
- x0=meta:get_int("x0");y0=meta:get_int("y0");z0=meta:get_int("z0"); -- direction of velocity
- if speed~=0 and (x0~=0 or y0~=0 or z0~=0) then -- set velocity direction
- local velocity = {x=x0,y=y0,z=z0};
- local v = math.sqrt(velocity.x^2+velocity.y^2+velocity.z^2); if v == 0 then v = 1 end
- v = v / speed;
- velocity.x=velocity.x/v;velocity.y=velocity.y/v;velocity.z=velocity.z/v;
- obj:setvelocity(velocity);
- end
-
- if meta:get_int("admin")==1 then
- luaent.lifetime = meta:get_float("lifetime");
- end
-
-
- local visual = meta:get_string("visual")
- obj:set_properties({visual=visual});
- local texture = meta:get_string("texture");
- if visual=="sprite" then
- obj:set_properties({textures={texture}})
- elseif visual == "cube" then
- obj:set_properties({textures={texture,texture,texture,texture,texture,texture}})
- end
- local scale = meta:get_int("scale");if scale<=0 then scale = 1 else scale = scale/100 end
- obj:set_properties({visual_size = {x=scale, y=scale}});
-
-
-
- end,
-
- action_off = function (pos, node,ttl)
- if type(ttl)~="number" then ttl = 1 end
- if ttl<0 then return end
- pos.x = round(pos.x);pos.y = round(pos.y);pos.z = round(pos.z);
- local obj = minetest.add_entity({x=pos.x,y=pos.y,z=pos.z}, "basic_machines:ball");
- local luaent = obj:get_luaentity();
- luaent.energy = -1;
- obj:set_properties({textures={"basic_machines_ball.png^[colorize:blue:120"}})
- end
- }
- },
-
- on_receive_fields = function(pos, formname, fields, sender)
-
- local name = sender:get_player_name();if minetest.is_protected(pos,name) then return end
-
- if fields.OK then
- local privs = minetest.get_player_privs(sender:get_player_name());
- local meta = minetest.get_meta(pos);
- local x0=0; local y0=0; local z0=0;
- --minetest.chat_send_all("form at " .. dump(pos) .. " fields " .. dump(fields))
- if fields.x0 then x0 = tonumber(fields.x0) or 0 end
- if fields.y0 then y0 = tonumber(fields.y0) or 0 end
- if fields.z0 then z0 = tonumber(fields.z0) or 0 end
- if not privs.privs and (math.abs(x0)>10 or math.abs(y0)>10 or math.abs(z0) > 10) then return end
-
- meta:set_int("x0",x0);meta:set_int("y0",y0);meta:set_int("z0",z0);
-
- local speed,energy,bounce,gravity,puncheable,solid;
- energy = meta:get_float("energy"); -- if positive activates, negative deactivates, 0 does nothing
- bounce = meta:get_int("bounce"); -- if nonzero bounces when hit obstacle, 0 gets absorbed
- gravity = meta:get_float("gravity"); -- gravity
- puncheable = meta:get_int("puncheable"); -- if 1 can be punched by players in protection, if 2 can be punched by anyone
- solid = meta:get_int("solid");
-
-
- if fields.speed then
- local speed = tonumber(fields.speed) or 0;
- if (speed > 10 or speed < 0) and not privs.privs then return end
- meta:set_float("speed", speed)
- end
-
- if fields.energy then
- local energy = tonumber(fields.energy) or 1;
- meta:set_float("energy", energy)
- end
-
- if fields.bounce then
- local bounce = tonumber(fields.bounce) or 1;
- meta:set_int("bounce",bounce)
- end
-
- if fields.gravity then
- local gravity = tonumber(fields.gravity) or 1;
- if (gravity<0 or gravity>30) and not privs.privs then return end
- meta:set_float("gravity", gravity)
- end
- if fields.puncheable then
- meta:set_int("puncheable", tonumber(fields.puncheable) or 0)
- end
-
- if fields.solid then
- meta:set_int("solid", tonumber(fields.solid) or 0)
- end
-
- if fields.lifetime then
- meta:set_int("lifetime", tonumber(fields.lifetime) or 0)
- end
-
- if fields.hurt then
- meta:set_float("hurt", tonumber(fields.hurt) or 0)
- end
-
- if fields.hp then
- meta:set_float("hp", math.abs(tonumber(fields.hp) or 0))
- end
-
- if fields.texture then
- meta:set_string ("texture", fields.texture);
- end
-
- if fields.scale then
- local scale = math.abs(tonumber(fields.scale) or 100);
- if scale>1000 and not privs.privs then scale = 1000 end
- meta:set_int("scale", scale)
- end
-
- if fields.visual then
- local visual = fields.visual or "";
- if visual~="sprite" and visual~="cube" then return end
- meta:set_string ("visual", fields.visual);
- end
-
- ball_spawner_update_form(pos);
- end
- end,
-
- after_dig_node = function(pos, oldnode, oldmetadata, digger)
- local name = digger:get_player_name();
- local inv = digger:get_inventory();
- inv:remove_item("main", ItemStack("basic_machines:ball_spawner"));
- local stack = ItemStack("basic_machines:ball_spell");
- local meta = oldmetadata["fields"];
- meta["formspec"]=nil;
- stack:set_metadata(minetest.serialize(meta));
- inv:add_item("main",stack);
- end
-
-})
-
-
-local spelltime = {};
-
--- ball as magic spell user can cast
-minetest.register_tool("basic_machines:ball_spell", {
- description = "ball spawner",
- inventory_image = "basic_machines_ball.png",
- tool_capabilities = {
- full_punch_interval = 2,
- max_drop_level=0,
- },
- on_use = function(itemstack, user, pointed_thing)
-
- local pos = user:getpos();pos.y=pos.y+1;
- local meta = minetest.deserialize(itemstack:get_metadata());
- if not meta then return end
- local owner = meta["owner"] or "";
-
- --if minetest.is_protected(pos,owner) then return end
-
- local t0 = spelltime[owner] or 0;
- local t1 = minetest.get_gametime();
- if t1-t0<2 then return end -- too soon
- spelltime[owner]=t1;
-
-
- local obj = minetest.add_entity({x=pos.x,y=pos.y,z=pos.z}, "basic_machines:ball");
- local luaent = obj:get_luaentity();
-
-
- local speed,energy,bounce,gravity,puncheable;
- speed = tonumber(meta["speed"]) or 0;
- energy = tonumber(meta["energy"]) or 0; -- if positive activates, negative deactivates, 0 does nothing
- bounce = tonumber(meta["bounce"]) or 0; -- if nonzero bounces when hit obstacle, 0 gets absorbed
- gravity = tonumber(meta["gravity"]) or 0; -- gravity
- puncheable = tonumber(meta["puncheable"]) or 0; -- if 1 can be punched by players in protection, if 2 can be punched by anyone
-
- if energy<0 then
- obj:set_properties({textures={"basic_machines_ball.png^[colorize:blue:120"}})
- end
-
- luaent.bounce = bounce;
- luaent.energy = energy;
- if gravity>0 then
- obj:setacceleration({x=0,y=-gravity,z=0});
- end
- luaent.puncheable = puncheable;
- luaent.owner = meta["owner"];
- luaent.hurt = math.min(tonumber(meta["hurt"]),basic_machines.ball.maxdamage);
-
- obj:set_hp( tonumber(meta["hp"]) );
-
- local x0,y0,z0;
- if speed>0 then luaent.speed = speed end
-
-
-
- local v = user:get_look_dir();
- v.x=v.x*speed;v.y=v.y*speed;v.z=v.z*speed;
- obj:setvelocity(v);
-
-
- if tonumber(meta["admin"])==1 then
- luaent.lifetime = tonumber(meta["lifetime"]);
- end
-
-
- obj:set_properties({textures={meta["texture"]}})
-
-
- end,
-
-
-})
-
-
-
--- minetest.register_craft({
- -- output = "basic_machines:ball_spawner",
- -- recipe = {
- -- {"basic_machines:power_cell"},
- -- {"basic_machines:keypad"}
- -- }
--- })
\ No newline at end of file
diff --git a/basic_machines/constructor.lua b/basic_machines/constructor.lua
deleted file mode 100644
index b9d059c..0000000
--- a/basic_machines/constructor.lua
+++ /dev/null
@@ -1,219 +0,0 @@
--- rnd 2016:
-
--- CONSTRUCTOR machine: used to make all other basic_machines
-
-basic_machines.craft_recipes = {
-["keypad"] = {item = "basic_machines:keypad", description = "Turns on/off lights and activates machines or opens doors", craft = {"default:wood","default:stick"}, tex = "keypad"},
-["light"]={item = "basic_machines:light_on", description = "Light in darkness", craft = {"default:torch 4"}, tex = "light"},
-["mover"]={item = "basic_machines:mover", description = "Can dig, harvest, plant, teleport or move items from/in inventories", craft = {"default:mese_crystal 6","default:stone 2", "basic_machines:keypad"}, tex = "basic_machine_mover_side"},
-
-["detector"] = {item = "basic_machines:detector", description = "Detect and measure players, objects,blocks,light level", craft = {"default:mese_crystal 4","basic_machines:keypad"}, tex = "detector"},
-
-["distributor"]= {item = "basic_machines:distributor", description = "Organize your circuits better", craft = {"default:steel_ingot","default:mese_crystal", "basic_machines:keypad"}, tex = "distributor"},
-
-["clock_generator"]= {item = "basic_machines:clockgen", description = "For making circuits that run non stop", craft = {"default:diamondblock","basic_machines:keypad"}, tex = "basic_machine_clock_generator"},
-
-["recycler"]= {item = "basic_machines:recycler", description = "Recycle old tools", craft = {"default:mese_crystal 8","default:diamondblock"}, tex = "recycler"},
-
-["enviroment"] = {item = "basic_machines:enviro", description = "Change gravity and more", craft = {"basic_machines:generator 8","basic_machines:clockgen"}, tex = "enviro"},
-
-["ball_spawner"]={item = "basic_machines:ball_spawner", description = "Spawn moving energy balls", craft = {"basic_machines:power_cell","basic_machines:keypad"}, tex = "basic_machines_ball"},
-
-["battery"]={item = "basic_machines:battery_0", description = "Power for machines", craft = {"default:bronzeblock 2","default:mese","default:diamond"}, tex = "basic_machine_battery"},
-
-["generator"]={item = "basic_machines:generator", description = "Generate power crystals", craft = {"default:diamondblock 5","basic_machines:battery 5","default:goldblock 5"}, tex = "basic_machine_generator"},
-
-["autocrafter"] = {item = "basic_machines:autocrafter", description = "Automate crafting", craft = { "default:steel_ingot 5", "default:mese_crystal 2", "default:diamondblock 2"}, tex = "pipeworks_autocrafter"},
-
-["grinder"] = {item = "basic_machines:grinder", description = "Makes dusts and grinds materials", craft = {"default:diamond 13","default:mese 4"}, tex = "grinder"},
-
-["power_block"] = {item = "basic_machines:power_block 5", description = "Energy cell, contains 11 energy units", craft = {"basic_machines:power_rod"}, tex = "power_block"},
-
-["power_cell"] = {item = "basic_machines:power_cell 5", description = "Energy cell, contains 1 energy unit", craft = {"basic_machines:power_block"}, tex = "power_cell"},
-
-["coal_lump"] = {item = "default:coal_lump", description = "Coal lump, contains 1 energy unit", craft = {"basic_machines:power_cell 2"}, tex = "default_coal_lump"},
-
-}
-
-basic_machines.craft_recipe_order = { -- order in which nodes appear
- "keypad","light","grinder","mover", "battery","generator","detector", "distributor", "clock_generator","recycler","autocrafter","ball_spawner", "enviroment", "power_block", "power_cell", "coal_lump",
-}
-
-
-
-local constructor_process = function(pos)
-
- local meta = minetest.get_meta(pos);
- local craft = basic_machines.craft_recipes[meta:get_string("craft")];
- if not craft then return end
- local item = craft.item;
- local craftlist = craft.craft;
-
- local inv = meta:get_inventory();
- for _,v in pairs(craftlist) do
- if not inv:contains_item("main", ItemStack(v)) then
- meta:set_string("infotext", "#CRAFTING: you need " .. v .. " to craft " .. craft.item)
- return
- end
- end
-
- for _,v in pairs(craftlist) do
- inv:remove_item("main", ItemStack(v));
- end
- inv:add_item("main", ItemStack(item));
-
-end
-
-local constructor_update_meta = function(pos)
- local meta = minetest.get_meta(pos);
- local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
- local craft = meta:get_string("craft");
-
- local description = basic_machines.craft_recipes[craft];
- local tex;
-
- if description then
- tex = description.tex;
- local i = 0;
- local itex;
-
- local inv = meta:get_inventory(); -- set up craft list
- for _,v in pairs(description.craft) do
- i=i+1;
- inv:set_stack("recipe", i, ItemStack(v))
- end
-
- for j = i+1,6 do
- inv:set_stack("recipe", j, ItemStack(""))
- end
-
- description = description.description
-
- else
- description = ""
- tex = ""
- end
-
-
- local textlist = " ";
-
- local selected = meta:get_int("selected") or 1;
- for _,v in ipairs(basic_machines.craft_recipe_order) do
- textlist = textlist .. v .. ", ";
-
- end
-
- local form =
- "size[8,10]"..
- "textlist[0,0;3,1.5;craft;" .. textlist .. ";" .. selected .."]"..
- "button[3.5,1;1.25,0.75;CRAFT;CRAFT]"..
- "image[3.65,0;1,1;".. tex .. ".png]"..
- "label[0,1.85;".. description .. "]"..
- "list[context;recipe;5,0;3,2;]"..
- "label[0,2.3;Put crafting materials here]"..
- "list[context;main;0,2.7;8,3;]"..
- --"list[context;dst;5,0;3,2;]"..
- "label[0,5.5;player inventory]"..
- "list[current_player;main;0,6;8,4;]"..
- "listring[context;main]"..
- "listring[current_player;main]";
- meta:set_string("formspec", form);
-end
-
-
-minetest.register_node("basic_machines:constructor", {
- description = "Constructor: used to make machines",
- tiles = {"constructor.png"},
- groups = {cracky=3, mesecon_effector_on = 1},
- sounds = default.node_sound_wood_defaults(),
- after_place_node = function(pos, placer)
- local meta = minetest.get_meta(pos);
- meta:set_string("infotext", "Constructor: To operate it insert materials, select item to make and click craft button.")
- meta:set_string("owner", placer:get_player_name());
- meta:set_string("craft","keypad")
- meta:set_int("selected",1);
- local inv = meta:get_inventory();inv:set_size("main", 24);--inv:set_size("dst",6);
- inv:set_size("recipe",8);
- end,
-
- on_rightclick = function(pos, node, player, itemstack, pointed_thing)
- local meta = minetest.get_meta(pos);
- local privs = minetest.get_player_privs(player:get_player_name());
- if minetest.is_protected(pos, player:get_player_name()) and not privs.privs then return end -- only owner can interact with recycler
- constructor_update_meta(pos);
- end,
-
- allow_metadata_inventory_put = function(pos, listname, index, stack, player)
- if listname == "recipe" then return 0 end
- local meta = minetest.get_meta(pos);
- local privs = minetest.get_player_privs(player:get_player_name());
- if meta:get_string("owner")~=player:get_player_name() and not privs.privs then return 0 end
- return stack:get_count();
- end,
-
- allow_metadata_inventory_take = function(pos, listname, index, stack, player)
- if listname == "recipe" then return 0 end
- local privs = minetest.get_player_privs(player:get_player_name());
- if minetest.is_protected(pos, player:get_player_name()) and not privs.privs then return 0 end
- return stack:get_count();
- end,
-
- on_metadata_inventory_put = function(pos, listname, index, stack, player)
- if listname == "recipe" then return 0 end
- local privs = minetest.get_player_privs(player:get_player_name());
- if minetest.is_protected(pos, player:get_player_name()) and not privs.privs then return 0 end
- return stack:get_count();
- end,
-
- allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
- return 0;
- end,
-
- mesecons = {effector = {
- action_on = function (pos, node,ttl)
- if type(ttl)~="number" then ttl = 1 end
- if ttl<0 then return end -- machines_TTL prevents infinite recursion
- constructor_process(pos);
- end
- }
- },
-
- on_receive_fields = function(pos, formname, fields, sender)
-
- if minetest.is_protected(pos, sender:get_player_name()) then return end
- local meta = minetest.get_meta(pos);
-
- if fields.craft then
- if string.sub(fields.craft,1,3)=="CHG" then
- local sel = tonumber(string.sub(fields.craft,5)) or 1
- meta:set_int("selected",sel);
-
- local i = 0;
- for _,v in ipairs(basic_machines.craft_recipe_order) do
- i=i+1;
- if i == sel then meta:set_string("craft",v); break; end
- end
- else
- return
- end
- end
-
- if fields.CRAFT then
- constructor_process(pos);
- end
-
- constructor_update_meta(pos);
- end,
-
-})
-
-
-minetest.register_craft({
- output = "basic_machines:constructor",
- recipe = {
- {"default:steel_ingot","default:steel_ingot","default:steel_ingot"},
- {"default:steel_ingot","default:copperblock","default:steel_ingot"},
- {"default:steel_ingot","default:steel_ingot","default:steel_ingot"},
-
- }
-})
\ No newline at end of file
diff --git a/basic_machines/depends.txt b/basic_machines/depends.txt
deleted file mode 100644
index 9d0fcb6..0000000
--- a/basic_machines/depends.txt
+++ /dev/null
@@ -1,5 +0,0 @@
-default
-protector?
-areas?
-boneworld?
-moreores?
\ No newline at end of file
diff --git a/basic_machines/enviro.lua b/basic_machines/enviro.lua
deleted file mode 100644
index 5d2c6d9..0000000
--- a/basic_machines/enviro.lua
+++ /dev/null
@@ -1,382 +0,0 @@
--- ENVIRO block: change physics and skybox for players
--- note: nonadmin players are limited in changes ( cant change skybox and have limits on other allowed changes)
-
--- rnd 2016:
-
-local enviro = {};
-enviro.skyboxes = {
- ["default"]={type = "regular", tex = {}},
- ["space"]={type="skybox", tex={"sky_pos_y.png","sky_neg_y.png","sky_pos_z.png","sky_neg_z.png","sky_neg_x.png","sky_pos_x.png",}}, -- need textures installed!
- ["caves"]={type = "cavebox", tex = {"black.png","black.png","black.png","black.png","black.png","black.png",}},
- };
-
-local space_start = 1100;
-local ENABLE_SPACE_EFFECTS = false -- enable damage outside protected areas
-
-local enviro_update_form = function (pos)
-
- local meta = minetest.get_meta(pos);
-
- local x0,y0,z0;
- x0=meta:get_int("x0");y0=meta:get_int("y0");z0=meta:get_int("z0");
-
- local skybox = meta:get_string("skybox");
- local skylist = "";
- local sky_ind,j;
- j=1;sky_ind = 3;
- for i,_ in pairs(enviro.skyboxes) do
- if i == skybox then sky_ind = j end
- skylist = skylist .. i .. ",";
- j=j+1;
- end
- local r = meta:get_int("r");
- local speed,jump, g, sneak;
- speed = meta:get_float("speed");jump = meta:get_float("jump");
- g = meta:get_float("g"); sneak = meta:get_int("sneak");
- local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z;
-
- local form =
- "size[8,8.5]".. -- width, height
- "field[0.25,0.5;1,1;x0;target;"..x0.."] field[1.25,0.5;1,1;y0;;"..y0.."] field[2.25,0.5;1,1;z0;;"..z0.."]"..
- "field[3.25,0.5;1,1;r;radius;"..r.."]"..
- --speed, jump, gravity,sneak
- "field[0.25,1.5;1,1;speed;speed;"..speed.."]"..
- "field[1.25,1.5;1,1;jump;jump;"..jump.."]"..
- "field[2.25,1.5;1,1;g;gravity;"..g.."]"..
- "field[3.25,1.5;1,1;sneak;sneak;"..sneak.."]"..
- "label[0.,3.0;Skybox selection]"..
- "dropdown[0.,3.35;3,1;skybox;"..skylist..";"..sky_ind.."]"..
- "button_exit[3.25,3.25;1,1;OK;OK]"..
- "list["..list_name..";fuel;3.25,2.25;1,1;]"..
- "list[current_player;main;0,4.5;8,4;]"..
- "listring[current_player;main]"..
- "listring["..list_name..";fuel]"..
- "listring[current_player;main]"
- meta:set_string("formspec",form)
-end
-
--- enviroment changer
-minetest.register_node("basic_machines:enviro", {
- description = "Changes enviroment for players around target location",
- tiles = {"enviro.png"},
- drawtype = "allfaces",
- paramtype = "light",
- param1=1,
- groups = {cracky=3, mesecon_effector_on = 1},
- sounds = default.node_sound_wood_defaults(),
- after_place_node = function(pos, placer)
- local meta = minetest.env:get_meta(pos)
- meta:set_string("infotext", "Right click to set it. Activate by signal.")
- meta:set_string("owner", placer:get_player_name()); meta:set_int("public",1);
- meta:set_int("x0",0);meta:set_int("y0",0);meta:set_int("z0",0); -- target
- meta:set_int("r",5); meta:set_string("skybox","default");
- meta:set_float("speed",1);
- meta:set_float("jump",1);
- meta:set_float("g",1);
- meta:set_int("sneak",1);
- meta:set_int("admin",0);
- local name = placer:get_player_name();
- meta:set_string("owner",name);
- local privs = minetest.get_player_privs(name);
- if privs.privs then meta:set_int("admin",1) end
- if privs.machines then meta:set_int("machines",1) end
-
- local inv = meta:get_inventory();
- inv:set_size("fuel",1*1);
-
- enviro_update_form(pos);
- end,
-
- mesecons = {effector = {
- action_on = function (pos, node,ttl)
- local meta = minetest.get_meta(pos);
- local machines = meta:get_int("machines");
- if not machines == 1 then meta:set_string("infotext","Error. You need machines privs.") return end
-
- local admin = meta:get_int("admin");
-
- local inv = meta:get_inventory(); local stack = ItemStack("default:diamond 1");
-
- if inv:contains_item("fuel", stack) then
- inv:remove_item("fuel", stack);
- else
- meta:set_string("infotext","Error. Insert diamond in fuel inventory")
- return
- end
-
- local x0,y0,z0,r,skybox,speed,jump,g,sneak;
- x0=meta:get_int("x0"); y0=meta:get_int("y0");z0=meta:get_int("z0"); -- target
- r= meta:get_int("r",5); skybox=meta:get_string("skybox");
- speed=meta:get_float("speed");jump= meta:get_float("jump");
- g=meta:get_float("g");sneak=meta:get_int("sneak"); if sneak~=0 then sneak = true else sneak = false end
-
- local players = minetest.get_connected_players();
- for _,player in pairs(players) do
- local pos1 = player:getpos();
- local dist = math.sqrt((pos1.x-pos.x)^2 + (pos1.y-pos.y)^2 + (pos1.z-pos.z)^2 );
- if dist<=r then
-
- player:set_physics_override({speed=speed,jump=jump,gravity=g,sneak=sneak})
-
- if admin == 1 then -- only admin can change skybox
- local sky = enviro.skyboxes[skybox];
- player:set_sky(0,sky["type"],sky["tex"]);
- end
- end
- end
-
- -- attempt to set acceleration to balls, if any around
- local objects = minetest.get_objects_inside_radius(pos, r)
-
- for _,obj in pairs(objects) do
- if obj:get_luaentity() then
- local obj_name = obj:get_luaentity().name or ""
- if obj_name == "basic_machines:ball" then
- obj:setacceleration({x=0,y=-g,z=0});
- end
- end
-
- end
-
-
-
-
- end
- }
- },
-
-
- on_receive_fields = function(pos, formname, fields, sender)
-
- local name = sender:get_player_name();if minetest.is_protected(pos,name) then return end
-
- if fields.OK then
- local privs = minetest.get_player_privs(sender:get_player_name());
- local meta = minetest.get_meta(pos);
- local x0=0; local y0=0; local z0=0;
- --minetest.chat_send_all("form at " .. dump(pos) .. " fields " .. dump(fields))
- if fields.x0 then x0 = tonumber(fields.x0) or 0 end
- if fields.y0 then y0 = tonumber(fields.y0) or 0 end
- if fields.z0 then z0 = tonumber(fields.z0) or 0 end
- if not privs.privs and (math.abs(x0)>10 or math.abs(y0)>10 or math.abs(z0) > 10) then return end
-
- meta:set_int("x0",x0);meta:set_int("y0",y0);meta:set_int("z0",z0);
- if privs.privs then -- only admin can set sky
- if fields.skybox then meta:set_string("skybox", fields.skybox) end
- end
- if fields.r then
- local r = tonumber(fields.r) or 0;
- if r > 10 and not privs.privs then return end
- meta:set_int("r", r)
- end
- if fields.g then
- local g = tonumber(fields.g) or 1;
- if (g<0.1 or g>40) and not privs.privs then return end
- meta:set_float("g", g)
- end
- if fields.speed then
- local speed = tonumber(fields.speed) or 1;
- if (speed>1 or speed < 0) and not privs.privs then return end
- meta:set_float("speed", speed)
- end
- if fields.jump then
- local jump = tonumber(fields.jump) or 1;
- if (jump<0 or jump>2) and not privs.privs then return end
- meta:set_float("jump", jump)
- end
- if fields.sneak then
- meta:set_int("sneak", tonumber(fields.sneak) or 0)
- end
-
-
- enviro_update_form(pos);
- end
- end,
-
- allow_metadata_inventory_take = function(pos, listname, index, stack, player)
- local meta = minetest.get_meta(pos);
- local privs = minetest.get_player_privs(player:get_player_name());
- if meta:get_string("owner")~=player:get_player_name() and not privs.privs then return 0 end
- return stack:get_count();
- end,
-
- allow_metadata_inventory_put = function(pos, listname, index, stack, player)
- local meta = minetest.get_meta(pos);
- local privs = minetest.get_player_privs(player:get_player_name());
- if meta:get_string("owner")~=player:get_player_name() and not privs.privs then return 0 end
- return stack:get_count();
- end,
-
-})
-
-
--- DEFAULT (SPAWN) PHYSICS VALUE/SKYBOX
-
-local reset_player_physics = function(player)
- if player then
- player:set_physics_override({speed=1,jump=1,gravity=1}) -- value set for extreme test space spawn
- local skybox = enviro.skyboxes["default"]; -- default skybox is "default"
- player:set_sky(0,skybox["type"],skybox["tex"]);
- end
-end
-
--- globally available function
-enviro_adjust_physics = function(player) -- adjust players physics/skybox 1 second after various events
- minetest.after(1, function()
- if player then
- local pos = player:getpos(); if not pos then return end
- if pos.y > space_start then -- is player in space or not?
- player:set_physics_override({speed=1,jump=0.5,gravity=0.1}) -- value set for extreme test space spawn
- local skybox = enviro.skyboxes["space"];
- player:set_sky(0,skybox["type"],skybox["tex"]);
- else
- player:set_physics_override({speed=1,jump=1,gravity=1}) -- value set for extreme test space spawn
- local skybox = enviro.skyboxes["default"];
- player:set_sky(0,skybox["type"],skybox["tex"]);
- end
- end
- end)
-end
-
-
--- restore default values/skybox on respawn of player
-minetest.register_on_respawnplayer(reset_player_physics)
-
--- when player joins, check where he is and adjust settings
-minetest.register_on_joinplayer(enviro_adjust_physics)
-
-
--- SERVER GLOBAL SPACE CODE: uncomment to enable it
-
-local round = math.floor;
-local protector_position = function(pos)
- local r = 20;
- local ry = 2*r;
- return {x=round(pos.x/r+0.5)*r,y=round(pos.y/ry+0.5)*ry,z=round(pos.z/r+0.5)*r};
-end
-
-local stimer = 0
-local enviro_space = {};
-minetest.register_globalstep(function(dtime)
- stimer = stimer + dtime;
- if stimer >= 5 then
- stimer = 0;
- local players = minetest.get_connected_players();
- for _,player in pairs(players) do
- local name = player:get_player_name();
- local pos = player:getpos();
- local inspace=0; if pos.y>space_start then inspace = 1 end
- local inspace0=enviro_space[name];
- if inspace~=inspace0 then -- only adjust player enviroment ONLY if change occured ( earth->space or space->earth !)
- enviro_space[name] = inspace;
- enviro_adjust_physics(player);
- end
-
- if ENABLE_SPACE_EFFECTS and inspace==1 then -- special space code
-
-
- if pos.y<1500 and pos.y>1120 then
- local hp = player:get_hp();
-
- if hp>0 then
- minetest.chat_send_player(name,"WARNING: you entered DEADLY RADIATION ZONE");
- local privs = minetest.get_player_privs(name)
- if not privs.kick then player:set_hp(hp-15) end
- end
- return
- else
-
- local ppos = protector_position(pos);
- local populated = (minetest.get_node(ppos).name=="basic_protect:protector");
- if populated then
- if minetest.get_meta(ppos):get_int("space") == 1 then populated = false end
- end
-
- if not populated then -- do damage if player found not close to protectors
- local hp = player:get_hp();
- local privs = minetest.get_player_privs(name);
- if hp>0 and not privs.kick then
- player:set_hp(hp-10); -- dead in 20/10 = 2 events
- minetest.chat_send_player(name,"WARNING: in space you must stay close to spawn or protected areas");
- end
- end
- end
-
- end
- end
- end
-end)
-
--- END OF SPACE CODE
-
-
--- AIR EXPERIMENT
--- minetest.register_node("basic_machines:air", {
- -- description = "enables breathing in space",
- -- drawtype = "liquid",
- -- tiles = {"default_water_source_animated.png"},
-
- -- drawtype = "glasslike",
- -- paramtype = "light",
- -- alpha = 150,
- -- sunlight_propagates = true, -- Sunlight shines through
- -- walkable = false, -- Would make the player collide with the air node
- -- pointable = false, -- You can't select the node
- -- diggable = false, -- You can't dig the node
- -- buildable_to = true,
- -- drop = "",
- -- groups = {not_in_creative_inventory=1},
- -- after_place_node = function(pos, placer, itemstack, pointed_thing)
- -- local r = 3;
- -- for i = -r,r do
- -- for j = -r,r do
- -- for k = -r,r do
- -- local p = {x=pos.x+i,y=pos.y+j,z=pos.z+k};
- -- if minetest.get_node(p).name == "air" then
- -- minetest.set_node(p,{name = "basic_machines:air"})
- -- end
- -- end
- -- end
- -- end
- -- end
-
--- })
-
--- minetest.register_abm({
- -- nodenames = {"basic_machines:air"},
- -- neighbors = {"air"},
- -- interval = 10,
- -- chance = 1,
- -- action = function(pos, node, active_object_count, active_object_count_wider)
- -- minetest.set_node(pos,{name = "air"})
- -- end
- -- });
-
-
-minetest.register_on_punchplayer( -- bring gravity closer to normal with each punch
- function(player, hitter, time_from_last_punch, tool_capabilities, dir, damage)
-
- if player:get_physics_override() == nil then return end
- local pos = player:getpos(); if pos.y>= space_start then return end
-
- local gravity = player:get_physics_override().gravity;
- if gravity<1 then
- gravity = 1;
- player:set_physics_override({gravity=gravity})
- end
- end
-
-)
-
-
-
--- RECIPE: extremely expensive
-
--- minetest.register_craft({
- -- output = "basic_machines:enviro",
- -- recipe = {
- -- {"basic_machines:generator", "basic_machines:clockgen","basic_machines:generator"},
- -- {"basic_machines:generator", "basic_machines:generator","basic_machines:generator"},
- -- {"basic_machines:generator", "basic_machines:generator", "basic_machines:generator"}
- -- }
--- })
\ No newline at end of file
diff --git a/basic_machines/grinder.lua b/basic_machines/grinder.lua
deleted file mode 100644
index e8defa8..0000000
--- a/basic_machines/grinder.lua
+++ /dev/null
@@ -1,354 +0,0 @@
---todo: when grinding multiple items compare battery maxpower with number of items and attempt to grind as much as possible
-
--- rnd 2016:
-
--- this node works as technic grinder
--- There is a certain fuel cost to operate
-
--- recipe list: [in] ={fuel cost, out, quantity of material required for processing}
-basic_machines.grinder_recipes = {
- ["default:stone"] = {2,"default:sand",1},
- ["default:desert_stone"] = {2,"default:desert_sand 4",1},
- ["default:cobble"] = {1,"default:gravel",1},
- ["default:gravel"] = {0.5,"default:dirt",1},
- ["default:dirt"] = {0.5,"default:clay_lump 4",1},
- ["es:aikerum_crystal"] ={16,"es:aikerum_dust 2",1}, -- added for es mod
- ["es:ruby_crystal"] = {16,"es:ruby_dust 2",1},
- ["es:emerald_crystal"] = {16,"es:emerald_dust 2",1},
- ["es:purpellium_lump"] = {16,"es:purpellium_dust 2",1},
- ["default:obsidian_shard"] = {199,"default:lava_source",1},
- ["gloopblocks:basalt"] = {1, "default:cobble",1}, -- enable coble farms with gloopblocks mod
- ["default:ice"] = {1, "default:snow 4",1},
- ["darkage:silt_lump"]={1,"darkage:chalk_powder",1},
-};
-
--- es gems dust cooking
-local es_gems = function()
- local es_gems = {
- {name = "emerald", cooktime = 1200},{name = "ruby", cooktime = 1500},{name = "purpellium", cooktime = 1800},
- {name = "aikerum", cooktime = 2000}}
-
- for _,v in pairs(es_gems) do
- minetest.register_craft({
- type = "cooking",
- recipe = "es:"..v.name.."_dust",
- output = "es:"..v.name .."_crystal",
- cooktime = v.cooktime
- })
- end
-end
-minetest.after(0,es_gems);
-
-
-local grinder_process = function(pos)
-
- local node = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name;
- local meta = minetest.get_meta(pos);local inv = meta:get_inventory();
-
-
- -- PROCESS: check out inserted items
- local stack = inv:get_stack("src",1);
- if stack:is_empty() then return end; -- nothing to do
-
- local src_item = stack:to_string();
- local p=string.find(src_item," "); if p then src_item = string.sub(src_item,1,p-1) else p = 0 end -- take first word to determine what item was
-
- local def = basic_machines.grinder_recipes[src_item];
- if not def then
- meta:set_string("infotext", "please insert valid materials"); return
- end-- unknown node
-
- if stack:get_count()< def[3] then
- meta:set_string("infotext", "Recipe requires at least " .. def[3] .. " " .. src_item);
- return
- end
-
-
-
- -- FUEL CHECK
- local fuel = meta:get_float("fuel");
-
-
- if fuel-def[1]<0 then -- we need new fuel, check chest below
- local fuellist = inv:get_list("fuel")
- if not fuellist then return end
-
- local fueladd, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
-
- local supply=0;
- if fueladd.time == 0 then -- no fuel inserted, try look for outlet
- -- No valid fuel in fuel list
- supply = basic_machines.check_power({x=pos.x,y=pos.y-1,z=pos.z} , def[1]) or 0; -- tweaked so 1 coal = 1 energy
- if supply>0 then
- fueladd.time = supply -- same as 10 coal
- else
- meta:set_string("infotext", "Please insert fuel");
- return;
- end
- else
- if supply==0 then -- Take fuel from fuel list if no supply available
- inv:set_stack("fuel",1,afterfuel.items[1])
- fueladd.time=fueladd.time*0.1/4 -- thats 1 for coal
- --minetest.chat_send_all("FUEL ADD TIME " .. fueladd.time)
- end
- end
- if fueladd.time>0 then
- fuel=fuel + fueladd.time
- meta:set_float("fuel",fuel);
- meta:set_string("infotext", "added fuel furnace burn time " .. fueladd.time .. ", fuel status " .. fuel);
- end
- if fuel-def[1]<0 then
- meta:set_string("infotext", "need at least " .. def[1]-fuel .. " fuel to complete operation "); return
- end
-
- end
-
-
-
- -- process items
-
- -- TO DO: check if there is room for item yyy
- local addstack = ItemStack(def[2]);
- if inv:room_for_item("dst", addstack) then
- inv:add_item("dst",addstack);
- else return
- end
-
- --take 1 item from src inventory for each activation
- stack=stack:take_item(1); inv:remove_item("src", stack)
-
- minetest.sound_play("grinder", {pos=pos,gain=0.5,max_hear_distance = 16,})
-
- fuel = fuel-def[1]; -- burn fuel
- meta:set_float("fuel",fuel);
- meta:set_string("infotext", "fuel " .. fuel);
-
-end
-
-
-local grinder_update_meta = function(pos)
- local meta = minetest.get_meta(pos);
- local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
- local form =
- "size[8,8]".. -- width, height
- --"size[6,10]".. -- width, height
- "label[0,0;IN] label[1,0;OUT] label[0,2;FUEL] "..
- "list["..list_name..";src;0.,0.5;1,1;]"..
- "list["..list_name..";dst;1.,0.5;3,3;]"..
- "list["..list_name..";fuel;0.,2.5;1,1;]"..
- "list[current_player;main;0,4;8,4;]"..
- "button[6.5,0.5;1,1;OK;OK]"..
- "button[6.5,1.5;1,1;help;help]"..
- "listring["..list_name..";dst]"..
- "listring[current_player;main]"..
- "listring["..list_name..";src]"..
- "listring[current_player;main]"..
- "listring["..list_name..";fuel]"..
- "listring[current_player;main]"
- meta:set_string("formspec", form)
-end
-
-minetest.register_node("basic_machines:grinder", {
- description = "Grinder",
- tiles = {"grinder.png"},
- groups = {cracky=3, mesecon_effector_on = 1},
- sounds = default.node_sound_wood_defaults(),
- after_place_node = function(pos, placer)
- local meta = minetest.get_meta(pos);
- meta:set_string("infotext", "Grinder: To operate it insert fuel, then insert item to grind or use keypad to activate it.")
- meta:set_string("owner", placer:get_player_name());
- meta:set_float("fuel",0);
- local inv = meta:get_inventory();inv:set_size("src", 1);inv:set_size("dst",9);inv:set_size("fuel",1);
- end,
-
- on_rightclick = function(pos, node, player, itemstack, pointed_thing)
- local meta = minetest.get_meta(pos);
- local privs = minetest.get_player_privs(player:get_player_name());
- if minetest.is_protected(pos, player:get_player_name()) and not privs.privs then return end -- only owner can interact with recycler
- grinder_update_meta(pos);
- end,
-
- allow_metadata_inventory_put = function(pos, listname, index, stack, player)
- local meta = minetest.get_meta(pos);
- local privs = minetest.get_player_privs(player:get_player_name());
- if meta:get_string("owner")~=player:get_player_name() and not privs.privs then return 0 end
- return stack:get_count();
- end,
-
- allow_metadata_inventory_take = function(pos, listname, index, stack, player)
- local meta = minetest.get_meta(pos);
- local privs = minetest.get_player_privs(player:get_player_name());
- if meta:get_string("owner")~=player:get_player_name() and not privs.privs then return 0 end
- return stack:get_count();
- end,
-
- on_metadata_inventory_put = function(pos, listname, index, stack, player)
- if listname =="dst" then return end
- grinder_process(pos);
- end,
-
- allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
- return 0;
- end,
-
- mesecons = {effector = {
- action_on = function (pos, node,ttl)
- if type(ttl)~="number" then ttl = 1 end
- if ttl<0 then return end -- machines_TTL prevents infinite recursion
- grinder_process(pos);
- end
- }
- },
-
- on_receive_fields = function(pos, formname, fields, sender)
- if fields.quit then return end
- local meta = minetest.get_meta(pos);
-
- if fields.help then
- --recipe list: [in] ={fuel cost, out, quantity of material required for processing}
- --basic_machines.grinder_recipes
- local text = "RECIPES\n\n";
- for key,v in pairs(basic_machines.grinder_recipes) do
- text = text .. "INPUT ".. key .. " " .. v[3] .. " OUTPUT " .. v[2] .. "\n"
- end
-
- local form = "size [6,7] textarea[0,0;6.5,8.5;grinderhelp;GRINDER RECIPES;".. text.."]"
- minetest.show_formspec(sender:get_player_name(), "grinderhelp", form)
-
- end
- grinder_update_meta(pos);
- end,
-
-})
-
-
--- minetest.register_craft({
- -- output = "basic_machines:grinder",
- -- recipe = {
- -- {"default:diamond","default:mese","default:diamond"},
- -- {"default:mese","default:diamondblock","default:mese"},
- -- {"default:diamond","default:mese","default:diamond"},
-
- -- }
--- })
-
-
-
-
--- REGISTER DUSTS
-
-
-local function register_dust(name,input_node_name,ingot,grindcost,cooktime,R,G,B)
-
- if not R then R = "FF" end
- if not G then G = "FF" end
- if not B then B = "FF" end
-
- local purity_table = {"33","66"};
-
- for i = 1,#purity_table do
- local purity = purity_table[i];
- minetest.register_craftitem("basic_machines:"..name.."_dust_".. purity, {
- description = name.. " dust purity " .. purity .. "%" ,
- inventory_image = "basic_machines_dust.png^[colorize:#"..R..G..B..":180",
- })
- end
-
- basic_machines.grinder_recipes[input_node_name] = {grindcost,"basic_machines:"..name.."_dust_".. purity_table[1].." 2",1} -- register grinder recipe
-
- if ingot~="" then
-
- for i = 1,#purity_table-1 do
- minetest.register_craft({
- type = "cooking",
- recipe = "basic_machines:"..name.."_dust_".. purity_table[i],
- output = "basic_machines:"..name.."_dust_".. purity_table[i+1],
- cooktime = cooktime
- })
- end
-
- minetest.register_craft({
- type = "cooking",
- recipe = "basic_machines:"..name.."_dust_".. purity_table[#purity_table],
- groups = {not_in_creative_inventory=1},
- output = ingot,
- cooktime = cooktime
- })
-
- end
-end
-
-
-register_dust("iron","default:iron_lump","default:steel_ingot",4,8,"99","99","99")
-register_dust("copper","default:copper_lump","default:copper_ingot",4,8,"C8","80","0D") --c8800d
-register_dust("tin","default:tin_lump","default:tin_ingot",4,8,"9F","9F","9F")
-register_dust("gold","default:gold_lump","default:gold_ingot",6,25,"FF","FF","00")
-
--- grinding ingots gives dust too
-basic_machines.grinder_recipes["default:steel_ingot"] = {4,"basic_machines:iron_dust_33 2",1};
-basic_machines.grinder_recipes["default:copper_ingot"] = {4,"basic_machines:copper_dust_33 2",1};
-basic_machines.grinder_recipes["default:gold_ingot"] = {6,"basic_machines:gold_dust_33 2",1};
-basic_machines.grinder_recipes["default:tin_ingot"] = {4,"basic_machines:tin_dust_33 2",1};
-
--- are moreores (tin, silver, mithril) present?
-
-local table = minetest.registered_items["moreores:tin_lump"]; if table then
- --register_dust("tin","moreores:tin_lump","moreores:tin_ingot",4,8,"FF","FF","FF")
- register_dust("silver","moreores:silver_lump","moreores:silver_ingot",5,15,"BB","BB","BB")
- register_dust("mithril","moreores:mithril_lump","moreores:mithril_ingot",16,750,"00","00","FF")
-
- basic_machines.grinder_recipes["moreores:tin_ingot"] = {4,"basic_machines:tin_dust_33 2",1};
- basic_machines.grinder_recipes["moreores:silver_ingot"] = {5,"basic_machines:silver_dust_33 2",1};
- basic_machines.grinder_recipes["moreores:mithril_ingot"] = {16,"basic_machines:mithril_dust_33 2",1};
-end
-
-
-register_dust("mese","default:mese_crystal","default:mese_crystal",8,250,"CC","CC","00")
-register_dust("diamond","default:diamond","default:diamond",16,500,"00","EE","FF") -- 0.3hr cooking time to make diamond!
-
--- darkage recipes and ice
-minetest.register_craft({
- type = "cooking",
- recipe = "default:ice",
- output = "default:water_flowing",
- cooktime = 4
-})
-
-minetest.register_craft({
- type = "cooking",
- recipe = "default:stone",
- output = "darkage:basalt",
- cooktime = 60
-})
-
-minetest.register_craft({
- type = "cooking",
- recipe = "darkage:slate",
- output = "darkage:schist",
- cooktime = 20
-})
-
--- dark age recipe: cook schist to get gneiss
-
-minetest.register_craft({
- type = "cooking",
- recipe = "darkage:gneiss",
- output = "darkage:marble",
- cooktime = 20
-})
-
-
-
-minetest.register_craft({
- output = "darkage:serpentine",
- recipe = {
- {"darkage:marble","default:cactus"}
- }
-})
-
-minetest.register_craft({
- output = "darkage:mud",
- recipe = {
- {"default:dirt","default:water_flowing"}
- }
-})
\ No newline at end of file
diff --git a/basic_machines/init.lua b/basic_machines/init.lua
deleted file mode 100644
index edad2dd..0000000
--- a/basic_machines/init.lua
+++ /dev/null
@@ -1,90 +0,0 @@
--- BASIC_MACHINES: lightweight automation mod for minetest
--- minetest 0.4.14
--- (c) 2015-2016 rnd
-
--- 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 .
-
-
-basic_machines = {};
-
-
-dofile(minetest.get_modpath("basic_machines").."/mark.lua") -- used for markings, borrowed and adapted from worldedit mod
-dofile(minetest.get_modpath("basic_machines").."/mover.lua") -- mover, detector, keypad, distributor
-dofile(minetest.get_modpath("basic_machines").."/technic_power.lua") -- technic power for mover
-dofile(minetest.get_modpath("basic_machines").."/recycler.lua") -- recycle old used tools
-dofile(minetest.get_modpath("basic_machines").."/grinder.lua") -- grind materials into dusts
-dofile(minetest.get_modpath("basic_machines").."/autocrafter.lua") -- borrowed and adapted from pipeworks mod
-dofile(minetest.get_modpath("basic_machines").."/constructor.lua") -- enable crafting of all machines
-
-dofile(minetest.get_modpath("basic_machines").."/protect.lua") -- enable interaction with players, adds local on protect/chat event handling
-
--- OPTIONAL ADDITIONAL STUFF ( comment to disable )
-
-dofile(minetest.get_modpath("basic_machines").."/ball.lua") -- interactive flying ball, can activate blocks or be used as a weapon
-dofile(minetest.get_modpath("basic_machines").."/enviro.lua") -- enviro blocks that can change surrounding enviroment physics, uncomment spawn/join code to change global physics, disabled by default
-minetest.after(0, function()
- dofile(minetest.get_modpath("basic_machines").."/mesecon_doors.lua") -- if you want open/close doors with signal, also steel doors are made impervious to dig through, removal by repeat punch
- dofile(minetest.get_modpath("basic_machines").."/mesecon_lights.lua") -- adds ability for other light blocks to toggle light
-end)
-
-
--- MACHINE PRIVILEGE
-minetest.register_privilege("machines", {
- description = "Player is expert basic_machine user: his machines work while not present on server, can spawn more than 2 balls at once",
-})
-
--- machines fuel related recipes
--- CHARCOAL
-
-minetest.register_craftitem("basic_machines:charcoal", {
- description = "Wood charcoal",
- inventory_image = "charcoal.png",
-})
-
-
-minetest.register_craft({
- type = 'cooking',
- recipe = "default:tree",
- cooktime = 30,
- output = "basic_machines:charcoal",
-})
-
-minetest.register_craft({
- output = "default:coal_lump",
- recipe = {
- {"basic_machines:charcoal"},
- {"basic_machines:charcoal"},
- }
-})
-
-minetest.register_craft({
- type = "fuel",
- recipe = "basic_machines:charcoal",
- -- note: to make it you need to use 1 tree block for fuel + 1 tree block, thats 2, caloric value 2*30=60
- burntime = 40, -- coal lump has 40, tree block 30, coal block 370 (9*40=360!)
-})
-
--- add since minetest doesnt have moreores tin ingot recipe
-minetest.register_craft({
- output = "default:tin_ingot",
- recipe = {
- {"moreores:tin_ingot"},
- }
-})
-
--- COMPATIBILITY
-minetest.register_alias("basic_machines:battery", "basic_machines:battery_0")
-
-
-print("[MOD] basic_machines " .. basic_machines.version .. " loaded.")
\ No newline at end of file
diff --git a/basic_machines/mark.lua b/basic_machines/mark.lua
deleted file mode 100644
index 9b55cf6..0000000
--- a/basic_machines/mark.lua
+++ /dev/null
@@ -1,154 +0,0 @@
--- rnd: code borrowed from machines, mark.lua
-
--- need for marking
-machines = {};
-
-machines.pos1 = {};machines.pos11 = {}; machines.pos2 = {};
-machines.marker1 = {}
-machines.marker11 = {}
-machines.marker2 = {}
-machines.marker_region = {}
-
-
---marks machines region position 1
-machines.mark_pos1 = function(name)
- local pos1, pos2 = machines.pos1[name], machines.pos2[name]
-
- if pos1 ~= nil then
- --make area stay loaded
- local manip = minetest.get_voxel_manip()
- manip:read_from_map(pos1, pos1)
- end
-
- if not machines[name] then machines[name]={} end
- machines[name].timer = 10;
- if machines.marker1[name] ~= nil then --marker already exists
- machines.marker1[name]:remove() --remove marker
- machines.marker1[name] = nil
- end
- if pos1 ~= nil then
- --add marker
- machines.marker1[name] = minetest.add_entity(pos1, "machines:pos1")
- if machines.marker1[name] ~= nil then
- machines.marker1[name]:get_luaentity().name = name
- end
- end
-end
-
---marks machines region position 1
-machines.mark_pos11 = function(name)
- local pos11 = machines.pos11[name];
-
- if pos11 ~= nil then
- --make area stay loaded
- local manip = minetest.get_voxel_manip()
- manip:read_from_map(pos11, pos11)
- end
-
- if not machines[name] then machines[name]={} end
- machines[name].timer = 10;
- if machines.marker11[name] ~= nil then --marker already exists
- machines.marker11[name]:remove() --remove marker
- machines.marker11[name] = nil
- end
- if pos11 ~= nil then
- --add marker
- machines.marker11[name] = minetest.add_entity(pos11, "machines:pos11")
- if machines.marker11[name] ~= nil then
- machines.marker11[name]:get_luaentity().name = name
- end
- end
-end
-
---marks machines region position 2
-machines.mark_pos2 = function(name)
- local pos1, pos2 = machines.pos1[name], machines.pos2[name]
-
- if pos2 ~= nil then
- --make area stay loaded
- local manip = minetest.get_voxel_manip()
- manip:read_from_map(pos2, pos2)
- end
-
- if not machines[name] then machines[name]={} end
- machines[name].timer = 10;
- if machines.marker2[name] ~= nil then --marker already exists
- machines.marker2[name]:remove() --remove marker
- machines.marker2[name] = nil
- end
- if pos2 ~= nil then
- --add marker
- machines.marker2[name] = minetest.add_entity(pos2, "machines:pos2")
- if machines.marker2[name] ~= nil then
- machines.marker2[name]:get_luaentity().name = name
- end
- end
-end
-
-
-
-minetest.register_entity(":machines:pos1", {
- initial_properties = {
- visual = "cube",
- visual_size = {x=1.1, y=1.1},
- textures = {"machines_pos1.png", "machines_pos1.png",
- "machines_pos1.png", "machines_pos1.png",
- "machines_pos1.png", "machines_pos1.png"},
- collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
- physical = false,
- },
- on_step = function(self, dtime)
- if not machines[self.name] then machines[self.name]={}; machines[self.name].timer = 10 end
- machines[self.name].timer = machines[self.name].timer - dtime
- if machines[self.name].timer<=0 or machines.marker1[self.name] == nil then
- self.object:remove()
- end
- end,
- on_punch = function(self, hitter)
- self.object:remove()
- machines.marker1[self.name] = nil
- machines[self.name].timer = 10
- end,
-})
-
-minetest.register_entity(":machines:pos11", {
- initial_properties = {
- visual = "cube",
- visual_size = {x=1.1, y=1.1},
- textures = {"machines_pos11.png", "machines_pos11.png",
- "machines_pos11.png", "machines_pos11.png",
- "machines_pos11.png", "machines_pos11.png"},
- collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
- physical = false,
- },
- on_step = function(self, dtime)
- if not machines[self.name] then machines[self.name]={}; machines[self.name].timer = 10 end
- machines[self.name].timer = machines[self.name].timer - dtime
- if machines[self.name].timer<=0 or machines.marker11[self.name] == nil then
- self.object:remove()
- end
- end,
- on_punch = function(self, hitter)
- self.object:remove()
- machines.marker11[self.name] = nil
- machines[self.name].timer = 10
- end,
-})
-
-minetest.register_entity(":machines:pos2", {
- initial_properties = {
- visual = "cube",
- visual_size = {x=1.1, y=1.1},
- textures = {"machines_pos2.png", "machines_pos2.png",
- "machines_pos2.png", "machines_pos2.png",
- "machines_pos2.png", "machines_pos2.png"},
- collisionbox = {-0.55, -0.55, -0.55, 0.55, 0.55, 0.55},
- physical = false,
- },
- on_step = function(self, dtime)
- if not machines[self.name] then machines[self.name]={}; machines[self.name].timer = 10 end
- if machines[self.name].timer<=0 or machines.marker2[self.name] == nil then
- self.object:remove()
- end
- end,
-})
diff --git a/basic_machines/mesecon_doors.lua b/basic_machines/mesecon_doors.lua
deleted file mode 100644
index 1db08cb..0000000
--- a/basic_machines/mesecon_doors.lua
+++ /dev/null
@@ -1,102 +0,0 @@
--- make doors open/close with signal
-local function door_signal_overwrite(name)
- local table = minetest.registered_nodes[name]; if not table then return end
- local table2 = {}
- for i,v in pairs(table) do table2[i] = v end
-
- -- 0.4.15: line 370 in doors defines thins
- local door_on_rightclick = table2.on_rightclick;
-
- -- this will make door toggle whenever its used
- table2.mesecons = {effector = {
- action_on = function (pos,node)
- local meta = minetest.get_meta(pos);local name = meta:get_string("owner");
- -- create virtual player
- local clicker = {};
- function clicker:get_wielded_item()
- local item = {}
- function item:get_name() return "" end
- return item
- end
- function clicker:get_player_name() return name end; -- define method get_player_name() returning owner name so that we can call on_rightclick function in door
- function clicker:is_player() return false end; -- method needed for mods that check this: like denaid areas mod
- if door_on_rightclick then door_on_rightclick(pos, nil, clicker,ItemStack(""),{}) end -- safety if it doesnt exist
- --minetest.swap_node(pos, {name = "protector:trapdoor", param1 = node.param1, param2 = node.param2}) -- more direct approach?, need to set param2 then too
- end
- }
- };
-
- minetest.register_node(":"..name, table2)
-end
-
-minetest.after(0,function()
- door_signal_overwrite("doors:door_wood");door_signal_overwrite("doors:door_steel")
- door_signal_overwrite("doors:door_wood_a");door_signal_overwrite("doors:door_wood_b");
- door_signal_overwrite("doors:door_steel_a");door_signal_overwrite("doors:door_steel_b");
- door_signal_overwrite("doors:door_glass_a");door_signal_overwrite("doors:door_glass_b");
- door_signal_overwrite("doors:door_obsidian_glass_a");door_signal_overwrite("doors:door_obsidian_glass_b");
-
- door_signal_overwrite("doors:trapdoor");door_signal_overwrite("doors:trapdoor_open");
- door_signal_overwrite("doors:trapdoor_steel");door_signal_overwrite("doors:trapdoor_steel_open");
-
- end
-);
-
-local function make_it_noclip(name)
-
- local table = minetest.registered_nodes[name]; if not table then return end
- local table2 = {}
- for i,v in pairs(table) do
- table2[i] = v
- end
- table2.walkable = false; -- cant be walked on
- minetest.register_node(":"..name, table2)
-end
-
-minetest.after(0,function()
- make_it_noclip("doors:trapdoor_open");
- make_it_noclip("doors:trapdoor_steel_open");
-end);
-
-
-
-local function make_it_nondiggable_but_removable(name, dropname)
-
- local table = minetest.registered_nodes[name]; if not table then return end
- local table2 = {}
- for i,v in pairs(table) do
- table2[i] = v
- end
- table2.groups.level = 99; -- cant be digged, but it can be removed by owner or if not protected
- table2.on_punch = function(pos, node, puncher, pointed_thing) -- remove node if owner repeatedly punches it 3x
- local pname = puncher:get_player_name();
- local meta = minetest.get_meta(pos);
- local owner = meta:get_string("doors_owner")
- if pname==owner or not minetest.is_protected(pos,pname) then -- can be dug by owner or if unprotected
- local t0 = meta:get_int("punchtime");local count = meta:get_int("punchcount");
- local t = minetest.get_gametime();
-
- if t-t0<2 then count = (count +1 ) % 3 else count = 0 end
-
- if count == 1 then
- minetest.chat_send_player(pname, "#steel door: punch me one more time to remove me");
- end
- if count == 2 then -- remove steel door and drop it
- minetest.set_node(pos, {name = "air"});
- local stack = ItemStack(dropname);minetest.add_item(pos,stack)
- end
-
- meta:set_int("punchcount",count);meta:set_int("punchtime",t);
- --minetest.chat_send_all("punch by "..name .. " count " .. count)
- end
- end
- minetest.register_node(":"..name, table2)
-end
-
-minetest.after(0,function()
- make_it_nondiggable_but_removable("doors:door_steel_a","doors:door_steel");
- make_it_nondiggable_but_removable("doors:door_steel_b","doors:door_steel");
-
- make_it_nondiggable_but_removable("doors:trapdoor_steel","doors:trapdoor_steel");
- make_it_nondiggable_but_removable("doors:trapdoor_steel_open","doors:trapdoor_steel");
-end);
\ No newline at end of file
diff --git a/basic_machines/mesecon_lights.lua b/basic_machines/mesecon_lights.lua
deleted file mode 100644
index de5445d..0000000
--- a/basic_machines/mesecon_lights.lua
+++ /dev/null
@@ -1,50 +0,0 @@
--- make other light blocks work with mesecon signals - can toggle on/off
-
-local function enable_toggle_light(name)
-
-local table = minetest.registered_nodes[name]; if not table then return end
- local table2 = {}
- for i,v in pairs(table) do
- table2[i] = v
- end
-
- if table2.mesecons then return end -- we dont want to overwrite existing stuff!
-
- local offname = "basic_machines:"..string.gsub(name, ":", "_").. "_OFF";
-
- table2.mesecons = {effector = { -- action to toggle light off
- action_off = function (pos,node,ttl)
- minetest.swap_node(pos,{name = offname});
- end
- }
- };
- minetest.register_node(":"..name, table2) -- redefine item
-
- -- STRANGE BUG1: if you dont make new table table3 and reuse table2 definition original node (definition one line above) is changed by below code too!???
- -- STRANGE BUG2: if you dont make new table3.. original node automatically changes to OFF node when placed ????
-
- local table3 = {}
- for i,v in pairs(table) do
- table3[i] = v
- end
-
- table3.light_source = 0; -- off block has light off
- table3.mesecons = {effector = {
- action_on = function (pos,node,ttl)
- minetest.swap_node(pos,{name = name});
- end
- }
- };
-
- -- REGISTER OFF BLOCK
- minetest.register_node(":"..offname, table3);
-
-end
-
-
-enable_toggle_light("xdecor:wooden_lightbox");
-enable_toggle_light("xdecor:iron_lightbox");
-enable_toggle_light("moreblocks:slab_meselamp_1");
-enable_toggle_light("moreblocks:slab_super_glow_glass");
-
-enable_toggle_light("darkage:lamp");
\ No newline at end of file
diff --git a/basic_machines/mover.lua b/basic_machines/mover.lua
deleted file mode 100644
index 148c1c7..0000000
--- a/basic_machines/mover.lua
+++ /dev/null
@@ -1,2518 +0,0 @@
-------------------------------------------------------------------------------------------------------------------------------------
--- BASIC MACHINES MOD by rnd
--- mod with basic simple automatization for minetest. No background processing, just one abm with 5s timer (clock generator), no other lag causing background processing.
-------------------------------------------------------------------------------------------------------------------------------------
-
-
-
--- *** SETTINGS *** --
-local machines_timer = 5 -- main timestep
-local machines_minstep = 1 -- minimal allowed activation timestep, if faster machines overheat
-local max_range = 10; -- machines normal range of operation
-local machines_operations = 10; -- 1 coal will provide 10 mover basic operations ( moving dirt 1 block distance)
-local machines_TTL = 16; -- time to live for signals, how many hops before signal dissipates
-basic_machines.version = "05/23/2018a";
-basic_machines.clockgen = 1; -- if 0 all background continuously running activity (clockgen/keypad) repeating is disabled
-
--- how hard it is to move blocks, default factor 1, note fuel cost is this multiplied by distance and divided by machine_operations..
-basic_machines.hardness = {
-["default:stone"]=4,["default:tree"]=2,["default:jungletree"]=2,["default:pine_tree"]=2,["default:aspen_tree"]=2,["default:acacia_tree"]=2,
-["default:lava_source"]=5950,["default:water_source"]=5950,["default:obsidian"]=20,["bedrock2:bedrock"]=999999};
---move machines for free
-basic_machines.hardness["basic_machines:mover"]=0.;
-basic_machines.hardness["basic_machines:keypad"]=0.;
-basic_machines.hardness["basic_machines:distributor"]=0.;
-basic_machines.hardness["basic_machines:battery"]=0.;
-basic_machines.hardness["basic_machines:detector"]=0.;
-basic_machines.hardness["basic_machines:generator"]=0.;
-basic_machines.hardness["basic_machines:clockgen"]=0.;
-basic_machines.hardness["basic_machines:ball_spawner"]=0.;
-basic_machines.hardness["basic_machines:light_on"]=0.;
-basic_machines.hardness["basic_machines:light_off"]=0.;
-
--- grief potential items need highest possible upgrades
-basic_machines.hardness["boneworld:acid_source_active"]=5950.;
-basic_machines.hardness["darkage:mud"]=5950.;
-
-basic_machines.hardness["es:toxic_water_source"]=5950.;basic_machines.hardness["es:toxic_water_flowing"]=5950;
-basic_machines.hardness["default:river_water_source"]=5950.;
-
--- farming operations are much cheaper
-basic_machines.hardness["farming:wheat_8"]=1;basic_machines.hardness["farming:cotton_8"]=1;
-basic_machines.hardness["farming:seed_wheat"]=0.5;basic_machines.hardness["farming:seed_cotton"]=0.5;
-
--- digging mese crystals more expensive
-basic_machines.hardness["mese_crystals:mese_crystal_ore1"] = 10;
-basic_machines.hardness["mese_crystals:mese_crystal_ore2"] = 10;
-basic_machines.hardness["mese_crystals:mese_crystal_ore3"] = 10;
-basic_machines.hardness["mese_crystals:mese_crystal_ore4"] = 10;
-
-
--- define which nodes are dug up completely, like a tree
-basic_machines.dig_up_table = {["default:cactus"]=true,["default:tree"]=true,["default:jungletree"]=true,["default:pinetree"]=true,
-["default:acacia_tree"]=true,["default:papyrus"]=true};
-
--- set up nodes for harvest when digging: [nodename] = {what remains after harvest, harvest result}
-basic_machines.harvest_table = {
-["mese_crystals:mese_crystal_ore4"] = {"mese_crystals:mese_crystal_ore1", "default:mese_crystal 3"}, -- harvesting mese crystals
-["mese_crystals:mese_crystal_ore3"] = {"mese_crystals:mese_crystal_ore1", "default:mese_crystal 2"},
-["mese_crystals:mese_crystal_ore2"] = {"mese_crystals:mese_crystal_ore1", "default:mese_crystal 1"},
-["mese_crystals:mese_crystal_ore1"] = {"mese_crystals:mese_crystal_ore1", ""},
-};
-
--- set up nodes for plant with reverse on and filter set (for example seeds -> plant) : [nodename] = plant_name
-basic_machines.plant_table = {["farming:seed_barley"]="farming:barley_1",["farming:beans"]="farming:beanpole_1", -- so it works with farming redo mod
-["farming:blueberries"]="farming:blueberry_1",["farming:carrot"]="farming:carrot_1",["farming:cocoa_beans"]="farming:cocoa_1",
-["farming:coffee_beans"]="farming:coffee_1",["farming:corn"]="farming:corn_1",["farming:blueberries"]="farming:blueberry_1",
-["farming:seed_cotton"]="farming:cotton_1",["farming:cucumber"]="farming:cucumber_1",["farming:grapes"]="farming:grapes_1",
-["farming:melon_slice"]="farming:melon_1",["farming:potato"]="farming:potato_1",["farming:pumpkin_slice"]="farming:pumpkin_1",
-["farming:raspberries"]="farming:raspberry_1",["farming:rhubarb"]="farming:rhubarb_1",["farming:tomato"]="farming:tomato_1",
-["farming:seed_wheat"]="farming:wheat_1"}
-
--- list of objects that cant be teleported with mover
-basic_machines.no_teleport_table = {
-["itemframes:item"] = true,
-["signs:text"] = true
-}
-
--- list of nodes mover cant take from in inventory mode
-basic_machines.limit_inventory_table = { -- node name = {list of bad inventories to take from}
- ["basic_machines:autocrafter"]= {["recipe"]=1, ["output"]=1},
- ["basic_machines:constructor"]= {["recipe"]=1},
- ["basic_machines:battery"] = {["upgrade"] = 1},
- ["basic_machines:generator"] = {["upgrade"] = 1},
- ["basic_machines:mover"] = {["upgrade"] = 1},
- ["moreblocks:circular_saw"] = {["input"]=1,["recycle"]=1,["micro"]=1,["output"]=1},
-}
-
--- when activated with keypad these will be "punched" to update their text too
-basic_machines.signs = {
-["default:sign_wall_wood"] = true,
-["signs:sign_wall_green"] = true,
-["signs:sign_wall_green"] = true,
-["signs:sign_wall_yellow"] = true,
-["signs:sign_wall_red"] = true,
-["signs:sign_wall_red"] = true,
-["signs:sign_wall_white_black"] = true,
-["signs:sign_yard"] = true
-}
-
--- *** END OF SETTINGS *** --
-
-
-
-local punchset = {};
-
-minetest.register_on_joinplayer(function(player)
- local name = player:get_player_name(); if name == nil then return end
- punchset[name] = {};
- punchset[name].state = 0;
-end)
-
-local get_mover_form = function(pos,player)
-
- if not player then return end
- local meta = minetest.get_meta(pos);
- local x0,y0,z0,x1,y1,z1,x2,y2,z2,prefer,mode,mreverse;
-
- x0=meta:get_int("x0");y0=meta:get_int("y0");z0=meta:get_int("z0");x1=meta:get_int("x1");y1=meta:get_int("y1");z1=meta:get_int("z1");x2=meta:get_int("x2");y2=meta:get_int("y2");z2=meta:get_int("z2");
-
- machines.pos1[player:get_player_name()] = {x=pos.x+x0,y=pos.y+y0,z=pos.z+z0};machines.mark_pos1(player:get_player_name()) -- mark pos1
- machines.pos11[player:get_player_name()] = {x=pos.x+x1,y=pos.y+y1,z=pos.z+z1};machines.mark_pos11(player:get_player_name()) -- mark pos11
- machines.pos2[player:get_player_name()] = {x=pos.x+x2,y=pos.y+y2,z=pos.z+z2};machines.mark_pos2(player:get_player_name()) -- mark pos2
-
- prefer = meta:get_string("prefer");
- local mreverse = meta:get_int("reverse");
- local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
- local mode_list = {["normal"]=1,["dig"]=2, ["drop"]=3, ["object"]=4, ["inventory"]=5, ["transport"]=6};
-
- local mode_string = meta:get_string("mode") or "";
-
- local meta1 = minetest.get_meta({x=pos.x+x0,y=pos.y+y0,z=pos.z+z0}); -- source meta
- local meta2 = minetest.get_meta({x=pos.x+x2,y=pos.y+y2,z=pos.z+z2}); -- target meta
-
-
- local inv1=1; local inv2=1;
- local inv1m = meta:get_string("inv1");local inv2m = meta:get_string("inv2");
-
- local list1 = meta1:get_inventory():get_lists(); local inv_list1 = ""; local j;
- j=1; -- stupid dropdown requires item index but returns string on receive so we have to find index.. grrr, one other solution: invert the table: key <-> value
-
-
- for i in pairs( list1) do
- inv_list1 = inv_list1 .. i .. ",";
- if i == inv1m then inv1=j end; j=j+1;
- end
- local list2 = meta2:get_inventory():get_lists(); local inv_list2 = "";
- j=1;
- for i in pairs( list2) do
- inv_list2 = inv_list2 .. i .. ",";
- if i == inv2m then inv2=j; end; j=j+1;
- end
-
- local upgrade = meta:get_float("upgrade"); if upgrade>0 then upgrade = upgrade - 1 end
- local seltab = meta:get_int("seltab");
- local form;
-
- if seltab == 1 then -- MODE --
- local mode_description = {
- ["normal"] = "This will move blocks as they are - without change.",
- ["dig"] = "This will transform blocks as if player digged them.",
- ["drop"] = "This will take block/item out of chest (you need to set filter) and will drop it",
- ["object"] = "make TELEPORTER/ELEVATOR. This will move any object inside sphere (with center source1 and radius defined by source2) to target position. For ELEVATOR teleport points need to be placed exactly vertically in line with mover and you need to upgrade with 1 diamondblock for every 100 height difference. ",
- ["inventory"] = "This will move items from inventory of any block at source position to any inventory of block at target position",
- ["transport"] = "This will move all blocks at source area to new area starting at target position. This mode preserves all inventories and other metadata",
- };
-
- local text = mode_description[mode_string] or "description";
- local mode_list = {["normal"]=1,["dig"]=2, ["drop"]=3, ["object"]=4, ["inventory"]=5, ["transport"]=6};
- mode = mode_list[mode_string] or 1;
-
- form = "size[8,8.25]" .. -- width, height
- --"size[6,10]" .. -- width, height
- "tabheader[0,0;tabs;MODE OF OPERATION,WHERE TO MOVE;".. seltab .. ";true;true]"..
- "label[0.,0;MODE selection]".."button[3,0.25;1,1;help;help]"..
- "dropdown[0.,0.35;3,1;mode;normal,dig,drop,object,inventory,transport;".. mode .."]"..
- "textarea[0.25,1.25;8,2.;description;;".. text.."]"..
-
- "field[0.25,3.5;3,1;prefer;FILTER;"..prefer.."]"..
-
- "list[nodemeta:"..pos.x..','..pos.y..','..pos.z ..";filter;3,3.4;1,1;]"..
- "list[nodemeta:"..pos.x..','..pos.y..','..pos.z ..";upgrade;5,3.4;1,1;]".."label[4,3;UPGRADE LVL ".. upgrade .."]" ..
- "list[current_player;main;0,4.5;8,4;]"..
- "listring[nodemeta:"..pos.x..','..pos.y..','..pos.z ..";upgrade]"..
- "listring[current_player;main]"..
- "listring[nodemeta:"..pos.x..','..pos.y..','..pos.z ..";filter]"..
- "listring[current_player;main] button_exit[5,0.25;1,1;OK;OK]"
-
- else -- POSITIONS
-
- local inventory_list1,inventory_list2;
- if mode_string == "inventory" then
- inventory_list1 = "label[4.5,0.25;source inventory] dropdown[4.5,0.75;1.5,1;inv1;".. inv_list1 ..";" .. inv1 .."]"
- inventory_list2 = "label[4.5,3.;target inventory] dropdown[4.5,3.5;1.5,1;inv2;".. inv_list2 .. ";" .. inv2 .."]"
- else
- inventory_list1 = ""; inventory_list2 = ""
- end
-
-
- form = "size[6,5.5]" .. -- width, height
- --"size[6,10]" .. -- width, height
- "tabheader[0,0;tabs;MODE OF OPERATION,WHERE TO MOVE;".. seltab .. ";true;true]"..
-
- "label[0.,0;" .. minetest.colorize("lawngreen","INPUT AREA - mover will dig here").."]"..
- "field[0.25,1.;1,1;x0;source1;"..x0.."] field[1.25,1.;1,1;y0;;"..y0.."] field[2.25,1.;1,1;z0;;"..z0.."]"..
- "image[3,0.75;1,1;machines_pos1.png]"..
- inventory_list1..
- "field[0.25,2;1,1;x1;source2;"..x1.."] field[1.25,2;1,1;y1;;"..y1.."] field[2.25,2;1,1;z1;;"..z1.."]"..
- "image[3,1.75;1,1;machines_pos11.png]"..
-
- "label[0.,2.75;" .. minetest.colorize("red","TARGET POSITION - mover will move to here").."]"..
-
- "field[0.25,3.75;1,1;x2;Target;"..x2.."] field[1.25,3.75;1,1;y2;;"..y2.."] field[2.25,3.75;1,1;z2;;"..z2.."]"..
- "image[3,3.5;1,1;machines_pos2.png]"..
- inventory_list2 ..
- "label[0.,4.25;REVERSE source and target (0/1/2)]"..
- "field[0.25,5;1.,1;reverse;;"..mreverse.."]" ..
- "listring[current_player;main] button[4,4.75;1,1;help;help] button_exit[5,4.75;1,1;OK;OK]"
- end
-
- return form
-end
-
-
-local find_and_connect_battery = function(pos)
- local r = 1;
- for i = 0,2 do
- local positions = minetest.find_nodes_in_area( --find battery
- {x=pos.x-r, y=pos.y-r, z=pos.z-r},
- {x=pos.x+r, y=pos.y+r, z=pos.z+r},
- "basic_machines:battery_" .. i )
- if #positions>0 then
- local meta = minetest.get_meta(pos);
- local fpos = positions[1] ;
- meta:set_int("batx", fpos.x);meta:set_int("baty", fpos.y); meta:set_int("batz", fpos.z)
- return fpos
- end -- pick first battery we found
- end
- return nil
-end
-
-
--- MOVER --
-minetest.register_node("basic_machines:mover", {
- description = "Mover - universal digging/harvesting/teleporting/transporting machine, its upgradeable.",
- tiles = {"compass_top.png","default_furnace_top.png", "basic_machine_mover_side.png","basic_machine_mover_side.png","basic_machine_mover_side.png","basic_machine_mover_side.png"},
- groups = {cracky=3, mesecon_effector_on = 1},
- sounds = default.node_sound_wood_defaults(),
- after_place_node = function(pos, placer)
- local meta = minetest.env:get_meta(pos)
- meta:set_string("infotext", "Mover block. Set it up by punching or right click. Activate it by keypad signal.")
- meta:set_string("owner", placer:get_player_name()); meta:set_int("public",0);
- meta:set_int("x0",0);meta:set_int("y0",-1);meta:set_int("z0",0); -- source1
- meta:set_int("x1",0);meta:set_int("y1",-1);meta:set_int("z1",0); -- source2: defines cube
- meta:set_int("pc",0); meta:set_int("dim",1);-- current cube position and dimensions
- meta:set_int("pc",0); meta:set_int("dim",1);-- current cube position and dimensions
- meta:set_int("x2",0);meta:set_int("y2",1);meta:set_int("z2",0);
- meta:set_float("fuel",0)
- meta:set_string("prefer", "");
- meta:set_string("mode", "normal");
- meta:set_float("upgrade", 1);
- meta:set_int("seltab",1);
-
- local privs = minetest.get_player_privs(placer:get_player_name());
- if privs.privs then meta:set_float("upgrade", -1); end -- means operation will be for free
-
- local inv = meta:get_inventory();inv:set_size("upgrade", 1*1);inv:set_size("filter", 1*1)
- local name = placer:get_player_name(); punchset[name].state = 0
-
-
- local text = "This machine can move anything. General idea is the following : \n\n"..
- "First you need to define rectangle work area (where it takes, marked by two number 1 boxes that appear in world) and target area (where it puts, marked by one number 2 box) by punching mover then following CHAT instructions exactly.\n\n"..
- "CHECK why it doesnt work: 1. did you click OK in mover after changing setting 2. does it have battery, 3. does battery have enough fuel\n\n"..
- "IMPORTANT: Please read the help button inside machine before first use.";
-
- local form = "size [5.5,5.5] textarea[0,0;6,7;help;MOVER INTRODUCTION;".. text.."]"
- minetest.show_formspec(name, "basic_machines:intro_mover", form)
-
-
-
- end,
-
- can_dig = function(pos, player) -- dont dig if upgrades inside, cause they will be destroyed
- local meta = minetest.get_meta(pos);
- local inv = meta:get_inventory();
- return not(inv:contains_item("upgrade", ItemStack({name="default:mese"})));
- end,
-
-
- on_rightclick = function(pos, node, player, itemstack, pointed_thing)
- local privs = minetest.get_player_privs(player:get_player_name());
- local cant_build = minetest.is_protected(pos,player:get_player_name());
- if not privs.privs and cant_build then return end -- only ppl sharing protection can setup
-
- local form = get_mover_form(pos,player)
- minetest.show_formspec(player:get_player_name(), "basic_machines:mover_"..minetest.pos_to_string(pos), form)
- end,
-
- allow_metadata_inventory_put = function(pos, listname, index, stack, player)
- if listname == "filter" then
- local meta = minetest.get_meta(pos);
- local itemname = stack:get_name() or "";
- meta:set_string("prefer",itemname);
- --minetest.chat_send_player(player:get_player_name(),"#mover: filter set as " .. itemname)
- local form = get_mover_form(pos,player)
- minetest.show_formspec(player:get_player_name(), "basic_machines:mover_"..minetest.pos_to_string(pos), form)
- return 1;
- end
-
- if listname == "upgrade" then
- -- update upgrades
- local meta = minetest.get_meta(pos);
- local upgrade = 0;
- local inv = meta:get_inventory();
-
- local upgrade_name = "default:mese";
- if meta:get_int("elevator")==1 then upgrade_name = "default:diamondblock" end
- if stack:get_name() == upgrade_name then
- --inv:contains_item("upgrade", ItemStack({name="default:mese"})) then
- upgrade = (inv:get_stack("upgrade", 1):get_count()) or 0;
- upgrade = upgrade + stack:get_count();
- if upgrade > 10 then upgrade = 10 end -- not more than 10
- meta:set_float("upgrade",upgrade+1);
-
- local form = get_mover_form(pos,player)
- minetest.show_formspec(player:get_player_name(), "basic_machines:mover_"..minetest.pos_to_string(pos), form)
- end
-
-
- end
-
- return stack:get_count();
- end,
-
- allow_metadata_inventory_take = function(pos, listname, index, stack, player)
- local meta = minetest.get_meta(pos);
- meta:set_float("upgrade",1); -- reset upgrade
- local form = get_mover_form(pos,player)
- minetest.show_formspec(player:get_player_name(), "basic_machines:mover_"..minetest.pos_to_string(pos), form)
- return stack:get_count();
- end,
-
- mesecons = {effector = {
- action_on = function (pos, node,ttl)
-
- if type(ttl)~="number" then ttl = 1 end
- local meta = minetest.get_meta(pos);
- local fuel = meta:get_float("fuel");
-
-
- local x0=meta:get_int("x0"); local y0=meta:get_int("y0"); local z0=meta:get_int("z0");
- local x2=meta:get_int("x2"); local y2=meta:get_int("y2"); local z2=meta:get_int("z2");
-
- local mode = meta:get_string("mode");
- local mreverse = meta:get_int("reverse")
- local pos1 = {x=x0+pos.x,y=y0+pos.y,z=z0+pos.z}; -- where to take from
- local pos2 = {x=x2+pos.x,y=y2+pos.y,z=z2+pos.z}; -- where to put
-
- local pc = meta:get_int("pc"); local dim = meta:get_int("dim"); pc = (pc+1) % dim;meta:set_int("pc",pc) -- cycle position
- local x1=meta:get_int("x1")-x0+1;local y1=meta:get_int("y1")-y0+1;local z1=meta:get_int("z1")-z0+1; -- get dimensions
-
- --pc = z*a*b+x*b+y, from x,y,z to pc
- -- set current input position
- pos1.y = y0 + (pc % y1); pc = (pc - (pc % y1))/y1;
- pos1.x = x0 + (pc % x1); pc = (pc - (pc % x1))/x1;
- pos1.z = z0 + pc;
- pos1.x = pos.x+pos1.x;pos1.y = pos.y+pos1.y;pos1.z = pos.z+pos1.z;
-
- -- special modes that use its own source/target positions:
- if mode == "transport" and mreverse<2 then
- pos2 = {x=meta:get_int("x2")-x0+pos1.x,y=meta:get_int("y2")-y0+pos1.y,z=meta:get_int("z2")-z0+pos1.z}; -- translation from pos1
- end
-
- if mreverse ~= 0 and mreverse ~= 2 then -- reverse pos1, pos2
- if mode == "object" then
- x0 = pos2.x-pos.x; y0 = pos2.y-pos.y; z0 = pos2.z-pos.z;
- pos2 = {x=pos1.x,y=pos1.y,z=pos1.z};
- else
- local post = {x=pos1.x,y=pos1.y,z=pos1.z};
- pos1 = {x=pos2.x,y=pos2.y,z=pos2.z};
- pos2 = {x=post.x,y=post.y,z=post.z};
- end
- end
-
-
- -- PROTECTION CHECK
- local owner = meta:get_string("owner");
- if (minetest.is_protected(pos1, owner) or minetest.is_protected(pos2, owner)) and mode~="object" then
- meta:set_string("infotext", "Mover block. Protection fail. ")
- return
- end
-
- local node1 = minetest.get_node(pos1);local node2 = minetest.get_node(pos2);
- local prefer = meta:get_string("prefer");
-
- -- FUEL COST: calculate
- local dist = math.abs(pos2.x-pos1.x)+math.abs(pos2.y-pos1.y)+math.abs(pos2.z-pos1.z);
- local hardness = basic_machines.hardness[node1.name];
- -- no free teleports from machine blocks
- if hardness == 0 and mode == "object" then hardness = 1 end
- local fuel_cost = hardness or 1;
-
- local upgrade = meta:get_float("upgrade") or 1;
-
- -- taking items from chests/inventory move
- if node1.name == "default:chest_locked" or mode == "inventory" then fuel_cost = basic_machines.hardness[prefer] or 1 end;
-
- fuel_cost=fuel_cost*dist/machines_operations; -- machines_operations=10 by default, so 10 basic operations possible with 1 coal
- if mode == "object" then
- fuel_cost=fuel_cost*0.1;
- if x2==0 and z2==0 then -- check if elevator mode
- local requirement = math.floor(math.abs(pos2.y-pos.y)/100)+1;
- if upgrade-10 then
- found_fuel=supply;
- elseif supply<0 then -- no battery at target location, try to find it!
- local fpos = find_and_connect_battery(pos);
- if not fpos then
- meta:set_string("infotext", "Can not find nearby battery to connect to!");
- minetest.sound_play("default_cool_lava", {pos=pos,gain=1.0,max_hear_distance = 8,})
- return
- end
-
- end
-
- if found_fuel~=0 then
- fuel = fuel+found_fuel;
- meta:set_float("fuel", fuel);
- meta:set_string("infotext", "Mover block refueled. Fuel ".. fuel);
-
- end
-
- end
-
- if fuel < fuel_cost then
- meta:set_string("infotext", "Mover block. Energy ".. fuel ..", needed energy " .. fuel_cost .. ". Put nonempty battery next to mover.");
- return
- end
-
-
- if mode == "object" then -- teleport objects and return
-
- -- if target is chest put items in it
- local target_chest = false
- if node2.name == "default:chest" or node2.name == "default:chest_locked" then
- target_chest = true
- end
- local r = math.max(math.abs(x1),math.abs(y1),math.abs(z1)); r = math.min(r,10);
- local teleport_any = false;
-
- if target_chest then -- put objects in target chest
- local cmeta = minetest.get_meta(pos2);
- local inv = cmeta:get_inventory();
-
- for _,obj in pairs(minetest.get_objects_inside_radius({x=x0+pos.x,y=y0+pos.y,z=z0+pos.z}, r)) do
- local lua_entity = obj:get_luaentity()
- if not obj:is_player() and lua_entity and lua_entity.itemstring ~= "" then
- local detected_obj = lua_entity.name or ""
- if not basic_machines.no_teleport_table[detected_obj] then -- object on no teleport list
- -- put item in chest
- local stack = ItemStack(lua_entity.itemstring)
- if inv:room_for_item("main", stack) then
- teleport_any = true;
- inv:add_item("main", stack);
- end
- obj:setpos({x=0,y=0,z=0}); -- patch for dupe, might not be needed if future minetest object management is better
- obj:remove();
- end
- end
- end
- if teleport_any then
- fuel = fuel - fuel_cost; meta:set_float("fuel",fuel);
- meta:set_string("infotext", "Mover block. Fuel "..fuel);
- minetest.sound_play("tng_transporter1", {pos=pos2,gain=1.0,max_hear_distance = 8,})
- end
- return
- end
-
- local times = tonumber(prefer) or 0; if times > 20 then times = 20 elseif times<0.2 then times = 0 end
- local velocityv;
- if times~=0 then
- velocityv = { x = pos2.x-x0-pos.x, y = pos2.y-y0-pos.y, z = pos2.z-z0-pos.z};
- local vv=math.sqrt(velocityv.x*velocityv.x+velocityv.y*velocityv.y+velocityv.z*velocityv.z);
- local velocitys=0;
- if times~=0 then velocitys = vv/times else vv = 0 end
- if vv ~= 0 then vv=velocitys/vv else vv = 0 end;
- velocityv.x = velocityv.x * vv; velocityv.y = velocityv.y * vv; velocityv.z = velocityv.z* vv
- end
-
- --minetest.chat_send_all(" times ".. times .. " v " .. minetest.pos_to_string(velocityv));
-
- -- move objects to another location
- local finalsound = true;
- for _,obj in pairs(minetest.get_objects_inside_radius({x=x0+pos.x,y=y0+pos.y,z=z0+pos.z}, r)) do
- if obj:is_player() then
- if not minetest.is_protected(obj:getpos(), owner) and (prefer == "" or obj:get_player_name()== prefer) then -- move player only from owners land
- obj:moveto(pos2, false)
- teleport_any = true;
- end
- else
-
- local lua_entity = obj:get_luaentity();
- local detected_obj = lua_entity.name or ""
- if not basic_machines.no_teleport_table[detected_obj] then -- object on no teleport list
- if times > 0 then
- local finalmove = true;
- -- move objects with set velocity in target direction
- obj:setvelocity(velocityv);
- if obj:get_luaentity() then -- interaction with objects like carts
- if lua_entity.name then
- if lua_entity.name == "basic_machines:ball" then -- move balls for free
- lua_entity.velocity = {x=velocityv.x*times,y=velocityv.y*times,z=velocityv.z*times};
- finalmove = false;
- finalsound = false;
- end
- if lua_entity.name == "carts:cart" then -- just accelerate cart
- lua_entity.velocity = {x=velocityv.x*times,y=velocityv.y*times,z=velocityv.z*times};
- fuel = fuel - fuel_cost; meta:set_float("fuel",fuel);
- meta:set_string("infotext", "Mover block. Fuel "..fuel);
- return;
- end
- end
- end
- --obj:setacceleration({x=0,y=0,z=0});
- if finalmove then -- dont move objects like balls to destination after delay
- minetest.after(times, function () if obj then obj:setvelocity({x=0,y=0,z=0}); obj:moveto(pos2, false) end end);
- end
- else
- obj:moveto(pos2, false)
- end
- end
- teleport_any = true;
- end
- end
-
- if teleport_any then
- fuel = fuel - fuel_cost; meta:set_float("fuel",fuel);
- meta:set_string("infotext", "Mover block. Fuel "..fuel);
- if finalsound then minetest.sound_play("tng_transporter1", {pos=pos2,gain=1.0,max_hear_distance = 8,}) end
- end
-
- return
- end
-
-
- local dig=false; if mode == "dig" then dig = true; end -- digs at target location
- local drop = false; if mode == "drop" then drop = true; end -- drops node instead of placing it
- local harvest = false; -- harvest mode for special nodes: mese crystals
-
-
- -- decide what to do if source or target are chests
- local source_chest=false; if string.find(node1.name,"default:chest") then source_chest=true end
- if node1.name == "air" then return end -- nothing to move
-
- local target_chest = false
- if node2.name == "default:chest" or node2.name == "default:chest_locked" then
- target_chest = true
- end
-
- if not(target_chest) and not(mode=="inventory") and minetest.get_node(pos2).name ~= "air" then return end -- do nothing if target nonempty and not chest
-
- local invName1="";local invName2="";
- if mode == "inventory" then
- invName1 = meta:get_string("inv1");invName2 = meta:get_string("inv2");
- if mreverse == 1 then -- reverse inventory names too
- local invNamet = invName1;invName1=invName2;invName2=invNamet;
- end
- end
-
-
- -- inventory mode
- if mode == "inventory" then
- --if prefer == "" then meta:set_string("infotext", "Mover block. must set nodes to move (filter) in inventory mode."); return; end
-
- -- forbidden nodes to take from in inventory mode - to prevent abuses :
- if basic_machines.limit_inventory_table[node1.name] then
- if basic_machines.limit_inventory_table[node1.name][invName1] then -- forbidden to take from this inventory
- return
- end
- end
-
- local stack, meta1,inv1;
- if prefer == "" then -- if prefer == "" then just pick one item from chest to transfer
- meta1 = minetest.get_meta(pos1);
- inv1 = meta1:get_inventory();
- if inv1:is_empty(invName1) then return end -- nothing to move
-
- local size = inv1:get_size(invName1);
-
- local found = false;
- for i = 1, size do -- find item to move in inventory
- stack = inv1:get_stack(invName1, i);
- if not stack:is_empty() then found = true break end
- end
- if not found then return end
- end
-
- -- can we move item to target inventory?
- if prefer~="" then
- stack = ItemStack(prefer);
- end
- local meta2 = minetest.get_meta(pos2); local inv2 = meta2:get_inventory();
- if not inv2:room_for_item(invName2, stack) then return end
-
- -- add item to target inventory and remove item from source inventory
- if prefer~="" then
- meta1 = minetest.get_meta(pos1); inv1 = meta1:get_inventory();
- end
-
- if inv1:contains_item(invName1, stack) then
- inv2:add_item(invName2, stack);
- inv1:remove_item(invName1, stack);
- else
- if upgrade == -1 then -- admin is owner.. just add stuff
- inv2:add_item(invName2, stack);
- else
- return -- item not found in chest
- end
- end
-
- minetest.sound_play("chest_inventory_move", {pos=pos2,gain=1.0,max_hear_distance = 8,})
- fuel = fuel - fuel_cost; meta:set_float("fuel",fuel);
- meta:set_string("infotext", "Mover block. Fuel "..fuel);
- return
- end
-
- -- filtering
- if prefer~="" then -- prefered node set
- if prefer~=node1.name and not source_chest and mode ~= "inventory" then return end -- only take prefered node or from chests/inventories
- if source_chest then -- take stuff from chest
-
- local cmeta = minetest.get_meta(pos1);
- local inv = cmeta:get_inventory();
- local stack = ItemStack(prefer);
-
- if inv:contains_item("main", stack) then
- inv:remove_item("main", stack);
- else
- return
- end
-
- if mreverse == 1 then -- planting mode: check if transform seed->plant is needed
- if basic_machines.plant_table[prefer]~=nil then
- prefer = basic_machines.plant_table[prefer];
- end
- end
- end
-
- node1 = {}; node1.name = prefer;
- end
-
- if (prefer == "" and source_chest) then return end -- doesnt know what to take out of chest/inventory
-
-
- -- if target chest put in chest
- if target_chest then
- local cmeta = minetest.get_meta(pos2);
- local inv = cmeta:get_inventory();
-
- -- dig tree or cactus
- local count = 0;-- check for cactus or tree
- local dig_up = false; -- digs up node as a tree
- if dig then
-
- if not source_chest and basic_machines.dig_up_table[node1.name] then dig_up = true end
- -- do we harvest the node?
- if not source_chest then
- if basic_machines.harvest_table[node1.name]~=nil then
- harvest = true
- local remains = basic_machines.harvest_table[node1.name][1];
- local result = basic_machines.harvest_table[node1.name][2];
- minetest.set_node(pos1,{name=remains});
- inv:add_item("main",result);
- end
- end
-
-
- if dig_up == true then -- dig up to 16 nodes
-
- local r = 1; if node1.name == "default:cactus" or node1.name == "default:papyrus" then r = 0 end
-
- local positions = minetest.find_nodes_in_area( --
- {x=pos1.x-r, y=pos1.y, z=pos1.z-r},
- {x=pos1.x+r, y=pos1.y+16, z=pos1.z+r},
- node1.name)
-
- for _, pos3 in ipairs(positions) do
- --if count>16 then break end
- minetest.set_node(pos3,{name="air"}); count = count+1;
- end
-
- inv:add_item("main", node1.name .. " " .. count-1);-- if tree or cactus was digged up
- end
-
-
- -- minetest drop code emulation
- if not harvest then
- local table = minetest.registered_items[node1.name];
- if table~=nil then --put in chest
- if table.drop~= nil then -- drop handling
- if table.drop.items then
- --handle drops better, emulation of drop code
- local max_items = table.drop.max_items or 0;
- if max_items==0 then -- just drop all the items (taking the rarity into consideration)
- max_items = #table.drop.items or 0;
- end
- local drop = table.drop;
- local i = 0;
- for k,v in pairs(drop.items) do
- if i > max_items then break end; i=i+1;
- local rare = v.rarity or 1;
- if math.random(1, rare)==1 then
- node1={};node1.name = v.items[math.random(1,#v.items)]; -- pick item randomly from list
- inv:add_item("main",node1.name);
-
- end
- end
- else
- inv:add_item("main",table.drop);
- end
- else
- inv:add_item("main",node1.name);
- end
- end
- end
-
- else -- if not dig just put it in
- inv:add_item("main",node1.name);
- end
-
- end
-
-
- minetest.sound_play("transporter", {pos=pos2,gain=1.0,max_hear_distance = 8,})
-
- if target_chest and source_chest then -- chest to chest transport has lower cost, *0.1
- fuel_cost=fuel_cost*0.1;
- end
-
- fuel = fuel - fuel_cost; meta:set_float("fuel",fuel);
- meta:set_string("infotext", "Mover block. Fuel "..fuel);
-
-
- if mode == "transport" then -- transport nodes parallel as defined by source1 and target, clone with complete metadata
- local meta1 = minetest.get_meta(pos1):to_table();
-
- minetest.set_node(pos2, minetest.get_node(pos1));
- minetest.get_meta(pos2):from_table(meta1);
- minetest.set_node(pos1,{name="air"});minetest.get_meta(pos1):from_table(nil)
- return;
- end
-
- -- REMOVE DIGGED NODE
- if not(target_chest) then
- if not drop then minetest.set_node(pos2, {name = node1.name}); end
- if drop then
- local stack = ItemStack(node1.name);
- minetest.add_item(pos2,stack) -- drops it
- end
- end
- if not(source_chest) and not(harvest) then
- if dig then nodeupdate(pos1) end
- minetest.set_node(pos1, {name = "air"});
- end
- end,
-
-
- action_off = function (pos, node,ttl) -- this toggles reverse option of mover
- if type(ttl)~="number" then ttl = 1 end
- local meta = minetest.get_meta(pos);
- local mreverse = meta:get_int("reverse");
- if mreverse == 1 then mreverse = 0 elseif mreverse==0 then mreverse = 1 end
- meta:set_int("reverse",mreverse);
- end
-
-
- }
- }
-})
-
--- KEYPAD --
-
-local function use_keypad(pos,ttl, again) -- position, time to live ( how many times can signal travel before vanishing to prevent infinite recursion ), do we want to activate again
-
- if ttl<0 then return end;
- local meta = minetest.get_meta(pos);
-
- local t0 = meta:get_int("t");
- local t1 = minetest.get_gametime();
- local T = meta:get_int("T"); -- temperature
-
- if t0>t1-machines_minstep then -- activated before natural time
- T=T+1;
- else
- if T>0 then
- T=T-1
- if t1-t0>5 then T = 0 end
- end
- end
- meta:set_int("T",T);
- meta:set_int("t",t1); -- update last activation time
-
- if T > 2 then -- overheat
- minetest.sound_play("default_cool_lava",{pos = pos, max_hear_distance = 16, gain = 0.25})
- meta:set_string("infotext","overheat: temperature ".. T)
- return
- end
-
-
- local name = meta:get_string("owner");
- if minetest.is_protected(pos,name) then meta:set_string("infotext", "Protection fail. reset."); meta:set_int("count",0); return end
- local count = meta:get_int("count") or 0; -- counts how many repeats left
-
- local repeating = meta:get_int("repeating");
-
- if repeating==1 and again~=1 then
- -- stop it
- meta:set_int("repeating",0);
- meta:set_int("count", 0)
- meta:set_int("T",4);
- meta:set_string("infotext", "#KEYPAD: reseting. Punch again after 5s to activate")
- return;
- end
-
-
-
- if count>0 then -- this is keypad repeating its activation
- count = count - 1; meta:set_int("count",count);
- else
- meta:set_int("repeating",0);
- --return
- end
-
- if count>=0 then
- meta:set_string("infotext", "Keypad operation: ".. count .." cycles left")
- else
- meta:set_string("infotext", "Keypad operation: activation ".. -count)
- end
-
- if count>0 then -- only trigger repeat if count on
- if repeating == 0 then meta:set_int("repeating",1); end-- its repeating now
- if basic_machines.clockgen==0 then return end
- minetest.after(machines_timer, function()
- use_keypad(pos,machines_TTL,1)
- end )
-
- end
-
- local x0,y0,z0,mode;
- x0=meta:get_int("x0");y0=meta:get_int("y0");z0=meta:get_int("z0");
- x0=pos.x+x0;y0=pos.y+y0;z0=pos.z+z0;
- mode = meta:get_int("mode");
-
- -- pass the signal on to target, depending on mode
-
- local tpos = {x=x0,y=y0,z=z0}; -- target position
- local node = minetest.get_node(tpos);if not node.name then return end -- error
- local text = meta:get_string("text");
-
- if text ~= "" then -- TEXT MODE; set text on target
- if text == "@" then -- keyboard mode, set text from input
- text = meta:get_string("input") or "";
- meta:set_string("input",""); -- clear input again
- end
-
- local bit = string.byte(text);
- if bit == 33 then -- if text starts with !, then we send chat text to all nearby players, radius 5
- text = string.sub(text,2) ; if not text or text == "" then return end
- local players = minetest.get_connected_players();
- for _,player in pairs(players) do
- local pos1 = player:getpos();
- local dist = math.sqrt((pos1.x-tpos.x)^2 + (pos1.y-tpos.y)^2 + (pos1.z-tpos.z)^2 );
- if dist<=5 then
- minetest.chat_send_player(player:get_player_name(), text)
- end
- end
- return
- elseif bit == 36 then-- text starts with $, play sound
- text = string.sub(text,2) ; if not text or text == "" then return end
- minetest.sound_play(text, {pos=pos,gain=1.0,max_hear_distance = 16,})
- end
-
- local tmeta = minetest.get_meta(tpos);if not tmeta then return end
-
- if basic_machines.signs[node.name] then -- update text on signs with signs_lib
- tmeta:set_string("infotext", text);
- tmeta:set_string("text",text);
- local table = minetest.registered_nodes[node.name];
- if not table.on_punch then return end -- error
- if signs_lib and signs_lib.update_sign then
- --signs_lib.update_sign(pos)
- table.on_punch(tpos, node, nil); -- warning - this can cause problems if no signs_lib installed
- end
-
- return
- end
-
- -- target is keypad, special functions: @, % that output to target keypad text
- if node.name == "basic_machines:keypad" then -- special modify of target keypad text and change its target
-
- x0=tmeta:get_int("x0");y0=tmeta:get_int("y0");z0=tmeta:get_int("z0");
- x0=tpos.x+x0;y0=tpos.y+y0;z0=tpos.z+z0;
- tpos = {x=x0,y=y0,z=z0};
-
- if string.byte(text) == 64 then -- target keypad's text starts with @ ( ascii code 64) -> character replacement
- text = string.sub(text,2); if not text or text == "" then return end
- --read words[j] from blocks above keypad:
- local j=0;
- text = string.gsub(text, "@",
- function()
- j=j+1;
- return minetest.get_meta({x=pos.x,y=pos.y+j,z=pos.z}):get_string("infotext")
- end
- ) ; -- replace every @ in ttext with string on blocks above
-
- -- set target keypad's text xxx
- --tmeta = minetest.get_meta(tpos);if not tmeta then return end
- tmeta:set_string("text", text);
- elseif string.byte(text) == 37 then -- target keypad's text starts with % ( ascii code 37) -> word extraction
-
- local ttext = minetest.get_meta({x=pos.x,y=pos.y+1,z=pos.z}):get_string("infotext")
- local i = tonumber(string.sub(text,2,2)) or 1; --read the number following the %
- --extract i-th word from text
- local j = 0;
- for word in string.gmatch(ttext, "%S+") do
- j=j+1; if j == i then text = word; break; end
- end
-
- -- set target keypad's target's text
- --tmeta = minetest.get_meta(tpos); if not tmeta then return end
- tmeta:set_string("text", text);
- else
-
- if string.byte(text) == 64 then -- if text starts with @ clear target keypad text
- tmeta:set_string("text","");
- return
- end
- -- just set text..
- --tmeta = minetest.get_meta(tpos); if not tmeta then return end
- tmeta:set_string("infotext", text);
- end
- return
- end
-
- if node.name == "basic_machines:detector" then -- change filter on detector
- if string.byte(text) == 64 then -- if text starts with @ clear the filter
- tmeta:set_string("node","");
- else
- tmeta:set_string("node",text);
- end
- return
- end
-
- if node.name == "basic_machines:mover" then -- change filter on mover
- if string.byte(text) == 64 then -- if text starts with @ clear the filter
- tmeta:set_string("prefer","");
- else
- tmeta:set_string("prefer",text);
- end
- return
- end
-
- if node.name == "basic_machines:distributor" then
- local i = string.find(text," ");
- if i then
- local ti = tonumber(string.sub(text,1,i-1)) or 1;
- local tm = tonumber(string.sub(text,i+1)) or 1;
- if ti>=1 and ti<=16 and tm>=-2 and tm<=2 then
- tmeta:set_int("active"..ti,tm)
- end
- end
- return
- end
-
- tmeta:set_string("infotext", text); -- else just set text
- end
-
-
- --activate target
- local table = minetest.registered_nodes[node.name];
- if not table then return end -- error
- if not table.mesecons then return end -- error
- if not table.mesecons.effector then return end -- error
- local effector=table.mesecons.effector;
-
- if mode == 3 then -- keypad in toggle mode
- local state = meta:get_int("state") or 0;state = 1-state; meta:set_int("state",state);
- if state == 0 then mode = 1 else mode = 2 end
- end
- -- pass the signal on to target
-
- if mode == 2 then -- on
- if not effector.action_on then return end
- effector.action_on(tpos,node,ttl-1); -- run
- elseif mode == 1 then -- off
- if not effector.action_off then return end
- effector.action_off(tpos,node,ttl-1); -- run
- end
-
-end
-
-local function check_keypad(pos,name,ttl) -- called only when manually activated via punch
- local meta = minetest.get_meta(pos);
- local pass = meta:get_string("pass");
- if pass == "" then
- local iter = meta:get_int("iter");
- local count = meta:get_int("count");
- if count value
-
- for i in pairs( list1) do
- inv_list1 = inv_list1 .. i .. ",";
- if i == inv1m then inv1=j end; j=j+1;
- end
-
- node=meta:get_string("node") or "";
- NOT=meta:get_int("NOT");
- local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
- local form =
- "size[4,6.25]" .. -- width, height
- "field[0.25,0.5;1,1;x0;source1;"..x0.."] field[1.25,0.5;1,1;y0;;"..y0.."] field[2.25,0.5;1,1;z0;;"..z0.."]"..
- "dropdown[3,0.25;1,1;op; ,AND,OR;".. op .."]"..
- "field[0.25,1.5;1,1;x1;source2;"..x1.."] field[1.25,1.5;1,1;y1;;"..y1.."] field[2.25,1.5;1,1;z1;;"..z1.."]"..
- "field[0.25,2.5;1,1;x2;target;"..x2.."] field[1.25,2.5;1,1;y2;;"..y2.."] field[2.25,2.5;1,1;z2;;"..z2.."]"..
- "field[0.25,3.5;2,1;node;Node/player/object: ;"..node.."]".."field[3.25,2.5;1,1;r;radius;"..r.."]"..
- "dropdown[0,4.5;3,1;mode;node,player,object,inventory,infotext,light;".. mode .."]"..
- "dropdown[0,5.5;3,1;inv1;"..inv_list1..";".. inv1 .."]"..
- "label[0.,4.0;" .. minetest.colorize("lawngreen", "MODE selection") .. "]"..
- "label[0.,5.2;inventory selection]"..
- "field[2.25,3.5;2,1;NOT;filter out -2/-1/0/1/2/3/4;"..NOT.."]"..
- "button[3.,4.4;1,1;help;help] button_exit[3.,5.4;1,1;OK;OK] "
-
- --if meta:get_string("owner")==player:get_player_name() then
- minetest.show_formspec(player:get_player_name(), "basic_machines:detector_"..minetest.pos_to_string(pos), form)
- -- else
- -- minetest.show_formspec(player:get_player_name(), "view_only_basic_machines_detector", form)
- -- end
- end,
-
- allow_metadata_inventory_put = function(pos, listname, index, stack, player)
- return 0
- end,
-
- allow_metadata_inventory_take = function(pos, listname, index, stack, player)
- return 0
- end,
-
- allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
- local meta = minetest.get_meta(pos);
- local mode = "node";
- if to_index == 2 then
- mode = "player";
- meta:set_int("r",math.max(meta:get_int("r"),1))
- end
- if to_index == 3 then
- mode = "object";
- meta:set_int("r",math.max(meta:get_int("r"),1))
- end
- meta:set_string("mode",mode)
- minetest.chat_send_player(player:get_player_name(), "DETECTOR: Mode of operation set to: "..mode)
- return count
- end,
-
- mesecons = {effector = {
- action_on = function (pos, node,ttl)
- if ttl<0 then return end
-
- local meta = minetest.get_meta(pos);
-
- local t0 = meta:get_int("t");
- local t1 = minetest.get_gametime();
- local T = meta:get_int("T"); -- temperature
-
- if t0>t1-machines_minstep then -- activated before natural time
- T=T+1;
- else
- if T>0 then T=T-1 end
- end
- meta:set_int("T",T);
- meta:set_int("t",t1); -- update last activation time
-
- if T > 2 then -- overheat
- minetest.sound_play("default_cool_lava",{pos = pos, max_hear_distance = 16, gain = 0.25})
- meta:set_string("infotext","overheat: temperature ".. T)
- return
- end
-
-
- local x0,y0,z0,x1,y1,z1,x2,y2,z2,r,node,NOT,mode,op;
- x0=meta:get_int("x0")+pos.x;y0=meta:get_int("y0")+pos.y;z0=meta:get_int("z0")+pos.z;
- x2=meta:get_int("x2")+pos.x;y2=meta:get_int("y2")+pos.y;z2=meta:get_int("z2")+pos.z;
-
- r = meta:get_int("r") or 0; NOT = meta:get_int("NOT")
- node=meta:get_string("node") or ""; mode=meta:get_string("mode") or ""; op = meta:get_string("op") or "";
-
- local trigger = false
- local detected_obj = "";
-
- if mode == "node" then
- local tnode = minetest.get_node({x=x0,y=y0,z=z0}).name; -- read node at source position
- detected_obj = tnode;
-
- if node~="" and string.find(tnode,"default:chest") then -- if source is chest, look inside chest for items
- local cmeta = minetest.get_meta({x=x0,y=y0,z=z0});
- local inv = cmeta:get_inventory();
- local stack = ItemStack(node)
- if inv:contains_item("main", stack) then trigger = true end
- else -- source not a chest
- if (node=="" and tnode~="air") or node == tnode then trigger = true end
- if r>0 and node~="" then
- local found_node = minetest.find_node_near({x=x0, y=y0, z=z0}, r, {node})
- if node ~= "" and found_node then trigger = true end
- end
- end
-
- -- operation: AND, OR... look at other source position too
- if op~= "" then
- local trigger1 = false;
- x1=meta:get_int("x1")+pos.x;y1=meta:get_int("y1")+pos.y;z1=meta:get_int("z1")+pos.z;
- tnode = minetest.get_node({x=x1,y=y1,z=z1}).name; -- read node at source position
-
- if node~="" and string.find(tnode,"default:chest") then -- it source is chest, look inside chest for items
- local cmeta = minetest.get_meta({x=x1,y=y1,z=z1});
- local inv = cmeta:get_inventory();
- local stack = ItemStack(node)
- if inv:contains_item("main", stack) then trigger1 = true end
- else -- source not a chest
- if (node=="" and tnode~="air") or node == tnode then trigger1 = true end
- if r>0 and node~="" then
- local found_node = minetest.find_node_near({x=x0, y=y0, z=z0}, r, {node})
- if node ~= "" and found_node then trigger1 = true end
- end
- end
- if op == "AND" then
- trigger = trigger and trigger1;
- elseif op == "OR" then
- trigger = trigger or trigger1;
- end
- end
-
- elseif mode=="inventory" then
- local cmeta = minetest.get_meta({x=x0,y=y0,z=z0});
- local inv = cmeta:get_inventory();
- local stack = ItemStack(node);
- local inv1m =meta:get_string("inv1");
- if inv:contains_item(inv1m, stack) then trigger = true end
- elseif mode == "infotext" then
- local cmeta = minetest.get_meta({x=x0,y=y0,z=z0});
- detected_obj = cmeta:get_string("infotext");
- if detected_obj == node or node =="" then trigger = true end
- elseif mode == "light" then
- detected_obj=minetest.get_node_light({x=x0,y=y0,z=z0}) or 0;
- if detected_obj>=(tonumber(node) or 0) or node == "" then trigger = true end
- else -- players/objects
- local objects = minetest.get_objects_inside_radius({x=x0,y=y0,z=z0}, r)
- local player_near=false;
- for _,obj in pairs(objects) do
- if mode == "player" then
- if obj:is_player() then
-
- player_near = true
- detected_obj = obj:get_player_name();
- if (node=="" or detected_obj==node) then
- trigger = true break
- end
-
- end;
- elseif mode == "object" and not obj:is_player() then
- if obj:get_luaentity() then
- detected_obj = obj:get_luaentity().itemstring or "";
- if detected_obj == "" then
- detected_obj = obj:get_luaentity().name or ""
- end
-
- if detected_obj==node then trigger=true break end
- end
- if node=="" then trigger = true break end
- end
- end
-
- if node~="" and NOT==-1 and not(trigger) and not(player_near) and mode == "player" then
- trigger = true
- end-- name specified, but noone around and negation -> 0
-
- end
-
- -- negation and output filtering
- local state = meta:get_int("state");
-
-
- if NOT == 1 then -- just go on normally
- -- -2: only false, -1: NOT, 0: no signal, 1: normal signal: 2: only true
- elseif NOT == -1 then trigger = not trigger -- NEGATION
- elseif NOT == -2 and trigger then return -- ONLY FALSE
- elseif NOT == 0 then return -- do nothing
- elseif NOT == 2 and not trigger then return -- ONLY TRUE
- elseif NOT == 3 and ((trigger and state == 1) or (not trigger and state == 0)) then return -- no change of state
- end
-
- local nstate;
- if trigger then nstate = 1 else nstate=0 end -- next detector output state
- if nstate~=state then meta:set_int("state",nstate) end -- update state if changed
-
-
- local node = minetest.get_node({x=x2,y=y2,z=z2});if not node.name then return end -- error
- local table = minetest.registered_nodes[node.name];
- if not table then return end -- error
- if not table.mesecons then return end -- error
- if not table.mesecons.effector then return end -- error
- local effector=table.mesecons.effector;
-
- if trigger then -- activate target node if succesful
- meta:set_string("infotext", "detector: on");
- if not effector.action_on then return end
- if NOT == 4 then -- set detected object name as target text (target must be keypad, if not changes infotext)
- if minetest.get_node({x=x2,y=y2,z=z2}).name == "basic_machines:keypad" then
- detected_obj = detected_obj or "";
- local tmeta = minetest.get_meta({x=x2,y=y2,z=z2});
- tmeta:set_string("text",detected_obj);
- end
- end
- effector.action_on({x=x2,y=y2,z=z2},node,ttl-1); -- run
- else
- meta:set_string("infotext", "detector: off");
- if not effector.action_off then return end
- effector.action_off({x=x2,y=y2,z=z2},node,ttl-1); -- run
- end
- end
- }
- }
-})
-
-
-minetest.register_chatcommand("clockgen", { -- test: toggle machine running with clockgens, useful for debugging
--- i.e. seeing how machines running affect server performance
- description = "",
- privs = {
- interact = true
- },
- func = function(name, param)
- local privs = minetest.get_player_privs(name);
- if not privs.privs then return end
- local player = minetest.get_player_by_name(name);
- if basic_machines.clockgen == 0 then basic_machines.clockgen = 1 else basic_machines.clockgen = 0 end
- minetest.chat_send_player(name, "#clockgen set to " .. basic_machines.clockgen);
- end
-})
-
-
--- CLOCK GENERATOR : periodically activates machine on top of it
-minetest.register_abm({
- nodenames = {"basic_machines:clockgen"},
- neighbors = {""},
- interval = machines_timer,
- chance = 1,
-
- action = function(pos, node, active_object_count, active_object_count_wider)
- if basic_machines.clockgen == 0 then return end
- local meta = minetest.get_meta(pos);
- local machines = meta:get_int("machines");
- if machines~=1 then -- no machines privilege
- if not minetest.get_player_by_name(meta:get_string("owner")) then -- owner not online
- return
- end
- end
-
- pos.y=pos.y+1;
- node = minetest.get_node(pos);if not node.name or node.name == "air" then return end
- local table = minetest.registered_nodes[node.name];
- if table and table.mesecons and table.mesecons.effector then -- check if all elements exist, safe cause it checks from left to right
- else return
- end
- local effector=table.mesecons.effector;
- if effector.action_on then
- effector.action_on(pos,node,machines_TTL);
- end
- end
- });
-
-minetest.register_node("basic_machines:clockgen", {
- description = "Clock generator - use sparingly, continually activates top block",
- tiles = {"basic_machine_clock_generator.png"},
- groups = {cracky=3, mesecon_effector_on = 1},
- sounds = default.node_sound_wood_defaults(),
- after_place_node = function(pos, placer)
- local meta = minetest.get_meta(pos);
- local owner = placer:get_player_name() or "";
- local privs = minetest.get_player_privs(owner);
- if privs.machines then meta:set_int("machines",1) end
-
- meta:set_string("owner",owner);
- meta:set_string("infotext","clock generator (owned by " .. owner .. "): place machine to be activated on top of generator");
- end
-})
-
-
-
--- DISTRIBUTOR --
-local get_distributor_form = function(pos,player)
- if not player then return end
- local meta = minetest.get_meta(pos);
- local privs = minetest.get_player_privs(player:get_player_name());
- local cant_build = minetest.is_protected(pos,player:get_player_name());
- --meta:get_string("owner")~=player:get_player_name() and
- if not privs.privs and cant_build then
- return
- end
-
- local p = {}; local active = {};
- local n = meta:get_int("n");
- local delay = meta:get_float("delay");
- for i =1,n do
- p[i]={x=meta:get_int("x"..i),y=meta:get_int("y"..i),z=meta:get_int("z"..i)};
- active[i]=meta:get_int("active"..i);
- end
-
- local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
- local form =
- "size[7,"..(0.75+(n)*0.75).."]" .. -- width, height
- "label[0,-0.25;" .. minetest.colorize("lawngreen","target: x y z, MODE -2=only OFF, -1=NOT input/0/1=input, 2 = only ON") .. "]";
- for i =1,n do
- form = form.."field[0.25,"..(0.5+(i-1)*0.75)..";1,1;x"..i..";;"..p[i].x.."] field[1.25,"..(0.5+(i-1)*0.75)..";1,1;y"..i..";;"..p[i].y.."] field[2.25,"..(0.5+(i-1)*0.75)..";1,1;z"..i..";;"..p[i].z.."] field [ 3.25,"..(0.5+(i-1)*0.75)..";1,1;active"..i..";;" .. active[i] .. "]"
- form = form .. "button[4.,"..(0.25+(i-1)*0.75)..";1.5,1;SHOW"..i..";SHOW "..i.."]".."button_exit[5.25,"..(0.25+(i-1)*0.75)..";1,1;SET"..i..";SET]".."button[6.25,"..(0.25+(i-1)*0.75)..";1,1;X"..i..";X]"
- end
-
- form=form.."button_exit[4.25,"..(0.25+(n)*0.75)..";1,1;ADD;ADD]".."button_exit[3.,"..(0.25+(n)*0.75)..";1,1;OK;OK]".."field[0.25,"..(0.5+(n)*0.75)..";1,1;delay;delay;"..delay .. "]";
- form = form.."button[6.25,"..(0.25+(n)*0.75)..";1,1;help;help]";
- return form
-
-end
-
-
-minetest.register_node("basic_machines:distributor", {
- description = "Distributor - can forward signal up to 16 different targets",
- tiles = {"distributor.png"},
- groups = {cracky=3, mesecon_effector_on = 1},
- sounds = default.node_sound_wood_defaults(),
- after_place_node = function(pos, placer)
- local meta = minetest.env:get_meta(pos)
- meta:set_string("infotext", "Distributor. Right click/punch to set it up.")
- meta:set_string("owner", placer:get_player_name()); meta:set_int("public",0);
- for i=1,10 do
- meta:set_int("x"..i,0);meta:set_int("y"..i,1);meta:set_int("z"..i,0);meta:set_int("active"..i,1) -- target i
- end
- meta:set_int("n",2); -- how many targets initially
- meta:set_float("delay",0); -- delay when transmitting signal
-
-
- meta:set_int("public",0); -- can other ppl set it up?
- local name = placer:get_player_name();punchset[name] = {}; punchset[name].node = ""; punchset[name].state = 0
- end,
-
- mesecons = {effector = {
- action_on = function (pos, node,ttl)
- if type(ttl)~="number" then ttl = 1 end
- if not(ttl>0) then return end
- local meta = minetest.get_meta(pos);
-
- local t0 = meta:get_int("t");
- local t1 = minetest.get_gametime();
- local T = meta:get_int("T"); -- temperature
-
- if t0>t1-machines_minstep then -- activated before natural time
- T=T+1;
- else
- if T>0 then
- T=T-1
- if t1-t0>5 then T = 0 end -- reset temperature if more than 5s elapsed since last punch
- end
-
- end
- meta:set_int("T",T);
- meta:set_int("t",t1); -- update last activation time
-
- if T > 2 then -- overheat
- minetest.sound_play("default_cool_lava",{pos = pos, max_hear_distance = 16, gain = 0.25})
- meta:set_string("infotext","overheat: temperature ".. T)
- return
- end
-
- local delay = minetest.get_meta(pos):get_float("delay");
-
- local activate = function()
- local posf = {}; local active = {};
- local n = meta:get_int("n");local delay = meta:get_float("delay");
- for i =1,n do
- posf[i]={x=meta:get_int("x"..i)+pos.x,y=meta:get_int("y"..i)+pos.y,z=meta:get_int("z"..i)+pos.z};
- active[i]=meta:get_int("active"..i);
- end
-
- local table,node;
-
- for i=1,n do
- if active[i]~=0 then
- node = minetest.get_node(posf[i]);if not node.name then return end -- error
- table = minetest.registered_nodes[node.name];
-
- if table and table.mesecons and table.mesecons.effector then -- check if all elements exist, safe cause it checks from left to right
- -- alternative way: overkill
- --ret = pcall(function() if not table.mesecons.effector then end end); -- exception handling to determine if structure exists
-
- local effector=table.mesecons.effector;
- local active_i = active[i];
-
- if (active_i == 1 or active_i == 2) and effector.action_on then -- normal OR only forward input ON
- effector.action_on(posf[i],node,ttl-1);
- elseif active_i == -1 and effector.action_off then
- effector.action_off(posf[i],node,ttl-1)
- end
- end
-
- end
- end
- end
-
- if delay>0 then
- minetest.after(delay, activate)
- elseif delay == 0 then
- activate()
- else -- delay <0 - do random activation: delay = -500 means 500/1000 chance to activate
- if math.random(1000)<=-delay then
- activate()
- end
- end
-
- end,
-
- action_off = function (pos, node,ttl)
-
- if type(ttl)~="number" then ttl = 1 end
- if not(ttl>0) then return end
- local meta = minetest.get_meta(pos);
-
-
- local t0 = meta:get_int("t");
- local t1 = minetest.get_gametime();
- local T = meta:get_int("T"); -- temperature
-
- if t0>t1-machines_minstep then -- activated before natural time
- T=T+1;
- else
- if T>0 then T=T-1 end
- end
- meta:set_int("T",T);
- meta:set_int("t",t1); -- update last activation time
-
- if T > 2 then -- overheat
- minetest.sound_play("default_cool_lava",{pos = pos, max_hear_distance = 16, gain = 0.25})
- meta:set_string("infotext","overheat: temperature ".. T)
- return
- end
- local delay = minetest.get_meta(pos):get_float("delay");
-
- local activate = function()
- local posf = {}; local active = {};
- local n = meta:get_int("n");
- for i =1,n do
- posf[i]={x=meta:get_int("x"..i)+pos.x,y=meta:get_int("y"..i)+pos.y,z=meta:get_int("z"..i)+pos.z};
- active[i]=meta:get_int("active"..i);
- end
-
- local node, table
-
-
- for i=1,n do
- if active[i]~=0 then
- node = minetest.get_node(posf[i]);if not node.name then return end -- error
- table = minetest.registered_nodes[node.name];
- if table and table.mesecons and table.mesecons.effector then
- local effector=table.mesecons.effector;
- if (active[i] == 1 or active[i]==-2) and effector.action_off then -- normal OR only forward input OFF
- effector.action_off(posf[i],node,ttl-1);
- elseif (active[i] == -1) and effector.action_on then
- effector.action_on(posf[i],node,ttl-1);
- end
- end
- end
- end
- end
-
- if delay>0 then minetest.after(delay, activate) else activate() end
-
- end
- }
- },
- on_rightclick = function(pos, node, player, itemstack, pointed_thing)
- local form = get_distributor_form(pos,player)
- if form then minetest.show_formspec(player:get_player_name(), "basic_machines:distributor_"..minetest.pos_to_string(pos), form) end
- end,
- }
-)
-
-
--- LIGHT --
-
-minetest.register_node("basic_machines:light_off", {
- description = "Light off",
- tiles = {"light_off.png"},
- groups = {cracky=3, mesecon_effector_on = 1},
- mesecons = {effector = {
- action_on = function (pos, node,ttl)
- minetest.swap_node(pos,{name = "basic_machines:light_on"});
- local meta = minetest.get_meta(pos);
- local deactivate = meta:get_int("deactivate");
-
- if deactivate > 0 then
- --meta:set_int("active",0);
- minetest.after(deactivate,
- function()
- --if meta:get_int("active") ~= 1 then -- was not activated again, so turn it off
- minetest.swap_node(pos,{name = "basic_machines:light_off"}); -- turn off again
- --meta:set_int("active",0);
- --end
- end
- )
- end
- end
- }
- },
-})
-
-
-minetest.register_node("basic_machines:light_on", {
- description = "Light on",
- tiles = {"light.png"},
- groups = {cracky=3, mesecon_effector_on = 1},
- light_source = LIGHT_MAX,
- after_place_node = function(pos, placer)
- local meta = minetest.get_meta(pos);
- local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
- local deactivate = meta:get_int("deactivate");
- local form = "size[2,2] field[0.25,0.5;2,1;deactivate;deactivate after ;"..deactivate.."]".."button_exit[0.,1;1,1;OK;OK]";
- meta:set_string("formspec", form);
- end,
- on_receive_fields = function(pos, formname, fields, player)
- if minetest.is_protected(pos, player:get_player_name()) then return end
- if fields.deactivate then
- local meta = minetest.get_meta(pos);
- local deactivate = tonumber(fields.deactivate) or 0;
- if deactivate <0 or deactivate > 600 then deactivate = 0 end
- meta:set_int("deactivate",deactivate);
- local form = "size[2,2] field[0.25,0.5;2,1;deactivate;deactivate after ;"..deactivate.."]".."button_exit[0.,1;1,1;OK;OK]";
- meta:set_string("formspec", form);
- end
-
- end,
-
- mesecons = {effector = {
- action_off = function (pos, node,ttl)
- minetest.swap_node(pos,{name = "basic_machines:light_off"});
- end,
- action_on = function (pos, node,ttl)
- local meta = minetest.get_meta(pos);
- local count = tonumber(meta:get_string("infotext")) or 0;
- meta:set_string("infotext",count+1); -- increase activate count
- end
- }
- },
-
-})
-
-
-
-punchset.known_nodes = {["basic_machines:mover"]=true,["basic_machines:keypad"]=true,["basic_machines:detector"]=true};
-
--- SETUP BY PUNCHING
-minetest.register_on_punchnode(function(pos, node, puncher, pointed_thing)
-
- -- STRANGE PROBLEM: if player doesnt move it takes another punch at same block for this function to run again, and it works normally if player moved at least one block from his previous position
- -- it only happens with keypad - maybe caused by formspec displayed..
-
- local name = puncher:get_player_name(); if name==nil then return end
- if punchset[name]== nil then -- set up punchstate
- punchset[name] = {}
- punchset[name].node = ""
- punchset[name].pos1 = {x=0,y=0,z=0};punchset[name].pos2 = {x=0,y=0,z=0};punchset[name].pos = {x=0,y=0,z=0};
- punchset[name].state = 0; -- 0 ready for punch, 1 ready for start position, 2 ready for end position
- return
- end
-
-
- -- check for known node names in case of first punch
- if punchset[name].state == 0 and not punchset.known_nodes[node.name] then return end
- -- from now on only punches with mover/keypad/... or setup punches
-
- if punchset.known_nodes[node.name] then -- check if player is suppose to be able to punch interact
- if node.name~="basic_machines:keypad" then -- keypad is supposed to be punch interactive!
- if minetest.is_protected(pos, name) then return end
- end
- end
-
- if node.name == "basic_machines:mover" then -- mover init code
- if punchset[name].state == 0 then
- -- if not puncher:get_player_control().sneak then
- -- return
- -- end
- minetest.chat_send_player(name, "MOVER: Now punch source1, source2, end position to set up mover.")
- punchset[name].node = node.name;punchset[name].pos = {x=pos.x,y=pos.y,z=pos.z};
- punchset[name].state = 1
- return
- end
- end
-
- if punchset[name].node == "basic_machines:mover" then -- mover code, not first punch
-
- if minetest.is_protected(pos,name) then
- minetest.chat_send_player(name, "MOVER: Punched position is protected. aborting.")
- punchset[name].node = "";
- punchset[name].state = 0; return
- end
-
- local meta = minetest.get_meta(punchset[name].pos); if not meta then return end;
- local range = meta:get_float("upgrade") or 1; range = range*max_range;
-
- if punchset[name].state == 1 then
- local privs = minetest.get_player_privs(puncher:get_player_name());
- if not privs.privs and (math.abs(punchset[name].pos.x - pos.x)>range or math.abs(punchset[name].pos.y - pos.y)>range or math.abs(punchset[name].pos.z - pos.z)>range) then
- minetest.chat_send_player(name, "MOVER: Punch closer to mover. reseting.")
- punchset[name].state = 0; return
- end
-
- if punchset[name].pos.x==pos.x and punchset[name].pos.y==pos.y and punchset[name].pos.z==pos.z then
- minetest.chat_send_player(name, "MOVER: Punch something else. aborting.")
- punchset[name].state = 0;
- return
- end
-
- punchset[name].pos1 = {x=pos.x,y=pos.y,z=pos.z};punchset[name].state = 2;
- machines.pos1[name] = punchset[name].pos1;machines.mark_pos1(name) -- mark position
- minetest.chat_send_player(name, "MOVER: Source1 position for mover set. Punch again to set source2 position.")
- return
- end
-
-
- if punchset[name].state == 2 then
- local privs = minetest.get_player_privs(puncher:get_player_name());
- if not privs.privs and (math.abs(punchset[name].pos.x - pos.x)>range or math.abs(punchset[name].pos.y - pos.y)>range or math.abs(punchset[name].pos.z - pos.z)>range) then
- minetest.chat_send_player(name, "MOVER: Punch closer to mover. reseting.")
- punchset[name].state = 0; return
- end
-
- if punchset[name].pos.x==pos.x and punchset[name].pos.y==pos.y and punchset[name].pos.z==pos.z then
- minetest.chat_send_player(name, "MOVER: Punch something else. aborting.")
- punchset[name].state = 0;
- return
- end
-
- punchset[name].pos11 = {x=pos.x,y=pos.y,z=pos.z};punchset[name].state = 3;
- machines.pos11[name] = {x=pos.x,y=pos.y,z=pos.z};
- machines.mark_pos11(name) -- mark pos11
- minetest.chat_send_player(name, "MOVER: Source2 position for mover set. Punch again to set target position.")
- return
- end
-
-
- if punchset[name].state == 3 then
- if punchset[name].node~="basic_machines:mover" then punchset[name].state = 0 return end
- local privs = minetest.get_player_privs(puncher:get_player_name());
-
- local elevator_mode = false;
- if punchset[name].pos.x == pos.x and punchset[name].pos.z == pos.z then -- check if elevator mode
- if math.abs(punchset[name].pos.y-pos.y)>3 then -- trying to make elevator?
-
- local meta = minetest.get_meta(punchset[name].pos);
- if meta:get_string("mode")=="object" then -- only if object mode
- --count number of diamond blocks to determine if elevator can be set up with this height distance
- local inv = meta:get_inventory();
- local upgrade = 0;
- if inv:get_stack("upgrade", 1):get_name() == "default:diamondblock" then
- upgrade = (inv:get_stack("upgrade", 1):get_count()) or 0;
- end
-
- local requirement = math.floor(math.abs(punchset[name].pos.y-pos.y)/100)+1;
- if upgraderange or math.abs(punchset[name].pos.y - pos.y)>range or math.abs(punchset[name].pos.z - pos.z)>range) then
- minetest.chat_send_player(name, "MOVER: Punch closer to mover. aborting.")
- punchset[name].state = 0; return
- end
-
- punchset[name].pos2 = {x=pos.x,y=pos.y,z=pos.z}; punchset[name].state = 0;
- machines.pos2[name] = punchset[name].pos2;machines.mark_pos2(name) -- mark pos2
-
- minetest.chat_send_player(name, "MOVER: End position for mover set.")
-
- local x0 = punchset[name].pos1.x-punchset[name].pos.x;
- local y0 = punchset[name].pos1.y-punchset[name].pos.y;
- local z0 = punchset[name].pos1.z-punchset[name].pos.z;
- local meta = minetest.get_meta(punchset[name].pos);
-
-
- local x1 = punchset[name].pos11.x-punchset[name].pos.x;
- local y1 = punchset[name].pos11.y-punchset[name].pos.y;
- local z1 = punchset[name].pos11.z-punchset[name].pos.z;
-
-
- local x2 = punchset[name].pos2.x-punchset[name].pos.x;
- local y2 = punchset[name].pos2.y-punchset[name].pos.y;
- local z2 = punchset[name].pos2.z-punchset[name].pos.z;
-
- if x0>x1 then x0,x1 = x1,x0 end -- this ensures that x0<=x1
- if y0>y1 then y0,y1 = y1,y0 end
- if z0>z1 then z0,z1 = z1,z0 end
-
- meta:set_int("x1",x1);meta:set_int("y1",y1);meta:set_int("z1",z1);
- meta:set_int("x0",x0);meta:set_int("y0",y0);meta:set_int("z0",z0);
- meta:set_int("x2",x2);meta:set_int("y2",y2);meta:set_int("z2",z2);
-
- meta:set_int("pc",0); meta:set_int("dim",(x1-x0+1)*(y1-y0+1)*(z1-z0+1))
- return
- end
- end
-
- -- KEYPAD
- if node.name == "basic_machines:keypad" then -- keypad init/usage code
-
- local meta = minetest.get_meta(pos);
- if not (meta:get_int("x0")==0 and meta:get_int("y0")==0 and meta:get_int("z0")==0) then -- already configured
- check_keypad(pos,name)-- not setup, just standard operation
- punchset[name].state = 0;
- return;
- else
- if minetest.is_protected(pos, name) then return minetest.chat_send_player(name, "KEYPAD: You must be able to build to set up keypad.") end
- --if meta:get_string("owner")~= name then minetest.chat_send_player(name, "KEYPAD: Only owner can set up keypad.") return end
- if punchset[name].state == 0 then
- minetest.chat_send_player(name, "KEYPAD: Now punch the target block.")
- punchset[name].node = node.name;punchset[name].pos = {x=pos.x,y=pos.y,z=pos.z};
- punchset[name].state = 1
- return
- end
- end
- end
-
- if punchset[name].node=="basic_machines:keypad" then -- keypad setup code
-
- if minetest.is_protected(pos,name) then
- minetest.chat_send_player(name, "KEYPAD: Punched position is protected. aborting.")
- punchset[name].node = "";
- punchset[name].state = 0; return
- end
-
- if punchset[name].state == 1 then
- local meta = minetest.get_meta(punchset[name].pos);
- local x = pos.x-punchset[name].pos.x;
- local y = pos.y-punchset[name].pos.y;
- local z = pos.z-punchset[name].pos.z;
- if math.abs(x)>max_range or math.abs(y)>max_range or math.abs(z)>max_range then
- minetest.chat_send_player(name, "KEYPAD: Punch closer to keypad. reseting.")
- punchset[name].state = 0; return
- end
-
- machines.pos1[name] = pos;
- machines.mark_pos1(name) -- mark pos1
-
- meta:set_int("x0",x);meta:set_int("y0",y);meta:set_int("z0",z);
- punchset[name].state = 0
- minetest.chat_send_player(name, "KEYPAD: Keypad target set with coordinates " .. x .. " " .. y .. " " .. z)
- meta:set_string("infotext", "Punch keypad to use it.");
- return
- end
- end
-
- -- DETECTOR "basic_machines:detector"
- if node.name == "basic_machines:detector" then -- detector init code
- local meta = minetest.get_meta(pos);
-
- --meta:get_string("owner")~= name
- if minetest.is_protected(pos,name) then minetest.chat_send_player(name, "DETECTOR: You must be able to build to set up detector.") return end
- if punchset[name].state == 0 then
- minetest.chat_send_player(name, "DETECTOR: Now punch the source block.")
- punchset[name].node = node.name;
- punchset[name].pos = {x=pos.x,y=pos.y,z=pos.z};
- punchset[name].state = 1
- return
- end
- end
-
- if punchset[name].node == "basic_machines:detector" then
-
- if minetest.is_protected(pos,name) then
- minetest.chat_send_player(name, "DETECTOR: Punched position is protected. aborting.")
- punchset[name].node = "";
- punchset[name].state = 0; return
- end
-
- if punchset[name].state == 1 then
- if math.abs(punchset[name].pos.x - pos.x)>max_range or math.abs(punchset[name].pos.y - pos.y)>max_range or math.abs(punchset[name].pos.z - pos.z)>max_range then
- minetest.chat_send_player(name, "DETECTOR: Punch closer to detector. aborting.")
- punchset[name].state = 0; return
- end
- minetest.chat_send_player(name, "DETECTOR: Now punch the target machine.")
- punchset[name].pos1 = {x=pos.x,y=pos.y,z=pos.z};
- machines.pos1[name] = pos;machines.mark_pos1(name) -- mark pos1
- punchset[name].state = 2
- return
- end
-
-
- if punchset[name].state == 2 then
- if math.abs(punchset[name].pos.x - pos.x)>max_range or math.abs(punchset[name].pos.y - pos.y)>max_range or math.abs(punchset[name].pos.z - pos.z)>max_range then
- minetest.chat_send_player(name, "DETECTOR: Punch closer to detector. aborting.")
- punchset[name].state = 0; return
- end
-
- if punchset[name].pos.x == pos.x and punchset[name].pos.y == pos.y and punchset[name].pos.z == pos.z then
- minetest.chat_send_player(name, "DETECTOR: Punch something else. aborting.")
- punchset[name].state = 0; return
- end
-
-
- minetest.chat_send_player(name, "DETECTOR: Setup complete.")
- machines.pos2[name] = pos;machines.mark_pos2(name) -- mark pos2
- local x = punchset[name].pos1.x-punchset[name].pos.x;
- local y = punchset[name].pos1.y-punchset[name].pos.y;
- local z = punchset[name].pos1.z-punchset[name].pos.z;
- local meta = minetest.get_meta(punchset[name].pos);
- meta:set_int("x0",x);meta:set_int("y0",y);meta:set_int("z0",z);
- x=pos.x-punchset[name].pos.x;y=pos.y-punchset[name].pos.y;z=pos.z-punchset[name].pos.z;
- meta:set_int("x2",x);meta:set_int("y2",y);meta:set_int("z2",z);
- punchset[name].state = 0
- return
- end
- end
-
-
- if punchset[name].node == "basic_machines:distributor" then
-
- if minetest.is_protected(pos,name) then
- minetest.chat_send_player(name, "DISTRIBUTOR: Punched position is protected. aborting.")
- punchset[name].node = "";
- punchset[name].state = 0; return
- end
-
- if punchset[name].state > 0 then
- if math.abs(punchset[name].pos.x - pos.x)>max_range or math.abs(punchset[name].pos.y - pos.y)>max_range or math.abs(punchset[name].pos.z - pos.z)>max_range then
- minetest.chat_send_player(name, "DISTRIBUTOR: Punch closer to distributor. aborting.")
- punchset[name].state = 0; return
- end
- minetest.chat_send_player(name, "DISTRIBUTOR: target set.")
- local meta = minetest.get_meta(punchset[name].pos);
- local x = pos.x-punchset[name].pos.x;
- local y = pos.y-punchset[name].pos.y;
- local z = pos.z-punchset[name].pos.z;
- local j = punchset[name].state;
-
- meta:set_int("x"..j,x);meta:set_int("y"..j,y);meta:set_int("z"..j,z);
- if x==0 and y==0 and z==0 then meta:set_int("active"..j,0) end
- machines.pos1[name] = pos;machines.mark_pos1(name) -- mark pos1
- punchset[name].state = 0;
- return
- end
-
- end
-
-
-
-end)
-
-
--- FORM PROCESSING for all machines
-minetest.register_on_player_receive_fields(function(player,formname,fields)
-
- -- MOVER
- local fname = "basic_machines:mover_"
- if string.sub(formname,0,string.len(fname)) == fname then
- local pos_s = string.sub(formname,string.len(fname)+1); local pos = minetest.string_to_pos(pos_s)
- local name = player:get_player_name(); if name==nil then return end
- local meta = minetest.get_meta(pos)
- local privs = minetest.get_player_privs(name);
- if (minetest.is_protected(pos,name) and not privs.privs) or not fields then return end -- only builder can interact
-
-
- if fields.help == "help" then
- local text = "version " .. basic_machines.version .. "\nSETUP: For interactive setup "..
- "punch the mover and then punch source1, source2, target node (follow instructions). Put charged battery within distance 1 from mover. For advanced setup right click mover. Positions are defined by x y z coordinates (see top of mover for orientation). Mover itself is at coordinates 0 0 0. "..
- "\n\nMODES of operation: normal (just teleport block), dig (digs and gives you resulted node - good for harvesting farms), drop "..
- "(drops node on ground), object (teleportation of player and objects. distance between source1/2 defines teleport radius). by setting filter you can specify move time for objects or names for players. "..
- "By setting 'filter' only selected nodes are moved.\nInventory mode can exchange items between node inventories. You need to select inventory name for source/target from the dropdown list on the right and enter node to be moved into filter."..
- "\n*advanced* You can reverse start/end position by setting reverse nonzero. This is useful for placing stuff at many locations-planting. If you put reverse=2/3 in transport mode it will disable parallel transport but will still do reverse effect with 3. If you activate mover with OFF signal it will toggle reverse." ..
- "\n\n FUEL CONSUMPTION depends on blocks to be moved and distance. For example, stone or tree is harder to move than dirt, harvesting wheat is very cheap and and moving lava is very hard."..
- "\n\n UPGRADE mover by moving mese blocks in upgrade inventory. Each mese block increases mover range by 10, fuel consumption is divided by (number of mese blocks)+1 in upgrade. Max 10 blocks are used for upgrade. Dont forget to click OK to refresh after upgrade. "..
- "\n\n Activate mover by keypad/detector signal or mese signal (if mesecons mod) .";
- local form = "size [6,7] textarea[0,0;6.5,8.5;help;MOVER HELP;".. text.."]"
- minetest.show_formspec(name, "basic_machines:help_mover", form)
- return
- end
-
- if fields.tabs then
- meta:set_int("seltab", tonumber(fields.tabs) or 1)
- local form = get_mover_form(pos,player)
- minetest.show_formspec(player:get_player_name(), "basic_machines:mover_"..minetest.pos_to_string(pos), form)
- return
- end
-
- if fields.OK == "OK" then --yyy
-
- local seltab = meta:get_int("seltab");
-
- if seltab == 2 then -- POSITIONS
-
- -- positions
- local x0,y0,z0,x1,y1,z1,x2,y2,z2;
- x0=tonumber(fields.x0) or 0;y0=tonumber(fields.y0) or -1;z0=tonumber(fields.z0) or 0
- x1=tonumber(fields.x1) or 0;y1=tonumber(fields.y1) or -1;z1=tonumber(fields.z1) or 0
- x2=tonumber(fields.x2) or 0;y2=tonumber(fields.y2) or 1;z2=tonumber(fields.z2) or 0;
-
- -- did the numbers change from last time?
- if meta:get_int("x0")~=x0 or meta:get_int("y0")~=y0 or meta:get_int("z0")~=z0 or
- meta:get_int("x1")~=x1 or meta:get_int("y1")~=y1 or meta:get_int("z1")~=z1 or
- meta:get_int("x2")~=x2 or meta:get_int("y2")~=y2 or meta:get_int("z2")~=z2 then
- -- are new numbers inside bounds?
- if not privs.privs and (math.abs(x1)>max_range or math.abs(y1)>max_range or math.abs(z1)>max_range or math.abs(x2)>max_range or math.abs(y2)>max_range or math.abs(z2)>max_range) then
- minetest.chat_send_player(name,"#mover: all coordinates must be between ".. -max_range .. " and " .. max_range .. ". For increased range set up positions by punching"); return
- end
- end
-
- --local range = meta:get_float("upgrade") or 1; range = range * max_range;
-
- local x = x0; x0 = math.min(x,x1); x1 = math.max(x,x1);
- local y = y0; y0 = math.min(y,y1); y1 = math.max(y,y1);
- local z = z0; z0 = math.min(z,z1); z1 = math.max(z,z1);
-
- if minetest.is_protected({x=pos.x+x0,y=pos.y+y0,z=pos.z+z0},name) then
- minetest.chat_send_player(name, "MOVER: position is protected. aborting.")
- return
- end
-
- if minetest.is_protected({x=pos.x+x1,y=pos.y+y1,z=pos.z+z1},name) then
- minetest.chat_send_player(name, "MOVER: position is protected. aborting.")
- return
- end
-
- meta:set_int("x0",x0);meta:set_int("y0",y0);meta:set_int("z0",z0);
- meta:set_int("x1",x1);meta:set_int("y1",y1);meta:set_int("z1",z1);
- meta:set_int("dim",(x1-x0+1)*(y1-y0+1)*(z1-z0+1))
- meta:set_int("x2",x2);meta:set_int("y2",y2);meta:set_int("z2",z2);
-
- if fields.reverse then
- meta:set_string("reverse",fields.reverse);
- end
-
- if fields.inv1 then
- meta:set_string("inv1",fields.inv1);
- end
-
- if fields.inv2 then
- meta:set_string("inv2",fields.inv2);
- end
-
- meta:set_string("infotext", "Mover block. Set up with source coordinates ".. x0 ..","..y0..","..z0.. " -> ".. x1 ..","..y1..","..z1.. " and target coord ".. x2 ..","..y2..",".. z2 .. ". Put charged battery next to it and start it with keypad/mese signal.");
-
- else -- MODE
-
- if fields.mode then
- meta:set_string("mode",fields.mode);
- end
-
-
- --filter
- local prefer = fields.prefer or "";
- if meta:get_string("prefer")~=prefer then
- meta:set_string("prefer",prefer);
- end
- end
-
- if meta:get_float("fuel")<0 then meta:set_float("fuel",0) end -- reset block
-
- -- display battery
- local fpos = find_and_connect_battery(pos);
-
- if not fpos then
- minetest.chat_send_player(name,"MOVER: please put battery nearby")
- else
- minetest.chat_send_player(name,"MOVER: battery found - displaying mark 1")
- machines.pos1[name] = fpos; machines.mark_pos1(name)
- end
-
- elseif fields.mode then
- meta:set_string("mode",fields.mode);
- local form = get_mover_form(pos,player)
- minetest.show_formspec(player:get_player_name(), "basic_machines:mover_"..minetest.pos_to_string(pos), form)
- return
- end
-
- return
- end
-
- -- KEYPAD
- fname = "basic_machines:keypad_"
- if string.sub(formname,0,string.len(fname)) == fname then
- local pos_s = string.sub(formname,string.len(fname)+1); local pos = minetest.string_to_pos(pos_s)
- local name = player:get_player_name(); if name==nil then return end
- local meta = minetest.get_meta(pos)
- local privs = minetest.get_player_privs(player:get_player_name());
- if (minetest.is_protected(pos,name) and not privs.privs) or not fields then return end -- only builder can interact
-
- if fields.help then
- local text = "target : represents coordinates ( x, y, z ) relative to keypad. (0,0,0) is keypad itself, (0,1,0) is one node above, (0,-1,0) one node below. X coordinate axes goes from east to west, Y from down to up, Z from south to north."..
- "\n\nPassword: enter password and press OK. Password will be encrypted. Next time you use keypad you will need to enter correct password to gain access."..
- "\n\nrepeat: number to control how many times activation is repeated after initial punch"..
-
- "\n\ntext: if set then text on target node will be changed. In case target is detector/mover, filter settings will be changed. Can be used for special operations."..
-
- "\n\n1=OFF/2=ON/3=TOGGLE control the way how target node is activated"..
-
- "\n**************************************************\nusage\n"..
-
- "\nJust punch ( left click ) keypad, then the target block will be activated."..
- "\nTo set text on other nodes ( text shows when you look at node ) just target the node and set nonempty text. Upon activation text will be set. When target node is another keypad, its \"text\" field will be set. When targets is mover/detector, its \"filter\" field will be set. To clear \"filter\" set text to \"@\". When target is distributor, you can change i-th target of distributor to mode mode with \"i mode\""..
-
- "\n\nkeyboard : to use keypad as keyboard for text input write \"@\" in \"text\" field and set any password. Next time keypad is used it will work as text input device."..
-
- "\n\ndisplaying messages to nearby players ( up to 5 blocks around keypad's target ): set text to \"!text\". Upon activation player will see \"text\" in their chat."..
-
- "\n\nplaying sound to nearby players : set text to \"$sound_name\""..
-
- "\n\nadvanced: "..
- "\ntext replacement : Suppose keypad A is set with text \"@some @. text @!\" and there are blocks on top of keypad A with infotext '1' and '2'. Suppose we target B with A and activate A. Then text of keypad B will be set to \"some 1. text 2!\""..
- "\nword extraction: Suppose similiar setup but now keypad A is set with text \"%1\". Then upon activation text of keypad B will be set to 1.st word of infotext";
-
- local form = "size [6,7] textarea[0,0;6.5,8.5;help;KEYPAD HELP;".. text.."]"
- minetest.show_formspec(name, "basic_machines:help_keypad", form)
- return
- end
-
- if fields.OK == "OK" then
- local x0,y0,z0,pass,mode;
- x0=tonumber(fields.x0) or 0;y0=tonumber(fields.y0) or 1;z0=tonumber(fields.z0) or 0
- pass = fields.pass or ""; mode = fields.mode or 1;
-
- if minetest.is_protected({x=pos.x+x0,y=pos.y+y0,z=pos.z+z0},name) then
- minetest.chat_send_player(name, "KEYPAD: position is protected. aborting.")
- return
- end
-
- if not privs.privs and (math.abs(x0)>max_range or math.abs(y0)>max_range or math.abs(z0)>max_range) then
- minetest.chat_send_player(name,"#keypad: all coordinates must be between ".. -max_range .. " and " .. max_range); return
- end
- meta:set_int("x0",x0);meta:set_int("y0",y0);meta:set_int("z0",z0);
-
- if fields.pass then
- if fields.pass~="" and string.len(fields.pass)<=16 then -- dont replace password with hash which is longer - 27 chars
- pass=minetest.get_password_hash(pos.x, pass..pos.y);pass=minetest.get_password_hash(pos.y, pass..pos.z);
- meta:set_string("pass",pass);
- end
- end
-
- if fields.text then
- meta:set_string("text", fields.text);
- if string.find(fields.text, "!") then minetest.log("action", string.format("%s set up keypad for message display at %s", name, minetest.pos_to_string(pos))) end
- end
-
- meta:set_int("iter",math.min(tonumber(fields.iter) or 1,500));meta:set_int("mode",mode);
- meta:set_string("infotext", "Punch keypad to use it.");
- if pass~="" then
- if fields.text~="@" then
- meta:set_string("infotext",meta:get_string("infotext").. ". Password protected.");
- else
- meta:set_string("infotext","punch keyboard to use it.");
- end
- end
-
- end
- return
- end
-
- fname = "basic_machines:check_keypad_"
- if string.sub(formname,0,string.len(fname)) == fname then
- local pos_s = string.sub(formname,string.len(fname)+1); local pos = minetest.string_to_pos(pos_s)
- local name = player:get_player_name(); if name==nil then return end
- local meta = minetest.get_meta(pos)
-
- if fields.OK == "OK" then
-
- local pass;
- pass = fields.pass or "";
-
- if meta:get_string("text")=="@" then -- keyboard mode
- meta:set_string("input", pass);
- meta:set_int("count",1);
- use_keypad(pos,machines_TTL,0);
- return
- end
-
-
- pass=minetest.get_password_hash(pos.x, pass..pos.y);pass=minetest.get_password_hash(pos.y, pass..pos.z);
-
- if pass~=meta:get_string("pass") then
- minetest.chat_send_player(name,"ACCESS DENIED. WRONG PASSWORD.")
- return
- end
- minetest.chat_send_player(name,"ACCESS GRANTED.")
-
- if meta:get_int("count")<=0 then -- only accept new operation requests if idle
- meta:set_int("count",meta:get_int("iter"));
- meta:set_int("active_repeats",0);
- use_keypad(pos,machines_TTL,0)
- else
- meta:set_int("count",0);
- meta:set_string("infotext","operation aborted by user. punch to activate.") -- reset
- end
-
- return
- end
- end
-
- -- DETECTOR
- local fname = "basic_machines:detector_"
- if string.sub(formname,0,string.len(fname)) == fname then
- local pos_s = string.sub(formname,string.len(fname)+1); local pos = minetest.string_to_pos(pos_s)
- local name = player:get_player_name(); if name==nil then return end
- local meta = minetest.get_meta(pos)
- local privs = minetest.get_player_privs(player:get_player_name());
- if (minetest.is_protected(pos,name) and not privs.privs) or not fields then return end -- only builder
-
- --minetest.chat_send_all("formname " .. formname .. " fields " .. dump(fields))
-
- if fields.help == "help" then
- local text = "SETUP: right click or punch and follow chat instructions. With detector you can detect nodes, objects, players, or items inside inventories."..
- "If detector activates it will trigger machine at target position.\n\nThere are 4 modes of operation - node/player/object/inventory detection. Inside node/player/object "..
- "write node/player/object name. If you detect players/objects you can specify range of detection. If you want detector to activate target precisely when its not triggered set NOT to 1\n\n"..
- "For example, to detect empty space write air, to detect tree write default:tree, to detect ripe wheat write farming:wheat_8, for flowing water write default:water_flowing ... "..
- "If source position is chest it will look into it and check if there are items inside. If mode is inventory it will check for items in specified inventory of source node."..
- "\n\nADVANCED: you can select second source and then select AND/OR from the right top dropdown list to do logical operations. You can also filter output signal:\n -2=only OFF,-1=NOT/0/1=normal,2=only ON, 3 only if changed"..
- " 4 = if target keypad set its text to detected object name" ;
- local form = "size [5.5,5.5] textarea[0,0;6,7;help;DETECTOR HELP;".. text.."]"
- minetest.show_formspec(name, "basic_machines:help_detector", form)
- end
-
- if fields.OK == "OK" then
-
-
- local x0,y0,z0,x1,y1,z1,x2,y2,z2,r,node,NOT;
- x0=tonumber(fields.x0) or 0;y0=tonumber(fields.y0) or 0;z0=tonumber(fields.z0) or 0
- x1=tonumber(fields.x1) or 0;y1=tonumber(fields.y1) or 0;z1=tonumber(fields.z1) or 0
- x2=tonumber(fields.x2) or 0;y2=tonumber(fields.y2) or 0;z2=tonumber(fields.z2) or 0
- r=tonumber(fields.r) or 1;
- NOT = tonumber(fields.NOT)
-
-
- if minetest.is_protected({x=pos.x+x0,y=pos.y+y0,z=pos.z+z0},name) then
- minetest.chat_send_player(name, "DETECTOR: position is protected. aborting.")
- return
- end
-
- if minetest.is_protected({x=pos.x+x2,y=pos.y+y2,z=pos.z+z2},name) then
- minetest.chat_send_player(name, "DETECTOR: position is protected. aborting.")
- return
- end
-
-
- if not privs.privs and (math.abs(x0)>max_range or math.abs(y0)>max_range or math.abs(z0)>max_range or math.abs(x1)>max_range or math.abs(y1)>max_range or math.abs(z1)>max_range) then
- minetest.chat_send_player(name,"#detector: all coordinates must be between ".. -max_range .. " and " .. max_range); return
- end
-
- if fields.inv1 then
- meta:set_string("inv1",fields.inv1);
- end
-
- meta:set_int("x0",x0);meta:set_int("y0",y0);meta:set_int("z0",z0);
- meta:set_int("x1",x1);meta:set_int("y1",y1);meta:set_int("z1",z1);
- meta:set_int("x2",x2);meta:set_int("y2",y2);meta:set_int("z2",z2);
-
- meta:set_int("r",math.min(r,10));
- meta:set_int("NOT",NOT);
- meta:set_string("node",fields.node or "");
-
- local mode = fields.mode or "node";
- meta:set_string("mode",mode);
- local op = fields.op or "";
- meta:set_string("op",op);
-
- end
- return
- end
-
-
- -- DISTRIBUTOR
- local fname = "basic_machines:distributor_"
- if string.sub(formname,0,string.len(fname)) == fname then
- local pos_s = string.sub(formname,string.len(fname)+1); local pos = minetest.string_to_pos(pos_s)
- local name = player:get_player_name(); if name==nil then return end
- local meta = minetest.get_meta(pos)
- local privs = minetest.get_player_privs(player:get_player_name());
- if (minetest.is_protected(pos,name) and not privs.privs) or not fields then return end -- only builder
- --minetest.chat_send_all("formname " .. formname .. " fields " .. dump(fields))
-
- if fields.OK == "OK" then
-
- local posf = {}; local active = {};
- local n = meta:get_int("n");
- for i = 1,n do
- posf[i]={x=tonumber(fields["x"..i]) or 0,y=tonumber(fields["y"..i]) or 0,z=tonumber(fields["z"..i]) or 0};
- active[i]=tonumber(fields["active"..i]) or 0;
-
- if (not (privs.privs) and math.abs(posf[i].x)>max_range or math.abs(posf[i].y)>max_range or math.abs(posf[i].z)>max_range) then
- minetest.chat_send_player(name,"#distributor: all coordinates must be between ".. -max_range .. " and " .. max_range);
- return
- end
-
- meta:set_int("x"..i,posf[i].x);meta:set_int("y"..i,posf[i].y);meta:set_int("z"..i,posf[i].z);
- if posf[i].x==0 and posf[i].y==0 and posf[i].z==0 then
- meta:set_int("active"..i,0); -- no point in activating itself
- else
- meta:set_int("active"..i,active[i]);
- end
- if fields.delay then
- meta:set_float("delay", fields.delay);
- end
- end
- end
-
- if fields["ADD"] then
- local n = meta:get_int("n");
- if n<16 then meta:set_int("n",n+1); end -- max 16 outputs
- local form = get_distributor_form(pos,player)
- minetest.show_formspec(player:get_player_name(), "basic_machines:distributor_"..minetest.pos_to_string(pos), form)
- return
- end
-
- -- SHOWING TARGET
- local j=-1;local n = meta:get_int("n");
- for i = 1,n do if fields["SHOW"..i] then j = i end end
- --show j-th point
- if j>0 then
- local posf={x=tonumber(fields["x"..j]) or 0,y=tonumber(fields["y"..j]) or 0,z=tonumber(fields["z"..j]) or 0};
- machines.pos1[player:get_player_name()] = {x=posf.x+pos.x,y=posf.y+pos.y,z=posf.z+pos.z};
- machines.mark_pos1(player:get_player_name())
- return;
- end
-
- --SETUP TARGET
- j=-1;
- for i = 1,n do if fields["SET"..i] then j = i end end
- -- set up j-th point
- if j>0 then
- punchset[name].node = "basic_machines:distributor";
- punchset[name].state = j
- punchset[name].pos = pos;
- minetest.chat_send_player(name,"[DISTRIBUTOR] punch the position to set target "..j);
- return;
- end
-
- -- REMOVE TARGET
- if n>0 then
- j=-1;
- for i = 1,n do if fields["X"..i] then j = i end end
- -- remove j-th point
- if j>0 then
- for i=j,n-1 do
- meta:set_int("x"..i, meta:get_int("x"..(i+1)))
- meta:set_int("y"..i, meta:get_int("y"..(i+1)))
- meta:set_int("z"..i, meta:get_int("z"..(i+1)))
- meta:set_int("active"..i, meta:get_int("active"..(i+1)))
- end
-
- meta:set_int("n",n-1);
- local form = get_distributor_form(pos,player)
- minetest.show_formspec(player:get_player_name(), "basic_machines:distributor_"..minetest.pos_to_string(pos), form)
- return;
- end
- end
-
- if fields.help == "help" then
- local text = "SETUP: to select target nodes for activation click SET then click target node.\n"..
- "You can add more targets with ADD. To see where target node is click SHOW button next to it.\n"..
- "Numbers in each row represent (from left to right) : first 3 numbers are target coordinates,\n"..
- "last number controls how signal is passed to target. For example, to only pass OFF signal use -2,\n"..
- "to only pass ON use 2, -1 negates the signal, 1 = pass original signal, 0 blocks signal\n"..
- "delay option adds delay to activations, in seconds. With negative delay activation is randomized with probability -delay/1000.\n\n"..
- "ADVANCED: you can use distributor as an event handler. First you must deactivate first target by putting 0 at\n"..
- "last place in first line. Meanings of first 2 numbers are as follows: first number 0/1 controls if node/n".. "listens to failed interact attempts around it, second number -1/1 listens to chat and can mute it";
- local form = "size [5.5,5.5] textarea[0,0;6,7;help;DISTRIBUTOR HELP;".. text.."]"
- minetest.show_formspec(name, "basic_machines:help_distributor", form)
- end
-
- end
-
-
-end)
-
-
-
--- CRAFTS --
-
--- minetest.register_craft({
- -- output = "basic_machines:keypad",
- -- recipe = {
- -- {"default:stick"},
- -- {"default:wood"},
- -- }
--- })
-
--- minetest.register_craft({
- -- output = "basic_machines:mover",
- -- recipe = {
- -- {"default:mese_crystal", "default:mese_crystal","default:mese_crystal"},
- -- {"default:mese_crystal", "default:mese_crystal","default:mese_crystal"},
- -- {"default:stone", "basic_machines:keypad", "default:stone"}
- -- }
--- })
-
--- minetest.register_craft({
- -- output = "basic_machines:detector",
- -- recipe = {
- -- {"default:mese_crystal", "default:mese_crystal"},
- -- {"default:mese_crystal", "default:mese_crystal"},
- -- {"basic_machines:keypad",""}
- -- }
--- })
-
--- minetest.register_craft({
- -- output = "basic_machines:light_on",
- -- recipe = {
- -- {"default:torch", "default:torch"},
- -- {"default:torch", "default:torch"}
- -- }
--- })
-
-
--- minetest.register_craft({
- -- output = "basic_machines:distributor",
- -- recipe = {
- -- {"default:steel_ingot"},
- -- {"default:mese_crystal"},
- -- {"basic_machines:keypad"}
- -- }
--- })
-
--- minetest.register_craft({
- -- output = "basic_machines:clockgen",
- -- recipe = {
- -- {"default:diamondblock"},
- -- {"basic_machines:keypad"}
- -- }
--- })
\ No newline at end of file
diff --git a/basic_machines/protect.lua b/basic_machines/protect.lua
deleted file mode 100644
index 6bcf063..0000000
--- a/basic_machines/protect.lua
+++ /dev/null
@@ -1,54 +0,0 @@
--- adds event handler for attempt to dig in protected area
-
--- tries to activate specially configured nearby distributor at points with coordinates of form 20i, registers dig attempts in radius 10 around
--- distributor must have first target filter set to 0 ( disabled ) to handle dig events
-
-local old_is_protected = minetest.is_protected
-local round = math.floor;
-local machines_TTL=5
-
-function minetest.is_protected(pos, digger)
-
- local is_protected = old_is_protected(pos, digger);
- if is_protected then -- only if protected
- local r = 20;local p = {x=round(pos.x/r+0.5)*r,y=round(pos.y/r+0.5)*r+1,z=round(pos.z/r+0.5)*r}
- if minetest.get_node(p).name == "basic_machines:distributor" then -- attempt to activate distributor at special grid location: coordinates of the form 10+20*i
- local meta = minetest.get_meta(p);
- if meta:get_int("active1") == 0 then -- first output is disabled, indicating ready to be used as event handler
- if meta:get_int("x1") ~= 0 then -- trigger protection event
- meta:set_string("infotext",digger); -- record diggers name onto distributor
- local table = minetest.registered_nodes["basic_machines:distributor"];
- local effector=table.mesecons.effector;
- local node = nil;
- effector.action_on(p,node,machines_TTL);
- end
- end
- end
- end
- return is_protected;
-
-end
-
-minetest.register_on_chat_message(function(name, message)
- local player = minetest.get_player_by_name(name);
- if not player then return end
- local pos = player:getpos();
- local r = 20;local p = {x=round(pos.x/r+0.5)*r,y=round(pos.y/r+0.5)*r+1,z=round(pos.z/r+0.5)*r}
- --minetest.chat_send_all(minetest.pos_to_string(p))
- if minetest.get_node(p).name == "basic_machines:distributor" then -- attempt to activate distributor at special grid location: coordinates of the form 20*i
- local meta = minetest.get_meta(p);
- if meta:get_int("active1") == 0 then -- first output is disabled, indicating ready to be used as event handler
- local y1 = meta:get_int("y1");
- if y1 ~= 0 then -- chat event, positive relays message, negative drops it
- meta:set_string("infotext",message); -- record diggers message
- local table = minetest.registered_nodes["basic_machines:distributor"];
- local effector=table.mesecons.effector;
- local node = nil;
- effector.action_on(p,node,machines_TTL);
- if y1<0 then return true
- end
- end
- end
- end
-end
-)
\ No newline at end of file
diff --git a/basic_machines/recycler.lua b/basic_machines/recycler.lua
deleted file mode 100644
index e80fea7..0000000
--- a/basic_machines/recycler.lua
+++ /dev/null
@@ -1,244 +0,0 @@
--- rnd 2015:
-
--- this node works as a reverse of crafting process with a 25% loss of items (aka recycling). You can select which recipe to use when recycling.
--- There is a fuel cost to recycle
-
--- prevent unrealistic recyclings
-local no_recycle_list = {
- ["default:steel_ingot"]=1,["default:copper_ingot"]=1,["default:bronze_ingot"]=1,["default:gold_ingot"]=1,
- ["dye:white"]=1,["dye:grey"]=1,["dye:dark_grey"]=1,["dye:black"]=1,
- ["dye:violet"]=1,["dye:blue"]=1,["dye:cyan"]=1,["dye:dark_green"]=1,
- ["dye:green"]=1,["dye:yellow"]=1,["dye:brown"]=1,["dye:orange"]=1,
- ["dye:red"]=1,["dye:magenta"]=1,["dye:pink"]=1,
-}
-
-
-local recycler_process = function(pos)
-
- local node = minetest.get_node({x=pos.x,y=pos.y-1,z=pos.z}).name;
- local meta = minetest.get_meta(pos);local inv = meta:get_inventory();
-
- -- FUEL CHECK
- local fuel = meta:get_float("fuel");
-
- if fuel-1<0 then -- we need new fuel, check chest below
- local fuellist = inv:get_list("fuel")
- if not fuellist then return end
-
- local fueladd, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
-
- local supply=0;
- if fueladd.time == 0 then -- no fuel inserted, try look for outlet
- -- No valid fuel in fuel list
- supply = basic_machines.check_power({x=pos.x,y=pos.y-1,z=pos.z},1) or 0;
- if supply>0 then
- fueladd.time = 40*supply -- same as 10 coal
- else
- meta:set_string("infotext", "Please insert fuel.");
- return;
- end
- else
- if supply==0 then -- Take fuel from fuel list if no supply available
- inv:set_stack("fuel", 1, afterfuel.items[1])
- fueladd.time = fueladd.time*0.1; -- thats 4 for coal
- end
- end
- if fueladd.time>0 then
- fuel=fuel + fueladd.time
- meta:set_float("fuel",fuel);
- meta:set_string("infotext", "added fuel furnace burn time " .. fueladd.time .. ", fuel status " .. fuel);
- end
- if fuel-1<0 then return end
- end
-
-
-
- -- RECYCLING: check out inserted items
- local stack = inv:get_stack("src",1);
- if stack:is_empty() then return end; -- nothing to do
-
- local src_item = stack:to_string();
- local p=string.find(src_item," "); if p then src_item = string.sub(src_item,1,p-1) end -- take first word to determine what item was
-
- -- look if we already handled this item
- local known_recipe=true;
- if src_item~=meta:get_string("node") then-- did we already handle this? if yes read from cache
- meta:set_string("node",src_item);
- meta:set_string("itemlist","{}");
- meta:set_int("reqcount",0);
- known_recipe=false;
- end
-
- local itemlist, reqcount;
- reqcount = 1; -- needed count of materials for recycle to work
-
- if not known_recipe then
-
- if no_recycle_list[src_item] then meta:set_string("node","") return end -- dont allow recycling of forbidden items
-
- local recipe = minetest.get_all_craft_recipes( src_item );
- local recipe_id = tonumber(meta:get_int("recipe")) or 1;
-
- if not recipe then
- return
- else
- itemlist = recipe[recipe_id];
- if not itemlist then meta:set_string("node","") return end;
- itemlist=itemlist.items;
- end
- local output = recipe[recipe_id].output or "";
- if string.find(output," ") then
- local par = string.find(output," ");
- --if (tonumber(string.sub(output, par)) or 0)>1 then itemlist = {} end
-
- if par then
- reqcount = tonumber(string.sub(output, par)) or 1;
- end
-
- end
-
- meta:set_string("itemlist",minetest.serialize(itemlist)); -- read cached itemlist
- meta:set_int("reqcount",reqcount);
- else
- itemlist=minetest.deserialize(meta:get_string("itemlist")) or {};
- reqcount = meta:get_int("reqcount") or 1;
- end
-
- if stack:get_count()0 then
- if pos.y>1500 then add_energy=2*add_energy end -- in space recharge is more efficient
- crystal = true;
- if add_energy<=capacity then
- stack:take_item(1);
- inv:set_stack("fuel", 1, stack)
- else
- meta:set_string("infotext", "recharge problem: capacity " .. capacity .. ", needed " .. energy+add_energy)
- return energy
- end
- else -- try do determine caloric value of fuel inside battery
- local fuellist = inv:get_list("fuel");if not fuellist then return energy end
- local fueladd, afterfuel = minetest.get_craft_result({method = "fuel", width = 1, items = fuellist})
- if fueladd.time > 0 then
- add_energy = fueladd.time/40;
- if energy+add_energy<=capacity then
- inv:set_stack("fuel", 1, afterfuel.items[1]);
- end
- end
- end
-
- if add_energy>0 then
- energy=energy+add_energy
- if energy<0 then energy = 0 end
- if energy>capacity then energy = capacity end -- excess energy is wasted
- meta:set_float("energy",energy);
- meta:set_string("infotext", "(R) energy: " .. math.ceil(energy*10)/10 .. " / ".. capacity);
- minetest.sound_play("electric_zap", {pos=pos,gain=0.05,max_hear_distance = 8,})
- end
-
- local full_coef = math.floor(energy/capacity*3); if full_coef > 2 then full_coef = 2 end
- minetest.swap_node(pos,{name = "basic_machines:battery_".. full_coef}) -- graphic energy
-
- return energy; -- new battery energy level
-end
-
-battery_upgrade = function(pos)
- local meta = minetest.get_meta(pos);
- local inv = meta:get_inventory();
- local count1,count2;count1=0;count2=0;
- local stack,item,count;
- for i=1,4 do
- stack = inv:get_stack("upgrade", i);item = stack:get_name();count= stack:get_count();
- if item == "default:mese" then
- count1=count1+count
- elseif item == "default:diamondblock" then
- count2=count2+count
- end
- end
- --if count11500 then count1 = 2*count1; count2=2*count2 end -- space increases efficiency
-
-
- meta:set_int("upgrade",count2); -- diamond for power
- -- adjust capacity
- --yyy
- local capacity = 3+3*count1; -- mese for capacity
- local maxpower = 1+count2*2; -- old 99 upgrade -> 200 power
-
- capacity = math.ceil(capacity*10)/10;
- local energy = 0;
- meta:set_float("capacity",capacity)
- meta:set_float("maxpower",maxpower)
- meta:set_float("energy",0)
- meta:set_string("infotext", "energy: " .. math.ceil(energy*10)/10 .. " / ".. capacity);
-end
-
-local machines_activate_furnace = minetest.registered_nodes["default:furnace"].on_metadata_inventory_put; -- this function will activate furnace
-
-minetest.register_node("basic_machines:battery_0", {
- description = "battery - stores energy, generates energy from fuel, can power nearby machines, or accelerate/run furnace above it. Its upgradeable.",
- tiles = {"basic_machine_outlet.png","basic_machine_side.png","basic_machine_battery_0.png"},
- groups = {cracky=3, mesecon_effector_on = 1},
- sounds = default.node_sound_wood_defaults(),
- after_place_node = function(pos, placer)
- local meta = minetest.get_meta(pos);
- meta:set_string("infotext","battery - stores energy, generates energy from fuel, can power nearby machines, or accelerate/run furnace above it when activated by keypad");
- meta:set_string("owner",placer:get_player_name());
- local inv = meta:get_inventory();inv:set_size("fuel", 1*1); -- place to put crystals
- inv:set_size("upgrade", 2*2);
- meta:set_int("upgrade",0); -- upgrade level determines energy storage capacity and max energy output
- meta:set_float("capacity",3);meta:set_float("maxpower",1);
- meta:set_float("energy",0);
- end,
-
- mesecons = {effector = {
- action_on = function (pos, node,ttl)
- if type(ttl)~="number" then ttl = 1 end
- if ttl<0 then return end -- machines_TTL prevents infinite recursion
-
- local meta = minetest.get_meta(pos);
- local energy = meta:get_float("energy");
- local capacity = meta:get_float("capacity");
- local full_coef = math.floor(energy/capacity*3);
-
- -- try to power furnace on top of it
- if energy>=1 then -- need at least 1 energy
- pos.y=pos.y+1; local node = minetest.get_node(pos).name;
-
- if node== "default:furnace" or node=="default:furnace_active" then
- local fmeta = minetest.get_meta(pos);
- local fuel_totaltime = fmeta:get_float("fuel_totaltime") or 0;
- local fuel_time = fmeta:get_float("fuel_time") or 0;
- local t0 = meta:get_int("ftime"); -- furnace time
- local t1 = minetest.get_gametime();
-
- if t1-t04 then -- accelerated cooking
- local src_time = fmeta:get_float("src_time") or 0
- energy = energy - 0.25*upgrade; -- use energy to accelerate burning
-
-
- if fuel_time>40 or fuel_totaltime == 0 or node=="default:furnace" then -- to add burn time: must burn for at least 40 secs or furnace out of fuel
-
- fmeta:set_float("fuel_totaltime",60);fmeta:set_float("fuel_time",0) -- add 60 second burn time to furnace
- energy=energy-0.5; -- use up energy to add fuel
-
- -- make furnace start if not already started
- if node~="default:furnace_active" and machines_activate_furnace then machines_activate_furnace(pos) end
- -- update energy display
- end
-
-
- if energy<0 then
- energy = 0
- else -- only accelerate if we had enough energy, note: upgrade*0.1*0.25=1 then -- no need to recharge yet, will still work next time
- local full_coef_new = math.floor(energy/capacity*3); if full_coef_new>2 then full_coef_new = 2 end
- pos.y = pos.y-1;
- if full_coef_new ~= full_coef then minetest.swap_node(pos,{name = "basic_machines:battery_".. full_coef_new}) end
- return
- else
- local infotext = meta:get_string("infotext");
- local new_infotext = "furnace needs at least 1 energy";
- if new_infotext~=infotext then -- dont update unnecesarilly
- meta:set_string("infotext", new_infotext);
- pos.y=pos.y-1; -- so that it points to battery again!
- end
- end
- else
- pos.y=pos.y-1;
- end
-
- end
-
- -- try to recharge by converting inserted fuel/power cells into energy
-
- if energy2 then full_coef_new = 2 end
- if full_coef_new ~= full_coef then minetest.swap_node(pos,{name = "basic_machines:battery_".. full_coef_new}) end
-
- end
- }},
-
- on_rightclick = function(pos, node, player, itemstack, pointed_thing)
- local meta = minetest.get_meta(pos);
- local privs = minetest.get_player_privs(player:get_player_name());
- if minetest.is_protected(pos,player:get_player_name()) and not privs.privs then return end -- only owner can interact with recycler
- battery_update_meta(pos);
- end,
-
- on_receive_fields = function(pos, formname, fields, sender)
- if fields.quit then return end
- local meta = minetest.get_meta(pos);
- battery_update_meta(pos);
- end,
-
- allow_metadata_inventory_put = function(pos, listname, index, stack, player)
- local meta = minetest.get_meta(pos);
- local privs = minetest.get_player_privs(player:get_player_name());
- if minetest.is_protected(pos,player:get_player_name()) and not privs.privs then return 0 end
- return stack:get_count();
- end,
-
- allow_metadata_inventory_take = function(pos, listname, index, stack, player)
- local meta = minetest.get_meta(pos);
- local privs = minetest.get_player_privs(player:get_player_name());
- if minetest.is_protected(pos,player:get_player_name()) and not privs.privs then return 0 end
- return stack:get_count();
- end,
-
- on_metadata_inventory_put = function(pos, listname, index, stack, player)
- if listname=="fuel" then
- battery_recharge(pos);
- battery_update_meta(pos);
- elseif listname == "upgrade" then
- battery_upgrade(pos);
- battery_update_meta(pos);
- end
- return stack:get_count();
- end,
-
- on_metadata_inventory_take = function(pos, listname, index, stack, player)
- if listname == "upgrade" then
- battery_upgrade(pos);
- battery_update_meta(pos);
- end
- return stack:get_count();
- end,
-
- allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
- return 0;
- end,
-
- can_dig = function(pos)
- local meta = minetest.get_meta(pos);
- if meta:get_int("upgrade")~=0 then return false else return true end
- end
-
-})
-
-
-
--- GENERATOR
-
-local generator_update_meta = function(pos)
- local meta = minetest.get_meta(pos);
- local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
-
- local form =
- "size[8,6.5]" .. -- width, height
- "label[0,0;POWER CRYSTALS] ".."label[6,0;UPGRADE] "..
- "label[1,1;UPGRADE LEVEL ".. meta:get_int("upgrade").." (generator)]"..
- "list["..list_name..";fuel;0.,0.5;1,1;]"..
- "list["..list_name..";upgrade;6.,0.5;2,1;]"..
- "list[current_player;main;0,2.5;8,4;]"..
- "button[4.5,1.5;1.5,1;OK;REFRESH]"..
- "button[6,1.5;1.5,1;help;help]"..
- "listring["..list_name..";fuel]"..
- "listring[current_player;main]"..
- "listring["..list_name..";upgrade]"..
- "listring[current_player;main]"
- meta:set_string("formspec", form)
-end
-
-
-
-generator_upgrade = function(pos)
- local meta = minetest.get_meta(pos);
- local inv = meta:get_inventory();
- local stack,item,count;
- count = 0
- for i=1,2 do
- stack = inv:get_stack("upgrade", i);item = stack:get_name();
- if item == "basic_machines:generator" then
- count= count + stack:get_count();
- end
- end
- meta:set_int("upgrade",count);
-end
-
-minetest.register_node("basic_machines:generator", {
- description = "Generator - very expensive, generates power crystals that provide power. Its upgradeable.",
- tiles = {"basic_machine_generator.png"},
- groups = {cracky=3, mesecon_effector_on = 1},
- sounds = default.node_sound_wood_defaults(),
- after_place_node = function(pos, placer)
- local meta = minetest.get_meta(pos);
- meta:set_string("infotext","generator - generates power crystals that provide power. Upgrade with up to 99 gold/diamond blocks.");
- meta:set_string("owner",placer:get_player_name());
- local inv = meta:get_inventory();
- inv:set_size("fuel", 1*1); -- here generated power crystals are placed
- inv:set_size("upgrade", 2*1);
- meta:set_int("upgrade",0); -- upgrade level determines quality of produced crystals
-
- end,
-
- on_rightclick = function(pos, node, player, itemstack, pointed_thing)
- local meta = minetest.get_meta(pos);
- local privs = minetest.get_player_privs(player:get_player_name());
- if minetest.is_protected(pos,player:get_player_name()) and not privs.privs then return end -- only owner can interact with recycler
- generator_update_meta(pos);
- end,
-
- on_receive_fields = function(pos, formname, fields, sender)
- if fields.quit then return end
- if fields.help then
- local text = "Generator slowly produces power crystals. Those can be used to recharge batteries and come in 3 flavors:\n\n low level (0-4), medium level (5-19) and high level (20+). Upgrading the generator (upgrade with generators) will increase the rate at which the crystals are produced.\n\nYou can automate the process of battery recharging by using mover in inventory mode, taking from inventory \"fuel\"";
- local form = "size [6,7] textarea[0,0;6.5,8.5;help;GENERATOR HELP;".. text.."]"
- minetest.show_formspec(sender:get_player_name(), "basic_machines:help_mover", form)
- return
- end
- local meta = minetest.get_meta(pos);
-
-
- generator_update_meta(pos);
- end,
-
- allow_metadata_inventory_put = function(pos, listname, index, stack, player)
- local meta = minetest.get_meta(pos);
- local privs = minetest.get_player_privs(player:get_player_name());
- if minetest.is_protected(pos,player:get_player_name()) and not privs.privs then return 0 end
- return stack:get_count();
- end,
-
- allow_metadata_inventory_take = function(pos, listname, index, stack, player)
- local meta = minetest.get_meta(pos);
- local privs = minetest.get_player_privs(player:get_player_name());
- if minetest.is_protected(pos,player:get_player_name()) and not privs.privs then return 0 end
- return stack:get_count();
- end,
-
- on_metadata_inventory_put = function(pos, listname, index, stack, player)
- if listname == "upgrade" then
- generator_upgrade(pos);
- generator_update_meta(pos);
- end
- return stack:get_count();
- end,
-
- on_metadata_inventory_take = function(pos, listname, index, stack, player)
- if listname == "upgrade" then
- generator_upgrade(pos);
- generator_update_meta(pos);
- end
- return stack:get_count();
- end,
-
- allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
- return 0;
- end,
-
- can_dig = function(pos)
- local meta = minetest.get_meta(pos);
- if meta:get_int("upgrade")~=0 then return false else return true end
- end
-
-})
-
-
-minetest.register_abm({
- nodenames = {"basic_machines:generator"},
- neighbors = {""},
- interval = 19,
- chance = 1,
- action = function(pos, node, active_object_count, active_object_count_wider)
- local meta = minetest.get_meta(pos);
- local upgrade = meta:get_int("upgrade");
- local inv = meta:get_inventory();
- local stack = inv:get_stack("fuel", 1);
- local crystal, text;
-
- if upgrade >= 20 then
- crystal = "basic_machines:power_rod " .. math.floor(1+(upgrade-20)*9/178)
- text = "high upgrade: power rod";
- elseif upgrade >=5 then
- crystal ="basic_machines:power_block " .. math.floor(1+(upgrade-5)*9/15);
- text = "medium upgrade: power block";
- else
- crystal ="basic_machines:power_cell " .. math.floor(1+2*upgrade);
- text = "low upgrade: power cell";
- end
- local morecrystal = ItemStack(crystal)
- stack:add_item(morecrystal);
- inv:set_stack("fuel", 1, stack)
- meta:set_string("infotext",text)
- end
-})
-
-
-
-
--- API for power distribution
-function basic_machines.check_power(pos, power_draw) -- mover checks power source - battery
-
- --minetest.chat_send_all(" battery: check_power " .. minetest.pos_to_string(pos) .. " " .. power_draw)
- local batname = "basic_machines:battery";
- if not string.find(minetest.get_node(pos).name,batname) then
- return -1 -- battery not found!
- end
-
- local meta = minetest.get_meta(pos);
- local energy = meta:get_float("energy");
- local capacity = meta:get_float("capacity");
- local maxpower = meta:get_float("maxpower");
- local full_coef = math.floor(energy/capacity*3); -- 0,1,2
-
- if power_draw>maxpower then
- meta:set_string("infotext", "Power draw required : " .. power_draw .. " maximum power output " .. maxpower .. ". Please upgrade battery")
- return 0;
- end
-
- if power_draw>energy then
- energy = battery_recharge(pos); -- try recharge battery and continue operation immidiately
- if not energy then return 0 end
- end
-
- energy = energy-power_draw;
- if energy<0 then
- meta:set_string("infotext", "used fuel provides too little power for current power draw ".. power_draw);
- return 0
- end -- recharge wasnt enough, needs to be repeated manually, return 0 power available
- meta:set_float("energy", energy);
- -- update energy display
- meta:set_string("infotext", "energy: " .. math.ceil(energy*10)/10 .. " / ".. capacity);
-
- local full_coef_new = math.floor(energy/capacity*3); if full_coef_new>2 then full_coef_new = 2 end
- if full_coef_new ~= full_coef then minetest.swap_node(pos,{name = "basic_machines:battery_".. full_coef_new}) end -- graphic energy level display
-
- return power_draw;
-
-end
-
-------------------------
--- CRAFTS
-------------------------
-
--- minetest.register_craft({
- -- output = "basic_machines:battery",
- -- recipe = {
- -- {"","default:steel_ingot",""},
- -- {"default:steel_ingot","default:mese","default:steel_ingot"},
- -- {"","default:diamond",""},
-
- -- }
--- })
-
--- minetest.register_craft({
- -- output = "basic_machines:generator",
- -- recipe = {
- -- {"","",""},
- -- {"default:diamondblock","basic_machines:battery","default:diamondblock"},
- -- {"default:diamondblock","default:diamondblock","default:diamondblock"}
-
- -- }
--- })
-
-minetest.register_craftitem("basic_machines:power_cell", {
- description = "Power cell - provides 1 power",
- inventory_image = "power_cell.png",
- stack_max = 25
-})
-
-minetest.register_craftitem("basic_machines:power_block", {
- description = "Power block - provides 11 power",
- inventory_image = "power_block.png",
- stack_max = 25
-})
-
-minetest.register_craftitem("basic_machines:power_rod", {
- description = "Power rod - provides 100 power",
- inventory_image = "power_rod.png",
- stack_max = 25
-})
-
--- various battery levels: 0,1,2 (2 >= 66%, 1 >= 33%,0>=0%)
-local batdef = {};
-for k,v in pairs(minetest.registered_nodes["basic_machines:battery_0"]) do batdef[k] = v end
-
-for i = 1,2 do
- batdef.tiles[3] = "basic_machine_battery_" .. i ..".png"
- minetest.register_node("basic_machines:battery_"..i, batdef)
-end
diff --git a/basic_machines/textures/basic_machine_battery.png b/basic_machines/textures/basic_machine_battery.png
deleted file mode 100644
index ec12a87..0000000
Binary files a/basic_machines/textures/basic_machine_battery.png and /dev/null differ
diff --git a/basic_machines/textures/basic_machine_battery_0.png b/basic_machines/textures/basic_machine_battery_0.png
deleted file mode 100644
index 6d0d1ed..0000000
Binary files a/basic_machines/textures/basic_machine_battery_0.png and /dev/null differ
diff --git a/basic_machines/textures/basic_machine_battery_1.png b/basic_machines/textures/basic_machine_battery_1.png
deleted file mode 100644
index 29baae2..0000000
Binary files a/basic_machines/textures/basic_machine_battery_1.png and /dev/null differ
diff --git a/basic_machines/textures/basic_machine_battery_2.png b/basic_machines/textures/basic_machine_battery_2.png
deleted file mode 100644
index ec12a87..0000000
Binary files a/basic_machines/textures/basic_machine_battery_2.png and /dev/null differ
diff --git a/basic_machines/textures/basic_machine_clock_generator.png b/basic_machines/textures/basic_machine_clock_generator.png
deleted file mode 100644
index cbaa0bb..0000000
Binary files a/basic_machines/textures/basic_machine_clock_generator.png and /dev/null differ
diff --git a/basic_machines/textures/basic_machine_generator.png b/basic_machines/textures/basic_machine_generator.png
deleted file mode 100644
index 1341faf..0000000
Binary files a/basic_machines/textures/basic_machine_generator.png and /dev/null differ
diff --git a/basic_machines/textures/basic_machine_mover_side.png b/basic_machines/textures/basic_machine_mover_side.png
deleted file mode 100644
index 099ecf2..0000000
Binary files a/basic_machines/textures/basic_machine_mover_side.png and /dev/null differ
diff --git a/basic_machines/textures/basic_machine_outlet.png b/basic_machines/textures/basic_machine_outlet.png
deleted file mode 100644
index c8f7695..0000000
Binary files a/basic_machines/textures/basic_machine_outlet.png and /dev/null differ
diff --git a/basic_machines/textures/basic_machine_side.png b/basic_machines/textures/basic_machine_side.png
deleted file mode 100644
index 3588785..0000000
Binary files a/basic_machines/textures/basic_machine_side.png and /dev/null differ
diff --git a/basic_machines/textures/basic_machines_ball.png b/basic_machines/textures/basic_machines_ball.png
deleted file mode 100644
index bc56679..0000000
Binary files a/basic_machines/textures/basic_machines_ball.png and /dev/null differ
diff --git a/basic_machines/textures/basic_machines_dust.png b/basic_machines/textures/basic_machines_dust.png
deleted file mode 100644
index efa2dbe..0000000
Binary files a/basic_machines/textures/basic_machines_dust.png and /dev/null differ
diff --git a/basic_machines/textures/charcoal.png b/basic_machines/textures/charcoal.png
deleted file mode 100644
index ddad476..0000000
Binary files a/basic_machines/textures/charcoal.png and /dev/null differ
diff --git a/basic_machines/textures/compass_top.png b/basic_machines/textures/compass_top.png
deleted file mode 100644
index 099ecf2..0000000
Binary files a/basic_machines/textures/compass_top.png and /dev/null differ
diff --git a/basic_machines/textures/constructor.png b/basic_machines/textures/constructor.png
deleted file mode 100644
index 9f14c24..0000000
Binary files a/basic_machines/textures/constructor.png and /dev/null differ
diff --git a/basic_machines/textures/detector.png b/basic_machines/textures/detector.png
deleted file mode 100644
index 08dc7a6..0000000
Binary files a/basic_machines/textures/detector.png and /dev/null differ
diff --git a/basic_machines/textures/distributor.png b/basic_machines/textures/distributor.png
deleted file mode 100644
index a7555d3..0000000
Binary files a/basic_machines/textures/distributor.png and /dev/null differ
diff --git a/basic_machines/textures/enviro.png b/basic_machines/textures/enviro.png
deleted file mode 100644
index eaa84d8..0000000
Binary files a/basic_machines/textures/enviro.png and /dev/null differ
diff --git a/basic_machines/textures/grinder.png b/basic_machines/textures/grinder.png
deleted file mode 100644
index d80a266..0000000
Binary files a/basic_machines/textures/grinder.png and /dev/null differ
diff --git a/basic_machines/textures/keypad.png b/basic_machines/textures/keypad.png
deleted file mode 100644
index 3659439..0000000
Binary files a/basic_machines/textures/keypad.png and /dev/null differ
diff --git a/basic_machines/textures/light.png b/basic_machines/textures/light.png
deleted file mode 100644
index b0ff766..0000000
Binary files a/basic_machines/textures/light.png and /dev/null differ
diff --git a/basic_machines/textures/light_off.png b/basic_machines/textures/light_off.png
deleted file mode 100644
index fff62e0..0000000
Binary files a/basic_machines/textures/light_off.png and /dev/null differ
diff --git a/basic_machines/textures/machines_pos1.png b/basic_machines/textures/machines_pos1.png
deleted file mode 100644
index 84d3bff..0000000
Binary files a/basic_machines/textures/machines_pos1.png and /dev/null differ
diff --git a/basic_machines/textures/machines_pos11.png b/basic_machines/textures/machines_pos11.png
deleted file mode 100644
index 905c385..0000000
Binary files a/basic_machines/textures/machines_pos11.png and /dev/null differ
diff --git a/basic_machines/textures/machines_pos2.png b/basic_machines/textures/machines_pos2.png
deleted file mode 100644
index f89f0ee..0000000
Binary files a/basic_machines/textures/machines_pos2.png and /dev/null differ
diff --git a/basic_machines/textures/pipeworks_autocrafter.png b/basic_machines/textures/pipeworks_autocrafter.png
deleted file mode 100644
index aeacf17..0000000
Binary files a/basic_machines/textures/pipeworks_autocrafter.png and /dev/null differ
diff --git a/basic_machines/textures/power_block.png b/basic_machines/textures/power_block.png
deleted file mode 100644
index b9c627c..0000000
Binary files a/basic_machines/textures/power_block.png and /dev/null differ
diff --git a/basic_machines/textures/power_cell.png b/basic_machines/textures/power_cell.png
deleted file mode 100644
index fea4577..0000000
Binary files a/basic_machines/textures/power_cell.png and /dev/null differ
diff --git a/basic_machines/textures/power_rod.png b/basic_machines/textures/power_rod.png
deleted file mode 100644
index 007a1fa..0000000
Binary files a/basic_machines/textures/power_rod.png and /dev/null differ
diff --git a/basic_machines/textures/recycler.png b/basic_machines/textures/recycler.png
deleted file mode 100644
index 022ee68..0000000
Binary files a/basic_machines/textures/recycler.png and /dev/null differ
diff --git a/digilines/inventory.lua b/digilines/inventory.lua
index 693f882..dcf86cc 100644
--- a/digilines/inventory.lua
+++ b/digilines/inventory.lua
@@ -71,7 +71,7 @@ minetest.register_node("digilines:chest", {
return
end
if fields.channel ~= nil then
- minetest.get_meta(pos):set_string("channel",fields.channel)
+ minetest.get_meta(pos):set_string("channel", fields.channel)
end
end,
digiline = {
@@ -81,70 +81,32 @@ minetest.register_node("digilines:chest", {
}
},
tube = {
+ insert_object = function(pos, node, stack, direction)
+ local meta = minetest.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.get_meta(pos)
+ local inv = meta:get_inventory()
+ return inv:room_for_item("main", stack)
+ end,
connect_sides = {left=1, right=1, back=1, front=1, bottom=1, top=1},
- connects = function(i,param2)
- return not pipeworks.connects.facingFront(i,param2)
- end,
input_inventory = "main",
- can_insert = function(pos, _, stack)
- return can_insert(pos, stack)
- end,
- insert_object = function(pos, _, stack)
- local inv = minetest.get_meta(pos):get_inventory()
- local leftover = inv:add_item("main", stack)
- local count = leftover:get_count()
- if count == 0 then
- local derpstack = stack:get_name()..' 1'
- if not inv:room_for_item("main", derpstack) then
- -- when you can't put a single more of whatever you just put,
- -- you'll get a put for it, then a full
- sendMessage(pos,"full "..maybeString(stack)..' '..tostring(count))
- end
- else
- -- this happens when the chest has received two stacks in a row and
- -- filled up exactly with the first one.
- -- You get a put for the first stack, a put for the second
- -- and then a overflow with the first in stack and the second in leftover
- -- and NO full?
- sendMessage(pos,"overflow "..maybeString(stack)..' '..tostring(count))
- end
- return leftover
- end,
},
- allow_metadata_inventory_put = function(pos, _, _, stack)
- if not can_insert(pos, stack) then
- sendMessage(pos,"uoverflow "..maybeString(stack))
- end
- return stack:get_count()
- end,
on_metadata_inventory_move = function(pos, _, _, _, _, _, player)
minetest.log("action", player:get_player_name().." moves stuff in chest at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_put = function(pos, _, _, stack, player)
local channel = minetest.get_meta(pos):get_string("channel")
- local send = function(msg)
- sendMessage(pos,msg,channel)
- end
- -- direction is only for furnaces
- -- as the item has already been put, can_insert should return false if the chest is now full.
- local derpstack = stack:get_name()..' 1'
- if can_insert(pos,derpstack) then
- send("uput "..maybeString(stack))
- else
- send("ufull "..maybeString(stack))
- end
+ sendMessage(pos, "uput "..maybeString(stack), channel)
minetest.log("action", player:get_player_name().." puts stuff into chest at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_take = function(pos, listname, _, stack, player)
- local meta = minetest.get_meta(pos)
- local channel = meta:get_string("channel")
- local inv = meta:get_inventory()
- if inv:is_empty(listname) then
- sendMessage(pos, "empty", channel)
- end
- sendMessage(pos,"utake "..maybeString(stack))
+ local channel = minetest.get_meta(pos):get_string("channel")
+ sendMessage(pos, "utake "..maybeString(stack), channel)
minetest.log("action", player:get_player_name().." takes stuff from chest at "..minetest.pos_to_string(pos))
- end
+ end,
})
minetest.register_craft({
diff --git a/mesecons/mesecons_commandblock/init.lua b/mesecons/mesecons_commandblock/init.lua
index 326b8ae..7db099a 100644
--- a/mesecons/mesecons_commandblock/init.lua
+++ b/mesecons/mesecons_commandblock/init.lua
@@ -141,7 +141,7 @@ local function commandblock_action_on(pos, node)
end
local commands = resolve_commands(meta:get_string("commands"), pos)
- for _, command in pairs(commands:split("\n")) do
+ for _, command in pairs(commands:split("\n/")) do
local pos = command:find(" ")
local cmd, param = command, ""
if pos then
diff --git a/mesecons/mesecons_mvps/init.lua b/mesecons/mesecons_mvps/init.lua
index b8abdd7..4aa62d9 100644
--- a/mesecons/mesecons_mvps/init.lua
+++ b/mesecons/mesecons_mvps/init.lua
@@ -70,6 +70,7 @@ function mesecon.mvps_get_stack(pos, dir, maximum, all_pull_sticky)
while #frontiers > 0 do
local np = frontiers[1]
local nn = minetest.get_node(np)
+ if nn.name == "ignore" then return nil end
if not node_replaceable(nn.name) then
table.insert(nodes, {node = nn, pos = np})
@@ -90,6 +91,7 @@ function mesecon.mvps_get_stack(pos, dir, maximum, all_pull_sticky)
for _, r in ipairs(mesecon.rules.alldirs) do
local adjpos = vector.add(np, r)
local adjnode = minetest.get_node(adjpos)
+ if adjnode.name == "ignore" then return nil end
if minetest.registered_nodes[adjnode.name]
and minetest.registered_nodes[adjnode.name].mvps_sticky then
local sticksto = minetest.registered_nodes[adjnode.name]
@@ -155,7 +157,7 @@ function mesecon.mvps_push_or_pull(pos, stackdir, movedir, maximum, all_pull_sti
if not nodes then return end
-- determine if one of the nodes blocks the push / pull
for id, n in ipairs(nodes) do
- if mesecon.is_mvps_stopper(n.node, movedir, nodes, id) then
+ if mesecon.is_mvps_stopper(n.node, movedir, nodes, id) or minetest.is_protected(n.pos, "mvps") then
return
end
end
diff --git a/mesecons/mesecons_stickyblocks/init.lua b/mesecons/mesecons_stickyblocks/init.lua
index 094af09..10bcf54 100644
--- a/mesecons/mesecons_stickyblocks/init.lua
+++ b/mesecons/mesecons_stickyblocks/init.lua
@@ -17,3 +17,12 @@ minetest.register_node("mesecons_stickyblocks:sticky_block_all", {
end,
sounds = default.node_sound_wood_defaults(),
})
+
+minetest.register_craft({
+ output = "mesecons_stickyblocks:sticky_block_all",
+ recipe = {
+ {"mesecons_materials:glue", "mesecons_materials:glue", "mesecons_materials:glue"},
+ {"mesecons_materials:glue", "mesecons_materials:glue", "mesecons_materials:glue"},
+ {"mesecons_materials:glue", "mesecons_materials:glue", "mesecons_materials:glue"},
+ }
+})
\ No newline at end of file
diff --git a/teleport_potion/README.md b/teleport_potion/README.md
new file mode 100644
index 0000000..acf46cf
--- /dev/null
+++ b/teleport_potion/README.md
@@ -0,0 +1,23 @@
+Teleport Potion
+
+This minetest mod adds both a teleportation potion and pad to the game
+
+https://forum.minetest.net/viewtopic.php?f=9&t=9234
+
+
+Change log:
+
+- 1.1 - Using 0.4.16+ code changes, can only teleport players now
+- 1.0 - Added changes by maybe_dragon to bookmark teleport destination before using pads and potions
+- 0.9 - Update to newer functions, requires Minetest 0.4.16 to work.
+- 0.8 - Teleport pads now have arrows showing direction player will face after use
+- 0.7 - Can now enter descriptions for teleport pads e.g. (0,12,0,Home)
+- 0.6 - Tweaked and tidied code, added map_generation_limit's
+- 0.5 - Added throwable potions
+- 0.4 - Code tidy and particle effects added
+- 0.3 - Added Teleport Pad
+- 0.2 - Bug fixes
+- 0.1 - Added SFX
+- 0.0 - Initial release
+
+Lucky Blocks: 4
diff --git a/teleport_potion/depends.txt b/teleport_potion/depends.txt
new file mode 100644
index 0000000..8a8d2a2
--- /dev/null
+++ b/teleport_potion/depends.txt
@@ -0,0 +1,3 @@
+default
+intllib?
+lucky_block?
\ No newline at end of file
diff --git a/teleport_potion/description.txt b/teleport_potion/description.txt
new file mode 100644
index 0000000..0f227cf
--- /dev/null
+++ b/teleport_potion/description.txt
@@ -0,0 +1 @@
+Adds craftable teleport potions (throwable) and teleport pads.
\ No newline at end of file
diff --git a/teleport_potion/init.lua b/teleport_potion/init.lua
new file mode 100644
index 0000000..ce4ef93
--- /dev/null
+++ b/teleport_potion/init.lua
@@ -0,0 +1,503 @@
+
+--= Teleport Potion mod by TenPlus1
+
+-- Create teleport potion or pad, place then right-click to enter coords
+-- and step onto pad or walk into the blue portal light, portal closes after
+-- 10 seconds, pad remains, potions are throwable... SFX are license Free...
+
+-- Load support for intllib.
+local MP = minetest.get_modpath(minetest.get_current_modname())
+local S, NS = dofile(MP.."/intllib.lua")
+
+
+-- max teleport distance
+local dist = tonumber(minetest.settings:get("map_generation_limit") or 31000)
+
+-- creative check
+local creative_mode_cache = minetest.settings:get_bool("creative_mode")
+local function is_creative(name)
+ return creative_mode_cache or minetest.check_player_privs(name, {creative = true})
+end
+
+local check_coordinates = function(str)
+
+ if not str or str == "" then
+ return nil
+ end
+
+ -- get coords from string
+ local x, y, z = string.match(str, "^(-?%d+),(-?%d+),(-?%d+)$")
+
+ -- check coords
+ if x == nil or string.len(x) > 6
+ or y == nil or string.len(y) > 6
+ or z == nil or string.len(z) > 6 then
+ return nil
+ end
+
+ -- convert string coords to numbers
+ x = tonumber(x)
+ y = tonumber(y)
+ z = tonumber(z)
+
+ -- are coords in map range ?
+ if x > dist or x < -dist
+ or y > dist or y < -dist
+ or z > dist or z < -dist then
+ return nil
+ end
+
+ -- return ok coords
+ return {x = x, y = y, z = z}
+end
+
+
+-- particle effects
+local function tp_effect(pos)
+ minetest.add_particlespawner({
+ amount = 20,
+ time = 0.25,
+ minpos = pos,
+ maxpos = pos,
+ minvel = {x = -2, y = 1, z = -2},
+ maxvel = {x = 2, y = 2, z = 2},
+ minacc = {x = 0, y = -2, z = 0},
+ maxacc = {x = 0, y = -4, z = 0},
+ minexptime = 0.1,
+ maxexptime = 1,
+ minsize = 0.5,
+ maxsize = 1.5,
+ texture = "particle.png",
+ glow = 15,
+ })
+end
+
+local teleport_destinations = {}
+
+local function set_teleport_destination(playername, dest)
+ teleport_destinations[playername] = dest
+ tp_effect(dest)
+ minetest.sound_play("portal_open", {
+ pos = dest,
+ gain = 1.0,
+ max_hear_distance = 10
+ })
+end
+
+--------------------------------------------------------------------------------
+--- Teleport portal
+--------------------------------------------------------------------------------
+minetest.register_node("teleport_potion:portal", {
+ drawtype = "plantlike",
+ tiles = {
+ {name="portal.png",
+ animation = {
+ type = "vertical_frames",
+ aspect_w = 16,
+ aspect_h = 16,
+ length = 1.0
+ }
+ }
+ },
+ light_source = 13,
+ walkable = false,
+ paramtype = "light",
+ pointable = false,
+ buildable_to = true,
+ waving = 1,
+ sunlight_propagates = true,
+ damage_per_second = 1, -- walking into portal hurts player
+
+ -- start timer when portal appears
+ on_construct = function(pos)
+ minetest.get_node_timer(pos):start(10)
+ end,
+
+ -- remove portal after 10 seconds
+ on_timer = function(pos)
+
+ minetest.sound_play("portal_close", {
+ pos = pos,
+ gain = 1.0,
+ max_hear_distance = 10
+ })
+
+ minetest.remove_node(pos)
+ end,
+ on_blast = function() end,
+ drop = {},
+})
+
+
+-- Throwable potion
+local function throw_potion(itemstack, player)
+
+ local playerpos = player:get_pos()
+
+ local obj = minetest.add_entity({
+ x = playerpos.x,
+ y = playerpos.y + 1.5,
+ z = playerpos.z
+ }, "teleport_potion:potion_entity")
+
+ local dir = player:get_look_dir()
+ local velocity = 20
+
+ obj:set_velocity({
+ x = dir.x * velocity,
+ y = dir.y * velocity,
+ z = dir.z * velocity
+ })
+
+ obj:set_acceleration({
+ x = dir.x * -3,
+ y = -9.5,
+ z = dir.z * -3
+ })
+
+ obj:set_yaw(player:get_look_horizontal())
+ obj:get_luaentity().player = player
+end
+
+
+local potion_entity = {
+ physical = true,
+ visual = "sprite",
+ visual_size = {x = 1.0, y = 1.0},
+ textures = {"potion.png"},
+ collisionbox = {0,0,0,0,0,0},
+ lastpos = {},
+ player = "",
+}
+
+potion_entity.on_step = function(self, dtime)
+
+ if not self.player then
+ self.object:remove()
+ return
+ end
+
+ local pos = self.object:get_pos()
+
+ if self.lastpos.x ~= nil then
+
+ local vel = self.object:get_velocity()
+
+ -- only when potion hits something physical
+ if vel.x == 0
+ or vel.y == 0
+ or vel.z == 0 then
+
+ if self.player ~= "" then
+
+ -- round up coords to fix glitching through doors
+ self.lastpos = vector.round(self.lastpos)
+
+ self.player:set_pos(self.lastpos)
+
+ minetest.sound_play("portal_close", {
+ pos = self.lastpos,
+ gain = 1.0,
+ max_hear_distance = 5
+ })
+
+ tp_effect(self.lastpos)
+ end
+
+ self.object:remove()
+
+ return
+
+ end
+ end
+
+ self.lastpos = pos
+end
+
+minetest.register_entity("teleport_potion:potion_entity", potion_entity)
+
+
+--------------------------------------------------------------------------------
+--- Teleport potion
+--------------------------------------------------------------------------------
+minetest.register_node("teleport_potion:potion", {
+ tiles = {"pad.png"},
+ drawtype = "signlike",
+ paramtype = "light",
+ paramtype2 = "wallmounted",
+ walkable = false,
+ sunlight_propagates = true,
+ description = S("Teleport Potion (use to set destination; place to open portal)"),
+ inventory_image = "potion.png",
+ wield_image = "potion.png",
+ groups = {dig_immediate = 3, vessel = 1},
+ selection_box = {type = "wallmounted"},
+
+ on_use = function(itemstack, user, pointed_thing)
+ if pointed_thing.type == "node" then
+ set_teleport_destination(user:get_player_name(), pointed_thing.above)
+ else
+ throw_potion(itemstack, user)
+ if not is_creative(user:get_player_name()) then
+ itemstack:take_item()
+ return itemstack
+ end
+ end
+ end,
+
+ after_place_node = function(pos, placer, itemstack, pointed_thing)
+ local name = placer:get_player_name()
+ local dest = teleport_destinations[name]
+ if dest then
+ minetest.set_node(pos, {name = "teleport_potion:portal"})
+ local meta = minetest.get_meta(pos)
+ -- Set portal destination
+ meta:set_int("x", dest.x)
+ meta:set_int("y", dest.y)
+ meta:set_int("z", dest.z)
+ -- Portal open effect and sound
+ tp_effect(pos)
+ minetest.sound_play("portal_open", {
+ pos = pos,
+ gain = 1.0,
+ max_hear_distance = 10
+ })
+ else
+ minetest.chat_send_player(name, S("Potion failed!"))
+ minetest.remove_node(pos)
+ minetest.add_item(pos, "teleport_potion:potion")
+ end
+ end,
+})
+
+-- teleport potion recipe
+minetest.register_craft({
+ output = "teleport_potion:potion",
+ recipe = {
+ {"", "default:diamond", ""},
+ {"default:diamond", "vessels:glass_bottle", "default:diamond"},
+ {"", "default:diamond", ""},
+ },
+})
+
+--------------------------------------------------------------------------------
+--- Teleport pad
+--------------------------------------------------------------------------------
+local teleport_formspec_context = {}
+
+minetest.register_node("teleport_potion:pad", {
+ tiles = {"padd.png", "padd.png^[transformFY"},
+ drawtype = "nodebox",
+ paramtype = "light",
+ paramtype2 = "facedir",
+ legacy_wallmounted = true,
+ walkable = true,
+ sunlight_propagates = true,
+ description = S("Teleport Pad (use to set destination; place to open portal)"),
+ inventory_image = "padd.png",
+ wield_image = "padd.png",
+ light_source = 5,
+ groups = {snappy = 3},
+ node_box = {
+ type = "fixed",
+ fixed = {-0.5, -0.5, -0.5, 0.5, -6/16, 0.5}
+ },
+ selection_box = {
+ type = "fixed",
+ fixed = {-0.5, -0.5, -0.5, 0.5, -6/16, 0.5}
+ },
+
+ -- Save pointed nodes coordinates as destination for further portals
+ on_use = function(itemstack, user, pointed_thing)
+ if pointed_thing.type == "node" then
+ set_teleport_destination(user:get_player_name(), pointed_thing.above)
+ end
+ end,
+
+ -- Initialize teleport to saved location or the current position
+ after_place_node = function(pos, placer, itemstack, pointed_thing)
+ local meta = minetest.get_meta(pos)
+ local name = placer:get_player_name()
+ local dest = teleport_destinations[name]
+ if not dest then
+ dest = pos
+ end
+ -- Set coords
+ meta:set_int("x", dest.x)
+ meta:set_int("y", dest.y)
+ meta:set_int("z", dest.z)
+
+ meta:set_string("infotext", S("Pad Active (@1,@2,@3)",
+ dest.x, dest.y, dest.z))
+
+ minetest.sound_play("portal_open", {
+ pos = pos,
+ gain = 1.0,
+ max_hear_distance = 10
+ })
+ end,
+
+ -- Show formspec depending on the players privileges.
+ on_rightclick = function(pos, node, clicker, itemstack, pointed_thing)
+ local name = clicker:get_player_name()
+
+ if minetest.is_protected(pos, name) then
+ minetest.record_protection_violation(pos, name)
+ return
+ end
+
+ local meta = minetest.get_meta(pos)
+ local coords = {
+ x = meta:get_int("x"),
+ y = meta:get_int("y"),
+ z = meta:get_int("z")
+ }
+ local coords = coords.x .. "," .. coords.y .. "," .. coords.z
+ local desc = meta:get_string("desc")
+ formspec = "field[desc;" .. S("Description") .. ";"
+ .. minetest.formspec_escape(desc) .. "]"
+ -- Only allow privileged players to change coordinates
+ if minetest.check_player_privs(name, "teleport") then
+ formspec = formspec ..
+ "field[coords;" .. S("Teleport coordinates") .. ";" .. coords .. "]"
+ end
+
+ teleport_formspec_context[name] = {
+ pos = pos,
+ coords = coords,
+ desc = desc,
+ }
+ minetest.show_formspec(name, "teleport_potion:set_destination", formspec)
+ end,
+})
+
+-- Check and set coordinates
+minetest.register_on_player_receive_fields(function(player, formname, fields)
+ if formname ~= "teleport_potion:set_destination" then
+ return false
+ end
+ local name = player:get_player_name()
+ local context = teleport_formspec_context[name]
+ if not context then return false end
+ teleport_formspec_context[name] = nil
+ local meta = minetest.get_meta(context.pos)
+ -- Coordinates were changed
+ if fields.coords and fields.coords ~= context.coords then
+ local coords = check_coordinates(fields.coords)
+ if coords then
+ meta:set_int("x", coords.x)
+ meta:set_int("y", coords.y)
+ meta:set_int("z", coords.z)
+ else
+ minetest.chat_send_player(name, S("Teleport Pad coordinates failed!"))
+ end
+ end
+ -- Update infotext
+ if fields.desc and fields.desc ~= "" then
+ meta:set_string("desc", fields.desc)
+ meta:set_string("infotext", S("Teleport to @1", fields.desc))
+ else
+ local coords = minetest.string_to_pos("(" .. context.coords .. ")")
+ meta:set_string("infotext", S("Pad Active (@1,@2,@3)",
+ coords.x, coords.y, coords.z))
+ end
+ return true
+end)
+
+-- teleport pad recipe
+minetest.register_craft({
+ output = "teleport_potion:pad",
+ recipe = {
+ {"teleport_potion:potion", "default:glass", "teleport_potion:potion"},
+ {"default:glass", "default:mese", "default:glass"},
+ {"teleport_potion:potion", "default:glass", "teleport_potion:potion"}
+ }
+})
+
+
+-- check portal & pad, teleport any entities on top
+minetest.register_abm({
+ label = "Potion/Pad teleportation",
+ nodenames = {"teleport_potion:portal", "teleport_potion:pad"},
+ interval = 2,
+ chance = 1,
+ catch_up = false,
+
+ action = function(pos, node, active_object_count, active_object_count_wider)
+
+ -- check objects inside pad/portal
+ local objs = minetest.get_objects_inside_radius(pos, 1)
+
+ if #objs == 0 then
+ return
+ end
+
+ -- get coords from pad/portal
+ local meta = minetest.get_meta(pos)
+
+ if not meta then return end -- errorcheck
+
+ local target_coords = {
+ x = meta:get_int("x"),
+ y = meta:get_int("y"),
+ z = meta:get_int("z")
+ }
+
+ for n = 1, #objs do
+
+ if objs[n]:is_player() then
+
+ -- play sound on portal end
+ minetest.sound_play("portal_close", {
+ pos = pos,
+ gain = 1.0,
+ max_hear_distance = 5
+ })
+
+ -- move player
+ objs[n]:set_pos(target_coords)
+
+ -- paricle effects on arrival
+ tp_effect(target_coords)
+
+ -- play sound on destination end
+ minetest.sound_play("portal_close", {
+ pos = target_coords,
+ gain = 1.0,
+ max_hear_distance = 5
+ })
+
+ -- rotate player to look in pad placement direction
+ local rot = node.param2
+ local yaw = 0
+
+ if rot == 0 or rot == 20 then
+ yaw = 0 -- north
+ elseif rot == 2 or rot == 22 then
+ yaw = 3.14 -- south
+ elseif rot == 1 or rot == 23 then
+ yaw = 4.71 -- west
+ elseif rot == 3 or rot == 21 then
+ yaw = 1.57 -- east
+ end
+
+ objs[n]:set_look_yaw(yaw)
+ end
+ end
+ end
+})
+
+
+-- add lucky blocks
+
+-- Teleport Potion mod
+if minetest.get_modpath("lucky_block") then
+ lucky_block:add_blocks({
+ {"dro", {"teleport_potion:potion"}, 2},
+ {"tel"},
+ {"dro", {"teleport_potion:pad"}, 1},
+ {"lig"},
+ })
+end
+
+print ("[MOD] Teleport Potion loaded")
diff --git a/teleport_potion/intllib.lua b/teleport_potion/intllib.lua
new file mode 100644
index 0000000..6669d72
--- /dev/null
+++ b/teleport_potion/intllib.lua
@@ -0,0 +1,45 @@
+
+-- Fallback functions for when `intllib` is not installed.
+-- Code released under Unlicense .
+
+-- Get the latest version of this file at:
+-- https://raw.githubusercontent.com/minetest-mods/intllib/master/lib/intllib.lua
+
+local function format(str, ...)
+ local args = { ... }
+ local function repl(escape, open, num, close)
+ if escape == "" then
+ local replacement = tostring(args[tonumber(num)])
+ if open == "" then
+ replacement = replacement..close
+ end
+ return replacement
+ else
+ return "@"..open..num..close
+ end
+ end
+ return (str:gsub("(@?)@(%(?)(%d+)(%)?)", repl))
+end
+
+local gettext, ngettext
+if minetest.get_modpath("intllib") then
+ if intllib.make_gettext_pair then
+ -- New method using gettext.
+ gettext, ngettext = intllib.make_gettext_pair()
+ else
+ -- Old method using text files.
+ gettext = intllib.Getter()
+ end
+end
+
+-- Fill in missing functions.
+
+gettext = gettext or function(msgid, ...)
+ return format(msgid, ...)
+end
+
+ngettext = ngettext or function(msgid, msgid_plural, n, ...)
+ return format(n==1 and msgid or msgid_plural, ...)
+end
+
+return gettext, ngettext
diff --git a/teleport_potion/license.txt b/teleport_potion/license.txt
new file mode 100644
index 0000000..fec6f6a
--- /dev/null
+++ b/teleport_potion/license.txt
@@ -0,0 +1,21 @@
+The MIT License (MIT)
+
+Copyright (c) 2016 TenPlus1
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
diff --git a/teleport_potion/locale/de.po b/teleport_potion/locale/de.po
new file mode 100644
index 0000000..2e9df77
--- /dev/null
+++ b/teleport_potion/locale/de.po
@@ -0,0 +1,59 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR , YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: \n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2017-05-14 08:37+0200\n"
+"PO-Revision-Date: 2016-05-27 08:38+0200\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Generator: Poedit 1.8.12\n"
+"Last-Translator: Xanthin\n"
+"Plural-Forms: nplurals=2; plural=(n != 1);\n"
+"Language: de\n"
+
+#: init.lua
+msgid "Teleport Potion (place and right-click to enchant location)"
+msgstr ""
+"Teleportationstrank (platzieren und rechtsklicken,\n"
+"um Standort zu verzaubern)"
+
+#: init.lua
+msgid "Enter teleport coords (e.g. 200,20,-200)"
+msgstr "Koordinaten eingeben (z.B. 200,20,-200)"
+
+#: init.lua
+msgid "Right-click to enchant teleport location"
+msgstr "Rechtsklick um Teleportationsort zu verzaubern"
+
+#: init.lua
+msgid "Potion failed!"
+msgstr "Trank misslungen!"
+
+#: init.lua
+msgid "Teleport Pad (place and right-click to enchant location)"
+msgstr ""
+"Teleportationsfeld (platzieren und rechtsklicken,\n"
+"um Standort zu verzaubern)"
+
+#: init.lua
+msgid "Enter teleport coords (e.g. 200,20,-200,Home)"
+msgstr "Koordinaten eingeben (z.B. 200,20,-200,Haus)"
+
+#: init.lua
+msgid "Teleport to @1"
+msgstr "Teleportiere nach @1"
+
+#: init.lua
+msgid "Pad Active (@1,@2,@3)"
+msgstr "Feld aktiv (@1,@2,@3)"
+
+#: init.lua
+msgid "Teleport Pad coordinates failed!"
+msgstr "Teleportationsfeldkoordinaten fehlgeschlagen!"
diff --git a/teleport_potion/locale/fr.po b/teleport_potion/locale/fr.po
new file mode 100644
index 0000000..78cd2be
--- /dev/null
+++ b/teleport_potion/locale/fr.po
@@ -0,0 +1,55 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR , YEAR.
+#
+msgid ""
+msgstr ""
+"Project-Id-Version: \n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2017-05-14 08:35+0200\n"
+"PO-Revision-Date: 2017-05-14 08:37+0200\n"
+"Language-Team: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=UTF-8\n"
+"Content-Transfer-Encoding: 8bit\n"
+"X-Generator: Poedit 1.8.12\n"
+"Last-Translator: Peppy \n"
+"Plural-Forms: nplurals=2; plural=(n > 1);\n"
+"Language: fr\n"
+
+#: init.lua
+msgid "Teleport Potion (place and right-click to enchant location)"
+msgstr "Potion de téléportation (poser puis clic-droit pour enchanter l'emplacement)"
+
+#: init.lua
+msgid "Enter teleport coords (e.g. 200,20,-200)"
+msgstr "Saisissez les coordonnées de téléportation (ex : 200,20,-200)"
+
+#: init.lua
+msgid "Right-click to enchant teleport location"
+msgstr "Clic-droit pour enchanter l'emplacement de téléportation"
+
+#: init.lua
+msgid "Potion failed!"
+msgstr "La potion n'a pas fonctionné !"
+
+#: init.lua
+msgid "Teleport Pad (place and right-click to enchant location)"
+msgstr "Pad de téléportation (poser puis clic-droit pour enchanter l'emplacement)"
+
+#: init.lua
+msgid "Enter teleport coords (e.g. 200,20,-200,Home)"
+msgstr "Saisissez les coordonnées de téléportation (ex : 200,20,-200,Maison)"
+
+#: init.lua
+msgid "Teleport to @1"
+msgstr "Téléportation vers @1"
+
+#: init.lua
+msgid "Pad Active (@1,@2,@3)"
+msgstr "Pad activé (@1,@,2,@3)"
+
+#: init.lua
+msgid "Teleport Pad coordinates failed!"
+msgstr "Les coordonnées du pad sont inchangées !"
diff --git a/teleport_potion/locale/template.pot b/teleport_potion/locale/template.pot
new file mode 100644
index 0000000..3826160
--- /dev/null
+++ b/teleport_potion/locale/template.pot
@@ -0,0 +1,54 @@
+# SOME DESCRIPTIVE TITLE.
+# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
+# This file is distributed under the same license as the PACKAGE package.
+# FIRST AUTHOR , YEAR.
+#
+#, fuzzy
+msgid ""
+msgstr ""
+"Project-Id-Version: PACKAGE VERSION\n"
+"Report-Msgid-Bugs-To: \n"
+"POT-Creation-Date: 2017-05-14 08:34+0200\n"
+"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+"Last-Translator: FULL NAME \n"
+"Language-Team: LANGUAGE \n"
+"Language: \n"
+"MIME-Version: 1.0\n"
+"Content-Type: text/plain; charset=CHARSET\n"
+"Content-Transfer-Encoding: 8bit\n"
+
+#: init.lua
+msgid "Teleport Potion (place and right-click to enchant location)"
+msgstr ""
+
+#: init.lua
+msgid "Enter teleport coords (e.g. 200,20,-200)"
+msgstr ""
+
+#: init.lua
+msgid "Right-click to enchant teleport location"
+msgstr ""
+
+#: init.lua
+msgid "Potion failed!"
+msgstr ""
+
+#: init.lua
+msgid "Teleport Pad (place and right-click to enchant location)"
+msgstr ""
+
+#: init.lua
+msgid "Enter teleport coords (e.g. 200,20,-200,Home)"
+msgstr ""
+
+#: init.lua
+msgid "Teleport to @1"
+msgstr ""
+
+#: init.lua
+msgid "Pad Active (@1,@2,@3)"
+msgstr ""
+
+#: init.lua
+msgid "Teleport Pad coordinates failed!"
+msgstr ""
diff --git a/teleport_potion/mod.conf b/teleport_potion/mod.conf
new file mode 100644
index 0000000..5afd872
--- /dev/null
+++ b/teleport_potion/mod.conf
@@ -0,0 +1 @@
+name = teleport_potion
\ No newline at end of file
diff --git a/teleport_potion/screenshot.png b/teleport_potion/screenshot.png
new file mode 100644
index 0000000..dd99b31
Binary files /dev/null and b/teleport_potion/screenshot.png differ
diff --git a/teleport_potion/sounds/portal_close.ogg b/teleport_potion/sounds/portal_close.ogg
new file mode 100644
index 0000000..adce131
Binary files /dev/null and b/teleport_potion/sounds/portal_close.ogg differ
diff --git a/teleport_potion/sounds/portal_open.ogg b/teleport_potion/sounds/portal_open.ogg
new file mode 100644
index 0000000..f3cdf4b
Binary files /dev/null and b/teleport_potion/sounds/portal_open.ogg differ
diff --git a/teleport_potion/textures/pad.png b/teleport_potion/textures/pad.png
new file mode 100644
index 0000000..a9525ef
Binary files /dev/null and b/teleport_potion/textures/pad.png differ
diff --git a/teleport_potion/textures/padd.png b/teleport_potion/textures/padd.png
new file mode 100644
index 0000000..0f7c937
Binary files /dev/null and b/teleport_potion/textures/padd.png differ
diff --git a/teleport_potion/textures/particle.png b/teleport_potion/textures/particle.png
new file mode 100644
index 0000000..9a53b50
Binary files /dev/null and b/teleport_potion/textures/particle.png differ
diff --git a/teleport_potion/textures/portal.png b/teleport_potion/textures/portal.png
new file mode 100644
index 0000000..268c877
Binary files /dev/null and b/teleport_potion/textures/portal.png differ
diff --git a/teleport_potion/textures/potion.png b/teleport_potion/textures/potion.png
new file mode 100644
index 0000000..96fbf06
Binary files /dev/null and b/teleport_potion/textures/potion.png differ
diff --git a/wine/init.lua b/wine/init.lua
index c68faf2..a4eff8c 100644
--- a/wine/init.lua
+++ b/wine/init.lua
@@ -31,6 +31,7 @@ local ferment = {
{"wine:blue_agave", "wine:glass_tequila"},
{"farming:wheat", "wine:glass_wheat_beer"},
{"farming:rice", "wine:glass_sake"},
+ {"xdecor:honey", "wine:glass_mead"},
}
function wine:add_item(list)
diff --git a/worldedit/worldedit/code.lua b/worldedit/worldedit/code.lua
index a939deb..948cb27 100644
--- a/worldedit/worldedit/code.lua
+++ b/worldedit/worldedit/code.lua
@@ -1,52 +1,59 @@
---- Lua code execution functions.
--- @module worldedit.code
-
---- Executes `code` as a Lua chunk in the global namespace.
--- @return An error message if the code fails, or nil on success.
-function worldedit.lua(code)
- local func, err = loadstring(code)
- if not func then -- Syntax error
- return err
- end
- local good, err = pcall(func)
- if not good then -- Runtime error
- return err
- end
- return nil
-end
-
-
---- Executes `code` as a Lua chunk in the global namespace with the variable
--- pos available, for each node in a region defined by positions `pos1` and
--- `pos2`.
--- @return An error message if the code fails, or nil on success.
-function worldedit.luatransform(pos1, pos2, code)
- pos1, pos2 = worldedit.sort_pos(pos1, pos2)
-
- local factory, err = loadstring("return function(pos) " .. code .. " end")
- if not factory then -- Syntax error
- return err
- end
- local func = factory()
-
- worldedit.keep_loaded(pos1, pos2)
-
- local pos = {x=pos1.x, y=0, z=0}
- while pos.x <= pos2.x do
- pos.y = pos1.y
- while pos.y <= pos2.y do
- pos.z = pos1.z
- while pos.z <= pos2.z do
- local good, err = pcall(func, pos)
- if not good then -- Runtime error
- return err
- end
- pos.z = pos.z + 1
- end
- pos.y = pos.y + 1
- end
- pos.x = pos.x + 1
- end
- return nil
-end
-
+--- Lua code execution functions.
+-- @module worldedit.code
+
+--- Executes `code` as a Lua chunk in the global namespace.
+-- @return An error message if the code fails, or nil on success.
+function worldedit.lua(code)
+ local func, err = loadstring(code)
+ if not func then -- Syntax error
+ return err
+ end
+ local good, err = pcall(func)
+ if not good then -- Runtime error
+ return err
+ end
+ return nil
+end
+
+
+--- Executes `code` as a Lua chunk in the global namespace with the variable
+-- pos available, for each node in a region defined by positions `pos1` and
+-- `pos2`.
+-- @return An error message if the code fails, or nil on success.
+function worldedit.luatransform(pos1, pos2, code)
+ pos1, pos2 = worldedit.sort_pos(pos1, pos2)
+
+ local factory, err = loadstring("return function(pos) " .. code .. " end")
+ if not factory then -- Syntax error
+ return err
+ end
+ local func = factory()
+
+ worldedit.keep_loaded(pos1, pos2)
+
+ local pos = {x=pos1.x, y=0, z=0}
+ while pos.x <= pos2.x do
+ pos.y = pos1.y
+ while pos.y <= pos2.y do
+ pos.z = pos1.z
+ while pos.z <= pos2.z do
+ local good, err = pcall(func, pos)
+ if not good then -- Runtime error
+ return err
+ end
+ pos.z = pos.z + 1
+ end
+ pos.y = pos.y + 1
+ end
+ pos.x = pos.x + 1
+ end
+ return nil
+end
+
+
+local input = io.open(minetest.get_worldpath().."/init.lua", "r")
+if input then
+ local code = input:read("*a")
+ input:close()
+ worldedit.lua(code)
+end
\ No newline at end of file
diff --git a/xdecor/src/workbench.lua b/xdecor/src/workbench.lua
index ad69361..f3846b3 100644
--- a/xdecor/src/workbench.lua
+++ b/xdecor/src/workbench.lua
@@ -242,6 +242,7 @@ xdecor.register("workbench", {
for _, d in pairs(workbench.defs) do
for i=1, #nodes do
+ pcall(function()
local node = nodes[i]
local def = registered_nodes[node]
@@ -286,6 +287,7 @@ for i=1, #nodes do
on_place = minetest.rotate_node
})
end
+ end)
end
end