diff options
Diffstat (limited to 'boost_cart')
19 files changed, 177 insertions, 72 deletions
diff --git a/boost_cart/README.txt b/boost_cart/README.txt index 4807105..3a5d295 100644 --- a/boost_cart/README.txt +++ b/boost_cart/README.txt @@ -1,23 +1,47 @@ -Minetest mod: boost_cart -======================= + Minetest mod: boost_cart +========================== Based on (and fully compatible with) the mod "carts" by PilzAdam -Target: Run smoothly and do not use too much CPU +Target: Run smoothly as possible even on laggy server -License of source code: ------------------------ -WTFPL -License of media (textures, sounds and models): ------------------------------------------------ + Features +---------- +- A fast cart for your railway or roller coaster (up to 10 m/s!) +- Boost and brake rails +- By mesecons controlled Start-Stop rails +- Detector rails that send a mesecons signal when the cart drives over them +- Rail junction switching with the 'right-left' walking keys +- Handbrake with the 'back' key + + + License for everything +------------------------ CC-0 -Authors of media files: ------------------------ -kddekadenz: - cart_bottom.png - cart_side.png - cart_top.png -Zeg9: - cart.x - cart.png
\ No newline at end of file + Authors +--------- +Hawk777 + carts_rail_ss.png + carts_rail_*_ss.png + +hexafraction + carts_rail_brk.png + carts_rail_*_brk.png + carts_rail_pwr.png + carts_rail_*_pwr.png + +kddekadenz + cart_bottom.png + cart_side.png + cart_top.png + +numberZero + carts_rail_dtc.png + carts_rail_dtc_on.png + carts_rail_*_dtc.png + carts_rail_*_dtc_on.png + +Zeg9 + cart.x + cart.png
\ No newline at end of file diff --git a/boost_cart/description.txt b/boost_cart/description.txt new file mode 100644 index 0000000..bbb244c --- /dev/null +++ b/boost_cart/description.txt @@ -0,0 +1 @@ +This mod offers improved minecarts and a few more rail types.
\ No newline at end of file diff --git a/boost_cart/detector.lua b/boost_cart/detector.lua index 17d1f16..43acea5 100644 --- a/boost_cart/detector.lua +++ b/boost_cart/detector.lua @@ -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 " .. 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 @@ -25,19 +25,27 @@ end boost_cart:register_rail("boost_cart:detectorrail", { description = "Detector rail", - tiles = {"carts_rail_dtc.png", "carts_rail_curved_dtc.png", "carts_rail_t_junction_dtc.png", "carts_rail_crossing_dtc.png"}, - groups = {dig_immediate = 2, attached_node = 1, rail = 1, connect_to_raillike = 1, detector_rail = 1}, + tiles = { + "carts_rail_dtc.png", "carts_rail_curved_dtc.png", + "carts_rail_t_junction_dtc.png", "carts_rail_crossing_dtc.png" + }, + groups = boost_cart:get_rail_groups({detector_rail = 1}), - mesecons = {receptor = {state = "off", rules = mesecons_rules }}, + mesecons = {receptor = {state = "off", rules = mesecons_rules}}, }) boost_cart:register_rail("boost_cart:detectorrail_on", { description = "Detector rail ON (you hacker you)", - 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"}, - groups = {dig_immediate = 2, attached_node = 1, rail = 1, connect_to_raillike = 1, detector_rail = 1, not_in_creative_inventory = 1}, + 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" + }, + groups = boost_cart:get_rail_groups({ + detector_rail = 1, not_in_creative_inventory = 1 + }), drop = "boost_cart:detectorrail", - mesecons = {receptor = {state = "on", rules = mesecons_rules }}, + mesecons = {receptor = {state = "on", rules = mesecons_rules}}, }) minetest.register_craft({ diff --git a/boost_cart/functions.lua b/boost_cart/functions.lua index bcbbaa0..e94ac07 100644 --- a/boost_cart/functions.lua +++ b/boost_cart/functions.lua @@ -55,7 +55,7 @@ function boost_cart:is_rail(pos, railtype) return minetest.get_item_group(node, "connect_to_raillike") == railtype end -function boost_cart:check_front_up_down(pos, dir_, check_down, railtype) +function boost_cart:check_front_up_down(pos, dir_, check_up, railtype) local dir = vector.new(dir_) local cur = nil @@ -66,7 +66,7 @@ function boost_cart:check_front_up_down(pos, dir_, check_down, railtype) return dir end -- Up - if check_down then + if check_up then dir.y = 1 cur = vector.add(pos, dir) if boost_cart:is_rail(cur, railtype) then @@ -212,4 +212,15 @@ function boost_cart:register_rail(name, def) end minetest.register_node(name, def) -end
\ No newline at end of file +end + +function boost_cart: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 = 1} + if type(additional_groups) == "table" then + for k, v in pairs(additional_groups) do + groups[k] = v + end + end + return groups +end diff --git a/boost_cart/init.lua b/boost_cart/init.lua index 42ea48c..2298516 100644 --- a/boost_cart/init.lua +++ b/boost_cart/init.lua @@ -24,7 +24,7 @@ end dofile(boost_cart.modpath.."/functions.lua") dofile(boost_cart.modpath.."/rails.lua") -if mesecon then +if minetest.global_exists(mesecon) then dofile(boost_cart.modpath.."/detector.lua") end @@ -44,7 +44,7 @@ boost_cart.cart = { driver = nil, punched = false, -- used to re-send velocity and position velocity = {x=0, y=0, z=0}, -- only used on punch - old_dir = {x=0, y=0, z=0}, + old_dir = {x=1, y=0, z=0}, -- random value to start the cart on punch old_pos = nil, old_switch = 0, railtype = nil, @@ -75,11 +75,15 @@ function boost_cart.cart:on_activate(staticdata, dtime_s) return end self.railtype = data.railtype + if data.old_dir then + self.old_dir = data.old_dir + end end function boost_cart.cart:get_staticdata() return minetest.serialize({ - railtype = self.railtype + railtype = self.railtype, + old_dir = self.old_dir }) end @@ -92,7 +96,7 @@ function boost_cart.cart:on_punch(puncher, time_from_last_punch, tool_capabiliti end if not puncher or not puncher:is_player() then - local cart_dir = boost_cart:get_rail_direction(pos, {x=1, y=0, z=0}, nil, nil, self.railtype) + local cart_dir = boost_cart:get_rail_direction(pos, self.old_dir, nil, nil, self.railtype) if vector.equals(cart_dir, {x=0, y=0, z=0}) then return end @@ -147,6 +151,7 @@ function boost_cart.cart:on_punch(puncher, time_from_last_punch, tool_capabiliti local f = 3 * (time_from_last_punch / punch_interval) self.velocity = vector.multiply(cart_dir, f) + self.old_dir = cart_dir self.old_pos = nil self.punched = true end @@ -189,7 +194,9 @@ function boost_cart.cart:on_step(dtime) if self.old_pos then -- Detection for "skipping" nodes local expected_pos = vector.add(self.old_pos, self.old_dir) - local found_path = boost_cart:pathfinder(pos, expected_pos, self.old_dir, ctrl, self.old_switch, self.railtype) + local found_path = boost_cart:pathfinder( + pos, expected_pos, self.old_dir, ctrl, self.old_switch, self.railtype + ) if not found_path then -- No rail found: reset back to the expected position @@ -198,20 +205,12 @@ function boost_cart.cart:on_step(dtime) end end - if vel.y == 0 then - -- Stop cart completely (do not swing) - for _,v in ipairs({"x", "z"}) do - if vel[v] ~= 0 and math.abs(vel[v]) < 0.9 then - vel[v] = 0 - update.vel = true - end - end - end - local cart_dir = boost_cart:velocity_to_dir(vel) local max_vel = boost_cart.speed_max if not dir then - dir, last_switch = boost_cart:get_rail_direction(pos, cart_dir, ctrl, self.old_switch, self.railtype) + dir, last_switch = boost_cart:get_rail_direction( + pos, cart_dir, ctrl, self.old_switch, self.railtype + ) end local new_acc = {x=0, y=0, z=0} @@ -244,26 +243,39 @@ function boost_cart.cart:on_step(dtime) -- Slow down or speed up.. local acc = dir.y * -1.8 - local speed_mod = tonumber(minetest.get_meta(pos):get_string("cart_acceleration")) - if speed_mod and speed_mod ~= 0 then - if speed_mod > 0 then - for _,v in ipairs({"x","y","z"}) do - if math.abs(vel[v]) >= max_vel then - speed_mod = 0 - break - end - end - end + local speed_mod_string = minetest.get_meta(pos):get_string("cart_acceleration") + local speed_mod = tonumber(speed_mod_string) + if speed_mod_string == "halt" then + vel = {x=0, y=0, z=0} + acc = 0 + pos = vector.round(pos) + update.pos = true + update.vel = true + elseif speed_mod and speed_mod ~= 0 then -- Try to make it similar to the original carts mod acc = acc + (speed_mod * 10) else acc = acc - 0.4 -- Handbrake - if ctrl and ctrl.down and math.abs(vel.x + vel.z) > 1.2 then + if ctrl and ctrl.down then acc = acc - 1.2 end end + if self.old_dir.y == 0 and not self.punched then + -- Stop the cart swing between two rail parts (handbrake) + if vector.equals(vector.multiply(self.old_dir, -1), dir) then + vel = {x=0, y=0, z=0} + acc = 0 + if self.old_pos then + pos = vector.new(self.old_pos) + update.pos = true + end + dir = vector.new(self.old_dir) + update.vel = true + end + end + new_acc = vector.multiply(dir, acc) end @@ -279,10 +291,12 @@ function boost_cart.cart:on_step(dtime) update.vel = true end end - + self.object:setacceleration(new_acc) self.old_pos = vector.new(pos) - self.old_dir = vector.new(dir) + if not vector.equals(dir, {x=0, y=0, z=0}) then + self.old_dir = vector.new(dir) + end self.old_switch = last_switch @@ -293,11 +307,13 @@ function boost_cart.cart:on_step(dtime) obj_:get_luaentity() and not obj_:get_luaentity().physical_state and obj_:get_luaentity().name == "__builtin:item" then + obj_:set_attach(self.object, "", {x=0, y=0, z=0}, {x=0, y=0, z=0}) self.attached_items[#self.attached_items + 1] = obj_ end end self.punched = false + update.vel = true -- update player animation end if not (update.vel or update.pos) then @@ -305,11 +321,11 @@ function boost_cart.cart:on_step(dtime) end local yaw = 0 - if dir.x < 0 then + if self.old_dir.x < 0 then yaw = 0.5 - elseif dir.x > 0 then + elseif self.old_dir.x > 0 then yaw = 1.5 - elseif dir.z < 0 then + elseif self.old_dir.z < 0 then yaw = 1 end self.object:setyaw(yaw * math.pi) @@ -355,4 +371,4 @@ minetest.register_craft({ {"default:steel_ingot", "", "default:steel_ingot"}, {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"}, }, -})
\ No newline at end of file +}) diff --git a/boost_cart/rails.lua b/boost_cart/rails.lua index 02c5f48..04d86b8 100644 --- a/boost_cart/rails.lua +++ b/boost_cart/rails.lua @@ -1,7 +1,10 @@ minetest.register_node(":default:rail", { description = "Rail", drawtype = "raillike", - tiles = {"default_rail.png", "default_rail_curved.png", "default_rail_t_junction.png", "default_rail_crossing.png"}, + tiles = { + "default_rail.png", "default_rail_curved.png", + "default_rail_t_junction.png", "default_rail_crossing.png" + }, inventory_image = "default_rail.png", wield_image = "default_rail.png", paramtype = "light", @@ -12,7 +15,7 @@ minetest.register_node(":default:rail", { 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}, + groups = boost_cart:get_rail_groups(), }) if minetest.get_modpath("moreores") then @@ -21,8 +24,11 @@ if minetest.get_modpath("moreores") then else boost_cart:register_rail(":carts:copperrail", { description = "Copper rail", - tiles = {"carts_rail_cp.png", "carts_rail_curved_cp.png", "carts_rail_t_junction_cp.png", "carts_rail_crossing_cp.png"}, - groups = {dig_immediate = 2, attached_node = 1, rail = 1, connect_to_raillike = 1}, + tiles = { + "carts_rail_cp.png", "carts_rail_curved_cp.png", + "carts_rail_t_junction_cp.png", "carts_rail_crossing_cp.png" + }, + groups = boost_cart:get_rail_groups(), }) minetest.register_craft({ @@ -39,9 +45,12 @@ end boost_cart:register_rail(":carts:powerrail", { description = "Powered rail", - tiles = {"carts_rail_pwr.png", "carts_rail_curved_pwr.png", "carts_rail_t_junction_pwr.png", "carts_rail_crossing_pwr.png"}, - groups = {dig_immediate = 2, attached_node = 1, rail = 1, connect_to_raillike = 1}, - + tiles = { + "carts_rail_pwr.png", "carts_rail_curved_pwr.png", + "carts_rail_t_junction_pwr.png", "carts_rail_crossing_pwr.png" + }, + groups = boost_cart:get_rail_groups(), + after_place_node = function(pos, placer, itemstack) if not mesecon then minetest.get_meta(pos):set_string("cart_acceleration", "0.5") @@ -72,19 +81,22 @@ minetest.register_craft({ boost_cart:register_rail(":carts:brakerail", { description = "Brake rail", - tiles = {"carts_rail_brk.png", "carts_rail_curved_brk.png", "carts_rail_t_junction_brk.png", "carts_rail_crossing_brk.png"}, - groups = {dig_immediate = 2, attached_node = 1, rail = 1, connect_to_raillike = 1}, + tiles = { + "carts_rail_brk.png", "carts_rail_curved_brk.png", + "carts_rail_t_junction_brk.png", "carts_rail_crossing_brk.png" + }, + groups = boost_cart:get_rail_groups(), after_place_node = function(pos, placer, itemstack) if not mesecon then - minetest.get_meta(pos):set_string("cart_acceleration", "-0.2") + minetest.get_meta(pos):set_string("cart_acceleration", "-0.3") end end, mesecons = { effector = { action_on = function(pos, node) - boost_cart:boost_rail(pos, -0.2) + minetest.get_meta(pos):set_string("cart_acceleration", "-0.3") end, action_off = function(pos, node) @@ -101,4 +113,37 @@ minetest.register_craft({ {"default:steel_ingot", "group:stick", "default:steel_ingot"}, {"default:steel_ingot", "default:coal_lump", "default:steel_ingot"}, } -})
\ No newline at end of file +}) + +boost_cart:register_rail("boost_cart:startstoprail", { + description = "Start-stop rail", + tiles = { + "carts_rail_ss.png", "carts_rail_curved_ss.png", + "carts_rail_t_junction_ss.png", "carts_rail_crossing_ss.png" + }, + groups = boost_cart:get_rail_groups(), + + after_place_node = function(pos, placer, itemstack) + if not mesecon then + minetest.get_meta(pos):set_string("cart_acceleration", "halt") + 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", "halt") + end, + }, + }, +}) + +minetest.register_craft({ + type = "shapeless", + output = "boost_cart:startstoprail 2", + recipe = {"carts:powerrail", "carts:brakerail"}, +}) diff --git a/boost_cart/screenshot.png b/boost_cart/screenshot.png Binary files differnew file mode 100644 index 0000000..e9eaa5b --- /dev/null +++ b/boost_cart/screenshot.png diff --git a/boost_cart/textures/carts_rail_crossing_dtc.png b/boost_cart/textures/carts_rail_crossing_dtc.png Binary files differindex cf04f0f..a2e4760 100644 --- a/boost_cart/textures/carts_rail_crossing_dtc.png +++ b/boost_cart/textures/carts_rail_crossing_dtc.png diff --git a/boost_cart/textures/carts_rail_crossing_dtc_on.png b/boost_cart/textures/carts_rail_crossing_dtc_on.png Binary files differindex b6f5b87..1adba4f 100644 --- a/boost_cart/textures/carts_rail_crossing_dtc_on.png +++ b/boost_cart/textures/carts_rail_crossing_dtc_on.png diff --git a/boost_cart/textures/carts_rail_crossing_ss.png b/boost_cart/textures/carts_rail_crossing_ss.png Binary files differnew file mode 100644 index 0000000..11a4226 --- /dev/null +++ b/boost_cart/textures/carts_rail_crossing_ss.png diff --git a/boost_cart/textures/carts_rail_curved_dtc.png b/boost_cart/textures/carts_rail_curved_dtc.png Binary files differindex 8117c27..0bf7501 100644 --- a/boost_cart/textures/carts_rail_curved_dtc.png +++ b/boost_cart/textures/carts_rail_curved_dtc.png diff --git a/boost_cart/textures/carts_rail_curved_dtc_on.png b/boost_cart/textures/carts_rail_curved_dtc_on.png Binary files differindex 032630f..71b8f93 100644 --- a/boost_cart/textures/carts_rail_curved_dtc_on.png +++ b/boost_cart/textures/carts_rail_curved_dtc_on.png diff --git a/boost_cart/textures/carts_rail_curved_ss.png b/boost_cart/textures/carts_rail_curved_ss.png Binary files differnew file mode 100644 index 0000000..5269fdd --- /dev/null +++ b/boost_cart/textures/carts_rail_curved_ss.png diff --git a/boost_cart/textures/carts_rail_dtc.png b/boost_cart/textures/carts_rail_dtc.png Binary files differindex 5e2ccef..fe306e4 100644 --- a/boost_cart/textures/carts_rail_dtc.png +++ b/boost_cart/textures/carts_rail_dtc.png diff --git a/boost_cart/textures/carts_rail_dtc_on.png b/boost_cart/textures/carts_rail_dtc_on.png Binary files differindex e81dbe1..715e063 100644 --- a/boost_cart/textures/carts_rail_dtc_on.png +++ b/boost_cart/textures/carts_rail_dtc_on.png diff --git a/boost_cart/textures/carts_rail_ss.png b/boost_cart/textures/carts_rail_ss.png Binary files differnew file mode 100644 index 0000000..9390394 --- /dev/null +++ b/boost_cart/textures/carts_rail_ss.png diff --git a/boost_cart/textures/carts_rail_t_junction_dtc.png b/boost_cart/textures/carts_rail_t_junction_dtc.png Binary files differindex b154f43..e50cf3b 100644 --- a/boost_cart/textures/carts_rail_t_junction_dtc.png +++ b/boost_cart/textures/carts_rail_t_junction_dtc.png diff --git a/boost_cart/textures/carts_rail_t_junction_dtc_on.png b/boost_cart/textures/carts_rail_t_junction_dtc_on.png Binary files differindex 9fda111..41a08d1 100644 --- a/boost_cart/textures/carts_rail_t_junction_dtc_on.png +++ b/boost_cart/textures/carts_rail_t_junction_dtc_on.png diff --git a/boost_cart/textures/carts_rail_t_junction_ss.png b/boost_cart/textures/carts_rail_t_junction_ss.png Binary files differnew file mode 100644 index 0000000..f101298 --- /dev/null +++ b/boost_cart/textures/carts_rail_t_junction_ss.png |