Compare commits

...

1 Commits

Author SHA1 Message Date
kno10 6e1e84c33b try to fix chest minecarts, at least for 5.9 2024-10-27 15:45:55 +01:00
2 changed files with 20 additions and 7 deletions

View File

@ -36,7 +36,11 @@ else
end
end
tsm_railcorridors.carts = { "mcl_minecarts:chest_minecart" }
tsm_railcorridors.carts = {
"mcl_minecarts:minecart", "mcl_minecarts:minecart",
"mcl_minecarts:chest_minecart", "mcl_minecarts:chest_minecart",
"mcl_minecarts:tnt_minecart"
}
-- This is called after a spawner has been placed by the game.
-- Use this to properly set up the metadata and stuff.
@ -54,9 +58,11 @@ end
function tsm_railcorridors.on_construct_cart(_, cart, pr_carts)
local l = cart:get_luaentity()
local inv = mcl_entity_invs.load_inv(l,27)
local items = tsm_railcorridors.get_treasures(pr_carts)
mcl_loot.fill_inventory(inv, "main", items, pr_carts)
mcl_entity_invs.save_inv(l)
if inv then -- otherwise probably not a chest minecart
local items = tsm_railcorridors.get_treasures(pr_carts)
mcl_loot.fill_inventory(inv, "main", items, pr_carts)
mcl_entity_invs.save_inv(l)
end
end
-- Fallback function. Returns a random treasure. This function is called for chests

View File

@ -397,7 +397,9 @@ end
-- This is a workaround thanks to the fact that minetest.add_entity is unreliable as fuck
-- See: https://github.com/minetest/minetest/issues/4759
-- FIXME: Kill this horrible hack with fire as soon you can.
local function RecheckCartHack(params)
local RecheckCartHack = nil
if not minetest.features.random_state_restore then -- proxy for minetest > 5.9.0, this feature will not be removed
RecheckCartHack = function(params)
local pos = params[1]
local cart_id = params[2]
-- Find cart
@ -412,6 +414,7 @@ local function RecheckCartHack(params)
end
minetest.log("info", "[tsm_railcorridors] Cart spawn FAILED: "..minetest.pos_to_string(pos))
end
end
-- Try to place a cobweb.
-- pos: Position of cobweb
@ -935,13 +938,17 @@ local function spawn_carts()
-- See <https://github.com/minetest/minetest/issues/4759>
local cart_id = tsm_railcorridors.carts[cart_type]
minetest.log("info", "[tsm_railcorridors] Cart spawn attempt: "..minetest.pos_to_string(cpos))
minetest.add_entity(cpos, cart_id)
local obj = minetest.add_entity(cpos, cart_id)
-- This checks if the cart is actually spawned, it's a giant hack!
-- Note that the callback function is also called there.
-- TODO: Move callback function to this position when the
-- minetest.add_entity bug has been fixed (supposedly in 5.9.0?)
minetest.after(3, RecheckCartHack, {cpos, cart_id})
if RecheckCartHack then
minetest.after(3, RecheckCartHack, {cpos, cart_id})
else
tsm_railcorridors.on_construct_cart(cpos, obj, pr_carts)
end
end
end
carts_table = {}