Major update. Add factory components.

Add some textures, move an API, and add assembly tables.
master
minermoder27 2014-06-09 08:31:04 +12:00
parent aad14f3c99
commit 17b9b69203
14 changed files with 396 additions and 67 deletions

View File

@ -1,11 +1,50 @@
buildtest={}
buildtest={
libs = {
allow_metadata_inventory_put = function(exc, isnumber)
return function(pos, listname, index, stack, player)
if listname==exc then
return stack:get_count()
end
local meta=minetest.get_meta(pos)
local inv=meta:get_inventory()
if inv:get_stack(listname, index):is_empty() then
local newStack = {name = stack:get_name()}
if isnumber==true then
newStack.count = stack:get_count()
end
inv:set_stack(listname, index, newStack)
end
return 0
end
end,
allow_metadata_inventory_take = function(exc)
return function(pos, listname, index, stack, player)
if listname==exc then
return stack:get_count()
end
local meta=minetest.get_meta(pos)
local inv=meta:get_inventory()
inv:set_stack(listname, index, nil)
return 0
end
end,
allow_metadata_inventory_move = function(exc, ok)
return function(pos, from_list, from_index, to_list, to_index, count, player)
if from_list==to_list or ok==true then
return count
end
return 0
end
end,
}
}
dofile(minetest.get_modpath("buildtest").."/pipes/pipes_defs.lua")
dofile(minetest.get_modpath("buildtest").."/misc/init.lua")
dofile(minetest.get_modpath("buildtest").."/pipes/pipes_init.lua")
dofile(minetest.get_modpath("buildtest").."/pumps/pump_init.lua")
dofile(minetest.get_modpath("buildtest").."/support/entity.lua")
dofile(minetest.get_modpath("buildtest").."/support/liquid.lua")
dofile(minetest.get_modpath("buildtest").."/misc/init.lua")
dofile(minetest.get_modpath("buildtest").."/crafts.lua")

195
misc/assembly.lua Normal file
View File

