1st attempt to handle numbers
parent
56d8bf0ca3
commit
0b6c9ab690
44
ball.lua
44
ball.lua
|
@ -501,9 +501,9 @@ minetest.register_node("basic_machines:ball_spawner", {
|
|||
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 fields.x0 then x0 = basic_machines.tonumber(fields.x0) or 0 end
|
||||
if fields.y0 then y0 = basic_machines.tonumber(fields.y0) or 0 end
|
||||
if fields.z0 then z0 = basic_machines.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);
|
||||
|
@ -517,44 +517,44 @@ minetest.register_node("basic_machines:ball_spawner", {
|
|||
|
||||
|
||||
if fields.speed then
|
||||
local speed = tonumber(fields.speed) or 0;
|
||||
local speed = basic_machines.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;
|
||||
local energy = basic_machines.tonumber(fields.energy) or 1;
|
||||
meta:set_float("energy", energy)
|
||||
end
|
||||
|
||||
if fields.bounce then
|
||||
local bounce = tonumber(fields.bounce) or 1;
|
||||
local bounce = basic_machines.tonumber(fields.bounce) or 1;
|
||||
meta:set_int("bounce",bounce)
|
||||
end
|
||||
|
||||
if fields.gravity then
|
||||
local gravity = tonumber(fields.gravity) or 1;
|
||||
local gravity = basic_machines.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)
|
||||
meta:set_int("puncheable", basic_machines.tonumber(fields.puncheable) or 0)
|
||||
end
|
||||
|
||||
if fields.solid then
|
||||
meta:set_int("solid", tonumber(fields.solid) or 0)
|
||||
meta:set_int("solid", basic_machines.tonumber(fields.solid) or 0)
|
||||
end
|
||||
|
||||
if fields.lifetime then
|
||||
meta:set_int("lifetime", tonumber(fields.lifetime) or 0)
|
||||
meta:set_int("lifetime", basic_machines.tonumber(fields.lifetime) or 0)
|
||||
end
|
||||
|
||||
if fields.hurt then
|
||||
meta:set_float("hurt", tonumber(fields.hurt) or 0)
|
||||
meta:set_float("hurt", basic_machines.tonumber(fields.hurt) or 0)
|
||||
end
|
||||
|
||||
if fields.hp then
|
||||
meta:set_float("hp", math.abs(tonumber(fields.hp) or 0))
|
||||
meta:set_float("hp", math.abs(basic_machines.tonumber(fields.hp) or 0))
|
||||
end
|
||||
|
||||
if fields.texture then
|
||||
|
@ -562,7 +562,7 @@ minetest.register_node("basic_machines:ball_spawner", {
|
|||
end
|
||||
|
||||
if fields.scale then
|
||||
local scale = math.abs(tonumber(fields.scale) or 100);
|
||||
local scale = math.abs(basic_machines.tonumber(fields.scale) or 100);
|
||||
if scale>1000 and not privs.privs then scale = 1000 end
|
||||
meta:set_int("scale", scale)
|
||||
end
|
||||
|
@ -621,11 +621,11 @@ minetest.register_tool("basic_machines:ball_spell", {
|
|||
|
||||
|
||||
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
|
||||
speed = basic_machines.tonumber(meta["speed"]) or 0;
|
||||
energy = basic_machines.tonumber(meta["energy"]) or 0; -- if positive activates, negative deactivates, 0 does nothing
|
||||
bounce = basic_machines.tonumber(meta["bounce"]) or 0; -- if nonzero bounces when hit obstacle, 0 gets absorbed
|
||||
gravity = basic_machines.tonumber(meta["gravity"]) or 0; -- gravity
|
||||
puncheable = basic_machines.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_bullet.png^[colorize:blue:120"}})
|
||||
|
@ -638,9 +638,9 @@ minetest.register_tool("basic_machines:ball_spell", {
|
|||
end
|
||||
luaent.puncheable = puncheable;
|
||||
luaent.owner = meta["owner"];
|
||||
luaent.hurt = math.min(tonumber(meta["hurt"]),basic_machines.ball.maxdamage);
|
||||
luaent.hurt = math.min(basic_machines.tonumber(meta["hurt"]),basic_machines.ball.maxdamage);
|
||||
|
||||
obj:set_hp( tonumber(meta["hp"]) );
|
||||
obj:set_hp( basic_machines.tonumber(meta["hp"]) );
|
||||
|
||||
local x0,y0,z0;
|
||||
if speed>0 then luaent.speed = speed end
|
||||
|
@ -652,8 +652,8 @@ minetest.register_tool("basic_machines:ball_spell", {
|
|||
obj:setvelocity(v);
|
||||
|
||||
|
||||
if tonumber(meta["admin"])==1 then
|
||||
luaent.lifetime = tonumber(meta["lifetime"]);
|
||||
if basic_machines.tonumber(meta["admin"])==1 then
|
||||
luaent.lifetime = basic_machines.tonumber(meta["lifetime"]);
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -208,7 +208,7 @@ minetest.register_node("basic_machines:constructor", {
|
|||
|
||||
if fields.craft then
|
||||
if string.sub(fields.craft,1,3)=="CHG" then
|
||||
local sel = tonumber(string.sub(fields.craft,5)) or 1
|
||||
local sel = basic_machines.tonumber(string.sub(fields.craft,5)) or 1
|
||||
meta:set_int("selected",sel);
|
||||
|
||||
local i = 0;
|
||||
|
|
34
init.lua
34
init.lua
|
@ -15,10 +15,37 @@
|
|||
-- You should have received a copy of the GNU General Public License
|
||||
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
basic_machines = {};
|
||||
|
||||
basic_machines.tonumber = function(number)
|
||||
local nr = tonumber(number)
|
||||
|
||||
-- nil check
|
||||
if not nr then
|
||||
nr = 0
|
||||
end
|
||||
|
||||
-- NaN check
|
||||
if nr ~= nr then
|
||||
nr = 0
|
||||
end
|
||||
|
||||
-- infinite number check
|
||||
if not (nr > -math.huge and nr < math.huge) then
|
||||
nr = 0
|
||||
end
|
||||
|
||||
-- prevent voxel manip crash for large numbers
|
||||
if nr > 99 then
|
||||
nr = 99
|
||||
end
|
||||
|
||||
if nr < -99 then
|
||||
nr = -99
|
||||
end
|
||||
|
||||
return nr
|
||||
end
|
||||
|
||||
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
|
||||
|
@ -33,10 +60,10 @@ dofile(minetest.get_modpath("basic_machines").."/protect.lua") -- enable interac
|
|||
|
||||
-- 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").."/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()
|
||||
-- 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)
|
||||
|
@ -55,7 +82,6 @@ minetest.register_craftitem("basic_machines:charcoal", {
|
|||
inventory_image = "charcoal.png",
|
||||
})
|
||||
|
||||
|
||||
minetest.register_craft({
|
||||
type = 'cooking',
|
||||
recipe = "default:tree",
|
||||
|
|
14
mark.lua
14
mark.lua
|
@ -1,15 +1,15 @@
|
|||
-- rnd: code borrowed from machines, mark.lua
|
||||
|
||||
-- need for marking
|
||||
machines = {};
|
||||
|
||||
machines.pos1 = {};machines.pos11 = {}; machines.pos2 = {};
|
||||
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]
|
||||
|
@ -19,7 +19,7 @@ machines.mark_pos1 = function(name)
|
|||
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
|
||||
|
@ -44,7 +44,7 @@ machines.mark_pos11 = function(name)
|
|||
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
|
||||
|
@ -69,7 +69,7 @@ machines.mark_pos2 = function(name)
|
|||
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
|
||||
|
|
|
@ -77,7 +77,7 @@ local recycler_process = function(pos)
|
|||
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;
|
||||
local recipe_id = basic_machines.tonumber(meta:get_int("recipe")) or 1;
|
||||
|
||||
if not recipe then
|
||||
return
|
||||
|
@ -89,10 +89,10 @@ local recycler_process = function(pos)
|
|||
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 (basic_machines.tonumber(string.sub(output, par)) or 0)>1 then itemlist = {} end
|
||||
|
||||
if par then
|
||||
reqcount = tonumber(string.sub(output, par)) or 1;
|
||||
reqcount = basic_machines.tonumber(string.sub(output, par)) or 1;
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -239,7 +239,7 @@ minetest.register_node("basic_machines:recycler", {
|
|||
local meta = minetest.get_meta(pos);
|
||||
local recipe=1;
|
||||
if fields.recipe then
|
||||
recipe = tonumber(fields.recipe) or 1;
|
||||
recipe = basic_machines.tonumber(fields.recipe) or 1;
|
||||
else return;
|
||||
end
|
||||
meta:set_int("recipe",recipe);
|
||||
|
|
Loading…
Reference in New Issue