diff options
Diffstat (limited to 'advtrains/track_reg_helper.lua')
-rw-r--r-- | advtrains/track_reg_helper.lua | 79 |
1 files changed, 11 insertions, 68 deletions
diff --git a/advtrains/track_reg_helper.lua b/advtrains/track_reg_helper.lua index f2ada81..e2f71e8 100644 --- a/advtrains/track_reg_helper.lua +++ b/advtrains/track_reg_helper.lua @@ -168,47 +168,12 @@ advtrains.ap.t_30deg_slope={ vst31={conns = conns(8,0,0,0.33), rail_y = 0.16, desc = "uphill 1/3", slope=true}, vst32={conns = conns(8,0,0.33,0.66), rail_y = 0.5, desc = "uphill 2/3", slope=true}, vst33={conns = conns(8,0,0.66,1), rail_y = 0.83, desc = "uphill 3/3", slope=true}, - vst41={conns = conns(8,0,0,1/4), rail_y = 1/4 - 1/8, desc = "uphill 1/4", slope=true}, - vst42={conns = conns(8,0,1/4,2/4), rail_y = 2/4 - 1/8, desc = "uphill 2/4", slope=true}, - vst43={conns = conns(8,0,2/4,3/4), rail_y = 3/4 - 1/8, desc = "uphill 3/4", slope=true}, - vst44={conns = conns(8,0,3/4,1), rail_y = 1 - 1/8, desc = "uphill 4/4", slope=true}, - vst51={conns = conns(8,0,0,1/5), rail_y = 1/5 - 1/10, desc = "uphill 1/5", slope=true}, - vst52={conns = conns(8,0,1/5,2/5), rail_y = 2/5 - 1/10, desc = "uphill 2/5", slope=true}, - vst53={conns = conns(8,0,2/5,3/5), rail_y = 3/5 - 1/10, desc = "uphill 3/5", slope=true}, - vst54={conns = conns(8,0,3/5,4/5), rail_y = 4/5 - 1/10, desc = "uphill 4/5", slope=true}, - vst55={conns = conns(8,0,4/5,1), rail_y = 5/5 - 1/10, desc = "uphill 5/5", slope=true}, - vst61={conns = conns(8,0,0,1/6), rail_y = 1/6 - 1/12, desc = "uphill 1/6", slope=true}, - vst62={conns = conns(8,0,1/6,2/6), rail_y = 2/6 - 1/12, desc = "uphill 2/6", slope=true}, - vst63={conns = conns(8,0,2/6,3/6), rail_y = 3/6 - 1/12, desc = "uphill 3/6", slope=true}, - vst64={conns = conns(8,0,3/6,4/6), rail_y = 4/6 - 1/12, desc = "uphill 4/6", slope=true}, - vst65={conns = conns(8,0,4/6,5/6), rail_y = 5/6 - 1/12, desc = "uphill 5/6", slope=true}, - vst66={conns = conns(8,0,5/6,1), rail_y = 6/6 - 1/12, desc = "uphill 6/6", slope=true}, - vst71={conns = conns(8,0,0,1/7), rail_y = 1/7 - 1/14, desc = "uphill 1/7", slope=true}, - vst72={conns = conns(8,0,1/7,2/7), rail_y = 2/7 - 1/14, desc = "uphill 2/7", slope=true}, - vst73={conns = conns(8,0,2/7,3/7), rail_y = 3/7 - 1/14, desc = "uphill 3/7", slope=true}, - vst74={conns = conns(8,0,3/7,4/7), rail_y = 4/7 - 1/14, desc = "uphill 4/7", slope=true}, - vst75={conns = conns(8,0,4/7,5/7), rail_y = 5/7 - 1/14, desc = "uphill 5/7", slope=true}, - vst76={conns = conns(8,0,5/7,6/7), rail_y = 6/7 - 1/14, desc = "uphill 6/7", slope=true}, - vst77={conns = conns(8,0,6/7,1), rail_y = 7/7 - 1/14, desc = "uphill 7/7", slope=true}, - vst81={conns = conns(8,0,0,1/8), rail_y = 1/8 - 1/16, desc = "uphill 1/8", slope=true}, - vst82={conns = conns(8,0,1/8,2/8), rail_y = 2/8 - 1/16, desc = "uphill 2/8", slope=true}, - vst83={conns = conns(8,0,2/8,3/8), rail_y = 3/8 - 1/16, desc = "uphill 3/8", slope=true}, - vst84={conns = conns(8,0,3/8,4/8), rail_y = 4/8 - 1/16, desc = "uphill 4/8", slope=true}, - vst85={conns = conns(8,0,4/8,5/8), rail_y = 5/8 - 1/16, desc = "uphill 5/8", slope=true}, - vst86={conns = conns(8,0,5/8,6/8), rail_y = 6/8 - 1/16, desc = "uphill 6/8", slope=true}, - vst87={conns = conns(8,0,6/8,7/8), rail_y = 7/8 - 1/16, desc = "uphill 7/8", slope=true}, - vst88={conns = conns(8,0,7/8,1), rail_y = 8/8 - 1/16, desc = "uphill 8/8", slope=true}, }, regsp=true, slopeplacer={ [2]={"vst1", "vst2"}, [3]={"vst31", "vst32", "vst33"}, - [4]={"vst41", "vst42", "vst43", "vst44"}, - [5]={"vst51", "vst52", "vst53", "vst54", "vst55"}, - [6]={"vst61", "vst62", "vst63", "vst64", "vst65", "vst66"}, - [7]={"vst71", "vst72", "vst73", "vst74", "vst75", "vst76", "vst77"}, - [8]={"vst81", "vst82", "vst83", "vst84", "vst85", "vst86", "vst87", "vst88"}, - max=8,--highest entry + max=3,--highest entry }, slopeplacer_45={ [2]={"vst1_45", "vst2_45"}, @@ -519,6 +484,11 @@ local function append_statemap_suffix(state_map, nnpref, rot) return t end +function advtrains.default_suitable_substrate(upos) + return core.registered_nodes[core.get_node(upos).name] + and core.registered_nodes[core.get_node(upos).name].walkable +end + function advtrains.register_tracks(tracktype, def, preset) if not preset.v25_format then error("advtrains.register_tracks(): A track preset for pre-v2.5 is used with advtrains 2.5+. Mod probably defines own track preset instead of using it from the advtrains.ap table! Please check track mod compatibility!") @@ -531,7 +501,7 @@ function advtrains.register_tracks(tracktype, def, preset) inventory_image = def.texture_prefix.."_placer.png", wield_image = def.texture_prefix.."_placer.png", groups={advtrains_trackplacer=1, digtron_on_place=1}, - liquids_pointable = true, + liquids_pointable = false, on_place = function(itemstack, placer, pointed_thing) local name = placer:get_player_name() if not name then @@ -543,20 +513,8 @@ function advtrains.register_tracks(tracktype, def, preset) if not advtrains.check_track_protection(pos, name) then return itemstack, false end - local node = core.get_node(pos) - local nname = node.name - local ndef = core.registered_nodes[nname] - if ndef ~= nil and ndef.buildable_to then - local s - if def.suitable_substrate ~= nil then - s = def.suitable_substrate(upos) - else - local unode = core.get_node(upos) - local uname = unode.name - local udef = core.registered_nodes[uname] - s = udef ~= nil and udef.walkable - end - if s then + if minetest.registered_nodes[minetest.get_node(pos).name] and minetest.registered_nodes[minetest.get_node(pos).name].buildable_to then + if (def.suitable_substrate and def.suitable_substrate or advtrains.default_suitable_substrate)(upos) then -- minetest.chat_send_all(nnprefix) local yaw = placer:get_look_horizontal() advtrains.trackplacer.place_track(pos, nnprefix, name, yaw) @@ -705,21 +663,6 @@ function sl.register_placer(def, preset) on_place = sl.create_slopeplacer_on_place(def, preset) }) end - -local function check_slope_exists(nodename_prefix, lookup, step) - if not lookup[step] then - return false - end - local placenodes = lookup[step] - while step > 0 do - if core.registered_nodes[nodename_prefix.."_"..placenodes[step]] == nil then - return false - end - step=step-1 - end - return true -end - --(itemstack, placer, pointed_thing) function sl.create_slopeplacer_on_place(def, preset) return function(istack, player, pt) @@ -774,7 +717,7 @@ function sl.create_slopeplacer_on_place(def, preset) --next node solid? if not minetest.registered_nodes[node.name] or not minetest.registered_nodes[node.name].buildable_to or advtrains.is_protected(pos, player:get_player_name()) then --do slopes of this distance exist? - if check_slope_exists(def.nodename_prefix, lookup, step) then + if lookup[step] then if minetest.settings:get_bool("creative_mode") or istack:get_count()>=step then --start placing local placenodes=lookup[step] @@ -798,7 +741,7 @@ function sl.create_slopeplacer_on_place(def, preset) pos=vector.add(pos, dirvec) end minetest.chat_send_player(player:get_player_name(), attrans("Can't place: no supporting node at upper end.")) - return istack + return itemstack end end |