summaryrefslogtreecommitdiff
path: root/railcart/railcart.lua
diff options
context:
space:
mode:
authorstujones11 <stujones111@gmail.com>2016-01-16 20:58:39 +0000
committerstujones11 <stujones111@gmail.com>2016-01-16 23:10:41 +0000
commit6f88d59d9d6ddac909df0000db8589c4f1b4ceca (patch)
tree9f28641173e3ac413efacbd79681ad345b7500d1 /railcart/railcart.lua
parent620ca56b952037860b750e87e930754fd1d7b002 (diff)
Give carts a chest-like inventory
Diffstat (limited to 'railcart/railcart.lua')
-rw-r--r--railcart/railcart.lua31
1 files changed, 31 insertions, 0 deletions
diff --git a/railcart/railcart.lua b/railcart/railcart.lua
index 68efda5..68174b6 100644
--- a/railcart/railcart.lua
+++ b/railcart/railcart.lua
@@ -19,6 +19,7 @@ railcart.cart = {
target = nil,
prev = nil,
accel = nil,
+ inv = nil,
dir = {x=0, y=0, z=0},
vel = {x=0, y=0, z=0},
acc = {x=0, y=0, z=0},
@@ -75,6 +76,14 @@ function railcart:save()
for k, v in pairs(cart) do
ref[k] = v
end
+ local inv = {}
+ if ref.inv then
+ local list = ref.inv:get_list("main")
+ for i, stack in ipairs(list) do
+ inv[i] = stack:to_string()
+ end
+ end
+ ref.inv = inv
ref.entity = nil
table.insert(carts, ref)
end
@@ -85,6 +94,28 @@ function railcart:save()
end
end
+function railcart:create_detached_inventory(id)
+ local inv = minetest.create_detached_inventory("railcart_"..tostring(id), {
+ on_put = function(inv, listname, index, stack, player)
+ railcart:save()
+ end,
+ on_take = function(inv, listname, index, stack, player)
+ railcart:save()
+ end,
+ allow_put = function(inv, listname, index, stack, player)
+ return 1
+ end,
+ allow_take = function(inv, listname, index, stack, player)
+ return stack:get_count()
+ end,
+ allow_move = function(inv, from_list, from_index, to_list, to_index, count, player)
+ return count
+ end,
+ })
+ inv:set_size("main", 32)
+ return inv
+end
+
function railcart:get_cart_ref(id)
local cart_ref = {}
for _, ref in pairs(minetest.luaentities) do