summaryrefslogtreecommitdiff
path: root/boost_cart
diff options
context:
space:
mode:
Diffstat (limited to 'boost_cart')
-rw-r--r--boost_cart/README.txt22
-rw-r--r--boost_cart/cart_entity.lua378
-rw-r--r--boost_cart/depends.txt3
-rw-r--r--boost_cart/detector.lua4
-rw-r--r--boost_cart/functions.lua9
-rw-r--r--boost_cart/init.lua366
-rw-r--r--boost_cart/rails.lua48
-rw-r--r--boost_cart/sounds/cart_rail.1.oggbin0 -> 7543 bytes
-rw-r--r--boost_cart/sounds/cart_rail.2.oggbin0 -> 8080 bytes
-rw-r--r--boost_cart/sounds/cart_rail.3.oggbin0 -> 7232 bytes
-rw-r--r--boost_cart/textures/carts_rail_crossing.pngbin0 -> 755 bytes
-rw-r--r--boost_cart/textures/carts_rail_crossing_brk.pngbin549 -> 765 bytes
-rw-r--r--boost_cart/textures/carts_rail_crossing_cp.pngbin495 -> 735 bytes
-rw-r--r--boost_cart/textures/carts_rail_crossing_dtc.pngbin458 -> 823 bytes
-rw-r--r--boost_cart/textures/carts_rail_crossing_dtc_on.pngbin458 -> 823 bytes
-rw-r--r--boost_cart/textures/carts_rail_crossing_pwr.pngbin458 -> 847 bytes
-rw-r--r--boost_cart/textures/carts_rail_crossing_ss.pngbin462 -> 813 bytes
-rw-r--r--boost_cart/textures/carts_rail_curved.pngbin0 -> 750 bytes
-rw-r--r--boost_cart/textures/carts_rail_curved_brk.pngbin537 -> 738 bytes
-rw-r--r--boost_cart/textures/carts_rail_curved_cp.pngbin488 -> 691 bytes
-rw-r--r--boost_cart/textures/carts_rail_curved_dtc.pngbin443 -> 780 bytes
-rw-r--r--boost_cart/textures/carts_rail_curved_dtc_on.pngbin443 -> 780 bytes
-rw-r--r--boost_cart/textures/carts_rail_curved_pwr.pngbin443 -> 798 bytes
-rw-r--r--boost_cart/textures/carts_rail_curved_ss.pngbin445 -> 832 bytes
-rw-r--r--boost_cart/textures/carts_rail_straight.pngbin0 -> 785 bytes
-rw-r--r--boost_cart/textures/carts_rail_straight_brk.pngbin0 -> 789 bytes
-rw-r--r--boost_cart/textures/carts_rail_straight_cp.pngbin0 -> 728 bytes
-rw-r--r--boost_cart/textures/carts_rail_straight_dtc.pngbin0 -> 830 bytes
-rw-r--r--boost_cart/textures/carts_rail_straight_dtc_on.pngbin0 -> 830 bytes
-rw-r--r--boost_cart/textures/carts_rail_straight_pwr.pngbin0 -> 836 bytes
-rw-r--r--boost_cart/textures/carts_rail_straight_ss.pngbin0 -> 843 bytes
-rw-r--r--boost_cart/textures/carts_rail_t_junction.pngbin0 -> 789 bytes
-rw-r--r--boost_cart/textures/carts_rail_t_junction_brk.pngbin538 -> 714 bytes
-rw-r--r--boost_cart/textures/carts_rail_t_junction_cp.pngbin496 -> 715 bytes
-rw-r--r--boost_cart/textures/carts_rail_t_junction_dtc.pngbin431 -> 752 bytes
-rw-r--r--boost_cart/textures/carts_rail_t_junction_dtc_on.pngbin431 -> 808 bytes
-rw-r--r--boost_cart/textures/carts_rail_t_junction_pwr.pngbin539 -> 761 bytes
-rw-r--r--boost_cart/textures/carts_rail_t_junction_ss.pngbin433 -> 813 bytes
-rw-r--r--boost_cart/textures/templates/crossing.pngbin0 -> 368 bytes
-rw-r--r--boost_cart/textures/templates/curved.pngbin0 -> 400 bytes
-rw-r--r--boost_cart/textures/templates/straight.pngbin0 -> 248 bytes
-rw-r--r--boost_cart/textures/templates/t_junction.pngbin0 -> 323 bytes
42 files changed, 421 insertions, 409 deletions
diff --git a/boost_cart/README.txt b/boost_cart/README.txt
index 3a5d295..7565ee8 100644
--- a/boost_cart/README.txt
+++ b/boost_cart/README.txt
@@ -1,6 +1,7 @@
Minetest mod: boost_cart
==========================
Based on (and fully compatible with) the mod "carts" by PilzAdam
+Also compatible with the carts mod in the subgame "minetest_game".
Target: Run smoothly as possible even on laggy server
@@ -16,31 +17,22 @@ Target: Run smoothly as possible even on laggy server
License for everything
------------------------
-CC-0
+CC-0, if not specified otherwise below
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
+Various authors
+ carts_rail_*.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
+klankbeeld (CC-BY 3.0)
+ http://freesound.org/people/klankbeeld/sounds/174042/
+ cart_rail.*.ogg
Zeg9
cart.x
diff --git a/boost_cart/cart_entity.lua b/boost_cart/cart_entity.lua
new file mode 100644
index 0000000..ba23713
--- /dev/null
+++ b/boost_cart/cart_entity.lua
@@ -0,0 +1,378 @@
+
+local HAVE_MESECONS_ENABLED = minetest.global_exists("mesecon")
+
+function boost_cart:on_rail_step(pos)
+ -- Play rail sound
+ if self.sound_counter <= 0 then
+ minetest.sound_play("cart_rail", {
+ pos = pos,
+ max_hear_distance = 40,
+ gain = 0.5
+ })
+ self.sound_counter = math.random(4, 15)
+ end
+ self.sound_counter = self.sound_counter - 1
+
+ if HAVE_MESECONS_ENABLED then
+ boost_cart:signal_detector_rail(pos)
+ end
+end
+
+local cart_entity = {
+ physical = false,
+ collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
+ visual = "mesh",
+ mesh = "cart.x",
+ visual_size = {x=1, y=1},
+ textures = {"cart.png"},
+
+ 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=1, y=0, z=0}, -- random value to start the cart on punch
+ old_pos = nil,
+ old_switch = 0,
+ sound_counter = 0,
+ railtype = nil,
+ attached_items = {}
+}
+
+function cart_entity:on_rightclick(clicker)
+ if not clicker or not clicker:is_player() then
+ return
+ end
+ local player_name = clicker:get_player_name()
+ if self.driver and player_name == self.driver then
+ self.driver = nil
+ boost_cart:manage_attachment(clicker, nil)
+ elseif not self.driver then
+ self.driver = player_name
+ boost_cart:manage_attachment(clicker, self.object)
+ end
+end
+
+function cart_entity:on_activate(staticdata, dtime_s)
+ self.object:set_armor_groups({immortal=1})
+ self.sound_counter = math.random(4, 15)
+
+ if string.sub(staticdata, 1, string.len("return")) ~= "return" then
+ return
+ end
+ local data = minetest.deserialize(staticdata)
+ if not data or type(data) ~= "table" then
+ return
+ end
+ self.railtype = data.railtype
+ if data.old_dir then
+ self.old_dir = data.old_dir
+ end
+end
+
+function cart_entity:get_staticdata()
+ return minetest.serialize({
+ railtype = self.railtype,
+ old_dir = self.old_dir
+ })
+end
+
+function cart_entity:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
+ local pos = self.object:getpos()
+ if not self.railtype 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 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
+ self.velocity = vector.multiply(cart_dir, 3)
+ self.punched = true
+ return
+ end
+
+ if puncher:get_player_control().sneak then
+ -- Pick up cart: Drop all attachments
+ if self.driver then
+ if self.old_pos then
+ self.object:setpos(self.old_pos)
+ end
+ local player = minetest.get_player_by_name(self.driver)
+ boost_cart:manage_attachment(player, nil)
+ end
+ for _, obj_ in pairs(self.attached_items) do
+ if obj_ then
+ obj_:set_detach()
+ end
+ end
+
+ local leftover = puncher:get_inventory():add_item("main", "carts:cart")
+ if not leftover:is_empty() then
+ minetest.add_item(self.object:getpos(), leftover)
+ end
+ self.object:remove()
+ return
+ end
+
+ local vel = self.object:getvelocity()
+ if puncher:get_player_name() == self.driver then
+ if math.abs(vel.x + vel.z) > boost_cart.punch_speed_max then
+ return
+ end
+ end
+
+ local punch_dir = boost_cart:velocity_to_dir(puncher:get_look_dir())
+ punch_dir.y = 0
+ local cart_dir = boost_cart:get_rail_direction(pos, punch_dir, nil, nil, self.railtype)
+ if vector.equals(cart_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 = 3 * (time_from_last_punch / punch_interval)
+
+ self.velocity = vector.multiply(cart_dir, f)
+ self.old_dir = cart_dir
+ self.punched = true
+end
+
+function cart_entity:on_step(dtime)
+ local vel = self.object:getvelocity()
+ if self.punched then
+ vel = vector.add(vel, self.velocity)
+ self.object:setvelocity(vel)
+ self.old_dir.y = 0
+ elseif vector.equals(vel, {x=0, y=0, z=0}) then
+ return
+ end
+
+ local pos = self.object:getpos()
+ local update = {}
+
+ if self.old_pos and not self.punched then
+ local flo_pos = vector.round(pos)
+ local flo_old = vector.round(self.old_pos)
+ if vector.equals(flo_pos, flo_old) then
+ -- Do not check one node multiple times
+ return
+ end
+ end
+
+ local ctrl, player
+
+ -- Get player controls
+ if self.driver then
+ player = minetest.get_player_by_name(self.driver)
+ if player then
+ ctrl = player:get_player_control()
+ end
+ end
+
+ if self.old_pos then
+ -- Detection for "skipping" nodes
+ local found_path = boost_cart:pathfinder(
+ pos, self.old_pos, self.old_dir, ctrl, self.old_switch, self.railtype
+ )
+
+ if not found_path then
+ -- No rail found: reset back to the expected position
+ pos = vector.new(self.old_pos)
+ update.pos = true
+ end
+ end
+
+ local cart_dir = boost_cart:velocity_to_dir(vel)
+
+ -- dir: New moving direction of the cart
+ -- switch_keys: Currently pressed L/R key, used to ignore the key on the next rail node
+ local dir, switch_keys = boost_cart:get_rail_direction(
+ pos, cart_dir, ctrl, self.old_switch, self.railtype
+ )
+
+ local new_acc = {x=0, y=0, z=0}
+ if vector.equals(dir, {x=0, y=0, z=0}) then
+ vel = {x=0, y=0, z=0}
+ pos = vector.round(pos)
+ update.pos = true
+ update.vel = true
+ else
+ -- Direction change detected
+ if not vector.equals(dir, self.old_dir) 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
+ -- Center on the rail
+ 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
+
+ -- Calculate current cart acceleration
+ local acc = nil
+
+ local acc_meta = minetest.get_meta(pos):get_string("cart_acceleration")
+ if acc_meta == "halt" then
+ -- Stop rail
+ vel = {x=0, y=0, z=0}
+ acc = false
+ pos = vector.round(pos)
+ update.pos = true
+ update.vel = true
+ mod_found = true
+ end
+ if acc == nil then
+ -- Meta speed modifier
+ local speed_mod = tonumber(acc_meta)
+ if speed_mod and speed_mod ~= 0 then
+ -- Try to make it similar to the original carts mod
+ acc = speed_mod * 10
+ end
+ end
+ if acc == nil and boost_cart.mtg_compat then
+ -- MTG Cart API adaption
+ local rail_node = minetest.get_node(vector.round(pos))
+ local railparam = carts.railparams[rail_node.name]
+ if railparam and railparam.acceleration then
+ acc = railparam.acceleration
+ end
+ end
+ if acc == nil then
+ -- Handbrake
+ if ctrl and ctrl.down then
+ acc = -2
+ else
+ acc = -0.4
+ end
+ end
+
+ -- Slow down or speed up, depending on Y direction
+ if acc then
+ acc = acc + dir.y * -2.5
+ else
+ acc = 0
+ end
+
+ if self.old_dir.y ~= 1 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
+ boost_cart.on_rail_step(self, vector.round(pos))
+
+ -- Limits
+ local max_vel = boost_cart.speed_max
+ for _,v in pairs({"x","y","z"}) do
+ if math.abs(vel[v]) > max_vel then
+ vel[v] = boost_cart:get_sign(vel[v]) * max_vel
+ new_acc[v] = 0
+ update.vel = true
+ end
+ end
+
+ self.object:setacceleration(new_acc)
+ self.old_pos = pos
+ if not vector.equals(dir, {x=0, y=0, z=0}) then
+ self.old_dir = dir
+ end
+ self.old_switch = switch_keys
+
+
+ if self.punched then
+ -- Collect dropped items
+ for _, obj_ in pairs(minetest.get_objects_inside_radius(pos, 1)) do
+ if not obj_:is_player() and
+ 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
+ end
+
+ if not (update.vel or update.pos) then
+ return
+ 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:setyaw(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)
+
+ self.object:setvelocity(vel)
+ if update.pos then
+ self.object:setpos(pos)
+ end
+end
+
+minetest.register_entity(":carts:cart", cart_entity)
+minetest.register_craftitem(":carts:cart", {
+ description = "Cart (Sneak+Click to pick up)",
+ inventory_image = minetest.inventorycube("cart_top.png", "cart_side.png", "cart_side.png"),
+ wield_image = "cart_side.png",
+ on_place = function(itemstack, placer, pointed_thing)
+ if not pointed_thing.type == "node" then
+ return
+ end
+ if boost_cart:is_rail(pointed_thing.under) then
+ minetest.add_entity(pointed_thing.under, "carts:cart")
+ elseif boost_cart:is_rail(pointed_thing.above) then
+ minetest.add_entity(pointed_thing.above, "carts:cart")
+ else
+ return
+ end
+
+ if not minetest.setting_getbool("creative_mode") then
+ itemstack:take_item()
+ end
+ return itemstack
+ end,
+})
+
+minetest.register_craft({
+ output = "carts:cart",
+ recipe = {
+ {"default:steel_ingot", "", "default:steel_ingot"},
+ {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
+ },
+})
diff --git a/boost_cart/depends.txt b/boost_cart/depends.txt
index bfb43df..705a8eb 100644
--- a/boost_cart/depends.txt
+++ b/boost_cart/depends.txt
@@ -1,3 +1,4 @@
default
mesecons?
-moreores? \ No newline at end of file
+moreores?
+carts? \ No newline at end of file
diff --git a/boost_cart/detector.lua b/boost_cart/detector.lua
index 43acea5..f345ac6 100644
--- a/boost_cart/detector.lua
+++ b/boost_cart/detector.lua
@@ -26,7 +26,7 @@ end
boost_cart:register_rail("boost_cart:detectorrail", {
description = "Detector rail",
tiles = {
- "carts_rail_dtc.png", "carts_rail_curved_dtc.png",
+ "carts_rail_straight_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}),
@@ -37,7 +37,7 @@ boost_cart:register_rail("boost_cart:detectorrail", {
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_straight_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({
diff --git a/boost_cart/functions.lua b/boost_cart/functions.lua
index e94ac07..fcdd1ad 100644
--- a/boost_cart/functions.lua
+++ b/boost_cart/functions.lua
@@ -6,10 +6,11 @@ function boost_cart:get_sign(z)
end
end
-function boost_cart:manage_attachment(player, status, obj)
+function boost_cart:manage_attachment(player, obj)
if not player then
return
end
+ local status = obj ~= nil
local player_name = player:get_player_name()
if default.player_attached[player_name] == status then
return
@@ -157,9 +158,9 @@ function boost_cart:get_rail_direction(pos_, dir, ctrl, old_switch, railtype)
return {x=0, y=0, z=0}
end
-function boost_cart:pathfinder(pos_, expected_pos, old_dir, ctrl, pf_switch, railtype)
+function boost_cart:pathfinder(pos_, old_pos, old_dir, ctrl, pf_switch, railtype)
local pos = vector.round(pos_)
- local pf_pos = vector.round(expected_pos)
+ local pf_pos = vector.round(old_pos)
local pf_dir = vector.new(old_dir)
for i = 1, 3 do
@@ -196,7 +197,7 @@ function boost_cart:register_rail(name, def)
drawtype = "raillike",
paramtype = "light",
sunlight_propagates = true,
- is_ground_content = true,
+ is_ground_content = false,
walkable = false,
selection_box = {
type = "fixed",
diff --git a/boost_cart/init.lua b/boost_cart/init.lua
index 42d3533..7dd5c44 100644
--- a/boost_cart/init.lua
+++ b/boost_cart/init.lua
@@ -4,8 +4,8 @@ boost_cart.modpath = minetest.get_modpath("boost_cart")
-- Maximal speed of the cart in m/s
boost_cart.speed_max = 10
--- Set to nil to disable punching the cart from inside (min = -1)
-boost_cart.punch_speed_min = 7
+-- Set to -1 to disable punching the cart from inside
+boost_cart.punch_speed_max = 7
if not boost_cart.modpath then
@@ -13,363 +13,23 @@ if not boost_cart.modpath then
"See also: http://dev.minetest.net/Installing_Mods")
end
-function vector.floor(v)
- return {
- x = math.floor(v.x),
- y = math.floor(v.y),
- z = math.floor(v.z)
- }
-end
-
-dofile(boost_cart.modpath.."/functions.lua")
-dofile(boost_cart.modpath.."/rails.lua")
-
-local HAVE_MESECONS_ENABLED = minetest.global_exists("mesecon")
-if HAVE_MESECONS_ENABLED then
- dofile(boost_cart.modpath.."/detector.lua")
-end
-
-- Support for non-default games
if not default.player_attached then
default.player_attached = {}
end
-boost_cart.cart = {
- physical = false,
- collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
- visual = "mesh",
- mesh = "cart.x",
- visual_size = {x=1, y=1},
- textures = {"cart.png"},
-
- 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=1, y=0, z=0}, -- random value to start the cart on punch
- old_pos = nil,
- old_switch = 0,
- railtype = nil,
- attached_items = {}
-}
-
-function boost_cart.cart:on_rightclick(clicker)
- if not clicker or not clicker:is_player() then
- return
- end
- local player_name = clicker:get_player_name()
- if self.driver and player_name == self.driver then
- self.driver = nil
- boost_cart:manage_attachment(clicker, false)
- elseif not self.driver then
- self.driver = player_name
- boost_cart:manage_attachment(clicker, true, self.object)
- end
-end
-
-function boost_cart.cart: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 not data or type(data) ~= "table" then
- 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,
- old_dir = self.old_dir
- })
-end
-
-function boost_cart.cart:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
- local pos = self.object:getpos()
- if not self.railtype then
- local bar = vector.floor(vector.add(pos, 0.1))
- local node = minetest.get_node(bar).name
- self.railtype = minetest.get_item_group(node, "connect_to_raillike")
- end
-
- if not puncher or not puncher:is_player() then
- 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
- self.velocity = vector.multiply(cart_dir, 3)
- self.old_pos = nil
- self.punched = true
- return
- end
-
- if puncher:get_player_control().sneak then
- -- Pick up cart: Drop all attachments
- if self.driver then
- if self.old_pos then
- self.object:setpos(self.old_pos)
- end
- local player = minetest.get_player_by_name(self.driver)
- boost_cart:manage_attachment(player, false)
- end
- for _,obj_ in ipairs(self.attached_items) do
- if obj_ then
- obj_:set_detach()
- end
- end
-
- local leftover = puncher:get_inventory():add_item("main", "carts:cart")
- if not leftover:is_empty() then
- minetest.add_item(self.object:getpos(), leftover)
- end
- self.object:remove()
- return
- end
-
- local vel = self.object:getvelocity()
- if puncher:get_player_name() == self.driver then
- if math.abs(vel.x + vel.z) > boost_cart.punch_speed_min then
- return
- end
- end
-
- local punch_dir = boost_cart:velocity_to_dir(puncher:get_look_dir())
- punch_dir.y = 0
- local cart_dir = boost_cart:get_rail_direction(pos, punch_dir, nil, nil, self.railtype)
- if vector.equals(cart_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 = 3 * (time_from_last_punch / punch_interval)
+dofile(boost_cart.modpath.."/functions.lua")
+dofile(boost_cart.modpath.."/rails.lua")
- self.velocity = vector.multiply(cart_dir, f)
- self.old_dir = cart_dir
- self.old_pos = nil
- self.punched = true
+if minetest.global_exists("mesecon") then
+ dofile(boost_cart.modpath.."/detector.lua")
+--else
+-- minetest.register_alias("carts:powerrail", "boost_cart:detectorrail")
+-- minetest.register_alias("carts:powerrail", "boost_cart:detectorrail_on")
end
-function boost_cart.cart:on_step(dtime)
- local vel = self.object:getvelocity()
- local update = {}
- if self.punched then
- vel = vector.add(vel, self.velocity)
- self.object:setvelocity(vel)
- self.old_dir.y = 0
- elseif vector.equals(vel, {x=0, y=0, z=0}) then
- return
- end
-
- -- dir: New moving direction of the cart
- -- last_switch: Currently pressed L/R key, used to ignore the key on the next rail node
- local dir, last_switch
- local pos = self.object:getpos()
-
- if self.old_pos and not self.punched then
- local flo_pos = vector.round(pos)
- local flo_old = vector.round(self.old_pos)
- if vector.equals(flo_pos, flo_old) then
- -- Do not check one node multiple times
- return
- end
- end
-
- local ctrl, player
-
- -- Get player controls
- if self.driver then
- player = minetest.get_player_by_name(self.driver)
- if player then
- ctrl = player:get_player_control()
- end
- end
-
- 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
- )
-
- if not found_path then
- -- No rail found: reset back to the expected position
- pos = expected_pos
- update.pos = true
- 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
- )
- end
-
- local new_acc = {x=0, y=0, z=0}
- if vector.equals(dir, {x=0, y=0, z=0}) then
- vel = {x=0, y=0, z=0}
- pos = vector.round(pos)
- update.pos = true
- update.vel = true
- else
- -- If the direction changed
- if dir.x ~= 0 and self.old_dir.z ~= 0 then
- vel.x = dir.x * math.abs(vel.z)
- vel.z = 0
- pos.z = math.floor(pos.z + 0.5)
- update.pos = true
- end
- if dir.z ~= 0 and self.old_dir.x ~= 0 then
- vel.z = dir.z * math.abs(vel.x)
- vel.x = 0
- pos.x = math.floor(pos.x + 0.5)
- update.pos = true
- end
- -- Up, down?
- if dir.y ~= self.old_dir.y then
- vel.y = dir.y * math.abs(vel.x + vel.z)
- pos = vector.round(pos)
- update.pos = true
- end
-
- -- Slow down or speed up..
- local acc = dir.y * -1.8
-
- 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 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
-
- if HAVE_MESECONS_ENABLED then
- boost_cart:signal_detector_rail(vector.round(pos))
- end
-
- -- Limits
- for _,v in ipairs({"x","y","z"}) do
- if math.abs(vel[v]) > max_vel then
- vel[v] = boost_cart:get_sign(vel[v]) * max_vel
- new_acc[v] = 0
- update.vel = true
- end
- end
-
- self.object:setacceleration(new_acc)
- self.old_pos = vector.new(pos)
- if not vector.equals(dir, {x=0, y=0, z=0}) then
- self.old_dir = vector.new(dir)
- end
- self.old_switch = last_switch
-
-
- if self.punched then
- -- Collect dropped items
- for _,obj_ in ipairs(minetest.get_objects_inside_radius(pos, 1)) do
- if not obj_:is_player() and
- 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
- return
- 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:setyaw(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)
-
- self.object:setvelocity(vel)
- if update.pos then
- self.object:setpos(pos)
- end
- update = nil
+boost_cart.mtg_compat = minetest.global_exists("carts") and carts.pathfinder
+if boost_cart.mtg_compat then
+ minetest.log("action", "[boost_cart] Overwriting definitions of similar carts mod")
end
-
-minetest.register_entity(":carts:cart", boost_cart.cart)
-minetest.register_craftitem(":carts:cart", {
- description = "Cart (Sneak+Click to pick up)",
- inventory_image = minetest.inventorycube("cart_top.png", "cart_side.png", "cart_side.png"),
- wield_image = "cart_side.png",
- on_place = function(itemstack, placer, pointed_thing)
- if not pointed_thing.type == "node" then
- return
- end
- if boost_cart:is_rail(pointed_thing.under) then
- minetest.add_entity(pointed_thing.under, "carts:cart")
- elseif boost_cart:is_rail(pointed_thing.above) then
- minetest.add_entity(pointed_thing.above, "carts:cart")
- else return end
-
- itemstack:take_item()
- return itemstack
- end,
-})
-
-minetest.register_craft({
- output = "carts:cart",
- recipe = {
- {"default:steel_ingot", "", "default:steel_ingot"},
- {"default:steel_ingot", "default:steel_ingot", "default:steel_ingot"},
- },
-})
+dofile(boost_cart.modpath.."/cart_entity.lua")
diff --git a/boost_cart/rails.lua b/boost_cart/rails.lua
index 04d86b8..c2a58cd 100644
--- a/boost_cart/rails.lua
+++ b/boost_cart/rails.lua
@@ -1,68 +1,53 @@
-minetest.register_node(":default:rail", {
+boost_cart:register_rail(":default:rail", {
description = "Rail",
- drawtype = "raillike",
tiles = {
- "default_rail.png", "default_rail_curved.png",
- "default_rail_t_junction.png", "default_rail_crossing.png"
+ "carts_rail_straight.png", "carts_rail_curved.png",
+ "carts_rail_t_junction.png", "carts_rail_crossing.png"
},
- inventory_image = "default_rail.png",
- wield_image = "default_rail.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 = boost_cart:get_rail_groups(),
+ groups = boost_cart:get_rail_groups()
})
+-- Moreores' copper rail
if minetest.get_modpath("moreores") then
- -- Moreores' copper rail
minetest.register_alias("carts:copperrail", "moreores:copper_rail")
else
boost_cart:register_rail(":carts:copperrail", {
description = "Copper rail",
tiles = {
- "carts_rail_cp.png", "carts_rail_curved_cp.png",
+ "carts_rail_straight_cp.png", "carts_rail_curved_cp.png",
"carts_rail_t_junction_cp.png", "carts_rail_crossing_cp.png"
},
- groups = boost_cart:get_rail_groups(),
+ groups = boost_cart:get_rail_groups()
})
minetest.register_craft({
output = "carts:copperrail 12",
recipe = {
+ {"default:copper_ingot", "", "default:copper_ingot"},
{"default:copper_ingot", "group:stick", "default:copper_ingot"},
- {"default:copper_ingot", "group:stick", "default:copper_ingot"},
- {"default:copper_ingot", "group:stick", "default:copper_ingot"},
+ {"default:copper_ingot", "", "default:copper_ingot"},
}
})
end
--- Speed up
-
+-- Power rail
boost_cart:register_rail(":carts:powerrail", {
description = "Powered rail",
tiles = {
- "carts_rail_pwr.png", "carts_rail_curved_pwr.png",
+ "carts_rail_straight_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")
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,
@@ -79,26 +64,24 @@ minetest.register_craft({
}
})
+-- Brake rail
boost_cart:register_rail(":carts:brakerail", {
description = "Brake rail",
tiles = {
- "carts_rail_brk.png", "carts_rail_curved_brk.png",
+ "carts_rail_straight_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.3")
end
end,
-
mesecons = {
effector = {
action_on = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "-0.3")
end,
-
action_off = function(pos, node)
minetest.get_meta(pos):set_string("cart_acceleration", "0")
end,
@@ -118,23 +101,20 @@ minetest.register_craft({
boost_cart:register_rail("boost_cart:startstoprail", {
description = "Start-stop rail",
tiles = {
- "carts_rail_ss.png", "carts_rail_curved_ss.png",
+ "carts_rail_straight_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,
diff --git a/boost_cart/sounds/cart_rail.1.ogg b/boost_cart/sounds/cart_rail.1.ogg
new file mode 100644
index 0000000..ba2d9ef
--- /dev/null
+++ b/boost_cart/sounds/cart_rail.1.ogg
Binary files differ
diff --git a/boost_cart/sounds/cart_rail.2.ogg b/boost_cart/sounds/cart_rail.2.ogg
new file mode 100644
index 0000000..1b930f0
--- /dev/null
+++ b/boost_cart/sounds/cart_rail.2.ogg
Binary files differ
diff --git a/boost_cart/sounds/cart_rail.3.ogg b/boost_cart/sounds/cart_rail.3.ogg
new file mode 100644
index 0000000..2db4991
--- /dev/null
+++ b/boost_cart/sounds/cart_rail.3.ogg
Binary files differ
diff --git a/boost_cart/textures/carts_rail_crossing.png b/boost_cart/textures/carts_rail_crossing.png
new file mode 100644
index 0000000..1591c70
--- /dev/null
+++ b/boost_cart/textures/carts_rail_crossing.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_crossing_brk.png b/boost_cart/textures/carts_rail_crossing_brk.png
index f9ce303..0e6adfa 100644
--- a/boost_cart/textures/carts_rail_crossing_brk.png
+++ b/boost_cart/textures/carts_rail_crossing_brk.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_crossing_cp.png b/boost_cart/textures/carts_rail_crossing_cp.png
index b04aa63..b2cd736 100644
--- a/boost_cart/textures/carts_rail_crossing_cp.png
+++ b/boost_cart/textures/carts_rail_crossing_cp.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_crossing_dtc.png b/boost_cart/textures/carts_rail_crossing_dtc.png
index a2e4760..8558c02 100644
--- a/boost_cart/textures/carts_rail_crossing_dtc.png
+++ b/boost_cart/textures/carts_rail_crossing_dtc.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_crossing_dtc_on.png b/boost_cart/textures/carts_rail_crossing_dtc_on.png
index 1adba4f..c5d0bf4 100644
--- a/boost_cart/textures/carts_rail_crossing_dtc_on.png
+++ b/boost_cart/textures/carts_rail_crossing_dtc_on.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_crossing_pwr.png b/boost_cart/textures/carts_rail_crossing_pwr.png
index dc317cf..ca9eac4 100644
--- a/boost_cart/textures/carts_rail_crossing_pwr.png
+++ b/boost_cart/textures/carts_rail_crossing_pwr.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_crossing_ss.png b/boost_cart/textures/carts_rail_crossing_ss.png
index 11a4226..d7b945a 100644
--- a/boost_cart/textures/carts_rail_crossing_ss.png
+++ b/boost_cart/textures/carts_rail_crossing_ss.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_curved.png b/boost_cart/textures/carts_rail_curved.png
new file mode 100644
index 0000000..8db11f3
--- /dev/null
+++ b/boost_cart/textures/carts_rail_curved.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_curved_brk.png b/boost_cart/textures/carts_rail_curved_brk.png
index c55183d..03f8bda 100644
--- a/boost_cart/textures/carts_rail_curved_brk.png
+++ b/boost_cart/textures/carts_rail_curved_brk.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_curved_cp.png b/boost_cart/textures/carts_rail_curved_cp.png
index 004ef56..b950453 100644
--- a/boost_cart/textures/carts_rail_curved_cp.png
+++ b/boost_cart/textures/carts_rail_curved_cp.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_curved_dtc.png b/boost_cart/textures/carts_rail_curved_dtc.png
index 0bf7501..67cc18b 100644
--- a/boost_cart/textures/carts_rail_curved_dtc.png
+++ b/boost_cart/textures/carts_rail_curved_dtc.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_curved_dtc_on.png b/boost_cart/textures/carts_rail_curved_dtc_on.png
index 71b8f93..b000d7b 100644
--- a/boost_cart/textures/carts_rail_curved_dtc_on.png
+++ b/boost_cart/textures/carts_rail_curved_dtc_on.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_curved_pwr.png b/boost_cart/textures/carts_rail_curved_pwr.png
index 4aef5dd..11d2dbf 100644
--- a/boost_cart/textures/carts_rail_curved_pwr.png
+++ b/boost_cart/textures/carts_rail_curved_pwr.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_curved_ss.png b/boost_cart/textures/carts_rail_curved_ss.png
index 5269fdd..934f499 100644
--- a/boost_cart/textures/carts_rail_curved_ss.png
+++ b/boost_cart/textures/carts_rail_curved_ss.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_straight.png b/boost_cart/textures/carts_rail_straight.png
new file mode 100644
index 0000000..36fdf4e
--- /dev/null
+++ b/boost_cart/textures/carts_rail_straight.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_straight_brk.png b/boost_cart/textures/carts_rail_straight_brk.png
new file mode 100644
index 0000000..d68e396
--- /dev/null
+++ b/boost_cart/textures/carts_rail_straight_brk.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_straight_cp.png b/boost_cart/textures/carts_rail_straight_cp.png
new file mode 100644
index 0000000..232cee8
--- /dev/null
+++ b/boost_cart/textures/carts_rail_straight_cp.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_straight_dtc.png b/boost_cart/textures/carts_rail_straight_dtc.png
new file mode 100644
index 0000000..85a76b2
--- /dev/null
+++ b/boost_cart/textures/carts_rail_straight_dtc.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_straight_dtc_on.png b/boost_cart/textures/carts_rail_straight_dtc_on.png
new file mode 100644
index 0000000..68bfa14
--- /dev/null
+++ b/boost_cart/textures/carts_rail_straight_dtc_on.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_straight_pwr.png b/boost_cart/textures/carts_rail_straight_pwr.png
new file mode 100644
index 0000000..252dea4
--- /dev/null
+++ b/boost_cart/textures/carts_rail_straight_pwr.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_straight_ss.png b/boost_cart/textures/carts_rail_straight_ss.png
new file mode 100644
index 0000000..b0f537e
--- /dev/null
+++ b/boost_cart/textures/carts_rail_straight_ss.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_t_junction.png b/boost_cart/textures/carts_rail_t_junction.png
new file mode 100644
index 0000000..0b55a0a
--- /dev/null
+++ b/boost_cart/textures/carts_rail_t_junction.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_t_junction_brk.png b/boost_cart/textures/carts_rail_t_junction_brk.png
index 5689ffe..d6fc78a 100644
--- a/boost_cart/textures/carts_rail_t_junction_brk.png
+++ b/boost_cart/textures/carts_rail_t_junction_brk.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_t_junction_cp.png b/boost_cart/textures/carts_rail_t_junction_cp.png
index 3da9094..e266bcc 100644
--- a/boost_cart/textures/carts_rail_t_junction_cp.png
+++ b/boost_cart/textures/carts_rail_t_junction_cp.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_t_junction_dtc.png b/boost_cart/textures/carts_rail_t_junction_dtc.png
index e50cf3b..b69c649 100644
--- a/boost_cart/textures/carts_rail_t_junction_dtc.png
+++ b/boost_cart/textures/carts_rail_t_junction_dtc.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_t_junction_dtc_on.png b/boost_cart/textures/carts_rail_t_junction_dtc_on.png
index 41a08d1..2a21d1f 100644
--- a/boost_cart/textures/carts_rail_t_junction_dtc_on.png
+++ b/boost_cart/textures/carts_rail_t_junction_dtc_on.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_t_junction_pwr.png b/boost_cart/textures/carts_rail_t_junction_pwr.png
index d7edaf1..a2e0f1d 100644
--- a/boost_cart/textures/carts_rail_t_junction_pwr.png
+++ b/boost_cart/textures/carts_rail_t_junction_pwr.png
Binary files differ
diff --git a/boost_cart/textures/carts_rail_t_junction_ss.png b/boost_cart/textures/carts_rail_t_junction_ss.png
index f101298..303c6cf 100644
--- a/boost_cart/textures/carts_rail_t_junction_ss.png
+++ b/boost_cart/textures/carts_rail_t_junction_ss.png
Binary files differ
diff --git a/boost_cart/textures/templates/crossing.png b/boost_cart/textures/templates/crossing.png
new file mode 100644
index 0000000..67b7168
--- /dev/null
+++ b/boost_cart/textures/templates/crossing.png
Binary files differ
diff --git a/boost_cart/textures/templates/curved.png b/boost_cart/textures/templates/curved.png
new file mode 100644
index 0000000..a9070dc
--- /dev/null
+++ b/boost_cart/textures/templates/curved.png
Binary files differ
diff --git a/boost_cart/textures/templates/straight.png b/boost_cart/textures/templates/straight.png
new file mode 100644
index 0000000..9911b36
--- /dev/null
+++ b/boost_cart/textures/templates/straight.png
Binary files differ
diff --git a/boost_cart/textures/templates/t_junction.png b/boost_cart/textures/templates/t_junction.png
new file mode 100644
index 0000000..8c6b621
--- /dev/null
+++ b/boost_cart/textures/templates/t_junction.png
Binary files differ