Cleaning up code. Fixed powered and brake rails not working.
parent
ddf972ef13
commit
e00e759952
|
@ -5,28 +5,21 @@
|
|||
License: AGPLv3
|
||||
]]--
|
||||
|
||||
minegistics = {}
|
||||
money = 100
|
||||
|
||||
local loaded = false
|
||||
minegistics.modpath = minetest.get_modpath("minegistics")
|
||||
dofile(minegistics.modpath .. DIR_DELIM .. "src" .. DIR_DELIM .. "mapgen.lua")
|
||||
dofile(minegistics.modpath .. DIR_DELIM .. "src" .. DIR_DELIM .. "power.lua")
|
||||
dofile(minegistics.modpath .. DIR_DELIM .. "src" .. DIR_DELIM .. "items.lua")
|
||||
dofile(minegistics.modpath .. DIR_DELIM .. "src" .. DIR_DELIM .. "hud.lua")
|
||||
dofile(minegistics.modpath .. DIR_DELIM .. "src" .. DIR_DELIM .. "formspec.lua")
|
||||
dofile(minegistics.modpath .. DIR_DELIM .. "src" .. DIR_DELIM .. "initial_items.lua")
|
||||
dofile(minegistics.modpath .. DIR_DELIM .. "src" .. DIR_DELIM .. "welcome_message.lua")
|
||||
dofile(minegistics.modpath .. DIR_DELIM .. "structures" .. DIR_DELIM .. "collector.lua")
|
||||
dofile(minegistics.modpath .. DIR_DELIM .. "structures" .. DIR_DELIM .. "factory.lua")
|
||||
dofile(minegistics.modpath .. DIR_DELIM .. "structures" .. DIR_DELIM .. "farm.lua")
|
||||
dofile(minegistics.modpath .. DIR_DELIM .. "structures" .. DIR_DELIM .. "market.lua")
|
||||
dofile(minegistics.modpath .. DIR_DELIM .. "structures" .. DIR_DELIM .. "town.lua")
|
||||
dofile(minegistics.modpath .. DIR_DELIM .. "structures" .. DIR_DELIM .. "warehouse.lua")
|
||||
dofile(minegistics.modpath .. DIR_DELIM .. "structures" .. DIR_DELIM .. "workshop.lua")
|
||||
local enable_fog = minetest.settings:get_bool("enable_fog")
|
||||
local menu_clouds = minetest.settings:get_bool("menu_clouds")
|
||||
local mip_map = minetest.settings:get_bool("mip_map")
|
||||
local smooth_lighting = minetest.settings:get_bool("smooth_lighting")
|
||||
|
||||
minetest.settings:set_bool("enable_fog", false)
|
||||
minetest.settings:set_bool("menu_clouds", false)
|
||||
minetest.settings:set_bool("mip_map", true)
|
||||
minetest.settings:set_bool("smooth_lighting", true)
|
||||
minetest.register_item(":", { type = "none", wield_image = "blank.png"})
|
||||
|
||||
--TODO create a power bar for hud for easy referance
|
||||
dofile(minetest.get_modpath("minegistics") .. DIR_DELIM .. "src" .. DIR_DELIM .. "do_file.lua")
|
||||
|
||||
--initializes the player and loads saved game
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
|
@ -68,6 +61,15 @@ minetest.register_item(":", { type = "none", wield_image = "blank.png"})
|
|||
end
|
||||
end)
|
||||
|
||||
--removes the player from hud lists
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
if player then
|
||||
local name = player:get_player_name()
|
||||
hud_bg_ids[name] = nil
|
||||
money_hud_ids[name] = nil
|
||||
end
|
||||
end)
|
||||
|
||||
--saves data
|
||||
minetest.register_on_shutdown(function()
|
||||
local save_vars = {
|
||||
|
@ -79,6 +81,10 @@ minetest.register_on_shutdown(function()
|
|||
local save_data = minetest.write_json(save_vars)
|
||||
local save_path = minetest.get_worldpath() .. DIR_DELIM .. "save_data.json"
|
||||
minetest.safe_file_write(save_path, save_data)
|
||||
minetest.settings:set_bool("enable_fog", enable_fog)
|
||||
minetest.settings:set_bool("menu_clouds", menu_clouds)
|
||||
minetest.settings:set_bool("mip_map", mip_map)
|
||||
minetest.settings:set_bool("smooth_lighting", smooth_lighting)
|
||||
end)
|
||||
|
||||
--main game loop
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
License: AGPLv3
|
||||
]]--
|
||||
|
||||
money = 100
|
||||
show_money_on_hud = true
|
||||
local item_buttons = {}
|
||||
local item_btn_keys = {}
|
||||
|
|
|
@ -6,39 +6,39 @@
|
|||
]]--
|
||||
|
||||
local give_if_not_gotten_already = function(inv, list, item)
|
||||
if not inv:contains_item(list, item) then
|
||||
inv:add_item(list, item)
|
||||
end
|
||||
if not inv:contains_item(list, item) then
|
||||
inv:add_item(list, item)
|
||||
end
|
||||
end
|
||||
|
||||
local give_initial_stuff = function(player)
|
||||
local inv = player:get_inventory()
|
||||
give_if_not_gotten_already(inv, "main", "minegistics:Market" .. " 1")
|
||||
give_if_not_gotten_already(inv, "main", "minegistics:Town" .. " 1")
|
||||
give_if_not_gotten_already(inv, "main", "minegistics:Collector" .. " 2")
|
||||
give_if_not_gotten_already(inv, "main", "minegistics:PowerPlant" .. " 1")
|
||||
give_if_not_gotten_already(inv, "main", "minegistics_trains:train" .. " 3")
|
||||
give_if_not_gotten_already(inv, "main", "minegistics_trains:rail" .. " 99")
|
||||
give_if_not_gotten_already(inv, "main", "minegistics_basenodes:coal_lump" .. " 99")
|
||||
minetest.log("action", "[give_initial_stuff] Giving initial stuff to "..player:get_player_name())
|
||||
local inv = player:get_inventory()
|
||||
give_if_not_gotten_already(inv, "main", "minegistics:Market" .. " 1")
|
||||
give_if_not_gotten_already(inv, "main", "minegistics:Town" .. " 1")
|
||||
give_if_not_gotten_already(inv, "main", "minegistics:Collector" .. " 2")
|
||||
give_if_not_gotten_already(inv, "main", "minegistics:PowerPlant" .. " 1")
|
||||
give_if_not_gotten_already(inv, "main", "minegistics_trains:train" .. " 3")
|
||||
give_if_not_gotten_already(inv, "main", "minegistics_trains:rail" .. " 99")
|
||||
give_if_not_gotten_already(inv, "main", "minegistics_basenodes:coal_lump" .. " 99")
|
||||
minetest.log("action", "[give_initial_stuff] Giving initial stuff to "..player:get_player_name())
|
||||
end
|
||||
|
||||
minetest.register_on_newplayer(function(player)
|
||||
if minetest.settings:get_bool("give_initial_stuff", true) then
|
||||
give_initial_stuff(player)
|
||||
end
|
||||
if minetest.settings:get_bool("give_initial_stuff", true) then
|
||||
give_initial_stuff(player)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_chatcommand("stuff", {
|
||||
params = "",
|
||||
privs = { give = true },
|
||||
description = "Give yourself initial items",
|
||||
func = function(name, param)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player or not player:is_player() then
|
||||
return false, "No player."
|
||||
end
|
||||
give_initial_stuff(player)
|
||||
return true
|
||||
end,
|
||||
params = "",
|
||||
privs = { give = true },
|
||||
description = "Give yourself initial items",
|
||||
func = function(name, param)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player or not player:is_player() then
|
||||
return false, "No player."
|
||||
end
|
||||
give_initial_stuff(player)
|
||||
return true
|
||||
end,
|
||||
})
|
||||
|
|
|
@ -6,12 +6,9 @@
|
|||
]]--
|
||||
|
||||
local abm_timer = 0
|
||||
|
||||
power_producers = {}
|
||||
power_consumers = {}
|
||||
|
||||
--TODO Add power lines and sub stations
|
||||
|
||||
minetest.register_node("minegistics:PowerPlant", {
|
||||
description = "Power Plant: Generates power. Requires coal for fuel.\n" ..
|
||||
"One power plant is needed for every 5 buildings.\n" ..
|
||||
|
|
|
@ -22,12 +22,12 @@ end
|
|||
|
||||
--shows the greeting formspec
|
||||
minetest.register_on_newplayer(function(player)
|
||||
local cb = function(player)
|
||||
if not player or not player:is_player() then
|
||||
return
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
minetest.show_formspec(name,"greeting",table.concat(greeting_formspec()))
|
||||
end
|
||||
minetest.after(2.0, cb, player)
|
||||
local cb = function(player)
|
||||
if not player or not player:is_player() then
|
||||
return
|
||||
end
|
||||
local name = player:get_player_name()
|
||||
minetest.show_formspec(name,"greeting",table.concat(greeting_formspec()))
|
||||
end
|
||||
minetest.after(2.0, cb, player)
|
||||
end)
|
||||
|
|
|
@ -1,14 +1,9 @@
|
|||
local WATER_ALPHA = "^[opacity:" .. 160
|
||||
local WATER_VISC = 1
|
||||
local LAVA_VISC = 7
|
||||
|
||||
--
|
||||
-- Craftitems
|
||||
--
|
||||
|
||||
-- Register Craftitems
|
||||
|
||||
|
||||
minetest.register_craftitem("minegistics_basenodes:coal_lump", {
|
||||
description = ("Coal Lump"),
|
||||
inventory_image = "default_coal_lump.png",
|
||||
|
@ -35,11 +30,6 @@ minetest.register_craftitem("minegistics_basenodes:iron_lump", {
|
|||
inventory_image = "default_iron_lump.png"
|
||||
})
|
||||
|
||||
minetest.register_craftitem("minegistics_basenodes:flint", {
|
||||
description = ("Flint"),
|
||||
inventory_image = "default_flint.png"
|
||||
})
|
||||
|
||||
minetest.register_craftitem("minegistics_basenodes:planks", {
|
||||
description = ("Lumber"),
|
||||
inventory_image = "default_wood.png"
|
||||
|
@ -66,16 +56,6 @@ minetest.register_node("minegistics_basenodes:dirt", {
|
|||
tiles ={"default_dirt.png"},
|
||||
})
|
||||
|
||||
minetest.register_node("minegistics_basenodes:sand", {
|
||||
description = "Sand",
|
||||
tiles ={"default_sand.png"},
|
||||
})
|
||||
|
||||
minetest.register_node("minegistics_basenodes:gravel", {
|
||||
description = "Gravel",
|
||||
tiles ={"default_gravel.png"},
|
||||
})
|
||||
|
||||
minetest.register_node("minegistics_basenodes:tree", {
|
||||
descriptions = "Woods",
|
||||
drawtype="mesh",
|
||||
|
@ -83,20 +63,6 @@ minetest.register_node("minegistics_basenodes:tree", {
|
|||
tiles={"minegistics_tree.png"}
|
||||
})
|
||||
|
||||
minetest.register_node("minegistics_basenodes:leaves", {
|
||||
description = "Normal Leaves",
|
||||
drawtype = "allfaces_optional",
|
||||
tiles = {"default_leaves.png"},
|
||||
paramtype = "light",
|
||||
is_ground_content = false,
|
||||
})
|
||||
|
||||
minetest.register_node("minegistics_basenodes:cobble", {
|
||||
description = "Cobblestone",
|
||||
tiles ={"default_cobble.png"},
|
||||
is_ground_content = false,
|
||||
})
|
||||
|
||||
minetest.register_node("minegistics_basenodes:stone_with_coal", {
|
||||
description = ("Coal Ore"),
|
||||
tiles = {"default_stone.png^default_mineral_coal.png"},
|
||||
|
@ -122,6 +88,12 @@ minetest.register_node("minegistics_basenodes:stone_with_gold", {
|
|||
tiles = {"default_stone.png^default_mineral_gold.png"},
|
||||
})
|
||||
|
||||
--
|
||||
-- Ore definitions
|
||||
--
|
||||
|
||||
-- Register ores
|
||||
|
||||
base_ores = {
|
||||
["minegistics_basenodes:stone_with_coal"] = "minegistics_basenodes:coal_lump",
|
||||
["minegistics_basenodes:stone_with_tin"] = "minegistics_basenodes:tin_lump",
|
||||
|
@ -130,62 +102,3 @@ base_ores = {
|
|||
["minegistics_basenodes:stone_with_gold"] = "minegistics_basenodes:gold_lump",
|
||||
["minegistics_basenodes:tree"] = "minegistics_basenodes:planks"
|
||||
}
|
||||
|
||||
minetest.register_node("minegistics_basenodes:river_water_source", {
|
||||
description = "River Water Source".."\n"..
|
||||
"Drowning damage: 1",
|
||||
drawtype = "liquid",
|
||||
waving = 3,
|
||||
tiles = { "default_river_water.png"..WATER_ALPHA },
|
||||
special_tiles = {
|
||||
{name = "default_river_water.png"..WATER_ALPHA, backface_culling = false},
|
||||
{name = "default_river_water.png"..WATER_ALPHA, backface_culling = true},
|
||||
},
|
||||
use_texture_alpha = "blend",
|
||||
paramtype = "light",
|
||||
walkable = false,
|
||||
pointable = false,
|
||||
diggable = false,
|
||||
buildable_to = true,
|
||||
is_ground_content = false,
|
||||
drowning = 1,
|
||||
liquidtype = "source",
|
||||
liquid_alternative_flowing = "minegistics_basenodes:river_water_flowing",
|
||||
liquid_alternative_source = "minegistics_basenodes:river_water_source",
|
||||
liquid_viscosity = 1,
|
||||
liquid_renewable = false,
|
||||
liquid_range = 2,
|
||||
post_effect_color = {a = 103, r = 30, g = 76, b = 90},
|
||||
groups = {water = 3, liquid = 3, },
|
||||
})
|
||||
|
||||
minetest.register_node("minegistics_basenodes:river_water_flowing", {
|
||||
description = "Flowing River Water".."\n"..
|
||||
"Drowning damage: 1",
|
||||
drawtype = "flowingliquid",
|
||||
waving = 3,
|
||||
tiles = {"default_river_water_flowing.png"..WATER_ALPHA},
|
||||
special_tiles = {
|
||||
{name = "default_river_water_flowing.png"..WATER_ALPHA,
|
||||
backface_culling = false},
|
||||
{name = "default_river_water_flowing.png"..WATER_ALPHA,
|
||||
backface_culling = false},
|
||||
},
|
||||
use_texture_alpha = "blend",
|
||||
paramtype = "light",
|
||||
paramtype2 = "flowingliquid",
|
||||
walkable = false,
|
||||
pointable = false,
|
||||
diggable = false,
|
||||
buildable_to = true,
|
||||
is_ground_content = false,
|
||||
drowning = 1,
|
||||
liquidtype = "flowing",
|
||||
liquid_alternative_flowing = "minegistics_basenodes:river_water_flowing",
|
||||
liquid_alternative_source = "minegistics_basenodes:river_water_source",
|
||||
liquid_viscosity = 1,
|
||||
liquid_renewable = false,
|
||||
liquid_range = 2,
|
||||
post_effect_color = {a = 103, r = 30, g = 76, b = 90},
|
||||
groups = {water = 3, liquid = 3, },
|
||||
})
|
||||
|
|
|
@ -18,10 +18,6 @@ local skies = {
|
|||
{"MinegisticSky", "#5f5f5e", 0.9, { density = 0 }},
|
||||
}
|
||||
|
||||
--
|
||||
-- API
|
||||
--
|
||||
|
||||
skybox = {}
|
||||
|
||||
skybox.set = function(player, number)
|
||||
|
@ -86,10 +82,6 @@ skybox.get_skies = function()
|
|||
return table.copy(skies)
|
||||
end
|
||||
|
||||
--
|
||||
-- registrations and load/save code
|
||||
--
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
local sky = player:get_meta():get_string("minegistics:skybox")
|
||||
if not sky or sky == "" then
|
||||
|
@ -104,39 +96,3 @@ minetest.register_on_joinplayer(function(player)
|
|||
skybox.clear(player)
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_privilege("skybox", {
|
||||
description = "Change sky box for yourself",
|
||||
})
|
||||
|
||||
minetest.register_chatcommand("skybox", {
|
||||
params = "<skybox> or <number> or \"off\" or empty to list skyboxes",
|
||||
description = "Change your sky box set",
|
||||
privs = "skybox",
|
||||
func = function(name, param)
|
||||
local player = minetest.get_player_by_name(name)
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
if param == nil or param == "" then
|
||||
minetest.chat_send_player(name, "Available sky boxes:")
|
||||
for _, v in ipairs(skies) do
|
||||
minetest.chat_send_player(name, v[1])
|
||||
end
|
||||
return
|
||||
elseif tonumber(param) ~= nil and tonumber(param) >= 1 and tonumber(param) <= table.getn(skies) then
|
||||
skybox.set(player, tonumber(param))
|
||||
return
|
||||
elseif param == "off" or param == "0" then
|
||||
skybox.clear(player)
|
||||
return
|
||||
end
|
||||
for k, v in ipairs(skies) do
|
||||
if v[1] == param then
|
||||
skybox.set(player, k)
|
||||
return
|
||||
end
|
||||
end
|
||||
minetest.chat_send_player(name, "Could not find that sky box.")
|
||||
end
|
||||
})
|
||||
|
|
|
@ -6,26 +6,6 @@ function trains:get_sign(z)
|
|||
end
|
||||
end
|
||||
|
||||
function trains:manage_attachment(player, obj)
|
||||
if not player then
|
||||
return
|
||||
end
|
||||
local status = obj ~= nil
|
||||
local player_name = player:get_player_name()
|
||||
if player_api.player_attached[player_name] == status then
|
||||
return
|
||||
end
|
||||
player_api.player_attached[player_name] = status
|
||||
|
||||
if status then
|
||||
player:set_attach(obj, "", {x=0, y=-4.5, z=0}, {x=0, y=0, z=0})
|
||||
player:set_eye_offset({x=0, y=-4, z=0},{x=0, y=-4, z=0})
|
||||
else
|
||||
player:set_detach()
|
||||
player:set_eye_offset({x=0, y=0, z=0},{x=0, y=0, z=0})
|
||||
end
|
||||
end
|
||||
|
||||
function trains:velocity_to_dir(v)
|
||||
if math.abs(v.x) > math.abs(v.z) then
|
||||
return {x=trains:get_sign(v.x), y=trains:get_sign(v.y), z=0}
|
||||
|
@ -56,36 +36,6 @@ function trains:is_rail(pos, railtype)
|
|||
return minetest.get_item_group(node, "connect_to_raillike") == railtype
|
||||
end
|
||||
|
||||
function trains:check_front_up_down(pos, dir_, check_up, railtype)
|
||||
local dir = vector.new(dir_)
|
||||
local cur
|
||||
|
||||
-- Front
|
||||
dir.y = 0
|
||||
cur = vector.add(pos, dir)
|
||||
if trains:is_rail(cur, railtype) then
|
||||
return dir
|
||||
--TODO Need to add elseif to check for structures.
|
||||
end
|
||||
-- Up
|
||||
if check_up then
|
||||
dir.y = 1
|
||||
cur = vector.add(pos, dir)
|
||||
if trains:is_rail(cur, railtype) then
|
||||
return dir
|
||||
end
|
||||
--TODO Need to add elseif to check for structures.
|
||||
end
|
||||
-- Down
|
||||
dir.y = -1
|
||||
cur = vector.add(pos, dir)
|
||||
if trains:is_rail(cur, railtype) then
|
||||
return dir
|
||||
end
|
||||
--TODO Need to add elseif to check for structures.
|
||||
return nil
|
||||
end
|
||||
|
||||
function trains:get_rail_direction(pos_, dir, old_switch, railtype)
|
||||
local pos = vector.round(pos_)
|
||||
local cur
|
||||
|
@ -152,7 +102,7 @@ function trains:get_rail_direction(pos_, dir, old_switch, railtype)
|
|||
end
|
||||
|
||||
function trains:pathfinder(pos_, old_pos, old_dir, distance,
|
||||
pf_switch, railtype)
|
||||
pf_switch, railtype)
|
||||
|
||||
local pos = vector.round(pos_)
|
||||
if vector.equals(old_pos, pos) then
|
||||
|
@ -184,45 +134,9 @@ function trains:pathfinder(pos_, old_pos, old_dir, distance,
|
|||
return pf_pos, pf_dir
|
||||
end
|
||||
|
||||
function trains:register_rail(name, def_overwrite, railparams)
|
||||
local def = {
|
||||
drawtype = "raillike",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
is_ground_content = false,
|
||||
walkable = false,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
|
||||
},
|
||||
}
|
||||
for k, v in pairs(def_overwrite) do
|
||||
def[k] = v
|
||||
end
|
||||
if not def.inventory_image then
|
||||
def.wield_image = def.tiles[1]
|
||||
def.inventory_image = def.tiles[1]
|
||||
end
|
||||
|
||||
if railparams then
|
||||
trains.railparams[name] = table.copy(railparams)
|
||||
end
|
||||
|
||||
minetest.register_node(name, def)
|
||||
end
|
||||
|
||||
function trains:get_rail_groups(additional_groups)
|
||||
-- Get the default rail groups and add more when a table is given
|
||||
local groups = {
|
||||
dig_immediate = 2,
|
||||
attached_node = 1,
|
||||
rail = 1,
|
||||
connect_to_raillike = minetest.raillike_group("rail")
|
||||
}
|
||||
if type(additional_groups) == "table" then
|
||||
for k, v in pairs(additional_groups) do
|
||||
groups[k] = v
|
||||
end
|
||||
end
|
||||
return groups
|
||||
function trains:register_rail(name, def, railparams)
|
||||
if railparams then
|
||||
trains.railparams[name] = table.copy(railparams)
|
||||
end
|
||||
minetest.register_node(name, def)
|
||||
end
|
||||
|
|
|
@ -1,4 +1,162 @@
|
|||
minetest.register_node("minegistics_trains:rail", {
|
||||
local rail_node_box = {
|
||||
type = "connected",
|
||||
connect_sides = {"front", "left", "back", "right"},
|
||||
--All box points start in the lower left corner, to upper right
|
||||
fixed = {
|
||||
--Base layer
|
||||
{-0.252, -0.5, -0.252, 0.244, -0.438, 0.244},
|
||||
--Railties Lower Left
|
||||
{-0.19, -0.438, -0.128, -0.128, -0.376, -0.066},
|
||||
{-0.128, -0.438, -0.19, -0.066, -0.376, -0.066},
|
||||
--Railties Top Left
|
||||
{-0.19, -0.438, 0.058, -0.128, -0.376, 0.12},
|
||||
{-0.128, -0.438, 0.058, -0.066, -0.376, 0.182},
|
||||
--Railties Lower Right
|
||||
{0.058, -0.438, -0.19, 0.12, -0.376, -0.066},
|
||||
{0.12, -0.438, -0.128, 0.182, -0.376, -0.066},
|
||||
--Railties Top Right
|
||||
{0.058, -0.438, 0.058, 0.12, -0.376, 0.182},
|
||||
{0.12, -0.438, 0.058, 0.182, -0.376, 0.12},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.128, -0.066, -0.314, -0.066},
|
||||
{-0.128, -0.376, 0.058, -0.066, -0.314, 0.12},
|
||||
{-0.066, -0.376, -0.066, 0.058, -0.314, 0.058},
|
||||
{0.058, -0.376, -0.128, 0.12, -0.314, -0.066},
|
||||
{0.058, -0.376, 0.058, 0.12, -0.314, 0.12}
|
||||
},
|
||||
connect_front = {
|
||||
--Base
|
||||
{-0.252, -0.5, -0.5, 0.244, -0.438, -0.252},
|
||||
--Railties
|
||||
{-0.19, -0.438, -0.438, 0.182, -0.376, -0.376},
|
||||
{-0.19, -0.438, -0.252, 0.182, -0.376, -0.19},
|
||||
{-0.066, -0.438, -0.128, 0.058, -0.376, -0.066},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.5, -0.066, -0.314, -0.128},
|
||||
{-0.128, -0.376, -0.066, -0.066, -0.314, -0.004},
|
||||
{0.058, -0.376, -0.5, 0.12, -0.314, -0.128},
|
||||
{0.058, -0.376, -0.066, 0.12, -0.314, -0.004,}
|
||||
},
|
||||
connect_left = {
|
||||
--Base
|
||||
{-0.5, -0.5, -0.252, -0.252, -0.438, 0.244},
|
||||
--Railties
|
||||
{-0.438, -0.438, -0.19, -0.376, -0.376, 0.182},
|
||||
{-0.252, -0.438, -0.19, -0.12, -0.376, 0.182},
|
||||
{-0.128, -0.438, -0.066, -0.066, -0.376, 0.058},
|
||||
--Rails
|
||||
{-0.5, -0.376, -0.128, -0.128, -0.314, -0.066},
|
||||
{-0.066, -0.376, -0.128, -0.004, -0.314, -0.066},
|
||||
{-0.5, -0.376, 0.058, -0.128, -0.314, 0.12},
|
||||
{-0.066, -0.376, 0.058, -0.004, -0.314, 0.12}
|
||||
},
|
||||
connect_back = {
|
||||
--Base
|
||||
{-0.252, -0.5, 0.244, 0.244, -0.438, 0.492},
|
||||
--Railties
|
||||
{-0.066, -0.438, 0.058, 0.058, -0.376, 0.12},
|
||||
{-0.19, -0.438, 0.182, 0.182, -0.376, 0.244},
|
||||
{-0.19, -0.438, 0.368, 0.182, -0.376, 0.43},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.004, -0.066, -0.314, 0.058},
|
||||
{-0.128, -0.376, 0.12, -0.066, -0.314, 0.492},
|
||||
{0.058, -0.376, -0.004, 0.12, -0.314, 0.058},
|
||||
{0.058, -0.376, 0.12, 0.12, -0.314, 0.492}
|
||||
},
|
||||
connect_right = {
|
||||
--Base
|
||||
{0.244, -0.5, -0.252, 0.492, -0.438, 0.244},
|
||||
--Railties
|
||||
{0.058, -0.438, -0.066, 0.12, -0.376, 0.058},
|
||||
{0.182, -0.438, -0.19, 0.244, -0.376, 0.182},
|
||||
{0.368, -0.438, -0.19, 0.43, -0.376, 0.182},
|
||||
--Rails
|
||||
{-0.004, -0.376, -0.128, 0.058, -0.314, -0.066},
|
||||
{0.12, -0.376, -0.128, 0.492, -0.314, -0.066},
|
||||
{-0.004, -0.376, 0.058, 0.058, -0.314, 0.12},
|
||||
{0.12, -0.376, 0.058, 0.492, -0.314, 0.12}
|
||||
}
|
||||
}
|
||||
|
||||
local rail_collision_box = {
|
||||
fixed = {
|
||||
--Base layer
|
||||
{-0.252, -0.5, -0.252, 0.244, -0.438, 0.244},
|
||||
--Railties Lower Left
|
||||
{-0.19, -0.438, -0.128, -0.128, -0.376, -0.066},
|
||||
{-0.128, -0.438, -0.19, -0.066, -0.376, -0.066},
|
||||
--Railties Top Left
|
||||
{-0.19, -0.438, 0.058, -0.128, -0.376, 0.12},
|
||||
{-0.128, -0.438, 0.058, -0.066, -0.376, 0.182},
|
||||
--Railties Lower Right
|
||||
{0.058, -0.438, -0.19, 0.12, -0.376, -0.066},
|
||||
{0.12, -0.438, -0.128, 0.182, -0.376, -0.066},
|
||||
--Railties Top Right
|
||||
{0.058, -0.438, 0.058, 0.12, -0.376, 0.182},
|
||||
{0.12, -0.438, 0.058, 0.182, -0.376, 0.12},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.128, -0.066, -0.314, -0.066},
|
||||
{-0.128, -0.376, 0.058, -0.066, -0.314, 0.12},
|
||||
{-0.066, -0.376, -0.066, 0.058, -0.314, 0.058},
|
||||
{0.058, -0.376, -0.128, 0.12, -0.314, -0.066},
|
||||
{0.058, -0.376, 0.058, 0.12, -0.314, 0.12}
|
||||
},
|
||||
connect_front = {
|
||||
--Base
|
||||
{-0.252, -0.5, -0.5, 0.244, -0.438, -0.252},
|
||||
--Railties
|
||||
{-0.19, -0.438, -0.438, 0.182, -0.376, -0.376},
|
||||
{-0.19, -0.438, -0.252, 0.182, -0.376, -0.19},
|
||||
{-0.066, -0.438, -0.128, 0.058, -0.376, -0.066},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.5, -0.066, -0.314, -0.128},
|
||||
{-0.128, -0.376, -0.066, -0.066, -0.314, -0.004},
|
||||
{0.058, -0.376, -0.5, 0.12, -0.314, -0.128},
|
||||
{0.058, -0.376, -0.066, 0.12, -0.004, -0.314}
|
||||
},
|
||||
connect_left = {
|
||||
--Base
|
||||
{-0.5, -0.5, -0.252, -0.252, -0.438, 0.244},
|
||||
--Railties
|
||||
{-0.438, -0.438, -0.19, -0.376, -0.376, 0.182},
|
||||
{-0.252, -0.438, -0.19, -0.12, -0.376, 0.182},
|
||||
{-0.128, -0.438, -0.066, -0.066, -0.376, 0.058},
|
||||
--Rails
|
||||
{-0.5, -0.376, -0.128, -0.128, -0.314, -0.066},
|
||||
{-0.066, -0.376, -0.128, -0.004, -0.314, -0.066},
|
||||
{-0.5, -0.376, 0.058, -0.128, -0.314, 0.12},
|
||||
{-0.066, -0.376, 0.058, -0.004, -0.314, 0.12}
|
||||
},
|
||||
connect_back = {
|
||||
--Base
|
||||
{-0.252, -0.5, 0.244, 0.244, -0.438, 0.492},
|
||||
--Railties
|
||||
{-0.066, 0.058, -0.438, 0.058, -0.376, 0.12},
|
||||
{-0.19, -0.438, 0.182, 0.182, -0.376, 0.244},
|
||||
{-0.19, -0.438, 0.368, 0.182, -0.376, 0.43},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.004, -0.066, -0.314, 0.058},
|
||||
{-0.128, -0.376, 0.12, -0.066, -0.314, 0.492},
|
||||
{0.058, -0.004, -0.376, 0.12, -0.314, 0.058},
|
||||
{0.058, -0.376, 0.12, 0.12, -0.314, 0.492}
|
||||
},
|
||||
connect_right = {
|
||||
--Base
|
||||
{0.244, -0.5, -0.252, 0.492, -0.438, 0.244},
|
||||
--Railties
|
||||
{0.058, -0.438, -0.066, 0.12, -0.376, 0.058},
|
||||
{0.182, -0.438, -0.19, 0.244, -0.376, 0.182},
|
||||
{0.368, -0.438, -0.19, 0.43, -0.376, 0.182},
|
||||
--Rails
|
||||
{-0.004, -0.376, -0.128, 0.058, -0.314, -0.066},
|
||||
{0.12, -0.376, -0.128, 0.492, -0.314, -0.066},
|
||||
{-0.004, -0.376, 0.058, 0.058, -0.314, 0.12},
|
||||
{0.12, -0.376, 0.058, 0.492, -0.314, 0.12}
|
||||
}
|
||||
}
|
||||
|
||||
trains:register_rail("minegistics_trains:rail", {
|
||||
description = ("Rail: For trains."),
|
||||
drawtype = "nodebox",
|
||||
paramtype = "light",
|
||||
use_texture_alpha = "clip",
|
||||
|
@ -11,167 +169,13 @@ minetest.register_node("minegistics_trains:rail", {
|
|||
"train_new_side.png",
|
||||
"train_new_side.png"
|
||||
},
|
||||
node_box = {
|
||||
type = "connected",
|
||||
connect_sides = {"front", "left", "back", "right"},
|
||||
--All box points start in the lower left corner, to upper right
|
||||
fixed = {
|
||||
--Base layer
|
||||
{-0.252, -0.5, -0.252, 0.244, -0.438, 0.244},
|
||||
--Railties Lower Left
|
||||
{-0.19, -0.438, -0.128, -0.128, -0.376, -0.066},
|
||||
{-0.128, -0.438, -0.19, -0.066, -0.376, -0.066},
|
||||
--Railties Top Left
|
||||
{-0.19, -0.438, 0.058, -0.128, -0.376, 0.12},
|
||||
{-0.128, -0.438, 0.058, -0.066, -0.376, 0.182},
|
||||
--Railties Lower Right
|
||||
{0.058, -0.438, -0.19, 0.12, -0.376, -0.066},
|
||||
{0.12, -0.438, -0.128, 0.182, -0.376, -0.066},
|
||||
--Railties Top Right
|
||||
{0.058, -0.438, 0.058, 0.12, -0.376, 0.182},
|
||||
{0.12, -0.438, 0.058, 0.182, -0.376, 0.12},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.128, -0.066, -0.314, -0.066},
|
||||
{-0.128, -0.376, 0.058, -0.066, -0.314, 0.12},
|
||||
{-0.066, -0.376, -0.066, 0.058, -0.314, 0.058},
|
||||
{0.058, -0.376, -0.128, 0.12, -0.314, -0.066},
|
||||
{0.058, -0.376, 0.058, 0.12, -0.314, 0.12}
|
||||
},
|
||||
connect_front = {
|
||||
--Base
|
||||
{-0.252, -0.5, -0.5, 0.244, -0.438, -0.252},
|
||||
--Railties
|
||||
{-0.19, -0.438, -0.438, 0.182, -0.376, -0.376},
|
||||
{-0.19, -0.438, -0.252, 0.182, -0.376, -0.19},
|
||||
{-0.066, -0.438, -0.128, 0.058, -0.376, -0.066},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.5, -0.066, -0.314, -0.128},
|
||||
{-0.128, -0.376, -0.066, -0.066, -0.314, -0.004},
|
||||
{0.058, -0.376, -0.5, 0.12, -0.314, -0.128},
|
||||
{0.058, -0.376, -0.066, 0.12, -0.314, -0.004,}
|
||||
},
|
||||
connect_left = {
|
||||
--Base
|
||||
{-0.5, -0.5, -0.252, -0.252, -0.438, 0.244},
|
||||
--Railties
|
||||
{-0.438, -0.438, -0.19, -0.376, -0.376, 0.182},
|
||||
{-0.252, -0.438, -0.19, -0.12, -0.376, 0.182},
|
||||
{-0.128, -0.438, -0.066, -0.066, -0.376, 0.058},
|
||||
--Rails
|
||||
{-0.5, -0.376, -0.128, -0.128, -0.314, -0.066},
|
||||
{-0.066, -0.376, -0.128, -0.004, -0.314, -0.066},
|
||||
{-0.5, -0.376, 0.058, -0.128, -0.314, 0.12},
|
||||
{-0.066, -0.376, 0.058, -0.004, -0.314, 0.12}
|
||||
},
|
||||
connect_back = {
|
||||
--Base
|
||||
{-0.252, -0.5, 0.244, 0.244, -0.438, 0.492},
|
||||
--Railties
|
||||
{-0.066, -0.438, 0.058, 0.058, -0.376, 0.12},
|
||||
{-0.19, -0.438, 0.182, 0.182, -0.376, 0.244},
|
||||
{-0.19, -0.438, 0.368, 0.182, -0.376, 0.43},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.004, -0.066, -0.314, 0.058},
|
||||
{-0.128, -0.376, 0.12, -0.066, -0.314, 0.492},
|
||||
{0.058, -0.376, -0.004, 0.12, -0.314, 0.058},
|
||||
{0.058, -0.376, 0.12, 0.12, -0.314, 0.492}
|
||||
},
|
||||
connect_right = {
|
||||
--Base
|
||||
{0.244, -0.5, -0.252, 0.492, -0.438, 0.244},
|
||||
--Railties
|
||||
{0.058, -0.438, -0.066, 0.12, -0.376, 0.058},
|
||||
{0.182, -0.438, -0.19, 0.244, -0.376, 0.182},
|
||||
{0.368, -0.438, -0.19, 0.43, -0.376, 0.182},
|
||||
--Rails
|
||||
{-0.004, -0.376, -0.128, 0.058, -0.314, -0.066},
|
||||
{0.12, -0.376, -0.128, 0.492, -0.314, -0.066},
|
||||
{-0.004, -0.376, 0.058, 0.058, -0.314, 0.12},
|
||||
{0.12, -0.376, 0.058, 0.492, -0.314, 0.12}
|
||||
}
|
||||
},
|
||||
collision_box = {
|
||||
fixed = {
|
||||
--Base layer
|
||||
{-0.252, -0.5, -0.252, 0.244, -0.438, 0.244},
|
||||
--Railties Lower Left
|
||||
{-0.19, -0.438, -0.128, -0.128, -0.376, -0.066},
|
||||
{-0.128, -0.438, -0.19, -0.066, -0.376, -0.066},
|
||||
--Railties Top Left
|
||||
{-0.19, -0.438, 0.058, -0.128, -0.376, 0.12},
|
||||
{-0.128, -0.438, 0.058, -0.066, -0.376, 0.182},
|
||||
--Railties Lower Right
|
||||
{0.058, -0.438, -0.19, 0.12, -0.376, -0.066},
|
||||
{0.12, -0.438, -0.128, 0.182, -0.376, -0.066},
|
||||
--Railties Top Right
|
||||
{0.058, -0.438, 0.058, 0.12, -0.376, 0.182},
|
||||
{0.12, -0.438, 0.058, 0.182, -0.376, 0.12},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.128, -0.066, -0.314, -0.066},
|
||||
{-0.128, -0.376, 0.058, -0.066, -0.314, 0.12},
|
||||
{-0.066, -0.376, -0.066, 0.058, -0.314, 0.058},
|
||||
{0.058, -0.376, -0.128, 0.12, -0.314, -0.066},
|
||||
{0.058, -0.376, 0.058, 0.12, -0.314, 0.12}
|
||||
},
|
||||
connect_front = {
|
||||
--Base
|
||||
{-0.252, -0.5, -0.5, 0.244, -0.438, -0.252},
|
||||
--Railties
|
||||
{-0.19, -0.438, -0.438, 0.182, -0.376, -0.376},
|
||||
{-0.19, -0.438, -0.252, 0.182, -0.376, -0.19},
|
||||
{-0.066, -0.438, -0.128, 0.058, -0.376, -0.066},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.5, -0.066, -0.314, -0.128},
|
||||
{-0.128, -0.376, -0.066, -0.066, -0.314, -0.004},
|
||||
{0.058, -0.376, -0.5, 0.12, -0.314, -0.128},
|
||||
{0.058, -0.376, -0.066, 0.12, -0.004, -0.314}
|
||||
},
|
||||
connect_left = {
|
||||
--Base
|
||||
{-0.5, -0.5, -0.252, -0.252, -0.438, 0.244},
|
||||
--Railties
|
||||
{-0.438, -0.438, -0.19, -0.376, -0.376, 0.182},
|
||||
{-0.252, -0.438, -0.19, -0.12, -0.376, 0.182},
|
||||
{-0.128, -0.438, -0.066, -0.066, -0.376, 0.058},
|
||||
--Rails
|
||||
{-0.5, -0.376, -0.128, -0.128, -0.314, -0.066},
|
||||
{-0.066, -0.376, -0.128, -0.004, -0.314, -0.066},
|
||||
{-0.5, -0.376, 0.058, -0.128, -0.314, 0.12},
|
||||
{-0.066, -0.376, 0.058, -0.004, -0.314, 0.12}
|
||||
},
|
||||
connect_back = {
|
||||
--Base
|
||||
{-0.252, -0.5, 0.244, 0.244, -0.438, 0.492},
|
||||
--Railties
|
||||
{-0.066, 0.058, -0.438, 0.058, -0.376, 0.12},
|
||||
{-0.19, -0.438, 0.182, 0.182, -0.376, 0.244},
|
||||
{-0.19, -0.438, 0.368, 0.182, -0.376, 0.43},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.004, -0.066, -0.314, 0.058},
|
||||
{-0.128, -0.376, 0.12, -0.066, -0.314, 0.492},
|
||||
{0.058, -0.004, -0.376, 0.12, -0.314, 0.058},
|
||||
{0.058, -0.376, 0.12, 0.12, -0.314, 0.492}
|
||||
},
|
||||
connect_right = {
|
||||
--Base
|
||||
{0.244, -0.5, -0.252, 0.492, -0.438, 0.244},
|
||||
--Railties
|
||||
{0.058, -0.438, -0.066, 0.12, -0.376, 0.058},
|
||||
{0.182, -0.438, -0.19, 0.244, -0.376, 0.182},
|
||||
{0.368, -0.438, -0.19, 0.43, -0.376, 0.182},
|
||||
--Rails
|
||||
{-0.004, -0.376, -0.128, 0.058, -0.314, -0.066},
|
||||
{0.12, -0.376, -0.128, 0.492, -0.314, -0.066},
|
||||
{-0.004, -0.376, 0.058, 0.058, -0.314, 0.12},
|
||||
{0.12, -0.376, 0.058, 0.492, -0.314, 0.12}
|
||||
}
|
||||
},
|
||||
|
||||
node_box = rail_node_box,
|
||||
collision_box = rail_collision_box,
|
||||
connects_to = {"group:new", "group:structures"},
|
||||
}, {})
|
||||
|
||||
})
|
||||
|
||||
minetest.register_node("minegistics_trains:brake_rail", {
|
||||
trains:register_rail("minegistics_trains:brake_rail", {
|
||||
description = ("Brake Rail: Reduces the speed of a train."),
|
||||
drawtype = "nodebox",
|
||||
paramtype = "light",
|
||||
use_texture_alpha = "clip",
|
||||
|
@ -184,167 +188,13 @@ minetest.register_node("minegistics_trains:brake_rail", {
|
|||
"train_new_side.png",
|
||||
"train_new_side.png"
|
||||
},
|
||||
node_box = {
|
||||
type = "connected",
|
||||
connect_sides = {"front", "left", "back", "right"},
|
||||
--All box points start in the lower left corner, to upper right
|
||||
fixed = {
|
||||
--Base layer
|
||||
{-0.252, -0.5, -0.252, 0.244, -0.438, 0.244},
|
||||
--Railties Lower Left
|
||||
{-0.19, -0.438, -0.128, -0.128, -0.376, -0.066},
|
||||
{-0.128, -0.438, -0.19, -0.066, -0.376, -0.066},
|
||||
--Railties Top Left
|
||||
{-0.19, -0.438, 0.058, -0.128, -0.376, 0.12},
|
||||
{-0.128, -0.438, 0.058, -0.066, -0.376, 0.182},
|
||||
--Railties Lower Right
|
||||
{0.058, -0.438, -0.19, 0.12, -0.376, -0.066},
|
||||
{0.12, -0.438, -0.128, 0.182, -0.376, -0.066},
|
||||
--Railties Top Right
|
||||
{0.058, -0.438, 0.058, 0.12, -0.376, 0.182},
|
||||
{0.12, -0.438, 0.058, 0.182, -0.376, 0.12},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.128, -0.066, -0.314, -0.066},
|
||||
{-0.128, -0.376, 0.058, -0.066, -0.314, 0.12},
|
||||
{-0.066, -0.376, -0.066, 0.058, -0.314, 0.058},
|
||||
{0.058, -0.376, -0.128, 0.12, -0.314, -0.066},
|
||||
{0.058, -0.376, 0.058, 0.12, -0.314, 0.12}
|
||||
},
|
||||
connect_front = {
|
||||
--Base
|
||||
{-0.252, -0.5, -0.5, 0.244, -0.438, -0.252},
|
||||
--Railties
|
||||
{-0.19, -0.438, -0.438, 0.182, -0.376, -0.376},
|
||||
{-0.19, -0.438, -0.252, 0.182, -0.376, -0.19},
|
||||
{-0.066, -0.438, -0.128, 0.058, -0.376, -0.066},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.5, -0.066, -0.314, -0.128},
|
||||
{-0.128, -0.376, -0.066, -0.066, -0.314, -0.004},
|
||||
{0.058, -0.376, -0.5, 0.12, -0.314, -0.128},
|
||||
{0.058, -0.376, -0.066, 0.12, -0.314, -0.004,}
|
||||
},
|
||||
connect_left = {
|
||||
--Base
|
||||
{-0.5, -0.5, -0.252, -0.252, -0.438, 0.244},
|
||||
--Railties
|
||||
{-0.438, -0.438, -0.19, -0.376, -0.376, 0.182},
|
||||
{-0.252, -0.438, -0.19, -0.12, -0.376, 0.182},
|
||||
{-0.128, -0.438, -0.066, -0.066, -0.376, 0.058},
|
||||
--Rails
|
||||
{-0.5, -0.376, -0.128, -0.128, -0.314, -0.066},
|
||||
{-0.066, -0.376, -0.128, -0.004, -0.314, -0.066},
|
||||
{-0.5, -0.376, 0.058, -0.128, -0.314, 0.12},
|
||||
{-0.066, -0.376, 0.058, -0.004, -0.314, 0.12}
|
||||
},
|
||||
connect_back = {
|
||||
--Base
|
||||
{-0.252, -0.5, 0.244, 0.244, -0.438, 0.492},
|
||||
--Railties
|
||||
{-0.066, -0.438, 0.058, 0.058, -0.376, 0.12},
|
||||
{-0.19, -0.438, 0.182, 0.182, -0.376, 0.244},
|
||||
{-0.19, -0.438, 0.368, 0.182, -0.376, 0.43},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.004, -0.066, -0.314, 0.058},
|
||||
{-0.128, -0.376, 0.12, -0.066, -0.314, 0.492},
|
||||
{0.058, -0.376, -0.004, 0.12, -0.314, 0.058},
|
||||
{0.058, -0.376, 0.12, 0.12, -0.314, 0.492}
|
||||
},
|
||||
connect_right = {
|
||||
--Base
|
||||
{0.244, -0.5, -0.252, 0.492, -0.438, 0.244},
|
||||
--Railties
|
||||
{0.058, -0.438, -0.066, 0.12, -0.376, 0.058},
|
||||
{0.182, -0.438, -0.19, 0.244, -0.376, 0.182},
|
||||
{0.368, -0.438, -0.19, 0.43, -0.376, 0.182},
|
||||
--Rails
|
||||
{-0.004, -0.376, -0.128, 0.058, -0.314, -0.066},
|
||||
{0.12, -0.376, -0.128, 0.492, -0.314, -0.066},
|
||||
{-0.004, -0.376, 0.058, 0.058, -0.314, 0.12},
|
||||
{0.12, -0.376, 0.058, 0.492, -0.314, 0.12}
|
||||
}
|
||||
},
|
||||
collision_box = {
|
||||
fixed = {
|
||||
--Base layer
|
||||
{-0.252, -0.5, -0.252, 0.244, -0.438, 0.244},
|
||||
--Railties Lower Left
|
||||
{-0.19, -0.438, -0.128, -0.128, -0.376, -0.066},
|
||||
{-0.128, -0.438, -0.19, -0.066, -0.376, -0.066},
|
||||
--Railties Top Left
|
||||
{-0.19, -0.438, 0.058, -0.128, -0.376, 0.12},
|
||||
{-0.128, -0.438, 0.058, -0.066, -0.376, 0.182},
|
||||
--Railties Lower Right
|
||||
{0.058, -0.438, -0.19, 0.12, -0.376, -0.066},
|
||||
{0.12, -0.438, -0.128, 0.182, -0.376, -0.066},
|
||||
--Railties Top Right
|
||||
{0.058, -0.438, 0.058, 0.12, -0.376, 0.182},
|
||||
{0.12, -0.438, 0.058, 0.182, -0.376, 0.12},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.128, -0.066, -0.314, -0.066},
|
||||
{-0.128, -0.376, 0.058, -0.066, -0.314, 0.12},
|
||||
{-0.066, -0.376, -0.066, 0.058, -0.314, 0.058},
|
||||
{0.058, -0.376, -0.128, 0.12, -0.314, -0.066},
|
||||
{0.058, -0.376, 0.058, 0.12, -0.314, 0.12}
|
||||
},
|
||||
connect_front = {
|
||||
--Base
|
||||
{-0.252, -0.5, -0.5, 0.244, -0.438, -0.252},
|
||||
--Railties
|
||||
{-0.19, -0.438, -0.438, 0.182, -0.376, -0.376},
|
||||
{-0.19, -0.438, -0.252, 0.182, -0.376, -0.19},
|
||||
{-0.066, -0.438, -0.128, 0.058, -0.376, -0.066},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.5, -0.066, -0.314, -0.128},
|
||||
{-0.128, -0.376, -0.066, -0.066, -0.314, -0.004},
|
||||
{0.058, -0.376, -0.5, 0.12, -0.314, -0.128},
|
||||
{0.058, -0.376, -0.066, 0.12, -0.004, -0.314}
|
||||
},
|
||||
connect_left = {
|
||||
--Base
|
||||
{-0.5, -0.5, -0.252, -0.252, -0.438, 0.244},
|
||||
--Railties
|
||||
{-0.438, -0.438, -0.19, -0.376, -0.376, 0.182},
|
||||
{-0.252, -0.438, -0.19, -0.12, -0.376, 0.182},
|
||||
{-0.128, -0.438, -0.066, -0.066, -0.376, 0.058},
|
||||
--Rails
|
||||
{-0.5, -0.376, -0.128, -0.128, -0.314, -0.066},
|
||||
{-0.066, -0.376, -0.128, -0.004, -0.314, -0.066},
|
||||
{-0.5, -0.376, 0.058, -0.128, -0.314, 0.12},
|
||||
{-0.066, -0.376, 0.058, -0.004, -0.314, 0.12}
|
||||
},
|
||||
connect_back = {
|
||||
--Base
|
||||
{-0.252, -0.5, 0.244, 0.244, -0.438, 0.492},
|
||||
--Railties
|
||||
{-0.066, 0.058, -0.438, 0.058, -0.376, 0.12},
|
||||
{-0.19, -0.438, 0.182, 0.182, -0.376, 0.244},
|
||||
{-0.19, -0.438, 0.368, 0.182, -0.376, 0.43},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.004, -0.066, -0.314, 0.058},
|
||||
{-0.128, -0.376, 0.12, -0.066, -0.314, 0.492},
|
||||
{0.058, -0.004, -0.376, 0.12, -0.314, 0.058},
|
||||
{0.058, -0.376, 0.12, 0.12, -0.314, 0.492}
|
||||
},
|
||||
connect_right = {
|
||||
--Base
|
||||
{0.244, -0.5, -0.252, 0.492, -0.438, 0.244},
|
||||
--Railties
|
||||
{0.058, -0.438, -0.066, 0.12, -0.376, 0.058},
|
||||
{0.182, -0.438, -0.19, 0.244, -0.376, 0.182},
|
||||
{0.368, -0.438, -0.19, 0.43, -0.376, 0.182},
|
||||
--Rails
|
||||
{-0.004, -0.376, -0.128, 0.058, -0.314, -0.066},
|
||||
{0.12, -0.376, -0.128, 0.492, -0.314, -0.066},
|
||||
{-0.004, -0.376, 0.058, 0.058, -0.314, 0.12},
|
||||
{0.12, -0.376, 0.058, 0.492, -0.314, 0.12}
|
||||
}
|
||||
},
|
||||
|
||||
node_box = rail_node_box,
|
||||
collision_box = rail_collision_box,
|
||||
connects_to = {"group:new", "group:structures"},
|
||||
}, {acceleration = -3})
|
||||
|
||||
})
|
||||
|
||||
minetest.register_node("minegistics_trains:power_rail", {
|
||||
trains:register_rail("minegistics_trains:power_rail", {
|
||||
description = ("Powered Rail: Increases the speed of a train."),
|
||||
drawtype = "nodebox",
|
||||
paramtype = "light",
|
||||
use_texture_alpha = "clip",
|
||||
|
@ -357,162 +207,7 @@ minetest.register_node("minegistics_trains:power_rail", {
|
|||
"train_new_side.png",
|
||||
"train_new_side.png"
|
||||
},
|
||||
node_box = {
|
||||
type = "connected",
|
||||
connect_sides = {"front", "left", "back", "right"},
|
||||
--All box points start in the lower left corner, to upper right
|
||||
fixed = {
|
||||
--Base layer
|
||||
{-0.252, -0.5, -0.252, 0.244, -0.438, 0.244},
|
||||
--Railties Lower Left
|
||||
{-0.19, -0.438, -0.128, -0.128, -0.376, -0.066},
|
||||
{-0.128, -0.438, -0.19, -0.066, -0.376, -0.066},
|
||||
--Railties Top Left
|
||||
{-0.19, -0.438, 0.058, -0.128, -0.376, 0.12},
|
||||
{-0.128, -0.438, 0.058, -0.066, -0.376, 0.182},
|
||||
--Railties Lower Right
|
||||
{0.058, -0.438, -0.19, 0.12, -0.376, -0.066},
|
||||
{0.12, -0.438, -0.128, 0.182, -0.376, -0.066},
|
||||
--Railties Top Right
|
||||
{0.058, -0.438, 0.058, 0.12, -0.376, 0.182},
|
||||
{0.12, -0.438, 0.058, 0.182, -0.376, 0.12},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.128, -0.066, -0.314, -0.066},
|
||||
{-0.128, -0.376, 0.058, -0.066, -0.314, 0.12},
|
||||
{-0.066, -0.376, -0.066, 0.058, -0.314, 0.058},
|
||||
{0.058, -0.376, -0.128, 0.12, -0.314, -0.066},
|
||||
{0.058, -0.376, 0.058, 0.12, -0.314, 0.12}
|
||||
},
|
||||
connect_front = {
|
||||
--Base
|
||||
{-0.252, -0.5, -0.5, 0.244, -0.438, -0.252},
|
||||
--Railties
|
||||
{-0.19, -0.438, -0.438, 0.182, -0.376, -0.376},
|
||||
{-0.19, -0.438, -0.252, 0.182, -0.376, -0.19},
|
||||
{-0.066, -0.438, -0.128, 0.058, -0.376, -0.066},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.5, -0.066, -0.314, -0.128},
|
||||
{-0.128, -0.376, -0.066, -0.066, -0.314, -0.004},
|
||||
{0.058, -0.376, -0.5, 0.12, -0.314, -0.128},
|
||||
{0.058, -0.376, -0.066, 0.12, -0.314, -0.004,}
|
||||
},
|
||||
connect_left = {
|
||||
--Base
|
||||
{-0.5, -0.5, -0.252, -0.252, -0.438, 0.244},
|
||||
--Railties
|
||||
{-0.438, -0.438, -0.19, -0.376, -0.376, 0.182},
|
||||
{-0.252, -0.438, -0.19, -0.12, -0.376, 0.182},
|
||||
{-0.128, -0.438, -0.066, -0.066, -0.376, 0.058},
|
||||
--Rails
|
||||
{-0.5, -0.376, -0.128, -0.128, -0.314, -0.066},
|
||||
{-0.066, -0.376, -0.128, -0.004, -0.314, -0.066},
|
||||
{-0.5, -0.376, 0.058, -0.128, -0.314, 0.12},
|
||||
{-0.066, -0.376, 0.058, -0.004, -0.314, 0.12}
|
||||
},
|
||||
connect_back = {
|
||||
--Base
|
||||
{-0.252, -0.5, 0.244, 0.244, -0.438, 0.492},
|
||||
--Railties
|
||||
{-0.066, -0.438, 0.058, 0.058, -0.376, 0.12},
|
||||
{-0.19, -0.438, 0.182, 0.182, -0.376, 0.244},
|
||||
{-0.19, -0.438, 0.368, 0.182, -0.376, 0.43},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.004, -0.066, -0.314, 0.058},
|
||||
{-0.128, -0.376, 0.12, -0.066, -0.314, 0.492},
|
||||
{0.058, -0.376, -0.004, 0.12, -0.314, 0.058},
|
||||
{0.058, -0.376, 0.12, 0.12, -0.314, 0.492}
|
||||
},
|
||||
connect_right = {
|
||||
--Base
|
||||
{0.244, -0.5, -0.252, 0.492, -0.438, 0.244},
|
||||
--Railties
|
||||
{0.058, -0.438, -0.066, 0.12, -0.376, 0.058},
|
||||
{0.182, -0.438, -0.19, 0.244, -0.376, 0.182},
|
||||
{0.368, -0.438, -0.19, 0.43, -0.376, 0.182},
|
||||
--Rails
|
||||
{-0.004, -0.376, -0.128, 0.058, -0.314, -0.066},
|
||||
{0.12, -0.376, -0.128, 0.492, -0.314, -0.066},
|
||||
{-0.004, -0.376, 0.058, 0.058, -0.314, 0.12},
|
||||
{0.12, -0.376, 0.058, 0.492, -0.314, 0.12}
|
||||
}
|
||||
},
|
||||
collision_box = {
|
||||
fixed = {
|
||||
--Base layer
|
||||
{-0.252, -0.5, -0.252, 0.244, -0.438, 0.244},
|
||||
--Railties Lower Left
|
||||
{-0.19, -0.438, -0.128, -0.128, -0.376, -0.066},
|
||||
{-0.128, -0.438, -0.19, -0.066, -0.376, -0.066},
|
||||
--Railties Top Left
|
||||
{-0.19, -0.438, 0.058, -0.128, -0.376, 0.12},
|
||||
{-0.128, -0.438, 0.058, -0.066, -0.376, 0.182},
|
||||
--Railties Lower Right
|
||||
{0.058, -0.438, -0.19, 0.12, -0.376, -0.066},
|
||||
{0.12, -0.438, -0.128, 0.182, -0.376, -0.066},
|
||||
--Railties Top Right
|
||||
{0.058, -0.438, 0.058, 0.12, -0.376, 0.182},
|
||||
{0.12, -0.438, 0.058, 0.182, -0.376, 0.12},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.128, -0.066, -0.314, -0.066},
|
||||
{-0.128, -0.376, 0.058, -0.066, -0.314, 0.12},
|
||||
{-0.066, -0.376, -0.066, 0.058, -0.314, 0.058},
|
||||
{0.058, -0.376, -0.128, 0.12, -0.314, -0.066},
|
||||
{0.058, -0.376, 0.058, 0.12, -0.314, 0.12}
|
||||
},
|
||||
connect_front = {
|
||||
--Base
|
||||
{-0.252, -0.5, -0.5, 0.244, -0.438, -0.252},
|
||||
--Railties
|
||||
{-0.19, -0.438, -0.438, 0.182, -0.376, -0.376},
|
||||
{-0.19, -0.438, -0.252, 0.182, -0.376, -0.19},
|
||||
{-0.066, -0.438, -0.128, 0.058, -0.376, -0.066},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.5, -0.066, -0.314, -0.128},
|
||||
{-0.128, -0.376, -0.066, -0.066, -0.314, -0.004},
|
||||
{0.058, -0.376, -0.5, 0.12, -0.314, -0.128},
|
||||
{0.058, -0.376, -0.066, 0.12, -0.004, -0.314}
|
||||
},
|
||||
connect_left = {
|
||||
--Base
|
||||
{-0.5, -0.5, -0.252, -0.252, -0.438, 0.244},
|
||||
--Railties
|
||||
{-0.438, -0.438, -0.19, -0.376, -0.376, 0.182},
|
||||
{-0.252, -0.438, -0.19, -0.12, -0.376, 0.182},
|
||||
{-0.128, -0.438, -0.066, -0.066, -0.376, 0.058},
|
||||
--Rails
|
||||
{-0.5, -0.376, -0.128, -0.128, -0.314, -0.066},
|
||||
{-0.066, -0.376, -0.128, -0.004, -0.314, -0.066},
|
||||
{-0.5, -0.376, 0.058, -0.128, -0.314, 0.12},
|
||||
{-0.066, -0.376, 0.058, -0.004, -0.314, 0.12}
|
||||
},
|
||||
connect_back = {
|
||||
--Base
|
||||
{-0.252, -0.5, 0.244, 0.244, -0.438, 0.492},
|
||||
--Railties
|
||||
{-0.066, 0.058, -0.438, 0.058, -0.376, 0.12},
|
||||
{-0.19, -0.438, 0.182, 0.182, -0.376, 0.244},
|
||||
{-0.19, -0.438, 0.368, 0.182, -0.376, 0.43},
|
||||
--Rails
|
||||
{-0.128, -0.376, -0.004, -0.066, -0.314, 0.058},
|
||||
{-0.128, -0.376, 0.12, -0.066, -0.314, 0.492},
|
||||
{0.058, -0.004, -0.376, 0.12, -0.314, 0.058},
|
||||
{0.058, -0.376, 0.12, 0.12, -0.314, 0.492}
|
||||
},
|
||||
connect_right = {
|
||||
--Base
|
||||
{0.244, -0.5, -0.252, 0.492, -0.438, 0.244},
|
||||
--Railties
|
||||
{0.058, -0.438, -0.066, 0.12, -0.376, 0.058},
|
||||
{0.182, -0.438, -0.19, 0.244, -0.376, 0.182},
|
||||
{0.368, -0.438, -0.19, 0.43, -0.376, 0.182},
|
||||
--Rails
|
||||
{-0.004, -0.376, -0.128, 0.058, -0.314, -0.066},
|
||||
{0.12, -0.376, -0.128, 0.492, -0.314, -0.066},
|
||||
{-0.004, -0.376, 0.058, 0.058, -0.314, 0.12},
|
||||
{0.12, -0.376, 0.058, 0.492, -0.314, 0.12}
|
||||
}
|
||||
},
|
||||
|
||||
node_box = rail_node_box,
|
||||
collision_box = rail_collision_box,
|
||||
connects_to = {"group:new", "group:structures"},
|
||||
|
||||
})
|
||||
}, {acceleration = 5})
|
||||
|
|
|
@ -8,24 +8,24 @@
|
|||
--TODO Set a limit to the size train will take from a location
|
||||
|
||||
local train_entity = {
|
||||
initial_properties = {
|
||||
physical = false,
|
||||
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
|
||||
visual = "mesh",
|
||||
mesh = "train.obj",
|
||||
visual_size = {x=1, y=1},
|
||||
textures = {"trains_train.png"}
|
||||
},
|
||||
initial_properties = {
|
||||
physical = false,
|
||||
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
|
||||
visual = "mesh",
|
||||
mesh = "train.obj",
|
||||
visual_size = {x=1, y=1},
|
||||
textures = {"trains_train.png"}
|
||||
},
|
||||
|
||||
punched = false,
|
||||
velocity = {x=0, y=0, z=0},
|
||||
old_dir = {x=1, y=0, z=0},
|
||||
old_pos = nil,
|
||||
old_switch = 0,
|
||||
railtype = nil,
|
||||
automation_timer = 0,
|
||||
town_train = false,
|
||||
crowd_sound = false
|
||||
punched = false,
|
||||
velocity = {x=0, y=0, z=0},
|
||||
old_dir = {x=1, y=0, z=0},
|
||||
old_pos = nil,
|
||||
old_switch = 0,
|
||||
railtype = nil,
|
||||
automation_timer = 0,
|
||||
town_train = false,
|
||||
crowd_sound = false
|
||||
}
|
||||
|
||||
local function get_object_id(object)
|
||||
|
@ -37,275 +37,285 @@ local function get_object_id(object)
|
|||
end
|
||||
|
||||
function train_entity:on_activate(staticdata, dtime_s)
|
||||
self.object:set_armor_groups({immortal=1})
|
||||
if string.sub(staticdata, 1, string.len("return")) ~= "return" then
|
||||
return
|
||||
end
|
||||
local data = minetest.deserialize(staticdata)
|
||||
if type(data) ~= "table" then
|
||||
return
|
||||
end
|
||||
self.railtype = data.railtype
|
||||
self.train_inv = data.train_inv
|
||||
self.town_train = data.town_train
|
||||
if data.old_dir then
|
||||
self.old_dir = data.old_dir
|
||||
end
|
||||
table.insert(train_cargo, get_object_id(self.object), {})
|
||||
self.object:set_armor_groups({immortal=1})
|
||||
if string.sub(staticdata, 1, string.len("return")) ~= "return" then
|
||||
return
|
||||
end
|
||||
local data = minetest.deserialize(staticdata)
|
||||
if type(data) ~= "table" then
|
||||
return
|
||||
end
|
||||
self.railtype = data.railtype
|
||||
self.train_inv = data.train_inv
|
||||
self.town_train = data.town_train
|
||||
if data.old_dir then
|
||||
self.old_dir = data.old_dir
|
||||
end
|
||||
table.insert(train_cargo, get_object_id(self.object), {})
|
||||
end
|
||||
|
||||
function train_entity:get_staticdata()
|
||||
return minetest.serialize({
|
||||
railtype = self.railtype,
|
||||
old_dir = self.old_dir,
|
||||
town_train = self.town_train,
|
||||
})
|
||||
return minetest.serialize({
|
||||
railtype = self.railtype,
|
||||
old_dir = self.old_dir,
|
||||
town_train = self.town_train,
|
||||
})
|
||||
end
|
||||
|
||||
function can_collect_train(player)
|
||||
local name = player:get_player_name()
|
||||
local inv = player:get_inventory()
|
||||
local creative = minetest.is_creative_enabled(name)
|
||||
local has_train = inv:contains_item("main", "minegistics_trains:train")
|
||||
return creative == false or has_train == false
|
||||
end
|
||||
|
||||
function train_entity:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
|
||||
local pos = self.object:get_pos()
|
||||
local vel = self.object:get_velocity()
|
||||
if not self.railtype or vector.equals(vel, {x=0, y=0, z=0}) then
|
||||
local node = minetest.get_node(pos).name
|
||||
self.railtype = minetest.get_item_group(node, "connect_to_raillike")
|
||||
end
|
||||
if not puncher or not puncher:is_player() then
|
||||
local train_dir = trains:get_rail_direction(pos, self.old_dir, nil, nil, self.railtype)
|
||||
if vector.equals(train_dir, {x=0, y=0, z=0}) then
|
||||
return
|
||||
end
|
||||
self.velocity = vector.multiply(train_dir, 2)
|
||||
self.punched = true
|
||||
return
|
||||
end
|
||||
if puncher:get_player_control().sneak then
|
||||
if self.sound_handle then
|
||||
minetest.sound_stop(self.sound_handle)
|
||||
end
|
||||
local inv = puncher:get_inventory()
|
||||
if not minetest.is_creative_enabled(puncher:get_player_name())
|
||||
or not inv:contains_item("main", "minegistics_trains:train") then
|
||||
local leftover = inv:add_item("main", "minegistics_trains:train")
|
||||
if not leftover:is_empty() then
|
||||
minetest.add_item(self.object:get_pos(), leftover)
|
||||
end
|
||||
end
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
local pos = self.object:get_pos()
|
||||
local vel = self.object:get_velocity()
|
||||
if not self.railtype or vector.equals(vel, {x=0, y=0, z=0}) then
|
||||
local node = minetest.get_node(pos).name
|
||||
self.railtype = minetest.get_item_group(node, "connect_to_raillike")
|
||||
end
|
||||
if not puncher or not puncher:is_player() then
|
||||
local train_dir = trains:get_rail_direction(pos, self.old_dir, nil, nil, self.railtype)
|
||||
if vector.equals(train_dir, {x=0, y=0, z=0}) then
|
||||
return
|
||||
end
|
||||
self.velocity = vector.multiply(train_dir, 2)
|
||||
self.punched = true
|
||||
return
|
||||
end
|
||||
if puncher:get_player_control().sneak then
|
||||
if self.sound_handle then
|
||||
minetest.sound_stop(self.sound_handle)
|
||||
end
|
||||
if can_collect_train(puncher) then
|
||||
local leftover = inv:add_item("main", "minegistics_trains:train")
|
||||
if not leftover:is_empty() then
|
||||
minetest.add_item(self.object:get_pos(), leftover)
|
||||
end
|
||||
end
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
|
||||
local punch_dir = trains:velocity_to_dir(puncher:get_look_dir())
|
||||
punch_dir.y = 0
|
||||
local train_dir = trains:get_rail_direction(pos, punch_dir, nil, nil, self.railtype)
|
||||
if vector.equals(train_dir, {x=0, y=0, z=0}) then
|
||||
return
|
||||
end
|
||||
local punch_dir = trains:velocity_to_dir(puncher:get_look_dir())
|
||||
punch_dir.y = 0
|
||||
local train_dir = trains:get_rail_direction(pos, punch_dir, nil, nil, self.railtype)
|
||||
if vector.equals(train_dir, {x=0, y=0, z=0}) then
|
||||
return
|
||||
end
|
||||
|
||||
local punch_interval = 1
|
||||
if tool_capabilities and tool_capabilities.full_punch_interval then
|
||||
punch_interval = tool_capabilities.full_punch_interval
|
||||
end
|
||||
time_from_last_punch = math.min(time_from_last_punch or punch_interval, punch_interval)
|
||||
local f = 2 * (time_from_last_punch / punch_interval)
|
||||
local punch_interval = 1
|
||||
if tool_capabilities and tool_capabilities.full_punch_interval then
|
||||
punch_interval = tool_capabilities.full_punch_interval
|
||||
end
|
||||
time_from_last_punch = math.min(time_from_last_punch or punch_interval, punch_interval)
|
||||
local f = 2 * (time_from_last_punch / punch_interval)
|
||||
|
||||
self.velocity = vector.multiply(train_dir, f)
|
||||
self.old_dir = train_dir
|
||||
self.punched = true
|
||||
self.velocity = vector.multiply(train_dir, f)
|
||||
self.old_dir = train_dir
|
||||
self.punched = true
|
||||
end
|
||||
|
||||
local function rail_on_step_event(handler, obj, dtime)
|
||||
if handler then
|
||||
handler(obj, dtime)
|
||||
end
|
||||
if handler then
|
||||
handler(obj, dtime)
|
||||
end
|
||||
end
|
||||
|
||||
local function rail_sound(self, dtime)
|
||||
if not self.sound_ttl then
|
||||
self.sound_ttl = 1.0
|
||||
return
|
||||
elseif self.sound_ttl > 0 then
|
||||
self.sound_ttl = self.sound_ttl - dtime
|
||||
return
|
||||
end
|
||||
self.sound_ttl = 1.0
|
||||
if self.sound_handle then
|
||||
local handle = self.sound_handle
|
||||
self.sound_handle = nil
|
||||
minetest.after(0.2, minetest.sound_stop, handle)
|
||||
end
|
||||
local vel = self.object:get_velocity()
|
||||
local speed = vector.length(vel)
|
||||
if speed > 0 then
|
||||
self.sound_handle = minetest.sound_play(
|
||||
"trains_train_moving", {
|
||||
object = self.object,
|
||||
gain = (speed / trains.speed_max) / 2,
|
||||
loop = true,
|
||||
})
|
||||
end
|
||||
if not self.sound_ttl then
|
||||
self.sound_ttl = 1.0
|
||||
return
|
||||
elseif self.sound_ttl > 0 then
|
||||
self.sound_ttl = self.sound_ttl - dtime
|
||||
return
|
||||
end
|
||||
self.sound_ttl = 1.0
|
||||
if self.sound_handle then
|
||||
local handle = self.sound_handle
|
||||
self.sound_handle = nil
|
||||
minetest.after(0.2, minetest.sound_stop, handle)
|
||||
end
|
||||
local vel = self.object:get_velocity()
|
||||
local speed = vector.length(vel)
|
||||
if speed > 0 then
|
||||
self.sound_handle = minetest.sound_play("trains_train_moving", {
|
||||
object = self.object,
|
||||
gain = (speed / trains.speed_max) / 2,
|
||||
loop = true,
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
local function get_railparams(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
return trains.railparams[node.name] or {}
|
||||
local node = minetest.get_node(pos)
|
||||
return trains.railparams[node.name] or {}
|
||||
end
|
||||
|
||||
local v3_len = vector.length
|
||||
|
||||
local function rail_on_step(self, dtime)
|
||||
local vel = self.object:get_velocity()
|
||||
if self.punched then
|
||||
vel = vector.add(vel, self.velocity)
|
||||
self.object:set_velocity(vel)
|
||||
self.old_dir.y = 0
|
||||
elseif vector.equals(vel, {x=0, y=0, z=0}) then
|
||||
return
|
||||
end
|
||||
local vel = self.object:get_velocity()
|
||||
|
||||
if self.punched then
|
||||
vel = vector.add(vel, self.velocity)
|
||||
self.object:set_velocity(vel)
|
||||
self.old_dir.y = 0
|
||||
elseif vector.equals(vel, {x=0, y=0, z=0}) then
|
||||
return
|
||||
end
|
||||
|
||||
local pos = self.object:get_pos()
|
||||
local train_dir = trains:velocity_to_dir(vel)
|
||||
local same_dir = vector.equals(train_dir, self.old_dir)
|
||||
local update = {}
|
||||
local pos = self.object:get_pos()
|
||||
local train_dir = trains:velocity_to_dir(vel)
|
||||
local same_dir = vector.equals(train_dir, self.old_dir)
|
||||
local update = {}
|
||||
|
||||
if self.old_pos and not self.punched and same_dir then
|
||||
local flo_pos = vector.round(pos)
|
||||
local flo_old = vector.round(self.old_pos)
|
||||
if vector.equals(flo_pos, flo_old) then
|
||||
return
|
||||
end
|
||||
end
|
||||
if self.old_pos and not self.punched and same_dir then
|
||||
local flo_pos = vector.round(pos)
|
||||
local flo_old = vector.round(self.old_pos)
|
||||
if vector.equals(flo_pos, flo_old) then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local stop_wiggle = false
|
||||
if self.old_pos and same_dir then
|
||||
local acc = self.object:get_acceleration()
|
||||
local distance = dtime * (v3_len(vel) + 0.5 * dtime * v3_len(acc))
|
||||
local stop_wiggle = false
|
||||
|
||||
if self.old_pos and same_dir then
|
||||
local acc = self.object:get_acceleration()
|
||||
local distance = dtime * (v3_len(vel) + 0.5 * dtime * v3_len(acc))
|
||||
|
||||
local new_pos, new_dir = trains:pathfinder(
|
||||
pos, self.old_pos, self.old_dir, distance,
|
||||
self.old_switch, self.railtype
|
||||
)
|
||||
local new_pos, new_dir = trains:pathfinder(
|
||||
pos, self.old_pos, self.old_dir, distance,
|
||||
self.old_switch, self.railtype
|
||||
)
|
||||
|
||||
if new_pos then
|
||||
pos = new_pos
|
||||
update.pos = true
|
||||
train_dir = new_dir
|
||||
end
|
||||
elseif self.old_pos and self.old_dir.y ~= 1 and not self.punched then
|
||||
stop_wiggle = true
|
||||
end
|
||||
if new_pos then
|
||||
pos = new_pos
|
||||
update.pos = true
|
||||
train_dir = new_dir
|
||||
end
|
||||
elseif self.old_pos and self.old_dir.y ~= 1 and not self.punched then
|
||||
stop_wiggle = true
|
||||
end
|
||||
|
||||
local railparams
|
||||
local railparams
|
||||
local dir, switch_keys = trains:get_rail_direction(pos, train_dir, self.old_switch, self.railtype)
|
||||
local dir_changed = not vector.equals(dir, self.old_dir)
|
||||
local new_acc = {x=0, y=0, z=0}
|
||||
|
||||
if stop_wiggle or vector.equals(dir, {x=0, y=0, z=0}) then
|
||||
vel = {x = 0, y = 0, z = 0}
|
||||
local pos_r = vector.round(pos)
|
||||
if not trains:is_rail(pos_r, self.railtype) and self.old_pos then
|
||||
pos = self.old_pos
|
||||
elseif not stop_wiggle then
|
||||
pos = pos_r
|
||||
else
|
||||
pos.y = math.floor(pos.y + 0.5)
|
||||
end
|
||||
update.pos = true
|
||||
update.vel = true
|
||||
else
|
||||
if dir_changed then
|
||||
vel = vector.multiply(dir, math.abs(vel.x + vel.z))
|
||||
update.vel = true
|
||||
if dir.y ~= self.old_dir.y then
|
||||
pos = vector.round(pos)
|
||||
update.pos = true
|
||||
end
|
||||
end
|
||||
|
||||
local dir, switch_keys = trains:get_rail_direction(
|
||||
pos, train_dir, self.old_switch, self.railtype
|
||||
)
|
||||
local dir_changed = not vector.equals(dir, self.old_dir)
|
||||
if dir.z ~= 0 and math.floor(pos.x + 0.5) ~= pos.x then
|
||||
pos.x = math.floor(pos.x + 0.5)
|
||||
update.pos = true
|
||||
end
|
||||
|
||||
if dir.x ~= 0 and math.floor(pos.z + 0.5) ~= pos.z then
|
||||
pos.z = math.floor(pos.z + 0.5)
|
||||
update.pos = true
|
||||
end
|
||||
|
||||
local new_acc = {x=0, y=0, z=0}
|
||||
if stop_wiggle or vector.equals(dir, {x=0, y=0, z=0}) then
|
||||
vel = {x = 0, y = 0, z = 0}
|
||||
local pos_r = vector.round(pos)
|
||||
if not trains:is_rail(pos_r, self.railtype)
|
||||
and self.old_pos then
|
||||
pos = self.old_pos
|
||||
elseif not stop_wiggle then
|
||||
pos = pos_r
|
||||
else
|
||||
pos.y = math.floor(pos.y + 0.5)
|
||||
end
|
||||
update.pos = true
|
||||
update.vel = true
|
||||
else
|
||||
if dir_changed then
|
||||
vel = vector.multiply(dir, math.abs(vel.x + vel.z))
|
||||
update.vel = true
|
||||
if dir.y ~= self.old_dir.y then
|
||||
pos = vector.round(pos)
|
||||
update.pos = true
|
||||
end
|
||||
end
|
||||
local acc = dir.y * -4.0
|
||||
|
||||
if dir.z ~= 0 and math.floor(pos.x + 0.5) ~= pos.x then
|
||||
pos.x = math.floor(pos.x + 0.5)
|
||||
update.pos = true
|
||||
end
|
||||
if dir.x ~= 0 and math.floor(pos.z + 0.5) ~= pos.z then
|
||||
pos.z = math.floor(pos.z + 0.5)
|
||||
update.pos = true
|
||||
end
|
||||
railparams = get_railparams(pos)
|
||||
|
||||
local acc = dir.y * -4.0
|
||||
local speed_mod = railparams.acceleration
|
||||
if speed_mod and speed_mod ~= 0 then
|
||||
acc = acc + speed_mod
|
||||
else
|
||||
acc = acc
|
||||
end
|
||||
new_acc = vector.multiply(dir, acc)
|
||||
end
|
||||
|
||||
railparams = get_railparams(pos)
|
||||
local max_vel = trains.speed_max
|
||||
|
||||
for _, v in pairs({"x","y","z"}) do
|
||||
if math.abs(vel[v]) > max_vel then
|
||||
vel[v] = trains:get_sign(vel[v]) * max_vel
|
||||
new_acc[v] = 0
|
||||
update.vel = true
|
||||
end
|
||||
end
|
||||
|
||||
local speed_mod = railparams.acceleration
|
||||
if speed_mod and speed_mod ~= 0 then
|
||||
-- Try to make it similar to the original trains mod
|
||||
acc = acc + speed_mod
|
||||
else
|
||||
acc = acc
|
||||
end
|
||||
self.object:set_acceleration(new_acc)
|
||||
self.old_pos = vector.round(pos)
|
||||
|
||||
if not vector.equals(dir, {x=0, y=0, z=0}) and not stop_wiggle then
|
||||
self.old_dir = vector.new(dir)
|
||||
end
|
||||
|
||||
self.old_switch = switch_keys
|
||||
|
||||
new_acc = vector.multiply(dir, acc)
|
||||
end
|
||||
if self.punched then
|
||||
self.punched = false
|
||||
update.vel = true
|
||||
end
|
||||
|
||||
local max_vel = trains.speed_max
|
||||
for _, v in pairs({"x","y","z"}) do
|
||||
if math.abs(vel[v]) > max_vel then
|
||||
vel[v] = trains:get_sign(vel[v]) * max_vel
|
||||
new_acc[v] = 0
|
||||
update.vel = true
|
||||
end
|
||||
end
|
||||
railparams = railparams or get_railparams(pos)
|
||||
|
||||
self.object:set_acceleration(new_acc)
|
||||
self.old_pos = vector.round(pos)
|
||||
if not vector.equals(dir, {x=0, y=0, z=0}) and not stop_wiggle then
|
||||
self.old_dir = vector.new(dir)
|
||||
end
|
||||
self.old_switch = switch_keys
|
||||
if not (update.vel or update.pos) then
|
||||
rail_on_step_event(railparams.on_step, self, dtime)
|
||||
return
|
||||
end
|
||||
|
||||
if self.punched then
|
||||
self.punched = false
|
||||
update.vel = true
|
||||
end
|
||||
local yaw = 0
|
||||
|
||||
if self.old_dir.x < 0 then
|
||||
yaw = 0.5
|
||||
elseif self.old_dir.x > 0 then
|
||||
yaw = 1.5
|
||||
elseif self.old_dir.z < 0 then
|
||||
yaw = 1
|
||||
end
|
||||
|
||||
self.object:set_yaw(yaw * math.pi)
|
||||
|
||||
railparams = railparams or get_railparams(pos)
|
||||
local anim = {x=0, y=0}
|
||||
if dir.y == -1 then
|
||||
anim = {x=1, y=1}
|
||||
elseif dir.y == 1 then
|
||||
anim = {x=2, y=2}
|
||||
end
|
||||
|
||||
self.object:set_animation(anim, 1, 0)
|
||||
|
||||
if not (update.vel or update.pos) then
|
||||
rail_on_step_event(railparams.on_step, self, dtime)
|
||||
return
|
||||
end
|
||||
if update.vel then
|
||||
self.object:set_velocity(vel)
|
||||
end
|
||||
|
||||
if update.pos then
|
||||
if dir_changed then
|
||||
self.object:set_pos(pos)
|
||||
else
|
||||
self.object:move_to(pos)
|
||||
end
|
||||
end
|
||||
|
||||
local yaw = 0
|
||||
if self.old_dir.x < 0 then
|
||||
yaw = 0.5
|
||||
elseif self.old_dir.x > 0 then
|
||||
yaw = 1.5
|
||||
elseif self.old_dir.z < 0 then
|
||||
yaw = 1
|
||||
end
|
||||
self.object:set_yaw(yaw * math.pi)
|
||||
|
||||
local anim = {x=0, y=0}
|
||||
if dir.y == -1 then
|
||||
anim = {x=1, y=1}
|
||||
elseif dir.y == 1 then
|
||||
anim = {x=2, y=2}
|
||||
end
|
||||
self.object:set_animation(anim, 1, 0)
|
||||
|
||||
if update.vel then
|
||||
self.object:set_velocity(vel)
|
||||
end
|
||||
if update.pos then
|
||||
if dir_changed then
|
||||
self.object:set_pos(pos)
|
||||
else
|
||||
self.object:move_to(pos)
|
||||
end
|
||||
end
|
||||
|
||||
rail_on_step_event(railparams.on_step, self, dtime)
|
||||
rail_on_step_event(railparams.on_step, self, dtime)
|
||||
end
|
||||
|
||||
--enables filled train mesh.
|
||||
|
@ -359,9 +369,6 @@ local function structure_check(train, dtime)
|
|||
train_inv[lump] = 0
|
||||
end
|
||||
if train_inv[lump] > 0 then
|
||||
if lump == "minegistics_basenodes:planks" then
|
||||
minetest.chat_send_all("ERROR ERROR ERROR ERROR")
|
||||
end
|
||||
contents:add_item("main", lump .. " " .. train_inv[lump])
|
||||
train_inv[lump] = 0
|
||||
ore_hauler = true
|
||||
|
@ -384,53 +391,6 @@ local function structure_check(train, dtime)
|
|||
set_train_filled(train)
|
||||
end
|
||||
end
|
||||
train:on_punch()
|
||||
elseif structure_name == "minegistics:Market" or structure_name == "minegistics:Warehouse" then
|
||||
if structure_name == "minegistics:Market" and train.town_train == true then
|
||||
minetest.get_meta(direction):set_int("has_town", 1)
|
||||
spawn_passengers(pos)
|
||||
if train.crowd_sound == false then
|
||||
minetest.sound_play('trains_people', {
|
||||
pos = pos,
|
||||
loop = false,
|
||||
max_hear_distance = 16
|
||||
})
|
||||
train.crowd_sound = true
|
||||
end
|
||||
else
|
||||
for _, lump in pairs(resources) do
|
||||
if train_inv[lump] == nil then
|
||||
train_inv[lump] = 0
|
||||
end
|
||||
if train_inv[lump] > 0 then
|
||||
contents:add_item("main", lump .. " " .. train_inv[lump])
|
||||
train_inv[lump] = 0
|
||||
end
|
||||
end
|
||||
for input, output in pairs(products) do
|
||||
if train_inv[output] == nil then
|
||||
train_inv[output] = 0
|
||||
end
|
||||
if train_inv[output] > 0 then
|
||||
contents:add_item("main", output .. " " .. train_inv[output])
|
||||
train_inv[output] = 0
|
||||
end
|
||||
end
|
||||
set_train_empty(train)
|
||||
train:on_punch()
|
||||
end
|
||||
elseif structure_name == "minegistics:PowerPlant" then
|
||||
for _, fuel in pairs(fuels) do
|
||||
if train_inv[fuel] == nil then
|
||||
train_inv[fuel] = 0
|
||||
end
|
||||
if train_inv[fuel] > 0 then
|
||||
contents:add_item("main", fuel .. " " .. train_inv[fuel])
|
||||
train_inv[fuel] = 0
|
||||
end
|
||||
end
|
||||
set_train_empty(train)
|
||||
train:on_punch()
|
||||
elseif structure_name == "minegistics:Town" then
|
||||
train.town_train = true
|
||||
spawn_passengers(pos)
|
||||
|
@ -442,6 +402,23 @@ local function structure_check(train, dtime)
|
|||
})
|
||||
train.crowd_sound = true
|
||||
end
|
||||
elseif structure_name == "minegistics:Market" and train.town_train == true then
|
||||
minetest.get_meta(direction):set_int("has_town", 1)
|
||||
spawn_passengers(pos)
|
||||
if train.crowd_sound == false then
|
||||
minetest.sound_play('trains_people', {
|
||||
pos = pos,
|
||||
loop = false,
|
||||
max_hear_distance = 16
|
||||
})
|
||||
train.crowd_sound = true
|
||||
end
|
||||
elseif contents ~= nil then
|
||||
for item, amount in pairs(train_inv) do
|
||||
contents:add_item("main", item .. " " .. amount)
|
||||
train_inv[item] = 0
|
||||
end
|
||||
set_train_empty(train)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -485,39 +462,43 @@ end
|
|||
minetest.register_entity("minegistics_trains:train", train_entity)
|
||||
|
||||
minetest.register_craftitem("minegistics_trains:train", {
|
||||
description = "Train: " ..
|
||||
"Carries resources from one building to another.\n" ..
|
||||
"Must be placed on a rail. (Shift+Click to pick up)",
|
||||
inventory_image = "train_wield.png",
|
||||
wield_image = "train_wield.png",
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
local under = pointed_thing.under
|
||||
local node = minetest.get_node(under)
|
||||
local udef = minetest.registered_nodes[node.name]
|
||||
if udef and udef.on_rightclick and
|
||||
not (placer and placer:is_player() and
|
||||
placer:get_player_control().sneak) then
|
||||
return udef.on_rightclick(under, node, placer, itemstack,
|
||||
pointed_thing) or itemstack
|
||||
end
|
||||
description = "Train: " ..
|
||||
"Carries resources from one building to another.\n" ..
|
||||
"Must be placed on a rail. (Shift+Click to pick up)",
|
||||
inventory_image = "train_wield.png",
|
||||
wield_image = "train_wield.png",
|
||||
on_place = function(itemstack, placer, pointed_thing)
|
||||
local under = pointed_thing.under
|
||||
local node = minetest.get_node(under)
|
||||
local udef = minetest.registered_nodes[node.name]
|
||||
|
||||
if udef and udef.on_rightclick and not (placer and placer:is_player() and placer:get_player_control().sneak) then
|
||||
return udef.on_rightclick(under, node, placer, itemstack,
|
||||
pointed_thing) or itemstack
|
||||
end
|
||||
|
||||
if not pointed_thing.type == "node" then
|
||||
return
|
||||
end
|
||||
if trains:is_rail(pointed_thing.under) then
|
||||
minetest.add_entity(pointed_thing.under, "minegistics_trains:train")
|
||||
elseif trains:is_rail(pointed_thing.above) then
|
||||
minetest.add_entity(pointed_thing.above, "minegistics_trains:train")
|
||||
else
|
||||
return
|
||||
end
|
||||
if not pointed_thing.type == "node" then
|
||||
return
|
||||
end
|
||||
|
||||
if trains:is_rail(pointed_thing.under) then
|
||||
minetest.add_entity(pointed_thing.under, "minegistics_trains:train")
|
||||
elseif trains:is_rail(pointed_thing.above) then
|
||||
minetest.add_entity(pointed_thing.above, "minegistics_trains:train")
|
||||
else
|
||||
return
|
||||
end
|
||||
|
||||
minetest.sound_play({name = "default_place_node_metal", gain = 0.5},
|
||||
{pos = pointed_thing.above}, true)
|
||||
minetest.sound_play('trains_people', {
|
||||
pos = pointed_thing.above,
|
||||
loop = false,
|
||||
max_hear_distance = 16
|
||||
})
|
||||
|
||||
if not minetest.is_creative_enabled(placer:get_player_name()) then
|
||||
itemstack:take_item()
|
||||
end
|
||||
return itemstack
|
||||
end,
|
||||
if not minetest.is_creative_enabled(placer:get_player_name()) then
|
||||
itemstack:take_item()
|
||||
end
|
||||
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue