Adapt to minecart v2.00

This commit is contained in:
Joachim Stolberg 2021-04-22 17:32:02 +02:00
parent d89b83ce18
commit 8f73850f40
6 changed files with 65 additions and 80 deletions

View File

@ -77,6 +77,32 @@ techage.register_node({"default:chest_locked", "default:chest_locked_open"}, {
end, end,
}) })
techage.register_node({"shop:shop"}, {
on_inv_request = function(pos, in_dir, access_type)
local meta = minetest.get_meta(pos)
if is_owner(pos, meta) then
return meta:get_inventory(), "main"
end
end,
on_pull_item = function(pos, in_dir, num)
local meta = minetest.get_meta(pos)
if is_owner(pos, meta) then
local inv = meta:get_inventory()
return techage.get_items(pos, inv, "register", num)
end
end,
on_push_item = function(pos, in_dir, stack)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return techage.put_items(inv, "stock", stack)
end,
on_unpull_item = function(pos, in_dir, stack)
local meta = minetest.get_meta(pos)
local inv = meta:get_inventory()
return techage.put_items(inv, "register", stack)
end,
})
techage.register_node({"default:furnace", "default:furnace_active"}, { techage.register_node({"default:furnace", "default:furnace_active"}, {
on_pull_item = function(pos, in_dir, num) on_pull_item = function(pos, in_dir, num)
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)

View File

@ -26,7 +26,7 @@ local techage_use_sqlite = minetest.settings:get_bool('techage_use_sqlite', fals
local string_split = string.split local string_split = string.split
local NodeDef = techage.NodeDef local NodeDef = techage.NodeDef
local Tube = techage.Tube local Tube = techage.Tube
local check_cart_for_loading = minecart.check_cart_for_loading local is_cart_available = minecart.is_cart_available
------------------------------------------------------------------- -------------------------------------------------------------------
-- Database -- Database
@ -385,7 +385,7 @@ function techage.push_items(pos, out_dir, stack, idx)
local npos, in_dir, name = get_dest_node(pos, out_dir) local npos, in_dir, name = get_dest_node(pos, out_dir)
if npos and NodeDef[name] and NodeDef[name].on_push_item then if npos and NodeDef[name] and NodeDef[name].on_push_item then
return NodeDef[name].on_push_item(npos, in_dir, stack, idx) return NodeDef[name].on_push_item(npos, in_dir, stack, idx)
elseif is_air_like(name) or check_cart_for_loading(npos) then elseif is_air_like(name) or is_cart_available(npos) then
minetest.add_item(npos, stack) minetest.add_item(npos, stack)
return true return true
end end

View File

@ -18,9 +18,6 @@ local S = techage.S
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
local S2P = minetest.string_to_pos local S2P = minetest.string_to_pos
local MP = minetest.get_modpath("minecart") local MP = minetest.get_modpath("minecart")
local cart = dofile(MP.."/cart_lib1.lua")
cart:init(true)
local function formspec() local function formspec()
return "size[8,6]".. return "size[8,6]"..
@ -33,16 +30,6 @@ local function formspec()
"listring[current_player;main]" "listring[current_player;main]"
end end
local function can_dig(pos, player)
local owner = M(pos):get_string("owner")
if owner ~= "" and (owner ~= player:get_player_name() or
not minetest.check_player_privs(player:get_player_name(), "minecart")) then
return false
end
local inv = minetest.get_meta(pos):get_inventory()
return inv:is_empty("main")
end
local function allow_metadata_inventory_put(pos, listname, index, stack, player) local function allow_metadata_inventory_put(pos, listname, index, stack, player)
local owner = M(pos):get_string("owner") local owner = M(pos):get_string("owner")
if owner ~= "" and owner ~= player:get_player_name() then if owner ~= "" and owner ~= player:get_player_name() then
@ -85,27 +72,24 @@ minetest.register_node("techage:chest_cart", {
is_ground_content = false, is_ground_content = false,
groups = {cracky = 2, crumbly = 2, choppy = 2}, groups = {cracky = 2, crumbly = 2, choppy = 2},
node_placement_prediction = "", node_placement_prediction = "",
diggable = false,
can_dig = can_dig, on_place = minecart.on_nodecart_place,
on_punch = minecart.on_nodecart_punch,
allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_take = allow_metadata_inventory_take, allow_metadata_inventory_take = allow_metadata_inventory_take,
after_place_node = function(pos) after_place_node = function(pos, placer)
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
inv:set_size('main', 4) inv:set_size('main', 4)
if placer and placer:is_player() then
minecart.show_formspec(pos, placer)
else
M(pos):set_string("formspec", formspec()) M(pos):set_string("formspec", formspec())
end, end
on_place = function(itemstack, placer, pointed_thing)
return cart.add_cart(itemstack, placer, pointed_thing, "techage:chest_cart")
end,
on_punch = function(pos, node, puncher, pointed_thing)
cart.node_on_punch(pos, node, puncher, pointed_thing, "techage:chest_cart_entity")
end, end,
set_cargo = function(pos, data) set_cargo = function(pos, data)
--print("set_cargo", P2S(pos), #data)
local inv = M(pos):get_inventory() local inv = M(pos):get_inventory()
for idx, stack in ipairs(data) do for idx, stack in ipairs(data) do
inv:set_stack("main", idx, stack) inv:set_stack("main", idx, stack)
@ -119,17 +103,16 @@ minetest.register_node("techage:chest_cart", {
local stack = inv:get_stack("main", idx) local stack = inv:get_stack("main", idx)
data[idx] = {name = stack:get_name(), count = stack:get_count()} data[idx] = {name = stack:get_name(), count = stack:get_count()}
end end
--print("get_cargo", P2S(pos), #data)
return data return data
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger) has_cargo = function(pos)
local name = oldmetadata.fields.removed_rail or "carts:rail" local inv = minetest.get_meta(pos):get_inventory()
minetest.add_node(pos, {name = name}) return not inv:is_empty("main")
end, end
}) })
minecart.register_cart_entity("techage:chest_cart_entity", "techage:chest_cart", { minecart.register_cart_entity("techage:chest_cart_entity", "techage:chest_cart", "chest", {
initial_properties = { initial_properties = {
physical = false, physical = false,
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
@ -138,9 +121,6 @@ minecart.register_cart_entity("techage:chest_cart_entity", "techage:chest_cart",
visual_size = {x=0.66, y=0.66, z=0.66}, visual_size = {x=0.66, y=0.66, z=0.66},
static_save = false, static_save = false,
}, },
on_activate = cart.on_activate,
on_punch = cart.on_punch,
on_step = cart.on_step,
}) })
techage.register_node({"techage:chest_cart"}, { techage.register_node({"techage:chest_cart"}, {

View File

@ -20,18 +20,21 @@ local S2P = minetest.string_to_pos
local Pipe = techage.LiquidPipe local Pipe = techage.LiquidPipe
local liquid = techage.liquid local liquid = techage.liquid
local MP = minetest.get_modpath("minecart") local MP = minetest.get_modpath("minecart")
local cart = dofile(MP.."/cart_lib1.lua")
cart:init(true)
local CAPACITY = 100 local CAPACITY = 100
local function on_rightclick(pos, node, clicker) local function on_rightclick(pos, node, clicker)
if clicker and clicker:is_player() then
if M(pos):get_int("userID") == 0 then
minecart.show_formspec(pos, clicker)
else
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
techage.set_activeformspec(pos, clicker) techage.set_activeformspec(pos, clicker)
M(pos):set_string("formspec", liquid.formspec(pos, nvm)) M(pos):set_string("formspec", liquid.formspec(pos, nvm))
minetest.get_node_timer(pos):start(2) minetest.get_node_timer(pos):start(2)
end end
end
end
local function node_timer(pos, elapsed) local function node_timer(pos, elapsed)
if techage.is_activeformspec(pos) then if techage.is_activeformspec(pos) then
@ -42,14 +45,6 @@ local function node_timer(pos, elapsed)
return false return false
end end
local function can_dig(pos, player)
local owner = M(pos):get_string("owner")
if owner ~= "" and owner ~= player:get_player_name() then
return false
end
return liquid.is_empty(pos)
end
local function take_liquid(pos, indir, name, amount) local function take_liquid(pos, indir, name, amount)
amount, name = liquid.srv_take(pos, indir, name, amount) amount, name = liquid.srv_take(pos, indir, name, amount)
if techage.is_activeformspec(pos) then if techage.is_activeformspec(pos) then
@ -116,30 +111,17 @@ minetest.register_node("techage:tank_cart", {
is_ground_content = false, is_ground_content = false,
groups = {cracky = 2, crumbly = 2, choppy = 2}, groups = {cracky = 2, crumbly = 2, choppy = 2},
node_placement_prediction = "", node_placement_prediction = "",
diggable = false,
on_place = minecart.on_nodecart_place,
on_punch = minecart.on_nodecart_punch,
after_place_node = function(pos) after_place_node = function(pos)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
nvm.liquid = {} nvm.liquid = nvm.liquid or {}
M(pos):set_string("formspec", liquid.formspec(pos, nvm))
end,
on_place = function(itemstack, placer, pointed_thing)
return cart.add_cart(itemstack, placer, pointed_thing, "techage:tank_cart")
end,
on_punch = function(pos, node, puncher, pointed_thing)
--print("on_punch")
local wielded_item = puncher:get_wielded_item():get_name()
if techage.liquid.is_container_empty(wielded_item) then
liquid.on_punch(pos, node, puncher, pointed_thing)
else
cart.node_on_punch(pos, node, puncher, pointed_thing, "techage:tank_cart_entity")
end
end, end,
set_cargo = function(pos, data) set_cargo = function(pos, data)
--print("set_cargo", P2S(pos), #data)
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
nvm.liquid = data nvm.liquid = data
end, end,
@ -148,16 +130,15 @@ minetest.register_node("techage:tank_cart", {
local nvm = techage.get_nvm(pos) local nvm = techage.get_nvm(pos)
local data = nvm.liquid local data = nvm.liquid
nvm.liquid = {} nvm.liquid = {}
--print("get_cargo", P2S(pos), #data)
return data return data
end, end,
on_timer = node_timer,
after_dig_node = function(pos, oldnode, oldmetadata, digger) has_cargo = function(pos)
local name = oldmetadata.fields.removed_rail or "carts:rail" return not liquid.is_empty(pos)
minetest.add_node(pos, {name = name})
end, end,
on_timer = node_timer,
liquid = { liquid = {
capa = CAPACITY, capa = CAPACITY,
peek = liquid.srv_peek, peek = liquid.srv_peek,
@ -167,7 +148,6 @@ minetest.register_node("techage:tank_cart", {
}, },
networks = networks_def, networks = networks_def,
on_rightclick = on_rightclick, on_rightclick = on_rightclick,
can_dig = can_dig,
}) })
techage.register_node({"techage:tank_cart"}, liquid.recv_message) techage.register_node({"techage:tank_cart"}, liquid.recv_message)
@ -175,7 +155,7 @@ techage.register_node({"techage:tank_cart"}, liquid.recv_message)
Pipe:add_secondary_node_names({"techage:tank_cart"}) Pipe:add_secondary_node_names({"techage:tank_cart"})
minecart.register_cart_entity("techage:tank_cart_entity", "techage:tank_cart", { minecart.register_cart_entity("techage:tank_cart_entity", "techage:tank_cart", "tank", {
initial_properties = { initial_properties = {
physical = false, physical = false,
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}, collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
@ -184,9 +164,7 @@ minecart.register_cart_entity("techage:tank_cart_entity", "techage:tank_cart", {
visual_size = {x=0.66, y=0.66, z=0.66}, visual_size = {x=0.66, y=0.66, z=0.66},
static_save = false, static_save = false,
}, },
on_activate = cart.on_activate, only_dig_if_empty = 1,
on_punch = cart.on_punch,
on_step = cart.on_step,
}) })
minetest.register_craft({ minetest.register_craft({

View File

@ -66,6 +66,7 @@ function techage.display.on_timer(pos)
-- check if display is loaded and a player in front of the display -- check if display is loaded and a player in front of the display
if node.name ~= "ignore" then if node.name ~= "ignore" then
local dir = minetest.facedir_to_dir(Param2ToFacedir[node.param2 % 6]) local dir = minetest.facedir_to_dir(Param2ToFacedir[node.param2 % 6])
dir.y = 0
local pos2 = vector.add(pos, vector.multiply(dir, RADIUS)) local pos2 = vector.add(pos, vector.multiply(dir, RADIUS))
for _, obj in pairs(minetest.get_objects_inside_radius(pos2, RADIUS)) do for _, obj in pairs(minetest.get_objects_inside_radius(pos2, RADIUS)) do
if obj:is_player() then if obj:is_player() then

View File

@ -32,7 +32,7 @@ local function switch_on(pos)
end end
local function node_timer(pos) local function node_timer(pos)
if minecart.check_cart_for_pushing(pos, nil, 1.5) then if minecart.is_cart_available(pos, nil, 1.5) then
switch_on(pos) switch_on(pos)
else else
switch_off(pos) switch_off(pos)