(untested, bugreports needed) Reorganization.

master
Drew Lemmy 2014-09-16 22:20:39 +01:00
parent 3c18e04b8c
commit 8c8701323b
29 changed files with 943 additions and 947 deletions

16
decor/crafting.lua Normal file
View File

@ -0,0 +1,16 @@
minetest.register_craft({
output = "factory:smoke_tube",
recipe = {
{"default:steel_ingot", "", "default:steel_ingot"},
{"default:steel_ingot", "", "default:steel_ingot"},
{"default:steel_ingot", "", "default:steel_ingot"}
}
})
minetest.register_craft({
output = 'factory:factory_brick 6',
recipe = {
{'factory:factory_lump', 'factory:factory_lump'},
{'factory:factory_lump', 'factory:factory_lump'},
}
})

6
decor/factorybrick.lua Normal file
View File

@ -0,0 +1,6 @@
minetest.register_node("factory:factory_brick", {
description = "Factory Brick",
tiles = {"factory_brick.png"},
is_ground_content = true,
groups = {cracky=3, stone=1}
})

3
decor/init.lua Normal file
View File

@ -0,0 +1,3 @@
dofile(factory.modpath.."/decor/crafting.lua")
dofile(factory.modpath.."/decor/smoketube.lua")
dofile(factory.modpath.."/decor/factorybrick.lua")

30
decor/smoketube.lua Normal file
View File

@ -0,0 +1,30 @@
minetest.register_node("factory:smoke_tube", {
drawtype = "nodebox",
tiles = {"factory_machine_brick_1.png"},
paramtype = "light",
description = "Smoke Tube",
groups = {cracky=3},
node_box = {
type = "fixed",
fixed = {
{-0.125,-0.5,0.3125,0.125,0.5,0.375},
{-0.125,-0.5,-0.375,0.125,0.5,-0.3125},
{0.3125,-0.5,-0.125,0.375,0.5,0.125},
{-0.375,-0.5,-0.125,-0.3125,0.5,0.125},
{0.125,-0.5,0.25,0.25,0.5,0.3125},
{0.25,-0.5,0.125,0.3125,0.5,0.25},
{0.25,-0.5,-0.25,0.3125,0.5,-0.125},
{0.125,-0.5,-0.3125,0.25,0.5,-0.25},
{-0.25,-0.5,-0.3125,-0.125,0.5,-0.25},
{-0.3125,-0.5,-0.25,-0.25,0.5,-0.125},
{-0.3125,-0.5,0.125,-0.25,0.5,0.25},
{-0.25,-0.5,0.25,-0.125,0.5,0.3125},
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.375,-0.5,-0.375,0.375,0.5,0.375},
}
},
})

213
init.lua
View File

