Init
parent
c9d793f95c
commit
0d36ac70e4
23
crafts.lua
23
crafts.lua
|
@ -1,43 +1,38 @@
|
|||
--default
|
||||
chemistry:register_reaction({"default:water_source",
|
||||
{"chemistry:O", "chemistry:O"},
|
||||
{"chemistry:H", "chemistry:H"},
|
||||
{"chemistry:H", "chemistry:H"},
|
||||
{"chemistry:H","chemistry:O","chemistry:H"},
|
||||
})
|
||||
|
||||
chemistry:register_reaction({"default:sand",
|
||||
{"chemistry:Si"},
|
||||
{"chemistry:O", "chemistry:O"},
|
||||
{"chemistry:Si", "chemistry:O", "chemistry:O"},
|
||||
})
|
||||
|
||||
chemistry:register_reaction({"default:stone_with_coal",
|
||||
{"chemistry:C", "chemistry:C"},
|
||||
{"chemistry:C"},
|
||||
})
|
||||
|
||||
--moreores
|
||||
chemistry:register_reaction({"moreores:gold_block",
|
||||
{"chemistry:Au", "chemistry:Au"},
|
||||
{"chemistry:Au"},
|
||||
})
|
||||
|
||||
chemistry:register_reaction({"moreores:silver_block",
|
||||
{"chemistry:Sg", "chemistry:Sg"},
|
||||
{"chemistry:Ag"},
|
||||
})
|
||||
|
||||
chemistry:register_reaction({"moreores:copper_block",
|
||||
{"chemistry:Cu", "chemistry:Cu"},
|
||||
{"chemistry:Cu"},
|
||||
})
|
||||
|
||||
chemistry:register_reaction({"moreores:tin_block",
|
||||
{"chemistry:Sn", "chemistry:Sn"},
|
||||
{"chemistry:Sn"},
|
||||
})
|
||||
|
||||
chemistry:register_reaction({"default:stone_with_iron",
|
||||
{"chemistry:Fe", "chemistry:Fe"},
|
||||
{"chemistry:Fe"},
|
||||
})
|
||||
|
||||
--diamonds
|
||||
chemistry:register_reaction({"diamonds:block",
|
||||
{"chemistry:C", "chemistry:C", "chemistry:C"},
|
||||
{"chemistry:C", "chemistry:C", "chemistry:C"},
|
||||
{"chemistry:C", "chemistry:C", "chemistry:C"},
|
||||
{"chemistry:C","chemistry:C","chemistry:C","chemistry:C"},
|
||||
})
|
||||
|
|
88
init.lua
88
init.lua
|
@ -174,93 +174,7 @@ minetest.register_node("chemistry:reactor", {
|
|||
inventory_image = "reactor.png",
|
||||
groups = {snappy=2,choppy=2,oddly_breakable_by_hand=3,flammable=3,chemistry=1},
|
||||
on_punch = function(pos)
|
||||
minetest.env:set_node(pos,{name="chemistry:extractor"})
|
||||
local numb = 0
|
||||
local atom = 1
|
||||
local candidates = deepcopy(chemistry.reactions)
|
||||
local candidate = 0
|
||||
local match = ""
|
||||
local node_name = minetest.env:get_node({x=pos.x+atom, y=pos.y+numb, z=pos.z}).name
|
||||
|
||||
while true do
|
||||
if node_name == "air" then
|
||||
return
|
||||
end
|
||||
|
||||
node_name = minetest.env:get_node({x=pos.x+atom, y=pos.y+numb, z=pos.z}).name
|
||||
|
||||
if node_name == "air" then
|
||||
atom = atom + 1
|
||||
numb = 0
|
||||
node_name = minetest.env:get_node({x=pos.x+atom, y=pos.y+numb, z=pos.z}).name
|
||||
end
|
||||
|
||||
if candidate == 1 then
|
||||
local count = 0
|
||||
local max = 0
|
||||
for xx in ipairs(candidates[1]) do
|
||||
if xx > 1 then
|
||||
for yy in ipairs(candidates[1][xx]) do
|
||||
max = max + 1
|
||||
node_name = minetest.env:get_node({x=pos.x+xx-1, y=pos.y+yy-1, z=pos.z}).name
|
||||
if node_name == candidates[1][xx][yy] then
|
||||
count = count + 1
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if count == max then
|
||||
minetest.env:add_node({x=pos.x-1, y=pos.y, z=pos.z}, {name=candidates[1][1]})
|
||||
for xx in ipairs(candidates[1]) do
|
||||
if xx > 1 then
|
||||
for yy in ipairs(candidates[1][xx]) do
|
||||
minetest.env:remove_node({x=pos.x+xx-1, y=pos.y+yy-1, z=pos.z})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
candidate = 0
|
||||
for reaction in ipairs(candidates) do
|
||||
local a = tostring(candidates[reaction][atom+1][numb+1])
|
||||
|
||||
if a == node_name then
|
||||
candidate = candidate+1
|
||||
candidates[candidate] = candidates[reaction]
|
||||
end
|
||||
|
||||
if candidate < reaction then
|
||||
if candidate ~= 0 then
|
||||
candidates[reaction] = nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
if candidate == 0 then
|
||||
return
|
||||
end
|
||||
|
||||
numb = numb + 1
|
||||
|
||||
end
|
||||
minetest.set_node(pos,{name="chemistry:extractor"})
|
||||
end,
|
||||
})
|
||||
|
||||
function deepcopy(t)
|
||||
if type(t) ~= 'table' then return t end
|
||||
local mt = getmetatable(t)
|
||||
local res = {}
|
||||
for k,v in pairs(t) do
|
||||
if type(v) == 'table' then
|
||||
v = deepcopy(v)
|
||||
end
|
||||
res[k] = v
|
||||
end
|
||||
setmetatable(res,mt)
|
||||
return res
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue