mirror of
https://github.com/SmallJoker/boost_cart.git
synced 2024-11-13 06:10:20 +01:00
Add boost_cart:register_rail(name, def)
This commit is contained in:
parent
adfcfe0841
commit
a7fd733819
35
detector.lua
35
detector.lua
|
@ -3,7 +3,7 @@ local mesecons_rules = mesecon.rules.flat
|
|||
function boost_cart:turnoff_detector_rail(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
if minetest.get_item_group(node.name, "detector_rail") == 1 then
|
||||
if node.name=="boost_cart:detectorrail_on" then --has not been dug
|
||||
if node.name == "boost_cart:detectorrail_on" then --has not been dug
|
||||
minetest.swap_node(pos, {name = "boost_cart:detectorrail", param2=node.param2})
|
||||
end
|
||||
mesecon.receptor_off(pos, mesecon_rules)
|
||||
|
@ -15,7 +15,7 @@ function boost_cart:signal_detector_rail(pos)
|
|||
if minetest.get_item_group(node.name, "detector_rail") ~= 1 then
|
||||
return
|
||||
end
|
||||
minetest.log("action", "Signaling detector at " .. vector.tostr(pos))
|
||||
--minetest.log("action", "Signaling detector at " .. minetest.pos_to_string(pos))
|
||||
if node.name == "boost_cart:detectorrail" then
|
||||
minetest.swap_node(pos, {name = "boost_cart:detectorrail_on", param2=node.param2})
|
||||
end
|
||||
|
@ -23,43 +23,20 @@ function boost_cart:signal_detector_rail(pos)
|
|||
minetest.after(0.5, boost_cart.turnoff_detector_rail, boost_cart, pos)
|
||||
end
|
||||
|
||||
minetest.register_node("boost_cart:detectorrail", {
|
||||
boost_cart:register_rail("boost_cart:detectorrail", {
|
||||
description = "Detector rail",
|
||||
drawtype = "raillike",
|
||||
tiles = {"carts_rail_dtc.png", "carts_rail_curved_dtc.png", "carts_rail_t_junction_dtc.png", "carts_rail_crossing_dtc.png"},
|
||||
inventory_image = "carts_rail_dtc.png",
|
||||
wield_image = "carts_rail_dtc.png",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
is_ground_content = true,
|
||||
walkable = false,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
|
||||
},
|
||||
groups = {dig_immediate = 2, attached_node = 1, rail = 1, connect_to_raillike = 1, detector_rail = 1},
|
||||
|
||||
|
||||
mesecons = {receptor = {state = "off", rules = mesecons_rules }},
|
||||
})
|
||||
|
||||
minetest.register_node("boost_cart:detectorrail_on", {
|
||||
boost_cart:register_rail("boost_cart:detectorrail_on", {
|
||||
description = "Detector rail ON (you hacker you)",
|
||||
drawtype = "raillike",
|
||||
tiles = {"carts_rail_dtc_on.png", "carts_rail_curved_dtc_on.png", "carts_rail_t_junction_dtc_on.png", "carts_rail_crossing_dtc_on.png"},
|
||||
inventory_image = "carts_rail_dtc_on.png",
|
||||
wield_image = "carts_rail_dtc_on.png",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
is_ground_content = true,
|
||||
walkable = false,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
-- but how to specify the dimensions for curved and sideways rails?
|
||||
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
|
||||
},
|
||||
groups = {dig_immediate = 2, attached_node = 1, rail = 1, connect_to_raillike = 1, detector_rail = 1, not_in_creative_inventory = 1},
|
||||
drop = "boost_cart:detectorrail",
|
||||
|
||||
|
||||
mesecons = {receptor = {state = "on", rules = mesecons_rules }},
|
||||
})
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ end
|
|||
function boost_cart:check_front_up_down(pos, dir_, check_down, railtype)
|
||||
local dir = vector.new(dir_)
|
||||
local cur = nil
|
||||
|
||||
|
||||
-- Front
|
||||
dir.y = 0
|
||||
cur = vector.add(pos, dir)
|
||||
|
@ -67,7 +67,7 @@ function boost_cart:get_rail_direction(pos_, dir, ctrl, old_switch, railtype)
|
|||
local pos = vector.round(pos_)
|
||||
local cur = nil
|
||||
local left_check, right_check = true, true
|
||||
|
||||
|
||||
-- Check left and right
|
||||
local left = {x=0, y=0, z=0}
|
||||
local right = {x=0, y=0, z=0}
|
||||
|
@ -78,7 +78,7 @@ function boost_cart:get_rail_direction(pos_, dir, ctrl, old_switch, railtype)
|
|||
left.z = dir.x
|
||||
right.z = -dir.x
|
||||
end
|
||||
|
||||
|
||||
if ctrl then
|
||||
if old_switch == 1 then
|
||||
left_check = false
|
||||
|
@ -100,13 +100,13 @@ function boost_cart:get_rail_direction(pos_, dir, ctrl, old_switch, railtype)
|
|||
right_check = true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Normal
|
||||
cur = boost_cart:check_front_up_down(pos, dir, true, railtype)
|
||||
if cur then
|
||||
return cur
|
||||
end
|
||||
|
||||
|
||||
-- Left, if not already checked
|
||||
if left_check then
|
||||
cur = boost_cart:check_front_up_down(pos, left, false, railtype)
|
||||
|
@ -114,7 +114,7 @@ function boost_cart:get_rail_direction(pos_, dir, ctrl, old_switch, railtype)
|
|||
return cur
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Right, if not already checked
|
||||
if right_check then
|
||||
cur = boost_cart:check_front_up_down(pos, right, false, railtype)
|
||||
|
@ -122,7 +122,7 @@ function boost_cart:get_rail_direction(pos_, dir, ctrl, old_switch, railtype)
|
|||
return cur
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
-- Backwards
|
||||
if not old_switch then
|
||||
cur = boost_cart:check_front_up_down(pos, {
|
||||
|
@ -134,7 +134,7 @@ function boost_cart:get_rail_direction(pos_, dir, ctrl, old_switch, railtype)
|
|||
return cur
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return {x=0, y=0, z=0}
|
||||
end
|
||||
|
||||
|
@ -147,4 +147,27 @@ function boost_cart:boost_rail(pos, amount)
|
|||
obj_:get_luaentity():on_punch()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function boost_cart:register_rail(name, def)
|
||||
local def_default = {
|
||||
drawtype = "raillike",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
is_ground_content = true,
|
||||
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_default) do
|
||||
def[k] = v
|
||||
end
|
||||
if not def.inventory_image then
|
||||
def.wield_image = def.tiles[1]
|
||||
def.inventory_image = def.tiles[1]
|
||||
end
|
||||
|
||||
minetest.register_node(name, def)
|
||||
end
|
4
init.lua
4
init.lua
|
@ -13,10 +13,6 @@ function vector.floor(v)
|
|||
}
|
||||
end
|
||||
|
||||
function vector.tostr(v)
|
||||
return string.format("{%.3f; %.3f; %.3f}", v.x, v.y, v.z)
|
||||
end
|
||||
|
||||
dofile(boost_cart.modpath.."/functions.lua")
|
||||
dofile(boost_cart.modpath.."/rails.lua")
|
||||
|
||||
|
|
53
rails.lua
53
rails.lua
|
@ -19,20 +19,9 @@ if minetest.get_modpath("moreores") then
|
|||
-- Moreores' copper rail
|
||||
minetest.register_alias("carts:copperrail", "moreores:copper_rail")
|
||||
else
|
||||
minetest.register_node(":carts:copperrail", {
|
||||
boost_cart:register_rail(":carts:copperrail", {
|
||||
description = "Copper rail",
|
||||
drawtype = "raillike",
|
||||
tiles = {"carts_rail_cp.png", "carts_rail_curved_cp.png", "carts_rail_t_junction_cp.png", "carts_rail_crossing_cp.png"},
|
||||
inventory_image = "carts_rail_cp.png",
|
||||
wield_image = "carts_rail_cp.png",
|
||||
paramtype = "light",
|
||||
is_ground_content = true,
|
||||
walkable = false,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
-- but how to specify the dimensions for curved and sideways rails?
|
||||
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
|
||||
},
|
||||
groups = {dig_immediate = 2, attached_node = 1, rail = 1, connect_to_raillike = 1},
|
||||
})
|
||||
|
||||
|
@ -48,34 +37,22 @@ end
|
|||
|
||||
-- Speed up
|
||||
|
||||
minetest.register_node(":carts:powerrail", {
|
||||
boost_cart:register_rail(":carts:powerrail", {
|
||||
description = "Powered rail",
|
||||
drawtype = "raillike",
|
||||
tiles = {"carts_rail_pwr.png", "carts_rail_curved_pwr.png", "carts_rail_t_junction_pwr.png", "carts_rail_crossing_pwr.png"},
|
||||
inventory_image = "carts_rail_pwr.png",
|
||||
wield_image = "carts_rail_pwr.png",
|
||||
paramtype = "light",
|
||||
is_ground_content = true,
|
||||
walkable = false,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
-- but how to specify the dimensions for curved and sideways rails?
|
||||
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
|
||||
},
|
||||
groups = {dig_immediate = 2, attached_node = 1, rail = 1, connect_to_raillike = 1},
|
||||
|
||||
|
||||
after_place_node = function(pos, placer, itemstack)
|
||||
if not mesecon then
|
||||
minetest.get_meta(pos):set_string("cart_acceleration", "0.5")
|
||||
end
|
||||
end,
|
||||
|
||||
|
||||
mesecons = {
|
||||
effector = {
|
||||
action_on = function(pos, node)
|
||||
boost_cart:boost_rail(pos, 0.5)
|
||||
end,
|
||||
|
||||
|
||||
action_off = function(pos, node)
|
||||
minetest.get_meta(pos):set_string("cart_acceleration", "0")
|
||||
end,
|
||||
|
@ -92,34 +69,22 @@ minetest.register_craft({
|
|||
}
|
||||
})
|
||||
|
||||
minetest.register_node(":carts:brakerail", {
|
||||
boost_cart:register_rail(":carts:brakerail", {
|
||||
description = "Brake rail",
|
||||
drawtype = "raillike",
|
||||
tiles = {"carts_rail_brk.png", "carts_rail_curved_brk.png", "carts_rail_t_junction_brk.png", "carts_rail_crossing_brk.png"},
|
||||
inventory_image = "carts_rail_brk.png",
|
||||
wield_image = "carts_rail_brk.png",
|
||||
paramtype = "light",
|
||||
is_ground_content = true,
|
||||
walkable = false,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
-- but how to specify the dimensions for curved and sideways rails?
|
||||
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
|
||||
},
|
||||
groups = {dig_immediate = 2, attached_node = 1, rail = 1, connect_to_raillike = 1},
|
||||
|
||||
|
||||
after_place_node = function(pos, placer, itemstack)
|
||||
if not mesecon then
|
||||
minetest.get_meta(pos):set_string("cart_acceleration", "-0.2")
|
||||
end
|
||||
end,
|
||||
|
||||
|
||||
mesecons = {
|
||||
effector = {
|
||||
action_on = function(pos, node)
|
||||
boost_cart:boost_rail(pos, -0.2)
|
||||
end,
|
||||
|
||||
|
||||
action_off = function(pos, node)
|
||||
minetest.get_meta(pos):set_string("cart_acceleration", "0")
|
||||
end,
|
||||
|
|
Loading…
Reference in New Issue
Block a user