summaryrefslogtreecommitdiff
path: root/railcart/init.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/init.lua
parent620ca56b952037860b750e87e930754fd1d7b002 (diff)
Give carts a chest-like inventory
Diffstat (limited to 'railcart/init.lua')
-rw-r--r--railcart/init.lua26
1 files changed, 25 insertions, 1 deletions
diff --git a/railcart/init.lua b/railcart/init.lua
index c18bc82..c637e3f 100644
--- a/railcart/init.lua
+++ b/railcart/init.lua
@@ -9,7 +9,14 @@ if input then
if data then
local carts = minetest.deserialize(data) or {}
for id, ref in pairs(carts) do
- railcart.allcarts[id] = railcart.cart:new(ref)
+ local cart = railcart.cart:new(ref)
+ local inv = railcart:create_detached_inventory(cart.id)
+ ref.inv = ref.inv or {}
+ for i, stack in pairs(ref.inv) do
+ inv:set_stack("main", i, stack)
+ end
+ cart.inv = inv
+ railcart.allcarts[id] = cart
end
end
input = nil
@@ -92,6 +99,22 @@ minetest.register_entity("railcart:cart_entity", {
if not is_valid_player(clicker) then
return
end
+ if clicker:get_player_control().sneak then
+ local name = clicker:get_player_name()
+ local cart = self.cart or {}
+ if cart.id and name then
+ local formspec = "size[8,9]"..
+ default.gui_bg..default.gui_bg_img..default.gui_slots..
+ "list[detached:railcart_"..cart.id..";main;0,0.3;8,4;]"..
+ "list[current_player;main;0,4.85;8,1;]"..
+ "list[current_player;main;0,6.08;8,3;8]"..
+ "listring[detached:railcart_"..cart.id..";main]"..
+ "listring[current_player;main]"..
+ default.get_hotbar_bg(0,4.85)
+ minetest.show_formspec(name, "inventory", formspec)
+ end
+ return
+ end
if self.driver and clicker == self.driver then
self.driver = nil
clicker:set_detach()
@@ -138,6 +161,7 @@ minetest.register_craftitem("railcart:cart", {
end
local cart = railcart.cart:new()
cart.id = #railcart.allcarts + 1
+ cart.inv = railcart:create_detached_inventory(cart.id)
cart.pos = pos
cart.prev = vector.new(pos)
cart.accel = railtrack:get_acceleration(pos)