@ -6,216 +6,11 @@ empty={item=ItemStack(nil),time=0}
factory.worldpath = minetest.get_worldpath()
factory.modpath = minetest.get_modpath("factory")
-- Settings
dofile(factory.modpath.."/settings.txt")
-- This below is the Crafter mod by the legend MasterGollum
function factory.register_craft(craft)
assert(craft.type ~= nil and craft.recipe ~= nil and craft.output ~= nil,
"Invalid craft definition, it must have type, recipe and output")
assert(type(craft.recipe)=="table" and type(craft.recipe[1])=="table","'recipe' must be a bidimensional table")
minetest.log("verbose","registerCraft ("..craft.type..", output="..craft.output.." recipe="..dump(craft.recipe))
craft._h=#craft.recipe
craft._w=#craft.recipe[1]
-- TODO check that all the arrays have the same length...
factory.crafts[#factory.crafts+1]=craft
end
function factory.get_craft_result(data)
assert(data.method ~= nil and data.items ~= nil, "Invalid call, method and items must be provided")
local w = 1
if data.width ~= nil and data.width>0 then
w=data.width
end
local r=nil
for zz,craft in ipairs(factory.crafts) do
r=factory._check_craft(data,w,craft)
if r ~= nil then
if factory.debug then
print("Craft found, returning "..dump(r.item))
end
return r
end
end
return factory.empty
end
function factory._check_craft(data,w,c)
if c.type == data.method then
-- Here we go..
for i=1,w-c._h+1 do
for j=1,w-c._w+1 do
local p=(i-1)*w+j
if factory.debug then
print("Checking data.items["..dump(i).."]["..dump(j).."]("..dump(p)..")="..dump(data.items[p]:get_name()).." vs craft.recipe[1][1]="..dump(c.recipe[1][1]))
end
if data.items[p]:get_name() == c.recipe[1][1] then
for m=1,c._h do
for n=1,c._w do
local q=(i+m-1-1)*w+j+n-1
if factory.debug then
print(" Checking data.items["..dump(i+m-1).."]["..dump(j+n-1).."]("..dump(q)..")="..dump(data.items[q]:get_name())..
" vs craft.recipe["..dump(m).."]["..dump(n).."]="..dump(c.recipe[m][n]))
end
if c.recipe[m][n] ~= data.items[q]:get_name() then
return nil
end
end
end
-- found! we still must check that is not any other stuff outside the limits of the recipe sizes...
-- Checking at right of the matching square
for m=i-c._h+1+1,w do
for n=j+c._w,w do
local q=(m-1)*w+n
if factory.debug then
print(" Checking right data.items["..dump(m).."]["..dump(n).."]("..dump(q)..")="..dump(data.items[q]:get_name()))
end
if data.items[q]:get_name() ~= "" then
return nil
end
end
end
-- Checking at left of the matching square (the first row has been already scanned)
for m=i-c._h+1+1+1,w do
for n=1,j-1 do
local q=(m-1)*w+n
if factory.debug then
print(" Checking left data.items["..dump(m).."]["..dump(n).."]("..dump(q)..")="..dump(data.items[q]:get_name()))
end
if data.items[q]:get_name() ~= "" then
return nil
end
end
end
-- Checking at bottom of the matching square
for m=i+c._h,w do
for n=j,j+c._w do
local q=(m-1)*w+n
if factory.debug then
print(" Checking bottom data.items["..dump(m).."]["..dump(n).."]("..dump(q)..")="..dump(data.items[q]:get_name()))
end
if data.items[q]:get_name() ~= "" then
return nil
end
end
end
if factory.debug then
print("Craft found! "..c.output)
end
return {item=ItemStack(c.output),time=1}
elseif data.items[p] ~= nil and data.items[p]:get_name() ~= "" then
if factory.debug then
print("Invalid data item "..dump(data.items[p]:get_name()))
end
return nil
end
end
end
end
end
-- GUI related stuff
factory_gui_bg = "bgcolor[#080808BB;true]"
factory_gui_bg_img = "background[5,5;1,1;gui_factoryformbg.png;true]"
factory_gui_bg_img_2 = "background[5,5;1,1;gui_factoryformbg2.png;true]"
factory_gui_slots = "listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]"
function factory.get_hotbar_bg(x,y)
local out = ""
for i=0,7,1 do
out = out .."image["..x+i..","..y..";1,1;gui_hb_bg.png]"
end
return out
end
function factory.swap_node(pos,name)
local node = minetest.get_node(pos)
if node.name == name then
return
end
node.name = name
minetest.swap_node(pos,node)
end
function factory.get_objects_with_square_radius(pos, rad)
rad = rad + .5;
local objs = {}
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, math.sqrt(3)*rad)) do
if not object:is_player() and object:get_luaentity() and (object:get_luaentity().name == "__builtin:item" or object:get_luaentity().name == "factory:moving_item") then
local opos = object:getpos()
if pos.x - rad <= opos.x and opos.x <= pos.x + rad and pos.y - rad <= opos.y and opos.y <= pos.y + rad and pos.z - rad <= opos.z and opos.z <= pos.z + rad then
objs[#objs + 1] = object
end
end
end
return objs
end
print(minetest.get_modpath("pipeworks"))
dofile(factory.modpath.."/nodes.lua")
dofile(factory.modpath.."/craftitems.lua")
dofile(factory.modpath.."/crafting.lua")
dofile(factory.modpath.."/belt.lua")
dofile(factory.modpath.."/ind_furnace.lua")
dofile(factory.modpath.."/ind_squeezer.lua")
dofile(factory.modpath.."/stp.lua")
dofile(factory.modpath.."/swapper.lua")
if factory.enableFan then dofile(factory.modpath.."/fan.lua") end
dofile(factory.modpath.."/storage_tank.lua")
if factory.enableMiner then dofile(factory.modpath.."/miner.lua") end
if factory.enableVacuum then dofile(factory.modpath.."/vacuum.lua") end
if factory.fertilizerGeneration then
minetest.register_on_generated(function(minp, maxp, seed)
if maxp.y >= 2 and minp.y <=0 then
-- Generate fertilizer
local perlin1 = minetest.get_perlin(576, 3, 0.6, 100)
local divlen = 16
local divs = (maxp.x-minp.x)/divlen + 1;
for divx=0,divs-1 do
for divz=0,divs-1 do
local x0 = minp.x + math.floor(divx*divlen)
local z0 = minp.z + math.floor(divz*divlen)
local x1 = minp.x + math.floor((divx+1)*divlen)
local z1 = minp.z + math.floor((divz+1)*divlen)
local grass_amount = math.floor(perlin1:get2d({x=x0, y=z0}) ^ 2)
local pr = PseudoRandom(seed+249)
for i=0,grass_amount do
local x = pr:next(x0, x1)
local z = pr:next(z0, z1)
local ground_y = nil
for y=30,0,-1 do
if minetest.get_node({x=x,y=y,z=z}).name ~= "air" then
ground_y = y
break
end
end
if ground_y then
local p = {x=x, y=ground_y+1, z=z}
local nn = minetest.get_node(p).name
if minetest.registered_nodes[nn] and
minetest.registered_nodes[nn].buildable_to then
nn = minetest.get_node({x=x,y=ground_y,z=z}).name
if nn == "default:dirt_with_grass" then
minetest.set_node(p, {name="factory:sapling_fertilizer"})
end
end
end
end
end
end
end
end)
end
dofile(factory.modpath.."/util/init.lua")
dofile(factory.modpath.."/machines/init.lua")
dofile(factory.modpath.."/items/init.lua")
dofile(factory.modpath.."/decor/init.lua")
print("Factory v0.5.1 is working")

89
items/crafting.lua Normal file
View File

@ -0,0 +1,89 @@
minetest.register_craft({
output = "factory:small_steel_gear 3",
recipe = {
{"default:steel_ingot", "", "default:steel_ingot"},
{"", "default:steel_ingot", ""},
{"default:steel_ingot", "", "default:steel_ingot"}
}
})
minetest.register_craft({
output = "factory:small_gold_gear 2",
recipe = {
{"default:gold_ingot", "", "default:gold_ingot"},
{"", "factory:small_steel_gear", ""},
{"default:gold_ingot", "", "default:gold_ingot"}
}
})
minetest.register_craft({
output = "factory:small_diamond_gear 2",
recipe = {
{"default:diamond", "", "default:diamond"},
{"", "factory:small_gold_gear", ""},
{"default:diamond", "", "default:diamond"}
}
})
minetest.register_craft({
output = "factory:scanner_chip",
recipe = {
{"default:steel_ingot", "default:stick", "default:mese_crystal"},
{"", "factory:tree_sap", ""},
{"default:mese_crystal", "", "default:steel_ingot"}
}
})
minetest.register_craft({
output = "factory:storage_tank",
recipe = {
{"default:glass", "default:steel_ingot", "default:glass"},
{"default:glass", "", "default:glass"},
{"default:glass", "default:steel_ingot", "default:glass"}
}
})
minetest.register_craft({
output = "factory:sapling_fertilizer",
recipe = {
{"default:dirt", "default:dirt"},
{"default:dirt", "default:dirt"},
}
})
minetest.register_craft({
type = "shapeless",
output = "factory:fan_blade",
recipe = {
"default:steel_ingot",
"factory:tree_sap",
"default:stick"
}
})
factory.register_craft({
type = "ind_squeezer",
output = "factory:tree_sap",
recipe = {{"default:tree"}}
})
factory.register_craft({
type = "ind_squeezer",
output = "factory:tree_sap",
recipe = {{"default:jungle_tree"}}
})
factory.register_craft({
type = "ind_squeezer",
output = "factory:compressed_clay",
recipe = {{"default:clay_lump"}}
})
minetest.register_craft({
type = "cooking",
output = "factory:factory_lump",
recipe = "factory:compressed_clay"
})

View File

@ -1,40 +1,24 @@
minetest.register_craftitem("factory:small_steel_gear", {
description = "Small Steel Gear",
inventory_image = "factory_small_steel_gear.png"
})
minetest.register_craftitem("factory:small_gold_gear", {
description = "Small Gold Gear",
inventory_image = "factory_small_gold_gear.png"
})
minetest.register_craftitem("factory:small_diamond_gear", {
description = "Small Diamond Gear",
inventory_image = "factory_small_diamond_gear.png"
})
minetest.register_craftitem("factory:tree_sap", {
description = "Tree Sap",
inventory_image = "factory_tree_sap.png"
})
minetest.register_craftitem("factory:compressed_clay", {
description = "Compressed Clay",
inventory_image = "factory_compressed_clay.png"
})
minetest.register_craftitem("factory:factory_lump", {
description = "Factory Lump",
inventory_image = "factory_lump.png"
})
minetest.register_craftitem("factory:scanner_chip", {
description = "Item Scanning Microchip",
inventory_image = "factory_scanner_chip.png"
})
minetest.register_craftitem("factory:fan_blade", {
description = "Small Fanblade",
inventory_image = "factory_fan_blade.png"
})
minetest.register_craftitem("factory:tree_sap", {
description = "Tree Sap",
inventory_image = "factory_tree_sap.png"
})
minetest.register_craftitem("factory:compressed_clay", {
description = "Compressed Clay",
inventory_image = "factory_compressed_clay.png"
})
minetest.register_craftitem("factory:factory_lump", {
description = "Factory Lump",
inventory_image = "factory_lump.png"
})
minetest.register_craftitem("factory:scanner_chip", {
description = "Item Scanning Microchip",
inventory_image = "factory_scanner_chip.png"
})
minetest.register_craftitem("factory:fan_blade", {
description = "Small Fanblade",
inventory_image = "factory_fan_blade.png"
})

14
items/gears.lua Normal file
View File

@ -0,0 +1,14 @@
minetest.register_craftitem("factory:small_steel_gear", {
description = "Small Steel Gear",
inventory_image = "factory_small_steel_gear.png"
})
minetest.register_craftitem("factory:small_gold_gear", {
description = "Small Gold Gear",
inventory_image = "factory_small_gold_gear.png"
})
minetest.register_craftitem("factory:small_diamond_gear", {
description = "Small Diamond Gear",
inventory_image = "factory_small_diamond_gear.png"
})

4
items/init.lua Normal file
View File

@ -0,0 +1,4 @@
dofile(factory.modpath.."/items/crafting.lua")
dofile(factory.modpath.."/items/craftitems.lua")
dofile(factory.modpath.."/items/gears.lua")
dofile(factory.modpath.."/items/storage_tank.lua")

94
machines/arm.lua Normal file
View File

@ -0,0 +1,94 @@
minetest.register_node("factory:arm",{
drawtype = "nodebox",
tiles = {"factory_steel_noise.png"},
paramtype = "light",
description = "Pneumatic Mover",
groups = {cracky=3},
paramtype2 = "facedir",
legacy_facedir_simple = true,
node_box = {
type = "fixed",
fixed = {
{-0.5,-0.5,-0.5,0.5,-0.4375,0.5}, --base1
{-0.125,-0.5,-0.375,0.125,0.0625,0.375}, --base2
{-0.125,0.25,-0.5,0.125,0.3125,0.375}, --tube
{-0.375,-0.5,-0.0625,0.375,0.0625,0.0625}, --base3
{-0.125,-0.125,0.375,0.125,0.125,0.5}, --tube2
{-0.125,0.0625,0.3125,0.125,0.25,0.375}, --NodeBox6
{-0.125,0.0625,-0.5,-0.0625,0.25,0.3125}, --NodeBox7
{0.0625,0.0625,-0.5,0.125,0.25,0.3125}, --NodeBox8
{-0.0625,0.0625,-0.5,0.0625,0.125,0.3125}, --NodeBox9
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.5,-0.5,-0.5,0.5,0.5,0.5},
}
},
})
minetest.register_abm({
nodenames = {"factory:arm"},
neighbors = nil,
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local all_objects = minetest.get_objects_inside_radius(pos, 0.8)
local _,obj
for _,obj in ipairs(all_objects) do
if not obj:is_player() and obj:get_luaentity() and (obj:get_luaentity().name == "__builtin:item" or obj:get_luaentity().name == "factory:moving_item") then
local a = minetest.facedir_to_dir(minetest.get_node(pos).param2)
local b = {x = pos.x + a.x, y = pos.y + a.y, z = pos.z + a.z,}
local target = minetest.get_node(b)
local stack = ItemStack(obj:get_luaentity().itemstring)
if target.name == "default:chest" or target.name == "default:chest_locked" then
local meta = minetest.env:get_meta(b)
local inv = meta:get_inventory()
if inv:room_for_item("main", stack) then
inv:add_item("main", stack)
obj:remove()
else
obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false)
end
end
if target.name == "factory:swapper" then
local meta = minetest.env:get_meta(b)
local inv = meta:get_inventory()
if inv:room_for_item("input", stack) then
inv:add_item("input", stack)
obj:remove()
else
obj:moveto({x = pos.x + a.x, y = pos.y + 1, z = pos.z + a.z}, false)
end
end
for i,v in ipairs(armDevicesFurnacelike) do
if target.name == v then
local a = minetest.facedir_to_dir(minetest.get_node(pos).param2)
local b = {x = pos.x + a.x, y = pos.y + a.y, z = pos.z + a.z,}
local meta = minetest.env:get_meta(b)
local inv = meta:get_inventory()
if minetest.dir_to_facedir({x = -a.x, y = -a.y, z = -a.z}) == minetest.get_node(b).param2 then
-- back, fuel
if inv:room_for_item("fuel", stack) then
inv:add_item("fuel", stack)
obj:remove()
else
obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false)
end
else
-- everytin else, src
if inv:room_for_item("src", stack) then
inv:add_item("src", stack)
obj:remove()
else
obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false)
end
end
end
end
end
end
end,
})

