diff options
author | stujones11 <stujones111@gmail.com> | 2016-01-23 17:10:53 +0000 |
---|---|---|
committer | stujones11 <stujones111@gmail.com> | 2016-01-23 17:10:53 +0000 |
commit | a23e20f05301849a7902c6b11c55e2a581b0831b (patch) | |
tree | 0f0c5cb5a6287b048b6a4943877f7a4f46ebb350 /railcart/railcart.lua | |
parent | 0e9a29ddfc38ce8c198be21bd9597a7d5f03a9d4 (diff) |
Don't assume table index is equal to cart id
Diffstat (limited to 'railcart/railcart.lua')
-rw-r--r-- | railcart/railcart.lua | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/railcart/railcart.lua b/railcart/railcart.lua index 655fffe..c80b507 100644 --- a/railcart/railcart.lua +++ b/railcart/railcart.lua @@ -52,7 +52,7 @@ function railcart.cart:on_step(dtime) return end self.timer = RAILCART_OBJECT_UPDATE_TIME - local entity = railcart:get_cart_ref(self.id) + local entity = railcart:get_cart_entity(self.id) if entity.object then return end @@ -116,7 +116,27 @@ function railcart:create_detached_inventory(id) return inv end -function railcart:get_cart_ref(id) +function railcart:remove_cart(id) + for i, cart in pairs(railcart.allcarts) do + if cart.id == id then + railcart.allcarts[i] = nil + railcart:save() + break + end + end +end + +function railcart:get_new_id() + local id = 0 + for _, cart in pairs(railcart.allcarts) do + if cart.id > id then + id = cart.id + end + end + return id + 1 +end + +function railcart:get_cart_entity(id) local cart_ref = {} for _, ref in pairs(minetest.luaentities) do if ref.cart then |