@ -0,0 +1,195 @@
buildtest.assembly = {
recipies = {
{ -- 2 wood to mesecon engine
from={
{name = "default:wood", count=1},
},
output={name="default:stick", count=8},
energy = 10,
},
{ -- cobble to lava
from={
{name = "bucket:bucket_empty", count=1},
{name = "default:cobble", count=2},
},
output={name="bucket:bucket_lava"},
energy = 100,
},
{ -- water+lava to obsidian+water
from={
{name = "bucket:bucket_water", count=1},
{name = "bucket:bucket_lava", count=1},
},
leave = {
{name = "bucket:bucket_water", count=1},
{name = "bucket:bucket_empty", count=1},
},
output={name="default:obsidian"},
energy = 15,
},
},
remove_items = function(inv, id)
if id==0 then return end
local rec = buildtest.assembly.recipies[buildtest.assembly.lookupId(inv, id)]
if rec==nil then return end
for ii=1, #rec.from do
inv:remove_item("in", rec.from[ii])
end
if rec.leave~=nil then
for ii=1, #rec.leave do
inv:add_item("in", rec.leave[ii])
end
end
end,
lookupId = function(inv, id)
local t = buildtest.assembly.get_recipies(inv)[id]
if t==nil then return 0 end
return t.id
end,
can_make = function(inv, id)
if id==0 then return end
local rec = buildtest.assembly.recipies[id]
local ok = true
for ii=1, #rec.from do
if inv:contains_item("in", rec.from[ii])==false then
ok = false
end
end
return ok
end,
can_make_rel = function(inv, id)
if id==0 then return end
return buildtest.assembly.can_make(inv, buildtest.assembly.lookupId(inv, id))
end,
get_recipies = function(inv)
local recipies = {}
for i=1, #buildtest.assembly.recipies do
if buildtest.assembly.can_make(inv, i) then
local rec = buildtest.assembly.recipies[i]
recipies[#recipies + 1] = {id=i, rec=rec, output = rec.output}
end
end
return recipies
end,
check_config = function(meta)
if buildtest.assembly.can_make_rel(meta:get_inventory(), meta:get_int("selected"))==false then
meta:set_int("selected", 0)
end
end,
set_formspec_params = function(pos, meta, inv)
buildtest.assembly.check_config(meta)
local formspec= "size[8,9]"..
"list[current_name;in;0,0;4,4;]"..
"list[current_player;main;0,5;8,4;]"
local selId = meta:get_int("selected")
if selId~=0 then
local sel = buildtest.assembly.get_recipies(inv)[selId]
if sel~=nil and sel.rec~=nil and sel.rec.energy~=nil and sel.output~=nil then
local h = 4.0 * meta:get_int("power") / sel.rec.energy
formspec = formspec .. "box[4,"..(4-h)..";0.25,"..h..";#FF0000FF]" .. "box[4,0;0.25,"..(4-h)..";#000000FF]" .. "label[4,4;"..(h*100/4).."%]"
end
end
local recs = buildtest.assembly.get_recipies(inv)
for i=1, #recs do
formspec = formspec .. "item_image_button[4.5,"..i..";1,1;"..recs[i].output.name..";item_sel_"..i..";"
if meta:get_int("selected")==i then
formspec = formspec .. "@"
end
formspec = formspec .. "]"
end
meta:set_string("formspec", formspec)
end,
set_formspec = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
buildtest.assembly.set_formspec_params(pos, meta, inv)
end,
add_energy = function(pos, energy)
local meta = minetest.get_meta(pos)
meta:set_int("power", meta:get_int("power") + energy)
buildtest.assembly.process_energy(pos)
end,
process_energy = function(pos)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
local selId = meta:get_int("selected")
if selId~=0 then
local sel = buildtest.assembly.get_recipies(inv)[selId]
if sel~=nil and sel.rec~=nil and sel.rec.energy~=nil and sel.output~=nil then
if meta:get_int("power") > sel.rec.energy then
local count = math.floor(meta:get_int("power") / sel.rec.energy)
meta:set_int("power", meta:get_int("power") % sel.rec.energy)
buildtest.assembly.remove_items(inv, selId)
--[[local ways = {
{x= 1,y= 0,z= 0},
{x=-1,y= 0,z= 0},
{x= 0,y= 1,z= 0},
{x= 0,y=-1,z= 0},
{x= 0,y= 0,z= 1},
{x= 0,y= 0,z=-1},
}
for i=1, #ways do
if minetest.get_node()
end]]--
--[[local obj = minetest.add_item(vector.add(pos, {x=0, y=1, z=0}), sel.output)
if obj ~= nil then
obj:setvelocity({x=(math.random()-0.5),y=math.random()+1,z=(math.random()-0.5)})
end]]--
buildtest.makeEnt(vector.add(pos, {x=0,y=1,z=0}), sel.output, 1, pos)
end
end
end
buildtest.assembly.set_formspec_params(pos, meta, inv)
end,
}
minetest.register_node("buildtest:assembly_table", {
description = "Buildtest Assembly Table",
tiles = {
"buildtest_assembly.png"
},
groups = {crackey = 3, buildtest_laser = 1},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("power", 0)
meta:set_int("selected", 0)
local inv = meta:get_inventory()
inv:set_size("in", 4*4)
buildtest.assembly.set_formspec_params(pos, meta, inv)
end,
on_metadata_inventory_move = function(pos, from_list, to_list, to_list, to_index, count, player)
buildtest.assembly.set_formspec(pos)
end,
on_metadata_inventory_put = function(pos, listname, index, stack, player)
buildtest.assembly.set_formspec(pos)
end,
on_metadata_inventory_take = function(pos, listname, index, stack, player)
buildtest.assembly.set_formspec(pos)
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 meta = minetest.get_meta(pos)
for name, val in pairs(fields) do
if strs:starts(name, "item_sel_") then
local id = tonumber(strs:rem_from_start(name, "item_sel_"))
meta:set_int("selected", id)
buildtest.assembly.set_formspec_params(pos, meta, meta:get_inventory())
end
end
end,
buildtest = {
on_laser = function(pos, speed)
end,
}
})

View File

@ -1,40 +1,7 @@
buildtest.autocraft = {
allow_metadata_inventory_put = function(exc, isnumber)
return function(pos, listname, index, stack, player)
if listname==exc then
return stack:get_count()
end
local meta=minetest.get_meta(pos)
local inv=meta:get_inventory()
if inv:get_stack(listname, index):is_empty() then
local newStack = {name = stack:get_name()}
if isnumber==true then
newStack.count = stack:get_count()
end
inv:set_stack(listname, index, newStack)
end
return 0
end
end,
allow_metadata_inventory_take = function(exc)
return function(pos, listname, index, stack, player)
if listname==exc then
return stack:get_count()
end
local meta=minetest.get_meta(pos)
local inv=meta:get_inventory()
inv:set_stack(listname, index, nil)
return 0
end
end,
allow_metadata_inventory_move = function(exc, ok)
return function(pos, from_list, from_index, to_list, to_index, count, player)
if from_list==to_list or ok==true then
return count
end
return 0
end
end,
allow_metadata_inventory_put = buildtest.libs.allow_metadata_inventory_put,
allow_metadata_inventory_take = buildtest.libs.allow_metadata_inventory_take,
allow_metadata_inventory_move = buildtest.libs.allow_metadata_inventory_move,
--------------------------------------------------------------------------------
do_craft = function(inventory)
local recipe=inventory:get_list("craft")

View File

@ -1 +1,4 @@
dofile(minetest.get_modpath("buildtest").."/misc/autocraft.lua")
dofile(minetest.get_modpath("buildtest").."/misc/autocraft.lua")
dofile(minetest.get_modpath("buildtest").."/misc/landmarks.lua")
dofile(minetest.get_modpath("buildtest").."/misc/assembly.lua")
dofile(minetest.get_modpath("buildtest").."/misc/lasers.lua")

46
misc/landmarks.lua Normal file
View File

@ -0,0 +1,46 @@
buildtest.landmarks = {
removeBeam = function()
end,
addBeam = function()
removeBeam()
end,
}
minetest.register_node("buildtest:landmark", {
description = "Buildtest Landmark",
drawtype = "torchlike",
--tiles = {"default_torch_on_floor.png", "default_torch_on_ceiling.png", "default_torch.png"},
tiles = {
"buildtest_landmark.png"
},
inventory_image = "buildtest_landmark.png",
wield_image = "buildtest_landmark.png",
paramtype = "light",
paramtype2 = "wallmounted",
sunlight_propagates = true,
is_ground_content = false,
walkable = false,
light_source = 7,
selection_box = {
type = "wallmnted",
wall_top = {-0.1, 0.5-0.6, -0.1, 0.1, 0.5, 0.1},
wall_bottom = {-0.1, -0.5, -0.1, 0.1, -0.5+0.6, 0.1},
wall_side = {-0.5, -0.3, -0.1, -0.5+0.3, 0.3, 0.1},
},
groups = {choppy=2,dig_immediate=3,attached_node=1},
legacy_wallmounted = true,
sounds = default.node_sound_defaults(),
mesecons = {
effector = {
action_off = function (pos, node)
local meta = minetest.get_meta(pos)
meta:set_int("on", 0)
end,
action_on = function (pos, node)
local meta = minetest.get_meta(pos)
meta:set_int("on", 1)
end,
},
},
})

61
misc/lasers.lua Normal file
View File

@ -0,0 +1,61 @@
minetest.register_node("buildtest:laser", {
description = "Buildtest Assembly Laser",
tiles = {
"buildtest_laser_top.png",
"buildtest_laser.png",
"buildtest_laser.png",
},
groups = {cracky=3},
buildtest = {
power = {
},
},
paramtype2 = "wallmounted",
on_rightclick = function(pos, node, player, itemstack, pointed_thing)
local meta = minetest.get_meta(pos)
local mode = meta:get_int("mode")
mode = (mode + 1) % 2
meta:set_int("mode", mode)
meta:set_string("infotext", "Laser. Mode: "..mode .. " (rightclick to change)")
end,
})
buildtest.pumps.pumpible["buildtest:laser"] = {
power = function(laser_pos, speed)
local meta = minetest.get_meta(pos)
local mode = meta:get_int("mode")
if mode==0 then
local pos = minetest.find_node_near(laser_pos, 5, {"group:buildtest_laser"})
if pos~=nil then
buildtest.assembly.add_energy(pos, speed)
end
elseif mode==1 then
local dirs = {
[0] = {y = 1},
[1] = {y = -1},
[2] = {x = 1},
[3] = {x = -1},
[4] = {z = 1},
[5] = {z = -1},
}
local pos = laser_pos
local dir = dirs[minetest.get_node(laser_pos).param2]
dir.x = dir.x or 0
dir.y = dir.y or 0
dir.z = dir.z or 0
for i=1, 30 do
pos = vector.add(pos, dir)
local node = minetest.get_node(pos)
if minetest.get_item_group(node.name, "buildtest_laser")~=0 then
local def = minetest.registered_nodes[node.name]
if def~=nil and def.buildtest~=nil and def.buildtest.on_laser~=nil then
def.buildtest.on_laser(pos, speed)
end
elseif node.name~="air" then
return
end
end
end
end,
}

View File

@ -62,9 +62,9 @@ buildtest.pipes.makepipe(function(set, nodes, count, name, id, clas, type)
end,
on_dig = buildtest.pipes.ond_funct,
--------------------------------------------------------------------------------
allow_metadata_inventory_put = buildtest.autocraft.allow_metadata_inventory_put(nil), -- {["green"]=1, ["black"]=1, ["red"]=1, ["white"]=1, ["blue"]=1, ["yellow"]=1,}
allow_metadata_inventory_take = buildtest.autocraft.allow_metadata_inventory_take(nil),
allow_metadata_inventory_move = buildtest.autocraft.allow_metadata_inventory_move(nil, true),
allow_metadata_inventory_put = buildtest.libs.allow_metadata_inventory_put(nil), -- {["green"]=1, ["black"]=1, ["red"]=1, ["white"]=1, ["blue"]=1, ["yellow"]=1,}
allow_metadata_inventory_take = buildtest.libs.allow_metadata_inventory_take(nil),
allow_metadata_inventory_move = buildtest.libs.allow_metadata_inventory_move(nil, true),
}
if count~=1 then
def.groups.not_in_creative_inventory=1

View File

@ -80,9 +80,9 @@ buildtest.pipes.makepipe(function(set, nodes, count, name, id, clas, type)
end,
on_dig = buildtest.pipes.ond_funct,
--------------------------------------------------------------------------------
allow_metadata_inventory_put = buildtest.autocraft.allow_metadata_inventory_put(nil), -- {["green"]=1, ["black"]=1, ["red"]=1, ["white"]=1, ["blue"]=1, ["yellow"]=1,}
allow_metadata_inventory_take = buildtest.autocraft.allow_metadata_inventory_take(nil),
allow_metadata_inventory_move = buildtest.autocraft.allow_metadata_inventory_move(nil, true),
allow_metadata_inventory_put = buildtest.libs.allow_metadata_inventory_put(nil), -- {["green"]=1, ["black"]=1, ["red"]=1, ["white"]=1, ["blue"]=1, ["yellow"]=1,}
allow_metadata_inventory_take = buildtest.libs.allow_metadata_inventory_take(nil),
allow_metadata_inventory_move = buildtest.libs.allow_metadata_inventory_move(nil, true),
}
if count~=1 then
def.groups.not_in_creative_inventory=1

View File

@ -54,9 +54,9 @@ buildtest.pipes.makepipe(function(set, nodes, count, name, id, clas, type)
minetest.show_formspec(clicker:get_player_name(), "buildtest:pipe_emr_"..name, formspec)
end,
--------------------------------------------------------------------------------
allow_metadata_inventory_put = buildtest.autocraft.allow_metadata_inventory_put(nil),
allow_metadata_inventory_take = buildtest.autocraft.allow_metadata_inventory_take(nil),
allow_metadata_inventory_move = buildtest.autocraft.allow_metadata_inventory_move(nil),
allow_metadata_inventory_put = buildtest.libs.allow_metadata_inventory_put(nil),
allow_metadata_inventory_take = buildtest.libs.allow_metadata_inventory_take(nil),
allow_metadata_inventory_move = buildtest.libs.allow_metadata_inventory_move(nil),
}
if count~=1 then
def.groups.not_in_creative_inventory=1

View File

@ -199,9 +199,9 @@ for m_on = 1, 2 do
mesecon.on_dignode(pos, node)
end,
allow_metadata_inventory_put = buildtest.autocraft.allow_metadata_inventory_put(nil, true),
allow_metadata_inventory_take = buildtest.autocraft.allow_metadata_inventory_take(nil),
allow_metadata_inventory_move = buildtest.autocraft.allow_metadata_inventory_move(nil),
allow_metadata_inventory_put = buildtest.libs.allow_metadata_inventory_put(nil, true),
allow_metadata_inventory_take = buildtest.libs.allow_metadata_inventory_take(nil),
allow_metadata_inventory_move = buildtest.libs.allow_metadata_inventory_move(nil),
}
if count~=1 or m_on==2 then
def.groups.not_in_creative_inventory=1

View File

@ -53,9 +53,9 @@ buildtest.pipes.makepipe(function(set, nodes, count, name, id, clas, type, tover
end,
on_dig = buildtest.pipes.ond_funct,
------------------------------------------------
allow_metadata_inventory_put = buildtest.autocraft.allow_metadata_inventory_put(nil),
allow_metadata_inventory_take = buildtest.autocraft.allow_metadata_inventory_take(nil),
allow_metadata_inventory_move = buildtest.autocraft.allow_metadata_inventory_move(nil, true),
allow_metadata_inventory_put = buildtest.libs.allow_metadata_inventory_put(nil),
allow_metadata_inventory_take = buildtest.libs.allow_metadata_inventory_take(nil),
allow_metadata_inventory_move = buildtest.libs.allow_metadata_inventory_move(nil, true),
}
if count~=1 then
def.groups.not_in_creative_inventory=1

View File

@ -274,7 +274,9 @@ buildtest.pipes.defaultPipes = {
"buildtest:autocraft",
"default:furnace",
"default:chest",
-----------
----------- BT FACTORY
"buildtest:assembly_table",
----------- BT PIPES
"buildtest:pipe_meseconoff",
"buildtest:pipe_meseconon",
"buildtest:pipe_sandstone",

View File

@ -31,12 +31,31 @@ minetest.register_node("buildtest:pump", {
end
})
minetest.register_node("buildtest:pump_pipe_act", {
groups = {oddly_breakable_by_hand=3},
})
buildtest.pumps.pumpible["buildtest:pump"] = {
power = function(pos, speed)
local topos = buildtest.pumps.findpipe(pos)
local pumppipepos = {x=pos.x, y=pos.y-1, z=pos.z}
local pipename = minetest.get_node(pumppipepos).name
while pipename=="buildtest:pump_pipe" do
pumppipepos.y = pumppipepos.y - 1
pipename = minetest.get_node(pumppipepos).name
end
local pipedef = minetest.registered_nodes[pipename]
if pipedef==nil then return end
if pipename=="air" or pipedef.liquidtype == "source" or pipedef.liquidtype == "flowing" then
minetest.set_node(pumppipepos, {name="buildtest:pump_pipe"})
if pipedef.liquidtype == "source" then
buildtest.makeEnt(topos, {name=pipename}, speed, pos)
end
end
end,
}
minetest.register_node("buildtest:pump_pipe_off", {
groups = {not_in_creative_inventory=1,oddly_breakable_by_hand=3},
minetest.register_node("buildtest:pump_pipe", {
groups = {oddly_breakable_by_hand=3},
})
minetest.register_abm({

View File

@ -20,6 +20,8 @@ buildtest.pumps = {
["itest:extractor_active"] = {"dst"},
["itest:extractor"] = {"dst"},
},
pumpible = {
},
hacky_swap_node = function(pos, name)
local node = minetest.get_node(pos)
local meta = minetest.get_meta(pos)
@ -117,13 +119,8 @@ buildtest.pumps.send_power = function(pipepos, speed, movecount)
object:remove()
end
end
elseif minetest.get_node(pipepos).name=="buildtest:pump" then
local topos = buildtest.pumps.findpipe(pipepos)
buildtest.makeEnt(topos, {name="default:water_source"}, speed, pipepos)
local pumppipepos = {x=pipepos.x, y=pipepos.y-1, z=pipepos.z}
if minetest.get_node(pumppipepos).name=="air" then
minetest.set_node(pumppipepos, {name="buildtest:pump_pipe_act"})
end
elseif buildtest.pumps.pumpible[minetest.get_node(pipepos).name]~=nil then
buildtest.pumps.pumpible[minetest.get_node(pipepos).name].power(pipepos, speed)
elseif strs:starts(minetest.get_node(pipepos).name, "buildtest:pipe_stripe_") then
local itemName = minetest.get_node(chestpos).name
if itemName~="air" and itemName~="ignore" then