View File

@ -1,220 +1,113 @@
minetest.register_craft({
output = "factory:belt 12",
recipe = {
{"", "default:gold_ingot", ""},
{"default:stone", "factory:small_steel_gear", "default:stone"},
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}
}
})
minetest.register_craft({
output = "factory:arm",
recipe = {
{"default:steel_ingot", "default:steel_ingot", "farming:hoe_steel"},
{"default:steel_ingot", "default:gold_ingot", "factory:small_steel_gear"},
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}
}
})
minetest.register_craft({
output = "factory:smoke_tube",
recipe = {
{"default:steel_ingot", "", "default:steel_ingot"},
{"default:steel_ingot", "", "default:steel_ingot"},
{"default:steel_ingot", "", "default:steel_ingot"}
}
})
minetest.register_craft({
output = "factory:ind_furnace",
recipe = {
{"factory:small_steel_gear", "default:steel_ingot", "factory:small_steel_gear"},
{"default:steel_ingot", "default:furnace", "default:steel_ingot"},
{"default:stonebrick", "default:obsidian", "default:stonebrick"}
}
})
minetest.register_craft({
output = "factory:small_steel_gear 3",
recipe = {
{"default:steel_ingot", "", "default:steel_ingot"},
{"", "default:steel_ingot", ""},
{"default:steel_ingot", "", "default:steel_ingot"}
}
})
minetest.register_craft({
output = "factory:small_gold_gear 2",
recipe = {
{"default:gold_ingot", "", "default:gold_ingot"},
{"", "factory:small_steel_gear", ""},
{"default:gold_ingot", "", "default:gold_ingot"}
}
})
minetest.register_craft({
output = "factory:small_diamond_gear 2",
recipe = {
{"default:diamond", "", "default:diamond"},
{"", "factory:small_gold_gear", ""},
{"default:diamond", "", "default:diamond"}
}
})
minetest.register_craft({
output = "factory:taker",
recipe = {
{"default:shovel_steel", "default:steel_ingot", "default:gold_ingot"},
{"factory:small_steel_gear", "factory:small_steel_gear", "default:gold_ingot"},
{"default:steel_ingot", "default:steelblock", "default:steel_ingot"}
}
})
minetest.register_craft({
type = "shapeless",
output = "factory:taker_gold",
recipe = {"factory:taker", "default:goldblock", "factory:small_gold_gear"}
})
minetest.register_craft({
type = "shapeless",
output = "factory:taker_diamond",
recipe = {"factory:taker_gold", "default:diamondblock", "factory:small_diamond_gear"}
})
minetest.register_craft({
type = "shapeless",
output = "factory:queuedarm",
recipe = {"factory:arm", "default:chest", "factory:small_gold_gear"}
})
factory.register_craft({
type = "ind_squeezer",
output = "factory:tree_sap",
recipe = {{"default:tree"}}
})
factory.register_craft({
type = "ind_squeezer",
output = "factory:tree_sap",
recipe = {{"default:jungle_tree"}}
})
factory.register_craft({
type = "ind_squeezer",
output = "factory:compressed_clay",
recipe = {{"default:clay_lump"}}
})
minetest.register_craft({
type = "cooking",
output = "factory:factory_lump",
recipe = "factory:compressed_clay"
})
minetest.register_craft({
output = 'factory:factory_brick 6',
recipe = {
{'factory:factory_lump', 'factory:factory_lump'},
{'factory:factory_lump', 'factory:factory_lump'},
}
})
minetest.register_craft({
output = "factory:ind_squeezer",
recipe = {
{"default:glass", "default:stick", "default:glass"},
{"default:glass", "default:steelblock", "default:glass"},
{"factory:small_gold_gear", "factory:ind_furnace", "factory:small_gold_gear"}
}
})
minetest.register_craft({
output = "factory:scanner_chip",
recipe = {
{"default:steel_ingot", "default:stick", "default:mese_crystal"},
{"", "factory:tree_sap", ""},
{"default:mese_crystal", "", "default:steel_ingot"}
}
})
minetest.register_craft({
output = "factory:swapper",
recipe = {
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
{"factory:arm", "factory:scanner_chip", "factory:arm"},
{"default:mese_crystal", "", "default:mese_crystal"}
}
})
minetest.register_craft({
type = "shapeless",
output = "factory:fan_blade",
recipe = {
"default:steel_ingot",
"factory:tree_sap",
"default:stick"
}
})
minetest.register_craft({
output = "factory:fan_on",
recipe = {
{"default:steel_ingot", "factory:fan_blade", "default:steel_ingot"},
{"factory:fan_blade", "factory:small_gold_gear", "factory:fan_blade"},
{"default:steel_ingot", "factory:fan_blade", "default:steel_ingot"}
}
})
minetest.register_craft({
output = "factory:fan_wall_on",
recipe = {
{"factory:fan_on", "", ""},
{"", "", ""},
{"", "", ""}
}
})
minetest.register_craft({
output = "factory:storage_tank",
recipe = {
{"default:glass", "default:steel_ingot", "default:glass"},
{"default:glass", "", "default:glass"},
{"default:glass", "default:steel_ingot", "default:glass"}
}
})
minetest.register_craft({
output = "factory:miner_on",
recipe = {
{"default:steel_ingot", "factory:fan_on", "default:steel_ingot"},
{"factory:small_gold_gear", "factory:taker_on", "factory:small_gold_gear"},
{"default:steel_ingot", "default:pick_mese", "default:steel_ingot"}
}
})
minetest.register_craft({
output = "factory:miner_upgraded_on",
recipe = {
{"", "factory:small_diamond_gear", ""},
{"factory:small_gold_gear", "factory:miner_on", "factory:small_gold_gear"},
{"default:gold_ingot", "default:pick_diamond", "default:gold_ingot"}
}
})
minetest.register_craft({
output = "factory:vacuum_on",
recipe = {
{"default:steel_ingot", "factory:taker_on", "default:steel_ingot"},
{"factory:small_steel_gear","factory:small_gold_gear", "factory:small_steel_gear"},
{"", "default:steel_ingot", ""}
}
})
minetest.register_craft({
output = "factory:sapling_fertilizer",
recipe = {
{"default:dirt", "default:dirt"},
{"default:dirt", "default:dirt"},
}
minetest.register_craft({
output = "factory:belt 12",
recipe = {
{"", "default:gold_ingot", ""},
{"default:stone", "factory:small_steel_gear", "default:stone"},
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}
}
})
minetest.register_craft({
output = "factory:arm",
recipe = {
{"default:steel_ingot", "default:steel_ingot", "farming:hoe_steel"},
{"default:steel_ingot", "default:gold_ingot", "factory:small_steel_gear"},
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}
}
})
minetest.register_craft({
output = "factory:ind_furnace",
recipe = {
{"factory:small_steel_gear", "default:steel_ingot", "factory:small_steel_gear"},
{"default:steel_ingot", "default:furnace", "default:steel_ingot"},
{"default:stonebrick", "default:obsidian", "default:stonebrick"}
}
})
minetest.register_craft({
output = "factory:taker",
recipe = {
{"default:shovel_steel", "default:steel_ingot", "default:gold_ingot"},
{"factory:small_steel_gear", "factory:small_steel_gear", "default:gold_ingot"},
{"default:steel_ingot", "default:steelblock", "default:steel_ingot"}
}
})
minetest.register_craft({
type = "shapeless",
output = "factory:taker_gold",
recipe = {"factory:taker", "default:goldblock", "factory:small_gold_gear"}
})
minetest.register_craft({
type = "shapeless",
output = "factory:taker_diamond",
recipe = {"factory:taker_gold", "default:diamondblock", "factory:small_diamond_gear"}
})
minetest.register_craft({
type = "shapeless",
output = "factory:queuedarm",
recipe = {"factory:arm", "default:chest", "factory:small_gold_gear"}
})
minetest.register_craft({
output = "factory:ind_squeezer",
recipe = {
{"default:glass", "default:stick", "default:glass"},
{"default:glass", "default:steelblock", "default:glass"},
{"factory:small_gold_gear", "factory:ind_furnace", "factory:small_gold_gear"}
}
})
minetest.register_craft({
output = "factory:swapper",
recipe = {
{"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
{"factory:arm", "factory:scanner_chip", "factory:arm"},
{"default:mese_crystal", "", "default:mese_crystal"}
}
})
minetest.register_craft({
output = "factory:fan_on",
recipe = {
{"default:steel_ingot", "factory:fan_blade", "default:steel_ingot"},
{"factory:fan_blade", "factory:small_gold_gear", "factory:fan_blade"},
{"default:steel_ingot", "factory:fan_blade", "default:steel_ingot"}
}
})
minetest.register_craft({
type = "shapeless",
output = "factory:fan_wall_on",
recipe = {"factory:fan_on"}
})
minetest.register_craft({
output = "factory:miner_on",
recipe = {
{"default:steel_ingot", "factory:fan_on", "default:steel_ingot"},
{"factory:small_gold_gear", "factory:taker_on", "factory:small_gold_gear"},
{"default:steel_ingot", "default:pick_mese", "default:steel_ingot"}
}
})
minetest.register_craft({
output = "factory:miner_upgraded_on",
recipe = {
{"", "factory:small_diamond_gear", ""},
{"factory:small_gold_gear", "factory:miner_on", "factory:small_gold_gear"},
{"default:gold_ingot", "default:pick_diamond", "default:gold_ingot"}
}
})
minetest.register_craft({
output = "factory:vacuum_on",
recipe = {
{"default:steel_ingot", "factory:taker_on", "default:steel_ingot"},
{"factory:small_steel_gear","factory:small_gold_gear", "factory:small_steel_gear"},
{"", "default:steel_ingot", ""}
}
})

13
machines/init.lua Normal file
View File

@ -0,0 +1,13 @@
dofile(factory.modpath.."/machines/crafting.lua")
dofile(factory.modpath.."/machines/belt.lua")
dofile(factory.modpath.."/machines/ind_furnace.lua")
dofile(factory.modpath.."/machines/ind_squeezer.lua")
dofile(factory.modpath.."/machines/stp.lua")
dofile(factory.modpath.."/machines/swapper.lua")
dofile(factory.modpath.."/machines/arm.lua")
dofile(factory.modpath.."/machines/taker.lua")
dofile(factory.modpath.."/machines/qarm.lua")
if factory.enableFan then dofile(factory.modpath.."/machines/fan.lua") end
if factory.enableVacuum then dofile(factory.modpath.."/machines/vacuum.lua") end
if factory.enableMiner then dofile(factory.modpath.."/machines/miner.lua") end

156
machines/qarm.lua Normal file
View File

@ -0,0 +1,156 @@
function qarm_handle (a, b, target, stack, minv, obj)
if target.name == "default:chest" or target.name == "default:chest_locked" then
local meta = minetest.env:get_meta(b)
local inv = meta:get_inventory()
if inv:room_for_item("main", stack) then
inv:add_item("main", stack)
if obj~=nil then obj:remove() end
elseif minv:room_for_item("main", stack) then
minv:add_item("main", stack)
if obj~=nil then obj:remove() end
else
if obj~=nil then obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false) end
end
end
if target.name == "factory:swapper" then
local meta = minetest.env:get_meta(b)
local inv = meta:get_inventory()
if inv:room_for_item("input", stack) then
inv:add_item("input", stack)
if obj~=nil then obj:remove() end
elseif minv:room_for_item("input", stack) then
minv:add_item("input", stack)
if obj~=nil then obj:remove() end
else
if obj~=nil then obj:moveto({x = pos.x + a.x, y = pos.y + 1, z = pos.z + a.z }, false) end
end
end
for i,v in ipairs(armDevicesFurnacelike) do
if target.name == v then
local meta = minetest.env:get_meta(b)
local inv = meta:get_inventory()
if minetest.dir_to_facedir({x = -a.x, y = -a.y, z = -a.z}) == minetest.get_node(b).param2 then
-- back, fuel
if inv:room_for_item("fuel", stack) then
inv:add_item("fuel", stack)
if obj~=nil then obj:remove() end
elseif minv:room_for_item("main", stack) then
minv:add_item("main", stack)
if obj~=nil then obj:remove() end
else
if obj~=nil then obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false) end
end
else
-- everytin else, src
if inv:room_for_item("src", stack) then
inv:add_item("src", stack)
if obj~=nil then obj:remove() end
elseif minv:room_for_item("main", stack) then
minv:add_item("main", stack)
if obj~=nil then obj:remove() end
else
if obj~=nil then obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false) end
end
end
end
end
end
factory.qformspec =
"size[8,8.5]"..
factory_gui_bg..
factory_gui_bg_img..
factory_gui_slots..
"list[current_name;main;0,0.3;8,3;]"..
"list[current_player;main;0,4.25;8,1;]"..
"list[current_player;main;0,5.5;8,3;8]"..
factory.get_hotbar_bg(0,4.25)
minetest.register_node("factory:queuedarm",{
drawtype = "nodebox",
tiles = {"factory_steel_noise.png"},
paramtype = "light",
description = "Queued Pneumatic Mover",
groups = {cracky=3},
paramtype2 = "facedir",
legacy_facedir_simple = true,
node_box = {
type = "fixed",
fixed = {
{-0.5,-0.5,-0.5,0.5,-0.4375,0.5}, --base1
{-0.125,-0.5,-0.375,0.125,0.0625,0.375}, --base2
{-0.125,0.25,-0.5,0.125,0.3125,0.375}, --tube
{-0.375,-0.5,-0.1875,0.375,0.0625,0.0625}, --base3
{-0.125,-0.125,0.375,0.125,0.125,0.5}, --tube2
{-0.125,0.0625,0.3125,0.125,0.25,0.375}, --nodebox6
{-0.125,0.0625,-0.5,-0.0625,0.25,0.3125}, --nodebox7
{0.0625,0.0625,-0.5,0.125,0.25,0.3125}, --nodebox8
{-0.0625,0.0625,-0.5,0.0625,0.125,0.3125}, --nodebox9
{-0.25,0.3125,-0.125,0.25,0.8,0.375}, --NodeBox10
{-0.1875,0.1875,-0.5,-0.125,0.3125,0.375}, --NodeBox11
{0.125,0.1875,-0.5,0.1875,0.3125,0.375}, --NodeBox12
{-0.125,0.3125,-0.4375,0.125,0.5,-0.125}, --NodeBox13
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.5,-0.5,-0.5,0.5,0.5,0.5},
}
},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec",factory.qformspec)
meta:set_string("infotext", "Queued Pneumatic Mover")
local inv = meta:get_inventory()
inv:set_size("main", 8*3)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", player:get_player_name()..
" moves stuff in queued mover at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name()..
" moves stuff to queued mover at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name()..
" takes stuff from queued mover at "..minetest.pos_to_string(pos))
end,
})
minetest.register_abm({
nodenames = {"factory:queuedarm"},
neighbors = nil,
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local mmeta = minetest.env:get_meta(pos)
local minv = mmeta:get_inventory()
local all_objects = minetest.get_objects_inside_radius(pos, 0.8)
local a = minetest.facedir_to_dir(minetest.get_node(pos).param2)
local b = {x = pos.x + a.x, y = pos.y + a.y, z = pos.z + a.z,}
local target = minetest.get_node(b)
for _,obj in ipairs(all_objects) do
if not obj:is_player() and obj:get_luaentity() and (obj:get_luaentity().name == "__builtin:item" or obj:get_luaentity().name == "factory:moving_item") then
local stack = ItemStack(obj:get_luaentity().itemstring)
qarm_handle(a, b, target, stack, minv, obj)
end
end
for i,stack in ipairs(minv:get_list("main")) do
if stack:get_name() ~= "" then
minv:remove_item("main", stack)
qarm_handle(a, b, target, stack, minv, nil)
return
end
end
end,
})

