forked from VoxeLibre/VoxeLibre
Update mineshafts for new rail and minecarts, add loot to generated chest and hopper minecarts (and remove notes about a hack)
This commit is contained in:
parent
5349d2cd43
commit
ac8cdd5fe1
|
@ -309,6 +309,20 @@ function DEFAULT_CART_DEF:on_death(killer)
|
||||||
kill_cart(self._staticdata)
|
kill_cart(self._staticdata)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Create a minecart
|
||||||
|
function mod.create_minecart(entity_id, pos, dir)
|
||||||
|
-- Setup cart data
|
||||||
|
local uuid = mcl_util.gen_uuid()
|
||||||
|
data = make_staticdata( nil, pos, dir )
|
||||||
|
data.uuid = uuid
|
||||||
|
data.cart_type = entity_id
|
||||||
|
update_cart_data(data)
|
||||||
|
save_cart_data(uuid)
|
||||||
|
|
||||||
|
return uuid
|
||||||
|
end
|
||||||
|
local create_minecart = mod.create_minecart
|
||||||
|
|
||||||
-- Place a minecart at pointed_thing
|
-- Place a minecart at pointed_thing
|
||||||
function mod.place_minecart(itemstack, pointed_thing, placer)
|
function mod.place_minecart(itemstack, pointed_thing, placer)
|
||||||
if not pointed_thing.type == "node" then
|
if not pointed_thing.type == "node" then
|
||||||
|
@ -332,13 +346,7 @@ function mod.place_minecart(itemstack, pointed_thing, placer)
|
||||||
|
|
||||||
local entity_id = entity_mapping[itemstack:get_name()]
|
local entity_id = entity_mapping[itemstack:get_name()]
|
||||||
|
|
||||||
-- Setup cart data
|
local uuid = create_minecart(entity_id, railpos, cart_dir)
|
||||||
local uuid = mcl_util.gen_uuid()
|
|
||||||
data = make_staticdata( nil, railpos, cart_dir )
|
|
||||||
data.uuid = uuid
|
|
||||||
data.cart_type = entity_id
|
|
||||||
update_cart_data(data)
|
|
||||||
save_cart_data(uuid)
|
|
||||||
|
|
||||||
-- Create the entity with the staticdata already setup
|
-- Create the entity with the staticdata already setup
|
||||||
local sd = minetest.serialize({ uuid=uuid, seq=1 })
|
local sd = minetest.serialize({ uuid=uuid, seq=1 })
|
||||||
|
|
|
@ -3,17 +3,38 @@
|
||||||
|
|
||||||
-- Adapted for MineClone 2!
|
-- Adapted for MineClone 2!
|
||||||
|
|
||||||
|
-- Imports
|
||||||
|
local create_minecart = mcl_minecarts.create_minecart
|
||||||
|
local get_cart_data = mcl_minecarts.get_cart_data
|
||||||
|
local save_cart_data = mcl_minecarts.save_cart_data
|
||||||
|
|
||||||
-- Node names (Don't use aliases!)
|
-- Node names (Don't use aliases!)
|
||||||
tsm_railcorridors.nodes = {
|
tsm_railcorridors.nodes = {
|
||||||
dirt = "mcl_core:dirt",
|
dirt = "mcl_core:dirt",
|
||||||
chest = "mcl_chests:chest",
|
chest = "mcl_chests:chest",
|
||||||
rail = "mcl_minecarts:rail",
|
rail = "mcl_minecarts:rail_v2",
|
||||||
torch_floor = "mcl_torches:torch",
|
torch_floor = "mcl_torches:torch",
|
||||||
torch_wall = "mcl_torches:torch_wall",
|
torch_wall = "mcl_torches:torch_wall",
|
||||||
cobweb = "mcl_core:cobweb",
|
cobweb = "mcl_core:cobweb",
|
||||||
spawner = "mcl_mobspawners:spawner",
|
spawner = "mcl_mobspawners:spawner",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local update_rail_connections = mcl_minecarts.update_rail_connections
|
||||||
|
local rails_to_update = {}
|
||||||
|
tsm_railcorridors.on_place_node = {
|
||||||
|
[tsm_railcorridors.nodes.rail] = function(pos, node)
|
||||||
|
rails_to_update[#rails_to_update + 1] = pos
|
||||||
|
end,
|
||||||
|
}
|
||||||
|
tsm_railcorridors.on_start = function()
|
||||||
|
rails_to_update = {}
|
||||||
|
end
|
||||||
|
tsm_railcorridors.on_finish = function()
|
||||||
|
for _,pos in pairs(rails_to_update) do
|
||||||
|
update_rail_connections(pos, {legacy = true, ignore_neighbor_connections = true})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local mg_name = minetest.get_mapgen_setting("mg_name")
|
local mg_name = minetest.get_mapgen_setting("mg_name")
|
||||||
|
|
||||||
if mg_name == "v6" then
|
if mg_name == "v6" then
|
||||||
|
@ -36,7 +57,11 @@ else
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
tsm_railcorridors.carts = { "mcl_minecarts:chest_minecart" }
|
tsm_railcorridors.carts = { "mcl_minecarts:chest_minecart", "mcl_minecarts:hopper_minecart", "mcl_minecarts:minecart" }
|
||||||
|
local has_loot = {
|
||||||
|
["mcl_minecarts:chest_minecart"] = true,
|
||||||
|
["mcl_minecarts:hopper_minceart"] = true,
|
||||||
|
}
|
||||||
|
|
||||||
-- This is called after a spawner has been placed by the game.
|
-- This is called after a spawner has been placed by the game.
|
||||||
-- Use this to properly set up the metadata and stuff.
|
-- Use this to properly set up the metadata and stuff.
|
||||||
|
@ -46,17 +71,32 @@ function tsm_railcorridors.on_construct_spawner(pos)
|
||||||
mcl_mobspawners.setup_spawner(pos, "mobs_mc:cave_spider", 0, 7)
|
mcl_mobspawners.setup_spawner(pos, "mobs_mc:cave_spider", 0, 7)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- This is called after a cart has been placed by the game.
|
-- This is called after a cart has been placed by the game.
|
||||||
-- Use this to properly set up entity metadata and stuff.
|
-- Use this to properly set up entity metadata and stuff.
|
||||||
|
-- * entity_id - type of cart to create
|
||||||
-- * pos: Position of cart
|
-- * pos: Position of cart
|
||||||
-- * cart: Cart entity
|
-- * pr: pseudorandom
|
||||||
function tsm_railcorridors.on_construct_cart(_, cart, pr_carts)
|
function tsm_railcorridors.create_cart_staticdata(entity_id, pos, pr)
|
||||||
local l = cart:get_luaentity()
|
local uuid = create_minecart(entity_id, pos, vector.new(1,0,0))
|
||||||
local inv = mcl_entity_invs.load_inv(l,27)
|
|
||||||
local items = tsm_railcorridors.get_treasures(pr_carts)
|
-- Fill the cart with loot
|
||||||
mcl_loot.fill_inventory(inv, "main", items, pr_carts)
|
local cartdata = get_cart_data(uuid)
|
||||||
mcl_entity_invs.save_inv(l)
|
if cartdata and has_loot[entity_id] then
|
||||||
|
local items = tsm_railcorridors.get_treasures(pr)
|
||||||
|
|
||||||
|
-- TODO: determine if we should convert to use mcl_loot
|
||||||
|
-- mcl_loot.fill_inventory(inv, "main", items, pr_carts)
|
||||||
|
-- Convert from ItemStack to itemstrings
|
||||||
|
for k,item in pairs(items) do
|
||||||
|
items[k] = item:to_string()
|
||||||
|
end
|
||||||
|
cartdata.inventory = items
|
||||||
|
|
||||||
|
print("cartdata = "..dump(cartdata))
|
||||||
|
save_cart_data(uuid)
|
||||||
|
end
|
||||||
|
|
||||||
|
return minetest.serialize({ uuid=uuid, seq=1 })
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Fallback function. Returns a random treasure. This function is called for chests
|
-- Fallback function. Returns a random treasure. This function is called for chests
|
||||||
|
@ -104,11 +144,11 @@ function tsm_railcorridors.get_treasures(pr)
|
||||||
stacks_min = 3,
|
stacks_min = 3,
|
||||||
stacks_max = 3,
|
stacks_max = 3,
|
||||||
items = {
|
items = {
|
||||||
{ itemstring = "mcl_minecarts:rail", weight = 20, amount_min = 4, amount_max = 8 },
|
{ itemstring = "mcl_minecarts:rail_v2", weight = 20, amount_min = 4, amount_max = 8 },
|
||||||
{ itemstring = "mcl_torches:torch", weight = 15, amount_min = 1, amount_max = 16 },
|
{ itemstring = "mcl_torches:torch", weight = 15, amount_min = 1, amount_max = 16 },
|
||||||
{ itemstring = "mcl_minecarts:activator_rail", weight = 5, amount_min = 1, amount_max = 4 },
|
{ itemstring = "mcl_minecarts:activator_rail_v2", weight = 5, amount_min = 1, amount_max = 4 },
|
||||||
{ itemstring = "mcl_minecarts:detector_rail", weight = 5, amount_min = 1, amount_max = 4 },
|
{ itemstring = "mcl_minecarts:detector_rail_v2", weight = 5, amount_min = 1, amount_max = 4 },
|
||||||
{ itemstring = "mcl_minecarts:golden_rail", weight = 5, amount_min = 1, amount_max = 4 },
|
{ itemstring = "mcl_minecarts:golden_rail_v2", weight = 5, amount_min = 1, amount_max = 4 },
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
-- non-MC loot: 50% chance to add a minecart, offered as alternative to spawning minecarts on rails.
|
-- non-MC loot: 50% chance to add a minecart, offered as alternative to spawning minecarts on rails.
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
local pairs = pairs
|
local pairs = pairs
|
||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
|
|
||||||
tsm_railcorridors = {}
|
tsm_railcorridors = {
|
||||||
|
after = {},
|
||||||
|
}
|
||||||
|
|
||||||
-- Load node names
|
-- Load node names
|
||||||
dofile(minetest.get_modpath(minetest.get_current_modname()).."/gameconfig.lua")
|
dofile(minetest.get_modpath(minetest.get_current_modname()).."/gameconfig.lua")
|
||||||
|
@ -169,6 +171,10 @@ local function SetNodeIfCanBuild(pos, node, check_above, can_replace_rail)
|
||||||
(can_replace_rail and name == tsm_railcorridors.nodes.rail)
|
(can_replace_rail and name == tsm_railcorridors.nodes.rail)
|
||||||
) then
|
) then
|
||||||
minetest.set_node(pos, node)
|
minetest.set_node(pos, node)
|
||||||
|
local after = tsm_railcorridors.on_place_node[node.name]
|
||||||
|
if after then
|
||||||
|
after(pos, node)
|
||||||
|
end
|
||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
return false
|
return false
|
||||||
|
@ -392,27 +398,6 @@ local function PlaceChest(pos, param2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- This function checks if a cart has ACTUALLY been spawned.
|
|
||||||
-- To be calld by minetest.after.
|
|
||||||
-- 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 pos = params[1]
|
|
||||||
local cart_id = params[2]
|
|
||||||
-- Find cart
|
|
||||||
for _, obj in ipairs(minetest.get_objects_inside_radius(pos, 1)) do
|
|
||||||
if obj ~= nil and obj:get_luaentity().name == cart_id then
|
|
||||||
-- Cart found! We can now safely call the callback func.
|
|
||||||
-- (calling it earlier has the danger of failing)
|
|
||||||
minetest.log("info", "[tsm_railcorridors] Cart spawn succeeded: "..minetest.pos_to_string(pos))
|
|
||||||
tsm_railcorridors.on_construct_cart(pos, obj, pr_carts)
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
minetest.log("info", "[tsm_railcorridors] Cart spawn FAILED: "..minetest.pos_to_string(pos))
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Try to place a cobweb.
|
-- Try to place a cobweb.
|
||||||
-- pos: Position of cobweb
|
-- pos: Position of cobweb
|
||||||
-- needs_check: If true, checks if any of the nodes above, below or to the side of the cobweb.
|
-- needs_check: If true, checks if any of the nodes above, below or to the side of the cobweb.
|
||||||
|
@ -935,13 +920,13 @@ local function spawn_carts()
|
||||||
-- See <https://github.com/minetest/minetest/issues/4759>
|
-- See <https://github.com/minetest/minetest/issues/4759>
|
||||||
local cart_id = tsm_railcorridors.carts[cart_type]
|
local cart_id = tsm_railcorridors.carts[cart_type]
|
||||||
minetest.log("info", "[tsm_railcorridors] Cart spawn attempt: "..minetest.pos_to_string(cpos))
|
minetest.log("info", "[tsm_railcorridors] Cart spawn attempt: "..minetest.pos_to_string(cpos))
|
||||||
minetest.add_entity(cpos, cart_id)
|
local cart_staticdata = nil
|
||||||
|
|
||||||
-- This checks if the cart is actually spawned, it's a giant hack!
|
-- Try to create cart staticdata
|
||||||
-- Note that the callback function is also called there.
|
local hook = tsm_railcorridors.create_cart_staticdata
|
||||||
-- TODO: Move callback function to this position when the
|
if hook then cart_staticdata = hook(cart_id, cpos, pr) end
|
||||||
-- minetest.add_entity bug has been fixed (supposedly in 5.9.0?)
|
|
||||||
minetest.after(3, RecheckCartHack, {cpos, cart_id})
|
minetest.add_entity(cpos, cart_id, cart_staticdata)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
carts_table = {}
|
carts_table = {}
|
||||||
|
@ -950,7 +935,7 @@ end
|
||||||
-- Start generation of a rail corridor system
|
-- Start generation of a rail corridor system
|
||||||
-- main_cave_coords is the center of the floor of the dirt room, from which
|
-- main_cave_coords is the center of the floor of the dirt room, from which
|
||||||
-- all corridors expand.
|
-- all corridors expand.
|
||||||
local function create_corridor_system(main_cave_coords)
|
local function create_corridor_system(main_cave_coords, pr)
|
||||||
|
|
||||||
-- Dirt room size
|
-- Dirt room size
|
||||||
local maxsize = 6
|
local maxsize = 6
|
||||||
|
@ -1105,13 +1090,22 @@ mcl_structures.register_structure("mineshaft",{
|
||||||
y_min = mcl_vars.mg_overworld_min,
|
y_min = mcl_vars.mg_overworld_min,
|
||||||
place_func = function(pos,_,pr,blockseed)
|
place_func = function(pos,_,pr,blockseed)
|
||||||
local r = pr:next(-50,-10)
|
local r = pr:next(-50,-10)
|
||||||
|
r = -10
|
||||||
local p = vector.offset(pos,0,r,0)
|
local p = vector.offset(pos,0,r,0)
|
||||||
if p.y < mcl_vars.mg_overworld_min + 5 then
|
if p.y < mcl_vars.mg_overworld_min + 5 then
|
||||||
p.y = mcl_vars.mg_overworld_min + 5
|
p.y = mcl_vars.mg_overworld_min + 5
|
||||||
end
|
end
|
||||||
if p.y > -10 then return true end
|
--if p.y > -10 then return true end
|
||||||
InitRandomizer(blockseed)
|
InitRandomizer(blockseed)
|
||||||
create_corridor_system(p)
|
|
||||||
|
local hook = tsm_railcorridors.on_start
|
||||||
|
if hook then hook() end
|
||||||
|
|
||||||
|
create_corridor_system(p, pr)
|
||||||
|
|
||||||
|
local hook = tsm_railcorridors.on_finish
|
||||||
|
if hook then hook() end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue