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
c127eb449e
commit
ea2d4ac889
|
@ -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
|
||||||
|
@ -37,19 +58,31 @@ else
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
-- TODO: Use minecart with chest instead of normal minecart
|
tsm_railcorridors.carts = { "mcl_minecarts:chest_minecart", "mcl_minecarts:hopper_minecart", "mcl_minecarts:minecart" }
|
||||||
tsm_railcorridors.carts = { "mcl_minecarts:minecart" }
|
local has_loot = {
|
||||||
|
["mcl_minecarts:chest_minecart"] = true,
|
||||||
|
["mcl_minecarts:hopper_minceart"] = true,
|
||||||
|
}
|
||||||
|
|
||||||
function tsm_railcorridors.on_construct_cart(pos, cart)
|
function tsm_railcorridors.create_cart_staticdata(entity_id,pos, pr)
|
||||||
-- TODO: Fill cart with treasures
|
local uuid = create_minecart(entity_id, pos, vector.new(1,0,0))
|
||||||
|
|
||||||
-- This is it? There's this giant hack announced in
|
-- Fill the cart with loot
|
||||||
-- the other file and I grep for the function and it's
|
local cartdata = get_cart_data(uuid)
|
||||||
-- a stub? :)
|
if cartdata and has_loot[entity_id] then
|
||||||
|
local items = tsm_railcorridors.get_treasures(pr)
|
||||||
|
|
||||||
-- The path here using some minetest.after hackery was
|
-- Convert from ItemStack to itemstrings
|
||||||
-- deactivated in init.lua - reactivate when this does
|
for k,item in pairs(items) do
|
||||||
-- something the function is called RecheckCartHack.
|
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
|
||||||
|
@ -102,11 +135,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")
|
||||||
|
@ -170,6 +172,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
|
||||||
|
@ -394,34 +400,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.
|
|
||||||
|
|
||||||
-- Why did anyone activate it in the first place? It doesn't
|
|
||||||
-- have a function seeing as there are no chest minecarts yet.
|
|
||||||
--[[
|
|
||||||
local function RecheckCartHack(params)
|
|
||||||
local pos = params[1]
|
|
||||||
local cart_id = params[2]
|
|
||||||
-- Find cart
|
|
||||||
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 1)) do
|
|
||||||
if obj 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)
|
|
||||||
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.
|
||||||
|
@ -944,16 +922,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.
|
|
||||||
|
|
||||||
-- minetest.after(3, RecheckCartHack, {cpos, cart_id})
|
minetest.add_entity(cpos, cart_id, cart_staticdata)
|
||||||
-- This whole recheck logic leads to a stub right now
|
|
||||||
-- it can be reenabled when chest carts are a thing.
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
carts_table = {}
|
carts_table = {}
|
||||||
|
@ -1117,13 +1092,22 @@ mcl_structures.register_structure("mineshaft",{
|
||||||
y_min = mcl_vars.mg_overworld_min,
|
y_min = mcl_vars.mg_overworld_min,
|
||||||
place_func = function(pos,def,pr,blockseed)
|
place_func = function(pos,def,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)
|
||||||
|
|
||||||
|
local hook = tsm_railcorridors.on_start
|
||||||
|
if hook then hook() end
|
||||||
|
|
||||||
create_corridor_system(p, pr)
|
create_corridor_system(p, pr)
|
||||||
|
|
||||||
|
local hook = tsm_railcorridors.on_finish
|
||||||
|
if hook then hook() end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ tsm_railcorridors_probability_chest (Chest probability) float 0.05 0.0 1.0
|
||||||
#of finding a cart in rail corridors with high rail damage will be lower.
|
#of finding a cart in rail corridors with high rail damage will be lower.
|
||||||
#NOTE: Due to a bug in Minetest <https://github.com/minetest/minetest/issues/4759>
|
#NOTE: Due to a bug in Minetest <https://github.com/minetest/minetest/issues/4759>
|
||||||
#carts often fail to spawn even if they should.
|
#carts often fail to spawn even if they should.
|
||||||
tsm_railcorridors_probability_cart (Cart probability) float 0.0 0.0 1.0
|
tsm_railcorridors_probability_cart (Cart probability) float 0.05 0.0 1.0
|
||||||
|
|
||||||
#If enabled, cobwebs may be placed in some corridors.
|
#If enabled, cobwebs may be placed in some corridors.
|
||||||
#Currently, cobwebs are only supported with the Mobs Redo mod.
|
#Currently, cobwebs are only supported with the Mobs Redo mod.
|
||||||
|
|
Loading…
Reference in New Issue