189
machines/taker.lua Normal file
View File

@ -0,0 +1,189 @@
function factory.register_taker(prefix, suffix, speed, name, ctiles)
-- Backwards compatiblity for any version below 0.5
minetest.register_alias("factory:"..prefix.."taker"..suffix, "factory:"..prefix.."taker"..suffix.."_on")
local nodeon = {
drawtype = "nodebox",
tiles = ctiles,
paramtype = "light",
description = name,
groups = {cracky=3, mesecon_effector_off = 1},
paramtype2 = "facedir",
legacy_facedir_simple = true,
node_box = {
type = "fixed",
fixed = {
{-0.5,-0.5,-0.5,0.5,-0.4375,0.5}, --base1
{-0.125,-0.5,-0.375,0.125,0.0625,0.375}, --base2
{-0.125,0.25,-0.5,0.125,0.3125,0.375}, --tube
{-0.375,-0.5,-0.0625,0.375,0.0625,0.0625}, --base3
{-0.125,-0.125,0.375,0.125,0.125,0.5}, --tube2
{-0.125,0.0625,0.3125,0.125,0.25,0.375}, --NodeBox6
{-0.125,0.0625,-0.5,-0.0625,0.25,0.3125}, --NodeBox7
{0.0625,0.0625,-0.5,0.125,0.25,0.3125}, --NodeBox8
{-0.0625,0.0625,-0.5,0.0625,0.125,0.3125}, --NodeBox9
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.5,-0.5,-0.5,0.5,0.5,0.5},
}
},
mesecons = {effector = {
action_on = function(pos, node)
minetest.swap_node(pos, {name="factory:"..prefix.."taker"..suffix.."_off", param2 = node.param2})
end
}}
}
local nodeoff = {
drawtype = "nodebox",
tiles = ctiles,
paramtype = "light",
description = name,
groups = {cracky=3, not_in_creative_inventory=1, mesecon_effector_on = 1},
paramtype2 = "facedir",
legacy_facedir_simple = true,
drop="factory:"..prefix.."taker"..suffix.."_on",
node_box = {
type = "fixed",
fixed = {
{-0.5,-0.5,-0.5,0.5,-0.4375,0.5}, --base1
{-0.125,-0.5,-0.375,0.125,0.0625,0.375}, --base2
{-0.125,0.25,-0.5,0.125,0.3125,0.375}, --tube
{-0.375,-0.5,-0.0625,0.375,0.0625,0.0625}, --base3
{-0.125,-0.125,0.375,0.125,0.125,0.5}, --tube2
{-0.125,0.0625,0.3125,0.125,0.25,0.375}, --NodeBox6
{-0.125,0.0625,-0.5,-0.0625,0.25,0.3125}, --NodeBox7
{0.0625,0.0625,-0.5,0.125,0.25,0.3125}, --NodeBox8
{-0.0625,0.0625,-0.5,0.0625,0.125,0.3125}, --NodeBox9
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.5,-0.5,-0.5,0.5,0.5,0.5},
}
},
mesecons = {effector = {
action_off = function(pos, node)
minetest.swap_node(pos, {name="factory:"..prefix.."taker"..suffix.."_on", param2 = node.param2})
end
}}
}
minetest.register_node("factory:"..prefix.."taker"..suffix.."_on", nodeon)
minetest.register_node("factory:"..prefix.."taker"..suffix.."_off", nodeoff)
minetest.register_abm({
nodenames = {"factory:"..prefix.."taker"..suffix.."_on"},
neighbors = nil,
interval = speed,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local facedir = minetest.get_node(pos).param2
local a = minetest.facedir_to_dir(minetest.get_node(pos).param2)
local b = {x = pos.x + a.x, y = pos.y + a.y, z = pos.z + a.z,}
local target = minetest.get_node(b)
if target.name == "default:chest" or target.name == "default:chest_locked" then
local meta = minetest.env:get_meta(b)
local inv = meta:get_inventory()
if not inv:is_empty("main") then
local list = inv:get_list("main")
local i,item
for i,item in ipairs(inv:get_list("main")) do
if item:get_name() ~= "" then
local droppos = {x = pos.x - (a.x/1.25), y = pos.y + 0.65, z = pos.z - (a.z/1.25)}
if factory.logTaker then print(name.." at "..pos.x..", "..pos.y..", "..pos.z.." takes "..item:get_name().." from "..target.name) end
minetest.item_drop(item:peek_item(1), "", droppos)
item:take_item()
inv:set_stack("main", i, item)
return
end
end
end
end
local targetp
if facedir == 1 then
targetp = {x = pos.x + 1, y = pos.y, z = pos.z}
elseif facedir == 2 then
targetp = {x = pos.x, y = pos.y, z = pos.z - 1}
elseif facedir == 3 then
targetp = {x = pos.x - 1, y = pos.y, z = pos.z}
elseif facedir == 0 then
targetp = {x = pos.x, y = pos.y, z = pos.z + 1}
end
taker_from_swapper(pos, targetp, facedir, a)
for i,v in ipairs(takerDevicesFurnacelike) do
if target.name == v then
local meta = minetest.env:get_meta(b)
local inv = meta:get_inventory()
if not inv:is_empty("dst") then
local list = inv:get_list("dst")
for k,item in ipairs(inv:get_list("dst")) do
if item:get_name() ~= "" then
local droppos = {x = pos.x - (a.x/1.25), y = pos.y + 0.65, z = pos.z - (a.z/1.25)}
if factory.logTaker then print(name.." at "..pos.x..", "..pos.y..", "..pos.z.." takes "..item:get_name().." from "..target.name) end
minetest.item_drop(item:peek_item(1), "", droppos)
item:take_item()
inv:set_stack("dst", k, item)
return
end
end
end
end
end
end,
})
end
function taker_from_swapper(pos, target, facedir, offset)
local node = minetest.get_node(target)
local takefrom = ""
-- 0 = none
-- 1 = left
-- 2 = middle
-- 3 = right
if node == nil or node.name ~= "factory:swapper" then return end
if facedir == 1 then
if node.param2 == 0 then takefrom = "loverflow" end
if node.param2 == 3 then takefrom = "overflow" end
if node.param2 == 2 then takefrom = "roverflow" end
end
if facedir == 2 then
if node.param2 == 1 then takefrom = "loverflow" end
if node.param2 == 0 then takefrom = "overflow" end
if node.param2 == 3 then takefrom = "roverflow" end
end
if facedir == 3 then
if node.param2 == 2 then takefrom = "loverflow" end
if node.param2 == 1 then takefrom = "overflow" end
if node.param2 == 0 then takefrom = "roverflow" end
end
if facedir == 0 then
if node.param2 == 3 then takefrom = "loverflow" end
if node.param2 == 2 then takefrom = "overflow" end
if node.param2 == 1 then takefrom = "roverflow" end
end
local meta = minetest.env:get_meta(target)
local inv = meta:get_inventory()
if takefrom ~= "" then
if not inv:is_empty(takefrom) then
local list = inv:get_list(takefrom)
for k,item in ipairs(inv:get_list(takefrom)) do
if not item:is_empty() and item:get_name() ~= "" then
local droppos = {x = pos.x - (offset.x/1.25), y = pos.y + 0.65, z = pos.z - (offset.z/1.25)}
if factory.logTaker then print("Taker at "..pos.x..", "..pos.y..", "..pos.z.." takes "..item:get_name().." from swapper") end
minetest.item_drop(item:peek_item(1), "", droppos)
item:take_item()
inv:set_stack(takefrom, k, item)
return
end
end
end
end
end
factory.register_taker("", "", 2.5, "Pneumatic Taker", {"factory_steel_noise_red.png"})
factory.register_taker("", "_gold", 1.8, "Pneumatic Taker Mk II", {"factory_steel_noise_gold.png"})
factory.register_taker("", "_diamond", 1.2, "Pneumatic Taker Mk III", {"factory_steel_noise_diamond.png"})

