ta4_chest bugfix

This commit is contained in:
Joachim Stolberg 2020-04-12 14:45:58 +02:00
parent 6c0737be1b
commit f3d8002832
6 changed files with 72 additions and 30 deletions

View File

@ -74,28 +74,6 @@ local function inv_state(nvm)
return "loaded"
end
-- Sort the items into the nvm inventory
-- If the nvm inventry is full, the items are stored in the main inventory
-- If the main inventory is also full, false is returned
local function sort_in(inv, nvm, stack)
if inv:is_empty("main") then -- the main inv is used for the case the nvm-inventory is full
for _,item in ipairs(nvm.inventory or {}) do
if item.name and (item.name == "" or item.name == stack:get_name()) then
local count = math.min(stack:get_count(), STACK_SIZE - item.count)
item.count = item.count + count
item.name = stack:get_name()
stack:set_count(stack:get_count() - count)
if stack:get_count() == 0 then
return true
end
end
end
inv:add_item("main", stack)
return true
end
return false
end
local function max_stacksize(item_name)
local ndef = minetest.registered_nodes[item_name] or minetest.registered_items[item_name] or minetest.registered_craftitems[item_name]
if ndef then
@ -112,6 +90,28 @@ local function get_stacksize(pos)
return size
end
-- Sort the items into the nvm inventory
-- If the nvm inventry is full, the items are stored in the main inventory
-- If the main inventory is also full, false is returned
local function sort_in(pos, inv, nvm, stack)
if inv:is_empty("main") then -- the main inv is used for the case the nvm-inventory is full
for _,item in ipairs(nvm.inventory or {}) do
if item.name and (item.name == "" or item.name == stack:get_name()) then
local count = math.min(stack:get_count(), get_stacksize(pos) - item.count)
item.count = item.count + count
item.name = stack:get_name()
stack:set_count(stack:get_count() - count)
if stack:get_count() == 0 then
return true
end
end
end
inv:add_item("main", stack)
return true
end
return false
end
local function get_item(inv, nvm, item_name, count)
local stack = {count = 0}
if not inv:is_empty("main") then
@ -425,7 +425,7 @@ techage.register_node({"techage:ta4_chest"}, {
on_push_item = function(pos, in_dir, stack)
local nvm = techage.get_nvm(pos)
local inv = M(pos):get_inventory()
local res = sort_in(inv, nvm, stack)
local res = sort_in(pos, inv, nvm, stack)
if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", formspec(pos))
end
@ -434,7 +434,7 @@ techage.register_node({"techage:ta4_chest"}, {
on_unpull_item = function(pos, in_dir, stack)
local nvm = techage.get_nvm(pos)
local inv = M(pos):get_inventory()
local res = sort_in(inv, nvm, stack)
local res = sort_in(pos, inv, nvm, stack)
if techage.is_activeformspec(pos) then
M(pos):set_string("formspec", formspec(pos))
end

View File

@ -31,9 +31,9 @@ local CAPACITY = 200
local function formspec(self, pos, nvm)
local amount = (nvm.liquid and nvm.liquid.amount) or 0
local lqd_name = (nvm.liquid and nvm.liquid.name) or "techage:liquid"
local arrow = "image[3,1;1,1;techage_form_arrow_bg.png^[transformR270]"
local arrow = "image[3,1.5;1,1;techage_form_arrow_bg.png^[transformR270]"
if nvm.running then
arrow = "image[3,1;1,1;techage_form_arrow_fg.png^[transformR270]"
arrow = "image[3,1.5;1,1;techage_form_arrow_fg.png^[transformR270]"
end
if amount > 0 then
lqd_name = lqd_name.." "..amount
@ -45,7 +45,7 @@ local function formspec(self, pos, nvm)
"box[0,-0.1;5.8,0.5;#c6e8ff]"..
"label[2.5,-0.1;"..minetest.colorize( "#000000", S("Electrolyzer")).."]"..
techage.power.formspec_label_bar(0.1, 0.8, S("Electricity"), PWR_NEEDED, nvm.taken)..
"image[3,1.5;1,1;techage_form_arrow_fg.png^[transformR270]"..
arrow..
"image_button[3,2.5;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[3,2.5;1,1;"..self:get_state_tooltip(nvm).."]"..
techage.item_image(4.5,2, lqd_name)

View File

@ -31,9 +31,9 @@ local CAPACITY = 100
local function formspec(self, pos, nvm)
local amount = (nvm.liquid and nvm.liquid.amount) or 0
local lqd_name = (nvm.liquid and nvm.liquid.name) or "techage:liquid"
local arrow = "image[3,1;1,1;techage_form_arrow_bg.png^[transformR270]"
local arrow = "image[2,1.5;1,1;techage_form_arrow_bg.png^[transformR270]"
if nvm.running then
arrow = "image[3,1;1,1;techage_form_arrow_fg.png^[transformR270]"
arrow = "image[2,1.5;1,1;techage_form_arrow_fg.png^[transformR270]"
end
if amount > 0 then
lqd_name = lqd_name.." "..amount
@ -45,7 +45,7 @@ local function formspec(self, pos, nvm)
"box[0,-0.1;5.8,0.5;#c6e8ff]"..
"label[2.5,-0.1;"..minetest.colorize( "#000000", S("Fuel Cell")).."]"..
techage.item_image(0.5,2, lqd_name)..
"image[2,1.5;1,1;techage_form_arrow_fg.png^[transformR270]"..
arrow..
"image_button[2,2.5;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
"tooltip[2,2.5;1,1;"..self:get_state_tooltip(nvm).."]"..
techage.power.formspec_label_bar(3.5, 0.8, S("Electricity"), PWR_CAPA, nvm.given)

View File

@ -136,6 +136,7 @@ else
-- Tools
dofile(MP.."/tools/trowel.lua")
dofile(MP.."/tools/repairkit.lua")
dofile(MP.."/tools/pipe_wrench.lua")
dofile(MP.."/basic_machines/blackhole.lua")
dofile(MP.."/basic_machines/forceload.lua")

Binary file not shown.

After

Width:  |  Height:  |  Size: 272 B

41
tools/pipe_wrench.lua Normal file
View File

@ -0,0 +1,41 @@
local S = techage.S
local function remove_pipe(itemstack, user, pointed_thing)
local pos = pointed_thing.under
if pos and user then
if minetest.is_protected(pos, user:get_player_name()) then
return itemstack
end
end
if(pos ~= nil) then
local node = minetest.get_node(pos)
if(node.name == "techage:oil_drillbit2") then
minetest.set_node(pos, {name = "air"})
itemstack:add_wear(65636/200)
return itemstack
end -- if(node.name
end -- if(pos ~= nil)
end -- remove_pipe
minetest.register_tool("techage:ta3_pipe_wrench", {
description = S("TA3 Pipe Wrench"),
inventory_image = "techage_pipe_wrench.png",
wield_image = "techage_pipe_wrench.png",
groups = {cracky=1},
on_use = remove_pipe,
stack_max = 1,
})
minetest.register_craft({
output = "techage:ta3_pipe_wrench",
recipe = {
{"hyperloop:hypersteel_ingot", "hyperloop:hypersteel_ingot", ""},
{"dye:red", "default:steel_ingot", "dye:red"},
{"default:steel_ingot", "", "default:steel_ingot"},
},
})