Adapt to minecart v2.00
This commit is contained in:
parent
d89b83ce18
commit
8f73850f40
@ -77,6 +77,32 @@ techage.register_node({"default:chest_locked", "default:chest_locked_open"}, {
|
||||
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"}, {
|
||||
on_pull_item = function(pos, in_dir, num)
|
||||
local meta = minetest.get_meta(pos)
|
||||
|
@ -26,7 +26,7 @@ local techage_use_sqlite = minetest.settings:get_bool('techage_use_sqlite', fals
|
||||
local string_split = string.split
|
||||
local NodeDef = techage.NodeDef
|
||||
local Tube = techage.Tube
|
||||
local check_cart_for_loading = minecart.check_cart_for_loading
|
||||
local is_cart_available = minecart.is_cart_available
|
||||
|
||||
-------------------------------------------------------------------
|
||||
-- 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)
|
||||
if npos and NodeDef[name] and NodeDef[name].on_push_item then
|
||||
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)
|
||||
return true
|
||||
end
|
||||
|
@ -18,9 +18,6 @@ local S = techage.S
|
||||
local P2S = function(pos) if pos then return minetest.pos_to_string(pos) end end
|
||||
local S2P = minetest.string_to_pos
|
||||
local MP = minetest.get_modpath("minecart")
|
||||
local cart = dofile(MP.."/cart_lib1.lua")
|
||||
|
||||
cart:init(true)
|
||||
|
||||
local function formspec()
|
||||
return "size[8,6]"..
|
||||
@ -33,16 +30,6 @@ local function formspec()
|
||||
"listring[current_player;main]"
|
||||
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 owner = M(pos):get_string("owner")
|
||||
if owner ~= "" and owner ~= player:get_player_name() then
|
||||
@ -85,27 +72,24 @@ minetest.register_node("techage:chest_cart", {
|
||||
is_ground_content = false,
|
||||
groups = {cracky = 2, crumbly = 2, choppy = 2},
|
||||
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_take = allow_metadata_inventory_take,
|
||||
|
||||
after_place_node = function(pos)
|
||||
after_place_node = function(pos, placer)
|
||||
local inv = M(pos):get_inventory()
|
||||
inv:set_size('main', 4)
|
||||
M(pos):set_string("formspec", formspec())
|
||||
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")
|
||||
if placer and placer:is_player() then
|
||||
minecart.show_formspec(pos, placer)
|
||||
else
|
||||
M(pos):set_string("formspec", formspec())
|
||||
end
|
||||
end,
|
||||
|
||||
set_cargo = function(pos, data)
|
||||
--print("set_cargo", P2S(pos), #data)
|
||||
local inv = M(pos):get_inventory()
|
||||
for idx, stack in ipairs(data) do
|
||||
inv:set_stack("main", idx, stack)
|
||||
@ -119,17 +103,16 @@ minetest.register_node("techage:chest_cart", {
|
||||
local stack = inv:get_stack("main", idx)
|
||||
data[idx] = {name = stack:get_name(), count = stack:get_count()}
|
||||
end
|
||||
--print("get_cargo", P2S(pos), #data)
|
||||
return data
|
||||
end,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
local name = oldmetadata.fields.removed_rail or "carts:rail"
|
||||
minetest.add_node(pos, {name = name})
|
||||
end,
|
||||
has_cargo = function(pos)
|
||||
local inv = minetest.get_meta(pos):get_inventory()
|
||||
return not inv:is_empty("main")
|
||||
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 = {
|
||||
physical = false,
|
||||
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},
|
||||
static_save = false,
|
||||
},
|
||||
on_activate = cart.on_activate,
|
||||
on_punch = cart.on_punch,
|
||||
on_step = cart.on_step,
|
||||
})
|
||||
|
||||
techage.register_node({"techage:chest_cart"}, {
|
||||
|
@ -20,17 +20,20 @@ local S2P = minetest.string_to_pos
|
||||
local Pipe = techage.LiquidPipe
|
||||
local liquid = techage.liquid
|
||||
local MP = minetest.get_modpath("minecart")
|
||||
local cart = dofile(MP.."/cart_lib1.lua")
|
||||
|
||||
cart:init(true)
|
||||
|
||||
local CAPACITY = 100
|
||||
|
||||
local function on_rightclick(pos, node, clicker)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
techage.set_activeformspec(pos, clicker)
|
||||
M(pos):set_string("formspec", liquid.formspec(pos, nvm))
|
||||
minetest.get_node_timer(pos):start(2)
|
||||
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)
|
||||
techage.set_activeformspec(pos, clicker)
|
||||
M(pos):set_string("formspec", liquid.formspec(pos, nvm))
|
||||
minetest.get_node_timer(pos):start(2)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function node_timer(pos, elapsed)
|
||||
@ -42,14 +45,6 @@ local function node_timer(pos, elapsed)
|
||||
return false
|
||||
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)
|
||||
amount, name = liquid.srv_take(pos, indir, name, amount)
|
||||
if techage.is_activeformspec(pos) then
|
||||
@ -116,30 +111,17 @@ minetest.register_node("techage:tank_cart", {
|
||||
is_ground_content = false,
|
||||
groups = {cracky = 2, crumbly = 2, choppy = 2},
|
||||
node_placement_prediction = "",
|
||||
diggable = false,
|
||||
|
||||
on_place = minecart.on_nodecart_place,
|
||||
on_punch = minecart.on_nodecart_punch,
|
||||
|
||||
after_place_node = function(pos)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.liquid = {}
|
||||
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
|
||||
nvm.liquid = nvm.liquid or {}
|
||||
end,
|
||||
|
||||
set_cargo = function(pos, data)
|
||||
--print("set_cargo", P2S(pos), #data)
|
||||
local nvm = techage.get_nvm(pos)
|
||||
nvm.liquid = data
|
||||
end,
|
||||
@ -148,16 +130,15 @@ minetest.register_node("techage:tank_cart", {
|
||||
local nvm = techage.get_nvm(pos)
|
||||
local data = nvm.liquid
|
||||
nvm.liquid = {}
|
||||
--print("get_cargo", P2S(pos), #data)
|
||||
return data
|
||||
end,
|
||||
on_timer = node_timer,
|
||||
|
||||
after_dig_node = function(pos, oldnode, oldmetadata, digger)
|
||||
local name = oldmetadata.fields.removed_rail or "carts:rail"
|
||||
minetest.add_node(pos, {name = name})
|
||||
has_cargo = function(pos)
|
||||
return not liquid.is_empty(pos)
|
||||
end,
|
||||
|
||||
on_timer = node_timer,
|
||||
|
||||
liquid = {
|
||||
capa = CAPACITY,
|
||||
peek = liquid.srv_peek,
|
||||
@ -167,7 +148,6 @@ minetest.register_node("techage:tank_cart", {
|
||||
},
|
||||
networks = networks_def,
|
||||
on_rightclick = on_rightclick,
|
||||
can_dig = can_dig,
|
||||
})
|
||||
|
||||
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"})
|
||||
|
||||
|
||||
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 = {
|
||||
physical = false,
|
||||
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},
|
||||
static_save = false,
|
||||
},
|
||||
on_activate = cart.on_activate,
|
||||
on_punch = cart.on_punch,
|
||||
on_step = cart.on_step,
|
||||
only_dig_if_empty = 1,
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
|
@ -66,6 +66,7 @@ function techage.display.on_timer(pos)
|
||||
-- check if display is loaded and a player in front of the display
|
||||
if node.name ~= "ignore" then
|
||||
local dir = minetest.facedir_to_dir(Param2ToFacedir[node.param2 % 6])
|
||||
dir.y = 0
|
||||
local pos2 = vector.add(pos, vector.multiply(dir, RADIUS))
|
||||
for _, obj in pairs(minetest.get_objects_inside_radius(pos2, RADIUS)) do
|
||||
if obj:is_player() then
|
||||
|
@ -32,7 +32,7 @@ local function switch_on(pos)
|
||||
end
|
||||
|
||||
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)
|
||||
else
|
||||
switch_off(pos)
|
||||
|
Loading…
Reference in New Issue
Block a user