479
nodes.lua
View File

@ -1,479 +0,0 @@
minetest.register_node("factory:arm",{
drawtype = "nodebox",
tiles = {"factory_steel_noise.png"},
paramtype = "light",
description = "Pneumatic Mover",
groups = {cracky=3},
paramtype2 = "facedir",
legacy_facedir_simple = true,
node_box = {
type = "fixed",
fixed = {
{-0.5,-0.5,-0.5,0.5,-0.4375,0.5}, --base1
{-0.125,-0.5,-0.375,0.125,0.0625,0.375}, --base2
{-0.125,0.25,-0.5,0.125,0.3125,0.375}, --tube
{-0.375,-0.5,-0.0625,0.375,0.0625,0.0625}, --base3
{-0.125,-0.125,0.375,0.125,0.125,0.5}, --tube2
{-0.125,0.0625,0.3125,0.125,0.25,0.375}, --NodeBox6
{-0.125,0.0625,-0.5,-0.0625,0.25,0.3125}, --NodeBox7
{0.0625,0.0625,-0.5,0.125,0.25,0.3125}, --NodeBox8
{-0.0625,0.0625,-0.5,0.0625,0.125,0.3125}, --NodeBox9
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.5,-0.5,-0.5,0.5,0.5,0.5},
}
},
})
minetest.register_abm({
nodenames = {"factory:arm"},
neighbors = nil,
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local all_objects = minetest.get_objects_inside_radius(pos, 0.8)
local _,obj
for _,obj in ipairs(all_objects) do
if not obj:is_player() and obj:get_luaentity() and (obj:get_luaentity().name == "__builtin:item" or obj:get_luaentity().name == "factory:moving_item") then
local a = minetest.facedir_to_dir(minetest.get_node(pos).param2)
local b = {x = pos.x + a.x, y = pos.y + a.y, z = pos.z + a.z,}
local target = minetest.get_node(b)
local stack = ItemStack(obj:get_luaentity().itemstring)
if target.name == "default:chest" or target.name == "default:chest_locked" then
local meta = minetest.env:get_meta(b)
local inv = meta:get_inventory()
if inv:room_for_item("main", stack) then
inv:add_item("main", stack)
obj:remove()
else
obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false)
end
end
if target.name == "factory:swapper" then
local meta = minetest.env:get_meta(b)
local inv = meta:get_inventory()
if inv:room_for_item("input", stack) then
inv:add_item("input", stack)
obj:remove()
else
obj:moveto({x = pos.x + a.x, y = pos.y + 1, z = pos.z + a.z}, false)
end
end
for i,v in ipairs(armDevicesFurnacelike) do
if target.name == v then
local a = minetest.facedir_to_dir(minetest.get_node(pos).param2)
local b = {x = pos.x + a.x, y = pos.y + a.y, z = pos.z + a.z,}
local meta = minetest.env:get_meta(b)
local inv = meta:get_inventory()
if minetest.dir_to_facedir({x = -a.x, y = -a.y, z = -a.z}) == minetest.get_node(b).param2 then
-- back, fuel
if inv:room_for_item("fuel", stack) then
inv:add_item("fuel", stack)
obj:remove()
else
obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false)
end
else
-- everytin else, src
if inv:room_for_item("src", stack) then
inv:add_item("src", stack)
obj:remove()
else
obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false)
end
end
end
end
end
end
end,
})
function factory.register_taker(prefix, suffix, speed, name, ctiles)
-- Backwards compatiblity for any version below 0.5
minetest.register_alias("factory:"..prefix.."taker"..suffix, "factory:"..prefix.."taker"..suffix.."_on")
local nodeon = {
drawtype = "nodebox",
tiles = ctiles,
paramtype = "light",
description = name,
groups = {cracky=3, mesecon_effector_off = 1},
paramtype2 = "facedir",
legacy_facedir_simple = true,
node_box = {
type = "fixed",
fixed = {
{-0.5,-0.5,-0.5,0.5,-0.4375,0.5}, --base1
{-0.125,-0.5,-0.375,0.125,0.0625,0.375}, --base2
{-0.125,0.25,-0.5,0.125,0.3125,0.375}, --tube
{-0.375,-0.5,-0.0625,0.375,0.0625,0.0625}, --base3
{-0.125,-0.125,0.375,0.125,0.125,0.5}, --tube2
{-0.125,0.0625,0.3125,0.125,0.25,0.375}, --NodeBox6
{-0.125,0.0625,-0.5,-0.0625,0.25,0.3125}, --NodeBox7
{0.0625,0.0625,-0.5,0.125,0.25,0.3125}, --NodeBox8
{-0.0625,0.0625,-0.5,0.0625,0.125,0.3125}, --NodeBox9
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.5,-0.5,-0.5,0.5,0.5,0.5},
}
},
mesecons = {effector = {
action_on = function(pos, node)
minetest.swap_node(pos, {name="factory:"..prefix.."taker"..suffix.."_off", param2 = node.param2})
end
}}
}
local nodeoff = {
drawtype = "nodebox",
tiles = ctiles,
paramtype = "light",
description = name,
groups = {cracky=3, not_in_creative_inventory=1, mesecon_effector_on = 1},
paramtype2 = "facedir",
legacy_facedir_simple = true,
drop="factory:"..prefix.."taker"..suffix.."_on",
node_box = {
type = "fixed",
fixed = {
{-0.5,-0.5,-0.5,0.5,-0.4375,0.5}, --base1
{-0.125,-0.5,-0.375,0.125,0.0625,0.375}, --base2
{-0.125,0.25,-0.5,0.125,0.3125,0.375}, --tube
{-0.375,-0.5,-0.0625,0.375,0.0625,0.0625}, --base3
{-0.125,-0.125,0.375,0.125,0.125,0.5}, --tube2
{-0.125,0.0625,0.3125,0.125,0.25,0.375}, --NodeBox6
{-0.125,0.0625,-0.5,-0.0625,0.25,0.3125}, --NodeBox7
{0.0625,0.0625,-0.5,0.125,0.25,0.3125}, --NodeBox8
{-0.0625,0.0625,-0.5,0.0625,0.125,0.3125}, --NodeBox9
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.5,-0.5,-0.5,0.5,0.5,0.5},
}
},
mesecons = {effector = {
action_off = function(pos, node)
minetest.swap_node(pos, {name="factory:"..prefix.."taker"..suffix.."_on", param2 = node.param2})
end
}}
}
minetest.register_node("factory:"..prefix.."taker"..suffix.."_on", nodeon)
minetest.register_node("factory:"..prefix.."taker"..suffix.."_off", nodeoff)
minetest.register_abm({
nodenames = {"factory:"..prefix.."taker"..suffix.."_on"},
neighbors = nil,
interval = speed,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local facedir = minetest.get_node(pos).param2
local a = minetest.facedir_to_dir(minetest.get_node(pos).param2)
local b = {x = pos.x + a.x, y = pos.y + a.y, z = pos.z + a.z,}
local target = minetest.get_node(b)
if target.name == "default:chest" or target.name == "default:chest_locked" then
local meta = minetest.env:get_meta(b)
local inv = meta:get_inventory()
if not inv:is_empty("main") then
local list = inv:get_list("main")
local i,item
for i,item in ipairs(inv:get_list("main")) do
if item:get_name() ~= "" then
local droppos = {x = pos.x - (a.x/1.25), y = pos.y + 0.65, z = pos.z - (a.z/1.25)}
if factory.logTaker then print(name.." at "..pos.x..", "..pos.y..", "..pos.z.." takes "..item:get_name().." from "..target.name) end
minetest.item_drop(item:peek_item(1), "", droppos)
item:take_item()
inv:set_stack("main", i, item)
return
end
end
end
end
local targetp
if facedir == 1 then
targetp = {x = pos.x + 1, y = pos.y, z = pos.z}
elseif facedir == 2 then
targetp = {x = pos.x, y = pos.y, z = pos.z - 1}
elseif facedir == 3 then
targetp = {x = pos.x - 1, y = pos.y, z = pos.z}
elseif facedir == 0 then
targetp = {x = pos.x, y = pos.y, z = pos.z + 1}
end
taker_from_swapper(pos, targetp, facedir, a)
for i,v in ipairs(takerDevicesFurnacelike) do
if target.name == v then
local meta = minetest.env:get_meta(b)
local inv = meta:get_inventory()
if not inv:is_empty("dst") then
local list = inv:get_list("dst")
for k,item in ipairs(inv:get_list("dst")) do
if item:get_name() ~= "" then
local droppos = {x = pos.x - (a.x/1.25), y = pos.y + 0.65, z = pos.z - (a.z/1.25)}
if factory.logTaker then print(name.." at "..pos.x..", "..pos.y..", "..pos.z.." takes "..item:get_name().." from "..target.name) end
minetest.item_drop(item:peek_item(1), "", droppos)
item:take_item()
inv:set_stack("dst", k, item)
return
end
end
end
end
end
end,
})
end
function taker_from_swapper(pos, target, facedir, offset)
local node = minetest.get_node(target)
local takefrom = ""
-- 0 = none
-- 1 = left
-- 2 = middle
-- 3 = right
if node == nil or node.name ~= "factory:swapper" then return end
if facedir == 1 then
if node.param2 == 0 then takefrom = "loverflow" end
if node.param2 == 3 then takefrom = "overflow" end
if node.param2 == 2 then takefrom = "roverflow" end
end
if facedir == 2 then
if node.param2 == 1 then takefrom = "loverflow" end
if node.param2 == 0 then takefrom = "overflow" end
if node.param2 == 3 then takefrom = "roverflow" end
end
if facedir == 3 then
if node.param2 == 2 then takefrom = "loverflow" end
if node.param2 == 1 then takefrom = "overflow" end
if node.param2 == 0 then takefrom = "roverflow" end
end
if facedir == 0 then
if node.param2 == 3 then takefrom = "loverflow" end
if node.param2 == 2 then takefrom = "overflow" end
if node.param2 == 1 then takefrom = "roverflow" end
end
local meta = minetest.env:get_meta(target)
local inv = meta:get_inventory()
if takefrom ~= "" then
if not inv:is_empty(takefrom) then
local list = inv:get_list(takefrom)
for k,item in ipairs(inv:get_list(takefrom)) do
if not item:is_empty() and item:get_name() ~= "" then
local droppos = {x = pos.x - (offset.x/1.25), y = pos.y + 0.65, z = pos.z - (offset.z/1.25)}
if factory.logTaker then print("Taker at "..pos.x..", "..pos.y..", "..pos.z.." takes "..item:get_name().." from swapper") end
minetest.item_drop(item:peek_item(1), "", droppos)
item:take_item()
inv:set_stack(takefrom, k, item)
return
end
end
end
end
end
factory.register_taker("", "", 2.5, "Pneumatic Taker", {"factory_steel_noise_red.png"})
factory.register_taker("", "_gold", 1.8, "Pneumatic Taker Mk II", {"factory_steel_noise_gold.png"})
factory.register_taker("", "_diamond", 1.2, "Pneumatic Taker Mk III", {"factory_steel_noise_diamond.png"})
minetest.register_node("factory:smoke_tube", {
drawtype = "nodebox",
tiles = {"factory_machine_brick_1.png"},
paramtype = "light",
description = "Smoke Tube",
groups = {cracky=3},
node_box = {
type = "fixed",
fixed = {
{-0.125,-0.5,0.3125,0.125,0.5,0.375},
{-0.125,-0.5,-0.375,0.125,0.5,-0.3125},
{0.3125,-0.5,-0.125,0.375,0.5,0.125},
{-0.375,-0.5,-0.125,-0.3125,0.5,0.125},
{0.125,-0.5,0.25,0.25,0.5,0.3125},
{0.25,-0.5,0.125,0.3125,0.5,0.25},
{0.25,-0.5,-0.25,0.3125,0.5,-0.125},
{0.125,-0.5,-0.3125,0.25,0.5,-0.25},
{-0.25,-0.5,-0.3125,-0.125,0.5,-0.25},
{-0.3125,-0.5,-0.25,-0.25,0.5,-0.125},
{-0.3125,-0.5,0.125,-0.25,0.5,0.25},
{-0.25,-0.5,0.25,-0.125,0.5,0.3125},
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.375,-0.5,-0.375,0.375,0.5,0.375},
}
},
})
function qarm_handle (a, b, target, stack, minv, obj)
if target.name == "default:chest" or target.name == "default:chest_locked" then
local meta = minetest.env:get_meta(b)
local inv = meta:get_inventory()
if inv:room_for_item("main", stack) then
inv:add_item("main", stack)
if obj~=nil then obj:remove() end
elseif minv:room_for_item("main", stack) then
minv:add_item("main", stack)
if obj~=nil then obj:remove() end
else
if obj~=nil then obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false) end
end
end
if target.name == "factory:swapper" then
local meta = minetest.env:get_meta(b)
local inv = meta:get_inventory()
if inv:room_for_item("input", stack) then
inv:add_item("input", stack)
if obj~=nil then obj:remove() end
elseif minv:room_for_item("input", stack) then
minv:add_item("input", stack)
if obj~=nil then obj:remove() end
else
if obj~=nil then obj:moveto({x = pos.x + a.x, y = pos.y + 1, z = pos.z + a.z }, false) end
end
end
for i,v in ipairs(armDevicesFurnacelike) do
if target.name == v then
local meta = minetest.env:get_meta(b)
local inv = meta:get_inventory()
if minetest.dir_to_facedir({x = -a.x, y = -a.y, z = -a.z}) == minetest.get_node(b).param2 then
-- back, fuel
if inv:room_for_item("fuel", stack) then
inv:add_item("fuel", stack)
if obj~=nil then obj:remove() end
elseif minv:room_for_item("main", stack) then
minv:add_item("main", stack)
if obj~=nil then obj:remove() end
else
if obj~=nil then obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false) end
end
else
-- everytin else, src
if inv:room_for_item("src", stack) then
inv:add_item("src", stack)
if obj~=nil then obj:remove() end
elseif minv:room_for_item("main", stack) then
minv:add_item("main", stack)
if obj~=nil then obj:remove() end
else
if obj~=nil then obj:moveto({x = pos.x + (a.x * 2), y = pos.y + 0.5, z = pos.z + (a.z * 2)}, false) end
end
end
end
end
end
factory.qformspec =
"size[8,8.5]"..
factory_gui_bg..
factory_gui_bg_img..
factory_gui_slots..
"list[current_name;main;0,0.3;8,3;]"..
"list[current_player;main;0,4.25;8,1;]"..
"list[current_player;main;0,5.5;8,3;8]"..
factory.get_hotbar_bg(0,4.25)
minetest.register_node("factory:queuedarm",{
drawtype = "nodebox",
tiles = {"factory_steel_noise.png"},
paramtype = "light",
description = "Queued Pneumatic Mover",
groups = {cracky=3},
paramtype2 = "facedir",
legacy_facedir_simple = true,
node_box = {
type = "fixed",
fixed = {
{-0.5,-0.5,-0.5,0.5,-0.4375,0.5}, --base1
{-0.125,-0.5,-0.375,0.125,0.0625,0.375}, --base2
{-0.125,0.25,-0.5,0.125,0.3125,0.375}, --tube
{-0.375,-0.5,-0.1875,0.375,0.0625,0.0625}, --base3
{-0.125,-0.125,0.375,0.125,0.125,0.5}, --tube2
{-0.125,0.0625,0.3125,0.125,0.25,0.375}, --nodebox6
{-0.125,0.0625,-0.5,-0.0625,0.25,0.3125}, --nodebox7
{0.0625,0.0625,-0.5,0.125,0.25,0.3125}, --nodebox8
{-0.0625,0.0625,-0.5,0.0625,0.125,0.3125}, --nodebox9
{-0.25,0.3125,-0.125,0.25,0.8,0.375}, --NodeBox10
{-0.1875,0.1875,-0.5,-0.125,0.3125,0.375}, --NodeBox11
{0.125,0.1875,-0.5,0.1875,0.3125,0.375}, --NodeBox12
{-0.125,0.3125,-0.4375,0.125,0.5,-0.125}, --NodeBox13
}
},
selection_box = {
type = "fixed",
fixed = {
{-0.5,-0.5,-0.5,0.5,0.5,0.5},
}
},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_string("formspec",factory.qformspec)
meta:set_string("infotext", "Queued Pneumatic Mover")
local inv = meta:get_inventory()
inv:set_size("main", 8*3)
end,
can_dig = function(pos,player)
local meta = minetest.get_meta(pos);
local inv = meta:get_inventory()
return inv:is_empty("main")
end,
on_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
minetest.log("action", player:get_player_name()..
" moves stuff in queued mover at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name()..
" moves stuff to queued mover at "..minetest.pos_to_string(pos))
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
minetest.log("action", player:get_player_name()..
" takes stuff from queued mover at "..minetest.pos_to_string(pos))
end,
})
minetest.register_abm({
nodenames = {"factory:queuedarm"},
neighbors = nil,
interval = 1,
chance = 1,
action = function(pos, node, active_object_count, active_object_count_wider)
local mmeta = minetest.env:get_meta(pos)
local minv = mmeta:get_inventory()
local all_objects = minetest.get_objects_inside_radius(pos, 0.8)
local a = minetest.facedir_to_dir(minetest.get_node(pos).param2)
local b = {x = pos.x + a.x, y = pos.y + a.y, z = pos.z + a.z,}
local target = minetest.get_node(b)
for _,obj in ipairs(all_objects) do
if not obj:is_player() and obj:get_luaentity() and (obj:get_luaentity().name == "__builtin:item" or obj:get_luaentity().name == "factory:moving_item") then
local stack = ItemStack(obj:get_luaentity().itemstring)
qarm_handle(a, b, target, stack, minv, obj)
end
end
for i,stack in ipairs(minv:get_list("main")) do
if stack:get_name() ~= "" then
minv:remove_item("main", stack)
qarm_handle(a, b, target, stack, minv, nil)
return
end
end
end,
})
minetest.register_node("factory:factory_brick", {
description = "Factory Brick",
tiles = {"factory_brick.png"},
is_ground_content = true,
groups = {cracky=3, stone=1}
})

