cleanup obsolete files, consitent syntax and forms, new keypad texture
parent
bca954d393
commit
4b87c9e114
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
5
ball.lua
5
ball.lua
|
@ -46,7 +46,10 @@ local ball_spawner_update_form = function (pos)
|
|||
local scale = meta:get_int("scale");
|
||||
|
||||
local form =
|
||||
"size[4.25,4.75]" .. -- width, height
|
||||
"size[4.25,4.75]".. -- width, height
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"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
|
||||
|
|
|
@ -39,24 +39,24 @@ basic_machines.craft_recipe_order = { -- order in which nodes appear
|
|||
"keypad","light","grinder","mover", "battery","generator","detector", "distributor", "clock_generator","recycler","autocrafter","ball_spawner", "power_block", "power_cell", "coal_lump",
|
||||
}
|
||||
|
||||
|
||||
|
||||
local constructor_process = function(pos)
|
||||
|
||||
|
||||
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
|
||||
if not inv:contains_item("main", ItemStack(v)) then
|
||||
meta:set_string("infotext", "#CRAFTING: you need " .. v .. " to craft " .. craft.item)
|
||||
return
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
for _,v in pairs(craftlist) do
|
||||
inv:remove_item("main", ItemStack(v));
|
||||
end
|
||||
|
@ -66,45 +66,48 @@ end
|
|||
|
||||
local constructor_update_meta = function(pos)
|
||||
local meta = minetest.get_meta(pos);
|
||||
local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
|
||||
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
|
||||
|
||||
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))
|
||||
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 = ""
|
||||
|
||||
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 =
|
||||
|
||||
local form =
|
||||
"size[8,10]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"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]"..
|
||||
|
@ -137,14 +140,14 @@ minetest.register_node("basic_machines:constructor", {
|
|||
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 minetest.is_protected(pos, player:get_player_name()) then
|
||||
|
@ -158,7 +161,7 @@ minetest.register_node("basic_machines:constructor", {
|
|||
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
|
||||
|
@ -171,8 +174,8 @@ minetest.register_node("basic_machines:constructor", {
|
|||
|
||||
return stack:get_count();
|
||||
end,
|
||||
|
||||
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
|
||||
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());
|
||||
|
||||
|
@ -183,59 +186,59 @@ minetest.register_node("basic_machines:constructor", {
|
|||
|
||||
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)
|
||||
|
||||
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)
|
||||
|
||||
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
|
||||
if minetest.is_protected(pos, sender:get_player_name()) then
|
||||
minetest.record_protection_violation(pos, sender:get_player_name())
|
||||
return
|
||||
end
|
||||
|
||||
local meta = minetest.get_meta(pos);
|
||||
|
||||
|
||||
if fields.craft then
|
||||
if string.sub(fields.craft,1,3)=="CHG" then
|
||||
local sel = basic_machines.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
|
||||
else
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
if fields.CRAFT then
|
||||
constructor_process(pos);
|
||||
end
|
||||
|
||||
|
||||
constructor_update_meta(pos);
|
||||
end,
|
||||
|
||||
|
||||
can_dig = function(pos)
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory();
|
||||
|
||||
|
||||
if not (inv:is_empty("main")) then return false end -- main inv must be empty to be dug
|
||||
|
||||
|
||||
return true
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
@ -248,6 +251,6 @@ minetest.register_craft({
|
|||
{"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"},
|
||||
|
||||
|
||||
}
|
||||
})
|
135
enviro.lua
135
enviro.lua
|
@ -5,18 +5,18 @@
|
|||
|
||||
local enviro = {};
|
||||
enviro.skyboxes = {
|
||||
["default"]={type = "regular", tex = {}},
|
||||
["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");
|
||||
|
||||
|
@ -34,9 +34,12 @@ local enviro_update_form = function (pos)
|
|||
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 =
|
||||
|
||||
local form =
|
||||
"size[8,8.5]".. -- width, height
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"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
|
||||
|
@ -54,7 +57,7 @@ local enviro_update_form = function (pos)
|
|||
"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",
|
||||
|
@ -86,51 +89,51 @@ minetest.register_node("basic_machines:enviro", {
|
|||
|
||||
local inv = meta:get_inventory();
|
||||
inv:set_size("fuel",1*1);
|
||||
|
||||
|
||||
enviro_update_form(pos);
|
||||
end,
|
||||
|
||||
mesecons = {effector = {
|
||||
action_on = function (pos, node,ttl)
|
||||
|
||||
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")
|
||||
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 ""
|
||||
|
@ -138,26 +141,26 @@ minetest.register_node("basic_machines:enviro", {
|
|||
obj:setacceleration({x=0,y=-g,z=0});
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
end
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
|
||||
|
||||
if minetest.is_protected(pos, sender:get_player_name()) then
|
||||
minetest.record_protection_violation(pos, sender:get_player_name())
|
||||
return
|
||||
end
|
||||
|
||||
local name = sender:get_player_name();
|
||||
|
||||
|
||||
if fields.OK then
|
||||
local privs = minetest.get_player_privs(sender:get_player_name());
|
||||
local meta = minetest.get_meta(pos);
|
||||
|
@ -167,40 +170,40 @@ minetest.register_node("basic_machines:enviro", {
|
|||
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
|
||||
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)
|
||||
meta:set_int("r", r)
|
||||
end
|
||||
if fields.g then
|
||||
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)
|
||||
meta:set_float("g", g)
|
||||
end
|
||||
if fields.speed then
|
||||
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)
|
||||
meta:set_float("speed", speed)
|
||||
end
|
||||
if fields.jump then
|
||||
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)
|
||||
meta:set_float("jump", jump)
|
||||
end
|
||||
if fields.sneak then
|
||||
meta:set_int("sneak", tonumber(fields.sneak) or 0)
|
||||
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)
|
||||
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
|
@ -213,7 +216,7 @@ minetest.register_node("basic_machines:enviro", {
|
|||
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)
|
||||
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
|
@ -226,13 +229,13 @@ minetest.register_node("basic_machines:enviro", {
|
|||
if meta:get_string("owner")~=player:get_player_name() and not privs.privs then return 0 end
|
||||
return stack:get_count();
|
||||
end,
|
||||
|
||||
|
||||
can_dig = function(pos, player) -- dont dig if fuel is inside, cause it will be destroyed
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory();
|
||||
return inv:is_empty("fuel")
|
||||
end,
|
||||
|
||||
|
||||
})
|
||||
|
||||
|
||||
|
@ -275,7 +278,7 @@ 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 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};
|
||||
|
@ -297,13 +300,13 @@ minetest.register_globalstep(function(dtime)
|
|||
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)
|
||||
|
@ -311,13 +314,13 @@ minetest.register_globalstep(function(dtime)
|
|||
end
|
||||
return
|
||||
else
|
||||
|
||||
|
||||
local ppos = protector_position(pos);
|
||||
local populated = (minetest.get_node(ppos).name=="basic_protect:protector");
|
||||
if populated then
|
||||
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);
|
||||
|
@ -327,7 +330,7 @@ minetest.register_globalstep(function(dtime)
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -341,7 +344,7 @@ end)
|
|||
-- description = "enables breathing in space",
|
||||
-- drawtype = "liquid",
|
||||
-- tiles = {"default_water_source_animated.png"},
|
||||
|
||||
|
||||
-- drawtype = "glasslike",
|
||||
-- paramtype = "light",
|
||||
-- alpha = 150,
|
||||
|
@ -352,7 +355,7 @@ end)
|
|||
-- buildable_to = true,
|
||||
-- drop = "",
|
||||
-- groups = {not_in_creative_inventory=1},
|
||||
-- after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
-- after_place_node = function(pos, placer, itemstack, pointed_thing)
|
||||
-- local r = 3;
|
||||
-- for i = -r,r do
|
||||
-- for j = -r,r do
|
||||
|
@ -365,10 +368,10 @@ end)
|
|||
-- end
|
||||
-- end
|
||||
-- end
|
||||
|
||||
|
||||
-- })
|
||||
|
||||
-- minetest.register_abm({
|
||||
-- minetest.register_abm({
|
||||
-- nodenames = {"basic_machines:air"},
|
||||
-- neighbors = {"air"},
|
||||
-- interval = 10,
|
||||
|
@ -378,23 +381,23 @@ end)
|
|||
-- 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
|
||||
|
||||
|
|
141
grinder.lua
141
grinder.lua
|
@ -24,7 +24,7 @@ basic_machines.grinder_recipes = {
|
|||
-- es gems dust cooking
|
||||
local es_gems = function()
|
||||
local es_gems = {
|
||||
{name = "emerald", cooktime = 1200},{name = "ruby", cooktime = 1500},{name = "purpellium", cooktime = 1800},
|
||||
{name = "emerald", cooktime = 1200},{name = "ruby", cooktime = 1500},{name = "purpellium", cooktime = 1800},
|
||||
{name = "aikerum", cooktime = 2000}}
|
||||
|
||||
for _,v in pairs(es_gems) do
|
||||
|
@ -32,53 +32,53 @@ local es_gems = function()
|
|||
type = "cooking",
|
||||
recipe = "es:"..v.name.."_dust",
|
||||
output = "es:"..v.name .."_crystal",
|
||||
cooktime = v.cooktime
|
||||
cooktime = v.cooktime
|
||||
})
|
||||
end
|
||||
end
|
||||
minetest.after(0,es_gems);
|
||||
|
||||
|
||||
local grinder_process = function(pos)
|
||||
|
||||
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 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
|
||||
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")
|
||||
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 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
|
||||
if supply>0 then
|
||||
fueladd.time = supply -- same as 10 coal
|
||||
else
|
||||
meta:set_string("infotext", "Please insert fuel");
|
||||
|
@ -90,51 +90,54 @@ local grinder_process = function(pos)
|
|||
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
|
||||
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
|
||||
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 =
|
||||
local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
|
||||
local form =
|
||||
"size[8,8]".. -- width, height
|
||||
--"size[6,10]".. -- width, height
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"label[0,0;IN] label[1,0;OUT] label[0,2;FUEL] "..
|
||||
"list["..list_name..";src;0.,0.5;1,1;]"..
|
||||
"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["..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]"..
|
||||
|
@ -160,14 +163,14 @@ minetest.register_node("basic_machines:grinder", {
|
|||
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)
|
||||
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
|
@ -180,7 +183,7 @@ minetest.register_node("basic_machines:grinder", {
|
|||
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 minetest.is_protected(pos, player:get_player_name()) then
|
||||
|
@ -193,25 +196,25 @@ minetest.register_node("basic_machines:grinder", {
|
|||
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)
|
||||
|
||||
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)
|
||||
|
||||
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 minetest.is_protected(pos, sender:get_player_name()) then
|
||||
|
@ -221,30 +224,34 @@ minetest.register_node("basic_machines:grinder", {
|
|||
|
||||
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
|
||||
--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.."]"
|
||||
|
||||
local form = "size[6,7]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"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,
|
||||
|
||||
|
||||
can_dig = function(pos)
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory();
|
||||
|
||||
|
||||
if not (inv:is_empty("fuel")) or not (inv:is_empty("src")) or not (inv:is_empty("dst")) then return false end -- all inv must be empty to be dug
|
||||
|
||||
|
||||
return true
|
||||
|
||||
|
||||
end
|
||||
|
||||
})
|
||||
|
@ -256,7 +263,7 @@ minetest.register_craft({
|
|||
{"default:diamond","default:mese","default:diamond"},
|
||||
{"default:mese","default:diamondblock","default:mese"},
|
||||
{"default:diamond","default:mese","default:diamond"},
|
||||
|
||||
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -265,13 +272,13 @@ minetest.register_craft({
|
|||
|
||||
|
||||
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
|
||||
|
||||
|
||||
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, {
|
||||
|
@ -279,11 +286,11 @@ local function register_dust(name,input_node_name,ingot,grindcost,cooktime,R,G,B
|
|||
inventory_image = "basic_machines_dust.png^[colorize:#"..R..G..B..":"..purity * 2,
|
||||
})
|
||||
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",
|
||||
|
@ -292,7 +299,7 @@ local function register_dust(name,input_node_name,ingot,grindcost,cooktime,R,G,B
|
|||
cooktime = cooktime
|
||||
})
|
||||
end
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
type = "cooking",
|
||||
recipe = "basic_machines:"..name.."_dust_".. purity_table[#purity_table],
|
||||
|
@ -300,7 +307,7 @@ local function register_dust(name,input_node_name,ingot,grindcost,cooktime,R,G,B
|
|||
output = ingot,
|
||||
cooktime = cooktime
|
||||
})
|
||||
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -319,11 +326,11 @@ basic_machines.grinder_recipes["default:tin_ingot"] = {4,"basic_machines:tin_dus
|
|||
|
||||
-- are moreores (tin, silver, mithril) present?
|
||||
|
||||
local table = minetest.registered_items["moreores:tin_lump"]; if table then
|
||||
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};
|
||||
|
|
63
mover.lua
63
mover.lua
|
@ -265,6 +265,9 @@ local get_mover_form = function(pos,player)
|
|||
|
||||
form = "size[8,8.25]" .. -- width, height
|
||||
--"size[6,10]" .. -- width, height
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"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 .."]"..
|
||||
|
@ -294,6 +297,9 @@ local get_mover_form = function(pos,player)
|
|||
|
||||
form = "size[6,5.5]" .. -- width, height
|
||||
--"size[6,10]" .. -- width, height
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"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").."]"..
|
||||
|
@ -1002,7 +1008,7 @@ minetest.register_node("basic_machines:mover", {
|
|||
if prefer ~= node1.name and
|
||||
not source_chest and
|
||||
mode ~= "inventory" then
|
||||
return
|
||||
return
|
||||
end
|
||||
|
||||
-- take stuff from chest
|
||||
|
@ -1493,6 +1499,9 @@ local function check_keypad(pos,name,ttl) -- called only when manually activated
|
|||
if meta:get_string("text") == "@" then -- keypad works as a keyboard
|
||||
local form =
|
||||
"size[3,1]" .. -- width, height
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"field[0.25,0.25;3,1;pass;Enter text: ;".."".."] button_exit[0.,0.5;1,1;OK;OK]";
|
||||
minetest.show_formspec(name, "basic_machines:check_keypad_"..minetest.pos_to_string(pos), form)
|
||||
return
|
||||
|
@ -1501,11 +1510,12 @@ local function check_keypad(pos,name,ttl) -- called only when manually activated
|
|||
pass = ""
|
||||
local form =
|
||||
"size[3,1.25]" .. -- width, height
|
||||
"bgcolor[#FF8888BB; false]" ..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"field[0.25,0.25;3,1;pass;Enter Password: ;".."".."] button_exit[0.,0.75;1,1;OK;OK]";
|
||||
minetest.show_formspec(name, "basic_machines:check_keypad_"..minetest.pos_to_string(pos), form)
|
||||
return
|
||||
|
||||
end
|
||||
|
||||
minetest.register_node("basic_machines:keypad", {
|
||||
|
@ -1550,7 +1560,9 @@ minetest.register_node("basic_machines:keypad", {
|
|||
pass = meta:get_string("pass");
|
||||
local form =
|
||||
"size[4.25,3.75]" .. -- width, height
|
||||
"bgcolor[#888888BB; false]" ..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"field[2.25,0.25;2.25,1;pass;Password: ;"..pass.."]" ..
|
||||
"field[0.25,2.5;3.25,1;text;text;".. text .."]" ..
|
||||
"field[0.25,0.25;1,1;mode;mode;"..mode.."]".. "field[1.25,0.25;1,1;iter;repeat;".. iter .."]"..
|
||||
|
@ -1638,6 +1650,9 @@ minetest.register_node("basic_machines:detector", {
|
|||
local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
|
||||
local form =
|
||||
"size[4,6.25]" .. -- width, height
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"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.."]"..
|
||||
|
@ -1949,6 +1964,9 @@ local get_distributor_form = function(pos,player)
|
|||
local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
|
||||
local form =
|
||||
"size[7,"..(0.75+(n)*0.75).."]" .. -- width, height
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"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] .. "]"
|
||||
|
@ -1958,7 +1976,6 @@ local get_distributor_form = function(pos,player)
|
|||
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
|
||||
|
||||
|
||||
|
@ -2164,7 +2181,11 @@ minetest.register_node("basic_machines:light_on", {
|
|||
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]";
|
||||
local form = "size[2,2]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"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)
|
||||
|
@ -2179,7 +2200,11 @@ minetest.register_node("basic_machines:light_on", {
|
|||
local deactivate = basic_machines.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]";
|
||||
local form = "size[2,2]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"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
|
||||
|
||||
|
@ -2535,7 +2560,11 @@ minetest.register_on_player_receive_fields(function(player,formname,fields)
|
|||
"\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.."]"
|
||||
local form = "size [6,7]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"textarea[0,0;6.5,8.5;help;MOVER HELP;".. text.."]"
|
||||
minetest.show_formspec(name, "basic_machines:help_mover", form)
|
||||
return
|
||||
end
|
||||
|
@ -2700,7 +2729,11 @@ minetest.register_on_player_receive_fields(function(player,formname,fields)
|
|||
"\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.."]"
|
||||
local form = "size[6,7]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"textarea[0,0;6.5,8.5;help;KEYPAD HELP;".. text.."]"
|
||||
minetest.show_formspec(name, "basic_machines:help_keypad", form)
|
||||
return
|
||||
end
|
||||
|
@ -2805,7 +2838,11 @@ minetest.register_on_player_receive_fields(function(player,formname,fields)
|
|||
"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.."]"
|
||||
local form = "size[5.5,5.5]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"textarea[0,0;6,7;help;DETECTOR HELP;".. text.."]"
|
||||
minetest.show_formspec(name, "basic_machines:help_detector", form)
|
||||
end
|
||||
|
||||
|
@ -2954,7 +2991,11 @@ minetest.register_on_player_receive_fields(function(player,formname,fields)
|
|||
"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.."]"
|
||||
local form = "size[5.5,5.5]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"textarea[0,0;6,7;help;DISTRIBUTOR HELP;".. text.."]"
|
||||
minetest.show_formspec(name, "basic_machines:help_distributor", form)
|
||||
end
|
||||
|
||||
|
|
117
recycler.lua
117
recycler.lua
|
@ -13,25 +13,25 @@ local no_recycle_list = {
|
|||
}
|
||||
|
||||
|
||||
local recycler_process = function(pos)
|
||||
|
||||
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")
|
||||
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 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
|
||||
if supply>0 then
|
||||
fueladd.time = 40*supply -- same as 10 coal
|
||||
else
|
||||
meta:set_string("infotext", "Please insert fuel.");
|
||||
|
@ -42,8 +42,8 @@ local recycler_process = function(pos)
|
|||
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
|
||||
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);
|
||||
|
@ -51,15 +51,15 @@ local recycler_process = function(pos)
|
|||
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
|
||||
|
||||
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
|
||||
|
@ -68,56 +68,56 @@ local recycler_process = function(pos)
|
|||
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 = basic_machines.tonumber(meta:get_int("recipe")) or 1;
|
||||
|
||||
if not recipe then
|
||||
|
||||
if not recipe then
|
||||
return
|
||||
else
|
||||
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
|
||||
if string.find(output," ") then
|
||||
local par = string.find(output," ");
|
||||
--if (basic_machines.tonumber(string.sub(output, par)) or 0)>1 then itemlist = {} end
|
||||
|
||||
|
||||
if par then
|
||||
reqcount = basic_machines.tonumber(string.sub(output, par)) or 1;
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
meta:set_string("itemlist",minetest.serialize(itemlist)); -- read cached itemlist
|
||||
meta:set_int("reqcount",reqcount);
|
||||
else
|
||||
else
|
||||
itemlist=minetest.deserialize(meta:get_string("itemlist")) or {};
|
||||
reqcount = meta:get_int("reqcount") or 1;
|
||||
end
|
||||
|
||||
|
||||
if stack:get_count()<reqcount then
|
||||
meta:set_string("infotext", "at least " .. reqcount .. " of " .. src_item .. " is needed ");
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
--empty dst inventory before proceeding
|
||||
-- local size = inv:get_size("dst");
|
||||
-- local size = inv:get_size("dst");
|
||||
-- for i=1,size do
|
||||
-- inv:set_stack("dst", i, ItemStack(""));
|
||||
-- end
|
||||
|
||||
|
||||
--take 1 item from src inventory for each activation
|
||||
stack=stack:take_item(reqcount); inv:remove_item("src", stack)
|
||||
|
||||
|
||||
for _, v in pairs(itemlist) do
|
||||
if math.random(1, 4)<=3 then -- probability 3/4 = 75%
|
||||
if not string.find(v,"group") then -- dont add if item described with group
|
||||
|
@ -129,12 +129,12 @@ local recycler_process = function(pos)
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
minetest.sound_play("recycler", {pos=pos,gain=0.5,max_hear_distance = 16,})
|
||||
|
||||
|
||||
|
||||
|
||||
fuel = fuel-1; -- burn fuel on succesful operation
|
||||
meta:set_float("fuel",fuel); meta:set_string("infotext", "fuel status " .. fuel .. ", recycling " .. meta:get_string("node"));
|
||||
end
|
||||
|
@ -142,10 +142,13 @@ end
|
|||
|
||||
local recycler_update_meta = function(pos)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
|
||||
local form =
|
||||
local list_name = "nodemeta:"..pos.x..','..pos.y..','..pos.z
|
||||
local form =
|
||||
"size[8,8]".. -- width, heightinv:get_stack
|
||||
--"size[6,10]".. -- width, height
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"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;]"..
|
||||
|
@ -158,7 +161,7 @@ local recycler_update_meta = function(pos)
|
|||
"listring["..list_name..";src]"..
|
||||
"listring[current_player;main]"..
|
||||
"listring["..list_name..";fuel]"..
|
||||
"listring[current_player;main]"
|
||||
"listring[current_player;main]"
|
||||
--"field[0.25,4.5;2,1;mode;mode;"..mode.."]"
|
||||
meta:set_string("formspec", form)
|
||||
end
|
||||
|
@ -176,14 +179,14 @@ minetest.register_node("basic_machines:recycler", {
|
|||
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
|
||||
recycler_update_meta(pos);
|
||||
end,
|
||||
|
||||
|
||||
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
|
||||
if minetest.is_protected(pos, player:get_player_name()) then
|
||||
|
@ -196,7 +199,7 @@ minetest.register_node("basic_machines:recycler", {
|
|||
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 minetest.is_protected(pos, player:get_player_name()) then
|
||||
|
@ -209,25 +212,25 @@ minetest.register_node("basic_machines:recycler", {
|
|||
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)
|
||||
|
||||
on_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||
if listname =="dst" then return end
|
||||
recycler_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)
|
||||
|
||||
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
|
||||
recycler_process(pos);
|
||||
end
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
on_receive_fields = function(pos, formname, fields, sender)
|
||||
|
||||
if minetest.is_protected(pos, sender:get_player_name()) then
|
||||
|
@ -246,16 +249,16 @@ minetest.register_node("basic_machines:recycler", {
|
|||
meta:set_string("node",""); -- this will force to reread recipe on next use
|
||||
recycler_update_meta(pos);
|
||||
end,
|
||||
|
||||
|
||||
can_dig = function(pos)
|
||||
|
||||
|
||||
local meta = minetest.get_meta(pos);
|
||||
local inv = meta:get_inventory();
|
||||
|
||||
|
||||
if not (inv:is_empty("fuel")) or not (inv:is_empty("src")) or not (inv:is_empty("dst")) then return false end -- all inv must be empty to be dug
|
||||
|
||||
|
||||
return true
|
||||
|
||||
|
||||
end
|
||||
|
||||
})
|
||||
|
@ -267,6 +270,6 @@ minetest.register_craft({
|
|||
{"default:mese_crystal","default:mese_crystal","default:mese_crystal"},
|
||||
{"default:mese_crystal","default:diamondblock","default:mese_crystal"},
|
||||
{"default:mese_crystal","default:mese_crystal","default:mese_crystal"},
|
||||
|
||||
|
||||
}
|
||||
})
|
|
@ -12,7 +12,9 @@ local battery_update_meta = function(pos)
|
|||
|
||||
local form =
|
||||
"size[8,6.5]".. -- width, height
|
||||
"bgcolor[#333333;false]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"label[0,0;FUEL] ".."label[6,0;UPGRADE] "..
|
||||
"box[1.45,0.48;2.15,1.01;#222222]"..
|
||||
"list["..list_name..";fuel;0.,0.5;1,1;]"..
|
||||
|
@ -271,7 +273,11 @@ minetest.register_node("basic_machines:battery_0", {
|
|||
"UPGRADE with diamondblocks for more available power output or with "..
|
||||
"meseblocks for more power storage capacity"
|
||||
|
||||
local form = "size [6,7] textarea[0,0;6.5,8.5;help;BATTERY HELP;".. text.."]"
|
||||
local form = "size[6,7]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"textarea[0,0;6.5,8.5;help;BATTERY HELP;".. text.."]"
|
||||
minetest.show_formspec(name, "basic_machines:help_battery", form)
|
||||
end
|
||||
end,
|
||||
|
@ -347,6 +353,9 @@ local generator_update_meta = function(pos)
|
|||
|
||||
local form =
|
||||
"size[8,6.5]" .. -- width, height
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"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;]"..
|
||||
|
@ -410,7 +419,11 @@ minetest.register_node("basic_machines:generator", {
|
|||
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.."]"
|
||||
local form = "size[6,7]"..
|
||||
default.gui_bg..
|
||||
default.gui_bg_img..
|
||||
default.gui_slots..
|
||||
"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
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 2.0 KiB |
Binary file not shown.
Before Width: | Height: | Size: 239 B |
Binary file not shown.
Before Width: | Height: | Size: 258 B |
Binary file not shown.
Before Width: | Height: | Size: 486 B After Width: | Height: | Size: 350 B |
Loading…
Reference in New Issue