diff options
author | orwell96 <mono96.mml@gmail.com> | 2016-08-21 16:30:36 +0200 |
---|---|---|
committer | orwell96 <mono96.mml@gmail.com> | 2016-08-21 16:30:36 +0200 |
commit | af6212170ed6d68c6210adfbc43982c304e7e15d (patch) | |
tree | 9f7c4a317c94fd8ad0d88ffdb6cb817f617f3e2e /tracks.lua | |
parent | 267434b2c18ad1386f9e8cd3829695de541eb8f0 (diff) | |
download | advtrains-af6212170ed6d68c6210adfbc43982c304e7e15d.tar.gz advtrains-af6212170ed6d68c6210adfbc43982c304e7e15d.tar.bz2 advtrains-af6212170ed6d68c6210adfbc43982c304e7e15d.zip |
Extending to 30deg rails, creating and adding the models
Diffstat (limited to 'tracks.lua')
-rw-r--r-- | tracks.lua | 213 |
1 files changed, 162 insertions, 51 deletions
@@ -124,66 +124,66 @@ end function advtrains.register_tracks_finer(tracktype, def)
local function make_switchfunc(suffix_target)
return function(pos, node)
- if advtrains.is_train_at_pos(pos) then return end
- advtrains.invalidate_all_paths()
- minetest.set_node(pos, {name=def.nodename_prefix.."_"..suffix_target, param2=node.param2})
- advtrains.reset_trackdb_position(pos)
+ if advtrains.is_train_at_pos(pos) then return end
+ advtrains.invalidate_all_paths()
+ minetest.set_node(pos, {name=def.nodename_prefix.."_"..suffix_target, param2=node.param2})
+ advtrains.reset_trackdb_position(pos)
+ end
end
-end
-local function make_overdef(img_suffix, conn1, conn2, switchfunc)
- return {
- tiles = {def.texture_prefix.."_"..img_suffix..".png"},
- inventory_image = def.texture_prefix.."_"..img_suffix..".png",
- wield_image = def.texture_prefix.."_"..img_suffix..".png",
- connect1=conn1,
- connect2=conn2,
- on_rightclick=switchfunc,
- }
-end
-local common_def=advtrains.merge_tables({
- description = def.description,
- drawtype = "mesh",
- mesh = "trackplane.b3d",
- paramtype="light",
- paramtype2="facedir",
- walkable = false,
- selection_box = {
- type = "fixed",
- fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
- },
- groups = {
- attached_node=1,
- ["advtrains_track_"..tracktype]=1,
- dig_immediate=2,
- not_in_creative_inventory=1,
- },
- rely1=0,
- rely2=0,
- railheight=0,
- drop="advtrains:placetrack_"..tracktype,
- --on_rightclick=function(pos, node, clicker)
- -- minetest.set_node(pos, {name=node.name, param2=(node.param2+1)%4})
- --end
- can_dig=function(pos)
- return not advtrains.is_train_at_pos(pos)
-end,
-after_dig_node=function(pos)
-advtrains.invalidate_all_paths()
-advtrains.reset_trackdb_position(pos)
+ local function make_overdef(img_suffix, conn1, conn2, switchfunc)
+ return {
+ tiles = {def.texture_prefix.."_"..img_suffix..".png"},
+ inventory_image = def.texture_prefix.."_"..img_suffix..".png",
+ wield_image = def.texture_prefix.."_"..img_suffix..".png",
+ connect1=conn1,
+ connect2=conn2,
+ on_rightclick=switchfunc,
+ }
+ end
+ local common_def=advtrains.merge_tables({
+ description = def.description,
+ drawtype = "mesh",
+ mesh = "trackplane.b3d",
+ paramtype="light",
+ paramtype2="facedir",
+ walkable = false,
+ selection_box = {
+ type = "fixed",
+ fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
+ },
+ groups = {
+ attached_node=1,
+ ["advtrains_track_"..tracktype]=1,
+ dig_immediate=2,
+ --not_in_creative_inventory=1,
+ },
+ rely1=0,
+ rely2=0,
+ railheight=0,
+ drop="advtrains:placetrack_"..tracktype,
+ --on_rightclick=function(pos, node, clicker)
+ -- minetest.set_node(pos, {name=node.name, param2=(node.param2+1)%4})
+ --end
+ can_dig=function(pos)
+ return not advtrains.is_train_at_pos(pos)
+ end,
+ after_dig_node=function(pos)
+ advtrains.invalidate_all_paths()
+ advtrains.reset_trackdb_position(pos)
end,
after_place_node=function(pos)
- advtrains.reset_trackdb_position(pos)
+ advtrains.reset_trackdb_position(pos)
end,
}, def.common or {})
minetest.register_node(def.nodename_prefix.."_st", advtrains.merge_tables(common_def, make_overdef("st", 0, 8), def.straight or {}))
- minetest.register_node(def.nodename_prefix.."_st_22", advtrains.merge_tables(common_def, make_overdef("st_22", 1, 9), def.straight22 or {}))
+ minetest.register_node(def.nodename_prefix.."_st_30", advtrains.merge_tables(common_def, make_overdef("st_30", 1, 9), def.straight30 or {}))
minetest.register_node(def.nodename_prefix.."_st_45", advtrains.merge_tables(common_def, make_overdef("st_45", 2, 10), def.straight45 or {}))
- minetest.register_node(def.nodename_prefix.."_st_67", advtrains.merge_tables(common_def, make_overdef("st_67", 3, 11), def.straight67 or {}))
+ minetest.register_node(def.nodename_prefix.."_st_60", advtrains.merge_tables(common_def, make_overdef("st_60", 3, 11), def.straight60 or {}))
minetest.register_node(def.nodename_prefix.."_cr", advtrains.merge_tables(common_def, make_overdef("cr", 0, 7), def.curve or {}))
- minetest.register_node(def.nodename_prefix.."_cr_22", advtrains.merge_tables(common_def, make_overdef("cr_22", 1, 8), def.curve45 or {}))
+ minetest.register_node(def.nodename_prefix.."_cr_30", advtrains.merge_tables(common_def, make_overdef("cr_30", 1, 8), def.curve45 or {}))
minetest.register_node(def.nodename_prefix.."_cr_45", advtrains.merge_tables(common_def, make_overdef("cr_45", 2, 9), def.curve45 or {}))
- minetest.register_node(def.nodename_prefix.."_cr_67", advtrains.merge_tables(common_def, make_overdef("cr_67", 3, 10), def.curve45 or {}))
+ minetest.register_node(def.nodename_prefix.."_cr_60", advtrains.merge_tables(common_def, make_overdef("cr_60", 3, 10), def.curve45 or {}))
--[[advtrains.trackplacer_register(def.nodename_prefix.."_st", 0, 8)
advtrains.trackplacer_register(def.nodename_prefix.."_st_45", 2, 10)
@@ -223,6 +223,108 @@ advtrains.reset_trackdb_position(pos) table.insert(advtrains.all_tracktypes, tracktype)
end
+--def must include: models_prefix, models_suffix(with dot)
+-- def.shared_texture="full_name.png" if shared texture for all models is wanted
+function advtrains.register_tracks_modeled(tracktype, def)
+ local function make_switchfunc(suffix_target)
+ return function(pos, node)
+ if advtrains.is_train_at_pos(pos) then return end
+ advtrains.invalidate_all_paths()
+ minetest.set_node(pos, {name=def.nodename_prefix.."_"..suffix_target, param2=node.param2})
+ advtrains.reset_trackdb_position(pos)
+ end
+ end
+ local function make_overdef(img_suffix, conn1, conn2, switchfunc)
+ return {
+ mesh = def.models_prefix.."_"..img_suffix..def.models_suffix,
+ tiles = {def.shared_texture or (def.texture_prefix.."_"..img_suffix..".png")},
+ inventory_image = def.texture_prefix.."_"..img_suffix..".png",
+ wield_image = def.texture_prefix.."_"..img_suffix..".png",
+ connect1=conn1,
+ connect2=conn2,
+ on_rightclick=switchfunc,
+ }
+ end
+ local common_def=advtrains.merge_tables({
+ description = def.description,
+ drawtype = "mesh",
+ paramtype="light",
+ paramtype2="facedir",
+ walkable = false,
+ selection_box = {
+ type = "fixed",
+ fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
+ },
+ groups = {
+ attached_node=1,
+ ["advtrains_track_"..tracktype]=1,
+ dig_immediate=2,
+ --not_in_creative_inventory=1,
+ },
+ rely1=0,
+ rely2=0,
+ railheight=0,
+ drop="advtrains:placetrack_"..tracktype,
+ --on_rightclick=function(pos, node, clicker)
+ -- minetest.set_node(pos, {name=node.name, param2=(node.param2+1)%4})
+ --end
+ can_dig=function(pos)
+ return not advtrains.is_train_at_pos(pos)
+ end,
+ after_dig_node=function(pos)
+ advtrains.invalidate_all_paths()
+ advtrains.reset_trackdb_position(pos)
+ end,
+ after_place_node=function(pos)
+ advtrains.reset_trackdb_position(pos)
+ end,
+ }, def.common or {})
+ minetest.register_node(def.nodename_prefix.."_st", advtrains.merge_tables(common_def, make_overdef("st", 0, 8), def.straight or {}))
+ minetest.register_node(def.nodename_prefix.."_st_30", advtrains.merge_tables(common_def, make_overdef("st_30", 1, 9), def.straight30 or {}))
+ minetest.register_node(def.nodename_prefix.."_st_45", advtrains.merge_tables(common_def, make_overdef("st_45", 2, 10), def.straight45 or {}))
+ minetest.register_node(def.nodename_prefix.."_st_60", advtrains.merge_tables(common_def, make_overdef("st_60", 3, 11), def.straight60 or {}))
+
+ minetest.register_node(def.nodename_prefix.."_cr", advtrains.merge_tables(common_def, make_overdef("cr", 0, 7), def.curve or {}))
+ minetest.register_node(def.nodename_prefix.."_cr_30", advtrains.merge_tables(common_def, make_overdef("cr_30", 1, 8), def.curve45 or {}))
+ minetest.register_node(def.nodename_prefix.."_cr_45", advtrains.merge_tables(common_def, make_overdef("cr_45", 2, 9), def.curve45 or {}))
+ minetest.register_node(def.nodename_prefix.."_cr_60", advtrains.merge_tables(common_def, make_overdef("cr_60", 3, 10), def.curve45 or {}))
+
+ --[[advtrains.trackplacer_register(def.nodename_prefix.."_st", 0, 8)
+ advtrains.trackplacer_register(def.nodename_prefix.."_st_45", 2, 10)
+ advtrains.trackplacer_register(def.nodename_prefix.."_cr", 0, 6)
+ advtrains.trackplacer_register(def.nodename_prefix.."_cr_45", 2, 8)
+ --]]
+ --[[
+ minetest.register_node(def.nodename_prefix.."_swl_st", advtrains.merge_tables(common_def, make_overdef("swl_st", 0, 8, make_switchfunc("swl_cr")), def.lswitchst or {}))
+ minetest.register_node(def.nodename_prefix.."_swl_st_45", advtrains.merge_tables(common_def, make_overdef("swl_st_45", 2, 10, make_switchfunc("swl_cr_45")), def.lswitchst45 or {}))
+ minetest.register_node(def.nodename_prefix.."_swl_cr", advtrains.merge_tables(common_def, make_overdef("swl_cr", 0, 6, make_switchfunc("swl_st")), def.lswitchcr or {}))
+ minetest.register_node(def.nodename_prefix.."_swl_cr_45", advtrains.merge_tables(common_def, make_overdef("swl_cr_45", 2, 8, make_switchfunc("swl_st_45")), def.lswitchcr45 or {}))
+
+ minetest.register_node(def.nodename_prefix.."_swr_st", advtrains.merge_tables(common_def, make_overdef("swr_st", 0, 8, make_switchfunc("swr_cr")), def.rswitchst or {}))
+ minetest.register_node(def.nodename_prefix.."_swr_st_45", advtrains.merge_tables(common_def, make_overdef("swr_st_45", 2, 10, make_switchfunc("swr_cr_45")), def.rswitchst45 or {}))
+ minetest.register_node(def.nodename_prefix.."_swr_cr", advtrains.merge_tables(common_def, make_overdef("swr_cr", 0, 10, make_switchfunc("swr_st")), def.rswitchcr or {}))
+ minetest.register_node(def.nodename_prefix.."_swr_cr_45", advtrains.merge_tables(common_def, make_overdef("swr_cr_45", 2, 12, make_switchfunc("swr_st_45")), def.rswitchcr45 or {}))
+
+ minetest.register_node(def.nodename_prefix.."_vert1", advtrains.merge_tables(common_def, make_overdef("vert1", 0, 8), {
+ mesh = "trackvertical1.b3d",
+ rely1=0,
+ rely2=0.5,
+ railheight=0.25,
+ description = def.description.." (vertical track lower node)",
+ }, def.vert1 or {}))
+ minetest.register_node(def.nodename_prefix.."_vert2", advtrains.merge_tables(common_def, make_overdef("vert2", 0, 8), {
+ mesh = "trackvertical2.b3d",
+ rely1=0.5,
+ rely2=1,
+ railheight=0.75,
+ description = def.description.." (vertical track upper node)",
+ },def.vert2 or {}))
+ ]]
+
+ advtrains.register_track_placer(def.nodename_prefix, def.texture_prefix, def.description)
+ table.insert(advtrains.all_tracktypes, tracktype)
+end
+
advtrains.register_tracks("regular", {
nodename_prefix="advtrains:track",
texture_prefix="advtrains_track",
@@ -230,11 +332,20 @@ advtrains.register_tracks("regular", { })
advtrains.register_tracks_finer("fineturns", {
- nodename_prefix="advtrains:dtrack",
+ nodename_prefix="advtrains:olddtrack",
texture_prefix="advtrains_dtrack",
description="Fine Turn Train Track",
})
+advtrains.register_tracks_modeled("default", {
+ nodename_prefix="advtrains:dtrack",
+ texture_prefix="advtrains_dtrack",
+ models_prefix="advtrains_dtrack",
+ models_suffix=".b3d",
+ shared_texture="advtrains_dtrack_rail.png",
+ description="New Default Train Track",
+})
+
function advtrains.is_track_and_drives_on(nodename, drives_on)
if not minetest.registered_nodes[nodename] then
return false
|