ta4_chest bugfixwith unstackable items, ta4_doser bugfixes, waterpump bugfix

This commit is contained in:
Joachim Stolberg 2020-04-07 22:19:36 +02:00
parent f956c19988
commit 5146d50d4b
7 changed files with 71 additions and 19 deletions

View File

@ -122,7 +122,6 @@ end
local function keep_running(pos, elapsed)
print("autocrafter keep_running")
local nvm = techage.get_nvm(pos)
local crd = CRD(pos)
local inv = M(pos):get_inventory()

View File

@ -239,6 +239,18 @@ minetest.register_craft({
recipe = {"default:chest", "techage:tubeS", "techage:iron_ingot"}
})
minetest.register_craft({
type = "shapeless",
output = "techage:chest_ta2",
recipe = {"default:chest_locked", "techage:tubeS", "techage:iron_ingot"}
})
minetest.register_craft({
type = "shapeless",
output = "techage:chest_ta2",
recipe = {"protector:chest", "techage:tubeS", "techage:iron_ingot"}
})
minetest.register_craft({
type = "shapeless",
output = "techage:chest_ta3",

View File

@ -95,6 +95,15 @@ local function sort_in(inv, nvm, stack)
return false
end
local function max_stack_size(item_name)
local ndef = minetest.registered_nodes[item_name] or minetest.registered_items[item_name] or minetest.registered_craftitems[item_name]
if ndef then
return ndef.stack_max
end
return 0
end
local function get_item(inv, nvm, item_name, count)
local stack = {count = 0}
if not inv:is_empty("main") then
@ -109,7 +118,7 @@ local function get_item(inv, nvm, item_name, count)
end
for _,item in ipairs(nvm.inventory or {}) do
if (item_name == nil and stack.name == nil) or item.name == item_name then
local num = math.min(item.count, count - stack.count)
local num = math.min(item.count, count - stack.count, max_stack_size(item.name))
item.count = item.count - num
stack.count = stack.count + num
if item.name ~= "" then
@ -132,7 +141,7 @@ local function formspec_container(x, y, nvm, inv)
local tbl = {"container["..x..","..y.."]"}
for i = 1,8 do
local xpos = i - 1
tbl[#tbl+1] = "box["..xpos..",0;0.8,0.9;#808080]"
tbl[#tbl+1] = "box["..(xpos - 0.03)..",0;0.86,0.9;#808080]"
local stack = get_stack(nvm, i)
if stack.name ~= "" then
local itemname = stack.name.." "..stack.count
@ -212,7 +221,7 @@ local function move_from_nvm_to_inv(pos, idx)
local nvm_stack = get_stack(nvm, idx)
if nvm_stack.count > 0 and inv_stack:get_count() == 0 then
local count = math.min(nvm_stack.count, 99)
local count = math.min(nvm_stack.count, max_stack_size(nvm_stack.name))
nvm_stack.count = nvm_stack.count - count
inv:set_stack("main", idx, {name = nvm_stack.name, count = count})
if nvm_stack.count == 0 then

View File

@ -194,21 +194,36 @@ function techage.is_ocean(pos)
return true
end
local function tooltip(name)
name = string.split(name, " ")[1]
local ndef = minetest.registered_nodes[name] or minetest.registered_items[name] or minetest.registered_craftitems[name]
if ndef and ndef.description then
return minetest.formspec_escape(ndef.description)
end
return ""
end
function techage.item_image(x, y, itemname)
local name, size = unpack(string.split(itemname, " "))
local label = ""
local tooltip = ""
local ndef = minetest.registered_nodes[name] or minetest.registered_items[name] or minetest.registered_craftitems[name]
if ndef and ndef.description then
local text = minetest.formspec_escape(ndef.description)
tooltip = "tooltip["..x..","..y..";1,1;"..text..";#0C3D32;#FFFFFF]"
end
if ndef and ndef.stack_max == 1 then
size = tonumber(size)
local offs = 0
if size < 10 then
offs = 0.65
elseif size < 100 then
offs = 0.5
elseif size < 1000 then
offs = 0.35
else
offs = 0.2
end
label = "label["..(x + offs)..","..(y + 0.45)..";"..tostring(size).."]"
end
return "box["..x..","..y..";0.85,0.9;#808080]"..
"item_image["..x..","..y..";1,1;"..itemname.."]"..
"tooltip["..x..","..y..";1,1;"..tooltip(itemname)..";#0C3D32;#FFFFFF]"
tooltip..
label
end
function techage.mydump(o, indent, nested, level)

View File

@ -81,6 +81,21 @@ local function del_liquids(pos)
Liquids[hash] = nil
end
-- if liquids are missing, update the cached liquid table
local function reload_liquids(pos)
local hash = minetest.hash_node_position(pos)
-- determine the available input liquids
local tbl = {}
for outdir = 1,4 do
local name, num = liquid.peek(pos, outdir)
if name then
tbl[name] = outdir
end
end
Liquids[hash] = tbl
return Liquids[hash]
end
local function reactor_cmnd(pos, cmnd, payload)
return techage.transfer(
pos,
@ -134,6 +149,7 @@ local function dosing(pos, nvm, elapsed)
if not nvm.techage_countdown or nvm.techage_countdown < 3 then
reactor_cmnd(pos, "stop")
State:nopower(pos, nvm, S("reactor has no power"))
return
end
State:idle(pos, nvm)
return
@ -157,7 +173,7 @@ local function dosing(pos, nvm, elapsed)
local starter = get_starter_name(pos)
for _,item in pairs(recipe.input) do
if item.name ~= "" then
local outdir = liquids[item.name]
local outdir = liquids[item.name] or reload_liquids(pos)[item.name]
if not outdir then
State:standby(pos, nvm)
reactor_cmnd(pos, "stop")
@ -286,7 +302,7 @@ minetest.register_node("techage:ta4_doser_on", {
},
tubelib2_on_update2 = function(pos, dir, tlib2, node)
liquid.update_network(pos)
liquid.update_network(pos, dir)
del_liquids(pos)
end,
on_receive_fields = on_receive_fields,

View File

@ -158,6 +158,7 @@ techage.register_node({"techage:ta4_reactor_stand"}, {
elseif topic == "stop" then
nvm.has_power = false
power.consumer_stop(pos, Cable)
stop_sound(pos)
minetest.get_node_timer(pos):stop()
M(pos):set_string("infotext", S("off"))
return true

View File

@ -86,7 +86,7 @@ local function pumping(pos, nvm)
if not nvm.running then
State:nopower(pos, nvm)
else
local leftover = liquid.put(pos, 6, "default:water_source", 1)
local leftover = liquid.put(pos, 6, "techage:water", 1)
if leftover and leftover > 0 then
State:blocked(pos, nvm)
return