105
util/craftingutil.lua Normal file
View File

@ -0,0 +1,105 @@
-- This below is the Crafter mod by the legend MasterGollum
function factory.register_craft(craft)
assert(craft.type ~= nil and craft.recipe ~= nil and craft.output ~= nil,
"Invalid craft definition, it must have type, recipe and output")
assert(type(craft.recipe)=="table" and type(craft.recipe[1])=="table","'recipe' must be a bidimensional table")
minetest.log("verbose","registerCraft ("..craft.type..", output="..craft.output.." recipe="..dump(craft.recipe))
craft._h=#craft.recipe
craft._w=#craft.recipe[1]
-- TODO check that all the arrays have the same length...
factory.crafts[#factory.crafts+1]=craft
end
function factory.get_craft_result(data)
assert(data.method ~= nil and data.items ~= nil, "Invalid call, method and items must be provided")
local w = 1
if data.width ~= nil and data.width>0 then
w=data.width
end
local r=nil
for zz,craft in ipairs(factory.crafts) do
r=factory._check_craft(data,w,craft)
if r ~= nil then
if factory.debug then
print("Craft found, returning "..dump(r.item))
end
return r
end
end
return factory.empty
end
function factory._check_craft(data,w,c)
if c.type == data.method then
-- Here we go..
for i=1,w-c._h+1 do
for j=1,w-c._w+1 do
local p=(i-1)*w+j
if factory.debug then
print("Checking data.items["..dump(i).."]["..dump(j).."]("..dump(p)..")="..dump(data.items[p]:get_name()).." vs craft.recipe[1][1]="..dump(c.recipe[1][1]))
end
if data.items[p]:get_name() == c.recipe[1][1] then
for m=1,c._h do
for n=1,c._w do
local q=(i+m-1-1)*w+j+n-1
if factory.debug then
print(" Checking data.items["..dump(i+m-1).."]["..dump(j+n-1).."]("..dump(q)..")="..dump(data.items[q]:get_name())..
" vs craft.recipe["..dump(m).."]["..dump(n).."]="..dump(c.recipe[m][n]))
end
if c.recipe[m][n] ~= data.items[q]:get_name() then
return nil
end
end
end
-- found! we still must check that is not any other stuff outside the limits of the recipe sizes...
-- Checking at right of the matching square
for m=i-c._h+1+1,w do
for n=j+c._w,w do
local q=(m-1)*w+n
if factory.debug then
print(" Checking right data.items["..dump(m).."]["..dump(n).."]("..dump(q)..")="..dump(data.items[q]:get_name()))
end
if data.items[q]:get_name() ~= "" then
return nil
end
end
end
-- Checking at left of the matching square (the first row has been already scanned)
for m=i-c._h+1+1+1,w do
for n=1,j-1 do
local q=(m-1)*w+n
if factory.debug then
print(" Checking left data.items["..dump(m).."]["..dump(n).."]("..dump(q)..")="..dump(data.items[q]:get_name()))
end
if data.items[q]:get_name() ~= "" then
return nil
end
end
end
-- Checking at bottom of the matching square
for m=i+c._h,w do
for n=j,j+c._w do
local q=(m-1)*w+n
if factory.debug then
print(" Checking bottom data.items["..dump(m).."]["..dump(n).."]("..dump(q)..")="..dump(data.items[q]:get_name()))
end
if data.items[q]:get_name() ~= "" then
return nil
end
end
end
if factory.debug then
print("Craft found! "..c.output)
end
return {item=ItemStack(c.output),time=1}
elseif data.items[p] ~= nil and data.items[p]:get_name() ~= "" then
if factory.debug then
print("Invalid data item "..dump(data.items[p]:get_name()))
end
return nil
end
end
end
end
end

46
util/gen.lua Normal file
View File

@ -0,0 +1,46 @@
if factory.fertilizerGeneration then
minetest.register_on_generated(function(minp, maxp, seed)
if maxp.y >= 2 and minp.y <=0 then
-- Generate fertilizer
local perlin1 = minetest.get_perlin(576, 3, 0.6, 100)
local divlen = 16
local divs = (maxp.x-minp.x)/divlen + 1;
for divx=0,divs-1 do
for divz=0,divs-1 do
local x0 = minp.x + math.floor(divx*divlen)
local z0 = minp.z + math.floor(divz*divlen)
local x1 = minp.x + math.floor((divx+1)*divlen)
local z1 = minp.z + math.floor((divz+1)*divlen)
local grass_amount = math.floor(perlin1:get2d({x=x0, y=z0}) ^ 2)
local pr = PseudoRandom(seed+249)
for i=0,grass_amount do
local x = pr:next(x0, x1)
local z = pr:next(z0, z1)
local ground_y = nil
for y=30,0,-1 do
if minetest.get_node({x=x,y=y,z=z}).name ~= "air" then
ground_y = y
break
end
end
if ground_y then
local p = {x=x, y=ground_y+1, z=z}
local nn = minetest.get_node(p).name
if minetest.registered_nodes[nn] and
minetest.registered_nodes[nn].buildable_to then
nn = minetest.get_node({x=x,y=ground_y,z=z}).name
if nn == "default:dirt_with_grass" then
minetest.set_node(p, {name="factory:sapling_fertilizer"})
end
end
end
end
end
end
end
end)
end

12
util/gui.lua Normal file
View File

@ -0,0 +1,12 @@
factory_gui_bg = "bgcolor[#080808BB;true]"
factory_gui_bg_img = "background[5,5;1,1;gui_factoryformbg.png;true]"
factory_gui_bg_img_2 = "background[5,5;1,1;gui_factoryformbg2.png;true]"
factory_gui_slots = "listcolors[#00000069;#5A5A5A;#141318;#30434C;#FFF]"
function factory.get_hotbar_bg(x,y)
local out = ""
for i=0,7,1 do
out = out .."image["..x+i..","..y..";1,1;gui_hb_bg.png]"
end
return out
end

4
util/init.lua Normal file
View File

@ -0,0 +1,4 @@
dofile(factory.modpath.."/util/craftingutil.lua")
dofile(factory.modpath.."/util/gui.lua")
dofile(factory.modpath.."/util/nodes.lua")
dofile(factory.modpath.."/util/gen.lua")

22
util/nodes.lua Normal file
View File

@ -0,0 +1,22 @@
function factory.swap_node(pos,name)
local node = minetest.get_node(pos)
if node.name == name then
return
end
node.name = name
minetest.swap_node(pos,node)
end
function factory.get_objects_with_square_radius(pos, rad)
rad = rad + .5;
local objs = {}
for _,object in ipairs(minetest.env:get_objects_inside_radius(pos, math.sqrt(3)*rad)) do
if not object:is_player() and object:get_luaentity() and (object:get_luaentity().name == "__builtin:item" or object:get_luaentity().name == "factory:moving_item") then
local opos = object:getpos()
if pos.x - rad <= opos.x and opos.x <= pos.x + rad and pos.y - rad <= opos.y and opos.y <= pos.y + rad and pos.z - rad <= opos.z and opos.z <= pos.z + rad then
objs[#objs + 1] = object
end
end
end
return objs
end