mirror of
https://github.com/mt-mods/pipeworks.git
synced 2024-12-26 19:00:24 +01:00
Merge pull request #8 from Novatux/master
Teleporter and accelerator tubes, crafting recipe for detector pipe, autocrafter
This commit is contained in:
commit
f8eb154f7a
75
autocrafter.lua
Normal file
75
autocrafter.lua
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
|
||||||
|
|
||||||
|
function autocraft(inventory)
|
||||||
|
local recipe=inventory:get_list("recipe")
|
||||||
|
local result
|
||||||
|
local new
|
||||||
|
result,new=minetest.get_craft_result({method="normal",width=3,items=recipe})
|
||||||
|
local input=inventory:get_list("input")
|
||||||
|
if result.item:is_empty() then return end
|
||||||
|
result=result.item
|
||||||
|
local to_use={}
|
||||||
|
for _,item in ipairs(recipe) do
|
||||||
|
if item~=nil and not item:is_empty() then
|
||||||
|
if to_use[item:get_name()]==nil then
|
||||||
|
to_use[item:get_name()]=1
|
||||||
|
else
|
||||||
|
to_use[item:get_name()]=to_use[item:get_name()]+1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local stack
|
||||||
|
for itemname,number in pairs(to_use) do
|
||||||
|
stack=ItemStack({name=itemname, count=number})
|
||||||
|
if not inventory:contains_item("src",stack) then return end
|
||||||
|
end
|
||||||
|
for itemname,number in pairs(to_use) do
|
||||||
|
stack=ItemStack({name=itemname, count=number})
|
||||||
|
inventory:remove_item("src",stack)
|
||||||
|
end
|
||||||
|
inventory:add_item("dst",result)
|
||||||
|
print(dump(new))
|
||||||
|
end
|
||||||
|
|
||||||
|
minetest.register_node("pipeworks:autocrafter",{
|
||||||
|
description = "Autocrafter",
|
||||||
|
drawtype="normal",
|
||||||
|
tiles={"pipeworks_autocrafter.png"},
|
||||||
|
groups={snappy=3,tubedevice=1,tubedevice_receiver=1},
|
||||||
|
tube={insert_object=function(pos,node,stack,direction)
|
||||||
|
local meta=minetest.env:get_meta(pos)
|
||||||
|
local inv=meta:get_inventory()
|
||||||
|
return inv:add_item("src",stack)
|
||||||
|
end,
|
||||||
|
can_insert=function(pos,node,stack,direction)
|
||||||
|
local meta=minetest.env:get_meta(pos)
|
||||||
|
local inv=meta:get_inventory()
|
||||||
|
return inv:room_for_item("src",stack)
|
||||||
|
end,
|
||||||
|
input_inventory="dst"},
|
||||||
|
on_construct = function(pos)
|
||||||
|
local meta = minetest.env:get_meta(pos)
|
||||||
|
meta:set_string("formspec",
|
||||||
|
"size[8,11]"..
|
||||||
|
"list[current_name;recipe;0,0;3,3;]"..
|
||||||
|
"list[current_name;src;0,3;8,3;]"..
|
||||||
|
"list[current_name;dst;4,0;4,3;]"..
|
||||||
|
"list[current_player;main;0,7;8,4;]")
|
||||||
|
meta:set_string("infotext", "Autocrafter")
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
inv:set_size("src",3*8)
|
||||||
|
inv:set_size("recipe",3*3)
|
||||||
|
inv:set_size("dst",4*3)
|
||||||
|
end,
|
||||||
|
can_dig = function(pos,player)
|
||||||
|
local meta = minetest.env:get_meta(pos);
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
return (inv:is_empty("src") and inv:is_empty("recipe") and inv:is_empty("dst"))
|
||||||
|
end})
|
||||||
|
|
||||||
|
minetest.register_abm({nodenames={"pipeworks:autocrafter"},interval=1,chance=1,
|
||||||
|
action=function(pos,node)
|
||||||
|
local meta=minetest.env:get_meta(pos)
|
||||||
|
local inv=meta:get_inventory()
|
||||||
|
autocraft(inv)
|
||||||
|
end})
|
@ -87,7 +87,12 @@ function tube_autoroute(pos)
|
|||||||
|
|
||||||
nsurround = pxm..pxp..pym..pyp..pzm..pzp
|
nsurround = pxm..pxp..pym..pyp..pzm..pzp
|
||||||
if is_tube(nctr.name) then
|
if is_tube(nctr.name) then
|
||||||
minetest.env:add_node(pos, { name = string.sub(nctr.name,1,-7)..nsurround })
|
local meta=minetest.env:get_meta(pos)
|
||||||
|
local meta0=meta:to_table()
|
||||||
|
nctr.name=string.sub(nctr.name,1,-7)..nsurround
|
||||||
|
minetest.env:add_node(pos, nctr)
|
||||||
|
local meta=minetest.env:get_meta(pos)
|
||||||
|
meta:from_table(meta0)
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
20
crafts.lua
20
crafts.lua
@ -115,7 +115,25 @@ if io.open(minetest.get_modpath("pipeworks").."/../technic/init.lua", "r") == ni
|
|||||||
output = "pipeworks:detector_tube_off_000000 2",
|
output = "pipeworks:detector_tube_off_000000 2",
|
||||||
recipe = {
|
recipe = {
|
||||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
|
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
|
||||||
{ "default:mese_crystal_fragment", "default:mese_crystal_fragment", "default:mese_crystal_fragment" },
|
{ "mesecons:mesecon", "mesecons:mesecon", "mesecons:mesecon" },
|
||||||
|
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_craft( {
|
||||||
|
output = "pipeworks:accelerator_tube_000000 2",
|
||||||
|
recipe = {
|
||||||
|
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
|
||||||
|
{ "default:mese_crystal_fragment", "default:steel_ingot", "default:mese_crystal_fragment" },
|
||||||
|
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
minetest.register_craft( {
|
||||||
|
output = "pipeworks:teleport_tube_000000 2",
|
||||||
|
recipe = {
|
||||||
|
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" },
|
||||||
|
{ "default:desert_stone", "default:mese_block", "default:desert_stone" },
|
||||||
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
|
{ "homedecor:plastic_sheeting", "homedecor:plastic_sheeting", "homedecor:plastic_sheeting" }
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
2
init.lua
2
init.lua
@ -328,5 +328,5 @@ dofile(minetest.get_modpath("pipeworks").."/crafts.lua")
|
|||||||
dofile(minetest.get_modpath("pipeworks").."/flowing_logic.lua")
|
dofile(minetest.get_modpath("pipeworks").."/flowing_logic.lua")
|
||||||
dofile(minetest.get_modpath("pipeworks").."/compat.lua")
|
dofile(minetest.get_modpath("pipeworks").."/compat.lua")
|
||||||
dofile(minetest.get_modpath("pipeworks").."/item_transport.lua")
|
dofile(minetest.get_modpath("pipeworks").."/item_transport.lua")
|
||||||
|
dofile(minetest.get_modpath("pipeworks").."/autocrafter.lua")
|
||||||
print("Pipeworks loaded!")
|
print("Pipeworks loaded!")
|
||||||
|
@ -153,10 +153,13 @@ minetest.register_entity("pipeworks:tubed_item", {
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
get_staticdata = function(self)
|
get_staticdata = function(self)
|
||||||
|
if self.start_pos==nil then return end
|
||||||
|
local velocity=self.object:getvelocity()
|
||||||
|
--self.object:setvelocity({x=0,y=0,z=0})
|
||||||
|
self.object:setpos(self.start_pos)
|
||||||
return minetest.serialize({
|
return minetest.serialize({
|
||||||
itemstring=self.itemstring,
|
itemstring=self.itemstring,
|
||||||
velocity=self.object:getvelocity(),
|
velocity=velocity,
|
||||||
start_pos=self.start_pos
|
start_pos=self.start_pos
|
||||||
})
|
})
|
||||||
end,
|
end,
|
||||||
@ -196,31 +199,35 @@ minetest.register_entity("pipeworks:tubed_item", {
|
|||||||
local velocitycopy={x=velocity.x,y=velocity.y,z=velocity.z}
|
local velocitycopy={x=velocity.x,y=velocity.y,z=velocity.z}
|
||||||
|
|
||||||
local moved=false
|
local moved=false
|
||||||
|
local speed=math.abs(velocity.x+velocity.y+velocity.z)
|
||||||
|
local vel={x=velocity.x/speed,y=velocity.y/speed,z=velocity.z/speed}
|
||||||
|
|
||||||
if math.abs(velocity.x)==1 then
|
if math.abs(vel.x)==1 then
|
||||||
local next_node=math.abs(pos.x-self.start_pos.x)
|
local next_node=math.abs(pos.x-self.start_pos.x)
|
||||||
if next_node >= 1 then
|
if next_node >= 1 then
|
||||||
self.start_pos.x=self.start_pos.x+velocity.x
|
self.start_pos.x=self.start_pos.x+vel.x
|
||||||
moved=true
|
moved=true
|
||||||
end
|
end
|
||||||
elseif math.abs(velocity.y)==1 then
|
elseif math.abs(vel.y)==1 then
|
||||||
local next_node=math.abs(pos.y-self.start_pos.y)
|
local next_node=math.abs(pos.y-self.start_pos.y)
|
||||||
if next_node >= 1 then
|
if next_node >= 1 then
|
||||||
self.start_pos.y=self.start_pos.y+velocity.y
|
self.start_pos.y=self.start_pos.y+vel.y
|
||||||
moved=true
|
moved=true
|
||||||
end
|
end
|
||||||
elseif math.abs(velocity.z)==1 then
|
elseif math.abs(vel.z)==1 then
|
||||||
local next_node=math.abs(pos.z-self.start_pos.z)
|
local next_node=math.abs(pos.z-self.start_pos.z)
|
||||||
if next_node >= 1 then
|
if next_node >= 1 then
|
||||||
self.start_pos.z=self.start_pos.z+velocity.z
|
self.start_pos.z=self.start_pos.z+vel.z
|
||||||
moved=true
|
moved=true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local sposcopy={x=self.start_pos.x,y=self.start_pos.y,z=self.start_pos.z}
|
||||||
|
|
||||||
node = minetest.env:get_node(self.start_pos)
|
node = minetest.env:get_node(self.start_pos)
|
||||||
if moved and minetest.get_item_group(node.name,"tubedevice_receiver")==1 then
|
if moved and minetest.get_item_group(node.name,"tubedevice_receiver")==1 then
|
||||||
if minetest.registered_nodes[node.name].tube and minetest.registered_nodes[node.name].tube.insert_object then
|
if minetest.registered_nodes[node.name].tube and minetest.registered_nodes[node.name].tube.insert_object then
|
||||||
leftover = minetest.registered_nodes[node.name].tube.insert_object(self.start_pos,node,stack,velocity)
|
leftover = minetest.registered_nodes[node.name].tube.insert_object(self.start_pos,node,stack,vel)
|
||||||
else
|
else
|
||||||
leftover = stack
|
leftover = stack
|
||||||
end
|
end
|
||||||
@ -249,7 +256,8 @@ minetest.register_entity("pipeworks:tubed_item", {
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if velocity.x~=velocitycopy.x or velocity.y~=velocitycopy.y or velocity.z~=velocitycopy.z then
|
if velocity.x~=velocitycopy.x or velocity.y~=velocitycopy.y or velocity.z~=velocitycopy.z or
|
||||||
|
self.start_pos.x~=sposcopy.x or self.start_pos.y~=sposcopy.y or self.start_pos.z~=sposcopy.z then
|
||||||
self.object:setpos(self.start_pos)
|
self.object:setpos(self.start_pos)
|
||||||
self.object:setvelocity(velocity)
|
self.object:setvelocity(velocity)
|
||||||
end
|
end
|
||||||
@ -278,13 +286,23 @@ function go_next(pos,velocity,stack)
|
|||||||
local len=1
|
local len=1
|
||||||
local n
|
local n
|
||||||
local can_go
|
local can_go
|
||||||
|
local speed=math.abs(velocity.x+velocity.y+velocity.z)
|
||||||
|
local vel={x=velocity.x/speed,y=velocity.y/speed,z=velocity.z/speed,speed=speed}
|
||||||
|
if speed>=4.1 then
|
||||||
|
speed=4
|
||||||
|
elseif speed>=1.1 then
|
||||||
|
speed=speed-0.1
|
||||||
|
else
|
||||||
|
speed=1
|
||||||
|
end
|
||||||
|
vel.speed=speed
|
||||||
if minetest.registered_nodes[cnode.name].tube and minetest.registered_nodes[cnode.name].tube.can_go then
|
if minetest.registered_nodes[cnode.name].tube and minetest.registered_nodes[cnode.name].tube.can_go then
|
||||||
can_go=minetest.registered_nodes[cnode.name].tube.can_go(pos,node,velocity,stack)
|
can_go=minetest.registered_nodes[cnode.name].tube.can_go(pos,node,vel,stack)
|
||||||
else
|
else
|
||||||
can_go=adjlist
|
can_go=adjlist
|
||||||
end
|
end
|
||||||
for _,vect in ipairs(can_go) do
|
for _,vect in ipairs(can_go) do
|
||||||
if vect.x~=-velocity.x or vect.y~=-velocity.y or vect.z~=-velocity.z then
|
if vect.x~=-vel.x or vect.y~=-vel.y or vect.z~=-vel.z then
|
||||||
npos=addVect(pos,vect)
|
npos=addVect(pos,vect)
|
||||||
node=minetest.env:get_node(npos)
|
node=minetest.env:get_node(npos)
|
||||||
tube_receiver=minetest.get_item_group(node.name,"tubedevice_receiver")
|
tube_receiver=minetest.get_item_group(node.name,"tubedevice_receiver")
|
||||||
@ -334,9 +352,9 @@ function go_next(pos,velocity,stack)
|
|||||||
end
|
end
|
||||||
until false
|
until false
|
||||||
meta:set_int("tubedir",n)
|
meta:set_int("tubedir",n)
|
||||||
velocity.x=tubes[n].vect.x
|
velocity.x=tubes[n].vect.x*vel.speed
|
||||||
velocity.y=tubes[n].vect.y
|
velocity.y=tubes[n].vect.y*vel.speed
|
||||||
velocity.z=tubes[n].vect.z
|
velocity.z=tubes[n].vect.z*vel.speed
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
local i=1
|
local i=1
|
||||||
@ -352,9 +370,9 @@ function go_next(pos,velocity,stack)
|
|||||||
break
|
break
|
||||||
end
|
end
|
||||||
until false
|
until false
|
||||||
velocity.x=chests[n].vect.x
|
velocity.x=chests[n].vect.x*speed
|
||||||
velocity.y=chests[n].vect.y
|
velocity.y=chests[n].vect.y*speed
|
||||||
velocity.z=chests[n].vect.z
|
velocity.z=chests[n].vect.z*speed
|
||||||
end
|
end
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
82
teleport_tube.lua
Normal file
82
teleport_tube.lua
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
|
||||||
|
filename=minetest.get_worldpath() .. "/teleport_tubes"
|
||||||
|
|
||||||
|
function read_file()
|
||||||
|
local f = io.open(filename, "r")
|
||||||
|
if f==nil then return {} end
|
||||||
|
local t = f:read("*all")
|
||||||
|
f:close()
|
||||||
|
if t=="" or t==nil then return {} end
|
||||||
|
return minetest.deserialize(t)
|
||||||
|
end
|
||||||
|
|
||||||
|
function write_file(tbl)
|
||||||
|
local f = io.open(filename, "w")
|
||||||
|
f:write(minetest.serialize(tbl))
|
||||||
|
f:close()
|
||||||
|
end
|
||||||
|
|
||||||
|
function add_tube_in_file(pos,channel)
|
||||||
|
tbl=read_file()
|
||||||
|
for _,val in ipairs(tbl) do
|
||||||
|
if val.x==pos.x and val.y==pos.y and val.z==pos.z then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
table.insert(tbl,{x=pos.x,y=pos.y,z=pos.z,channel=channel})
|
||||||
|
write_file(tbl)
|
||||||
|
end
|
||||||
|
|
||||||
|
function remove_tube_in_file(pos)
|
||||||
|
tbl=read_file()
|
||||||
|
newtbl={}
|
||||||
|
for _,val in ipairs(tbl) do
|
||||||
|
if val.x~=pos.x or val.y~=pos.y or val.z~=pos.z then
|
||||||
|
table.insert(newtbl,val)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
write_file(newtbl)
|
||||||
|
end
|
||||||
|
|
||||||
|
function get_tubes_in_file(pos,channel)
|
||||||
|
tbl=read_file()
|
||||||
|
newtbl={}
|
||||||
|
for _,val in ipairs(tbl) do
|
||||||
|
if val.channel==channel and (val.x~=pos.x or val.y~=pos.y or val.z~=pos.z) then
|
||||||
|
table.insert(newtbl,val)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return newtbl
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
register_tube("pipeworks:teleport_tube","Teleporter pneumatic tube segment",plain_textures,noctr_textures,end_textures,
|
||||||
|
short_texture,inv_texture,
|
||||||
|
{tube={can_go=function(pos,node,velocity,stack)
|
||||||
|
velocity.x=0
|
||||||
|
velocity.y=0
|
||||||
|
velocity.z=0
|
||||||
|
local meta = minetest.env:get_meta(pos)
|
||||||
|
channel=meta:get_string("channel")
|
||||||
|
goto=get_tubes_in_file(pos,channel)
|
||||||
|
if goto[1]==nil then return {} end
|
||||||
|
pos.x=goto[1].x
|
||||||
|
pos.y=goto[1].y
|
||||||
|
pos.z=goto[1].z
|
||||||
|
return meseadjlist
|
||||||
|
end},
|
||||||
|
on_construct = function(pos)
|
||||||
|
local meta = minetest.env:get_meta(pos)
|
||||||
|
meta:set_string("channel","0")
|
||||||
|
meta:set_string("formspec","size[9,1;]field[0,0.5;9,1;channel;Channel:;${channel}]")
|
||||||
|
add_tube_in_file(pos,"0")
|
||||||
|
end,
|
||||||
|
on_receive_fields = function(pos,formname,fields,sender)
|
||||||
|
local meta = minetest.env:get_meta(pos)
|
||||||
|
meta:set_string("channel",fields.channel)
|
||||||
|
remove_tube_in_file(pos)
|
||||||
|
add_tube_in_file(pos,fields.channel)
|
||||||
|
end,
|
||||||
|
after_dig_node = function(pos)
|
||||||
|
remove_tube_in_file(pos)
|
||||||
|
end})
|
BIN
textures/pipeworks_autocrafter.png
Normal file
BIN
textures/pipeworks_autocrafter.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 167 B |
10
tubes.lua
10
tubes.lua
@ -371,3 +371,13 @@ register_tube("pipeworks:detector_tube_off","Detector tube segment",detector_pla
|
|||||||
groups={mesecon=2},
|
groups={mesecon=2},
|
||||||
mesecons={receptor={state="off",
|
mesecons={receptor={state="off",
|
||||||
rules=mesecons_rules}}})
|
rules=mesecons_rules}}})
|
||||||
|
|
||||||
|
register_tube("pipeworks:accelerator_tube","Accelerator pneumatic tube segment",plain_textures,noctr_textures,end_textures,
|
||||||
|
short_texture,inv_texture,
|
||||||
|
{tube={can_go=function(pos,node,velocity,stack)
|
||||||
|
velocity.speed=velocity.speed+1
|
||||||
|
return meseadjlist
|
||||||
|
end}})
|
||||||
|
|
||||||
|
modpath=minetest.get_modpath("pipeworks")
|
||||||
|
dofile(modpath.."/teleport_tube.lua")
|
Loading…
Reference in New Issue
Block a user