Compare commits
94 Commits
Author | SHA1 | Date |
---|---|---|
SmallJoker | e4edb96d30 | |
SmallJoker | 3386942d71 | |
SmallJoker | d486143f42 | |
SmallJoker | 34155473a9 | |
SmallJoker | 7e275e1985 | |
SmallJoker | c6b9e4b672 | |
SmallJoker | 3781f6d4c0 | |
SmallJoker | f4c1a2ec3b | |
SmallJoker | 57d09fac79 | |
SmallJoker | 49028ca123 | |
SmallJoker | ca55c6f3c0 | |
SmallJoker | 4498605509 | |
SmallJoker | e19d8701ce | |
SmallJoker | 9a2a2b9d69 | |
SmallJoker | 6ac106c1a7 | |
SmallJoker | be0c56edef | |
SmallJoker | 5502952bbd | |
SmallJoker | ad93d338b3 | |
SmallJoker | e3688b5380 | |
SmallJoker | 2229ededa5 | |
SmallJoker | e8119a63cd | |
SmallJoker | 11a1ebad74 | |
SmallJoker | 3c646ee4df | |
SmallJoker | af25c5411b | |
SmallJoker | b80d3aed4c | |
SmallJoker | 08918701b0 | |
SmallJoker | 66e4613432 | |
SmallJoker | 61b19d77d9 | |
SmallJoker | acf697cd43 | |
SmallJoker | 8b4487c2b8 | |
SmallJoker | cba969903a | |
SmallJoker | 71af46f027 | |
SmallJoker | 99d0480169 | |
SmallJoker | de5fb1825a | |
SmallJoker | cf9b82de37 | |
SmallJoker | 74d8b8f931 | |
SmallJoker | 75132269d7 | |
SmallJoker | b741282843 | |
SmallJoker | 7d6132e748 | |
SmallJoker | 4391d2356f | |
SmallJoker | 5526754e37 | |
Stefan Sauer | f3bc9d795d | |
SmallJoker | eb6a833b66 | |
Christopher Head | d166b7ea68 | |
SmallJoker | 947d8633ff | |
Christopher Head | 9d059b8e31 | |
SmallJoker | cbe0ab9770 | |
SmallJoker | d63f8ae024 | |
SmallJoker | 46c03dd4d1 | |
SmallJoker | d54ca696c5 | |
SmallJoker | 3cac3d8701 | |
SmallJoker | 73722136a0 | |
SmallJoker | 307b5d1f92 | |
SmallJoker | 6e01bf2bf9 | |
SmallJoker | 1b53ebd8e6 | |
SmallJoker | ddb6801b5c | |
SmallJoker | 145ca1c61d | |
Craig Davison | afb52ba3b4 | |
SmallJoker | d58f9930d1 | |
SmallJoker | a7fd733819 | |
number Zero | adfcfe0841 | |
SmallJoker | 79905e47f4 | |
SmallJoker | 159d4ec603 | |
SmallJoker | df04aa2a4d | |
SmallJoker | 670f961d35 | |
SmallJoker | eb610a5e9c | |
SmallJoker | f88f0be7ec | |
SmallJoker | 1aaa83b428 | |
SmallJoker | b6d17c1b34 | |
SmallJoker | 573d56de1a | |
SmallJoker | 2929d2ceb7 | |
SmallJoker | 717721c912 | |
SmallJoker | b6f476db37 | |
SmallJoker | a59864dd74 | |
SmallJoker | 5373a05c9a | |
SmallJoker | 0fa8c88574 | |
SmallJoker | f52e4e3641 | |
SmallJoker | faaa422fae | |
SmallJoker | c8f03513e3 | |
SmallJoker | 21e309c414 | |
SmallJoker | c07c92a1fb | |
SmallJoker | 3d0401f633 | |
SmallJoker | 59b1512cc3 | |
SmallJoker | 70f07f4158 | |
SmallJoker | c106499bd5 | |
SmallJoker | fa2f2cb71c | |
SmallJoker | 64fa36e796 | |
SmallJoker | 8280738bf6 | |
SmallJoker | 4652679f7d | |
SmallJoker | 007037c633 | |
SmallJoker | a38aa7d83b | |
SmallJoker | dc20f048b1 | |
SmallJoker | 6332c670d9 | |
SmallJoker | e8a8ad4324 |
72
README.txt
|
@ -1,23 +1,57 @@
|
|||
Minetest mod: boost_cart
|
||||
=======================
|
||||
Based on the mod "carts" by PilzAdam
|
||||
Target: Run smoothly and do not use too much CPU
|
||||
Minetest mod: boost_cart
|
||||
==========================
|
||||
Based on (and fully compatible with) the mod "carts" by PilzAdam
|
||||
and the one contained in the subgame "minetest_game".
|
||||
Target: Run smoothly as possible, even on laggy servers.
|
||||
|
||||
License of source code:
|
||||
-----------------------
|
||||
WTFPL
|
||||
|
||||
License of media (textures, sounds and models):
|
||||
-----------------------------------------------
|
||||
CC-0
|
||||
Features
|
||||
----------
|
||||
- A fast cart for your railway or roller coaster
|
||||
- Easily configurable cart speed using the Advanced Settings
|
||||
- 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
|
||||
- Support for non-minetest_game subgames
|
||||
|
||||
Authors of media files:
|
||||
-----------------------
|
||||
kddekadenz:
|
||||
cart_bottom.png
|
||||
cart_side.png
|
||||
cart_top.png
|
||||
|
||||
Zeg9:
|
||||
cart.x
|
||||
cart.png
|
||||
Settings
|
||||
----------
|
||||
This mod can be adjusted to fit the conditions of a player or server.
|
||||
Use the Advanced Settings dialog in the main menu or tune your
|
||||
minetest.conf file manually:
|
||||
|
||||
boost_cart.speed_max = 10
|
||||
^ Possible values: 1 ... 100
|
||||
^ Maximal speed of the cart in m/s
|
||||
|
||||
boost_cart.punch_speed_max = 7
|
||||
^ Possible values: -1 ... 100
|
||||
^ Maximal speed to which the driving player can accelerate the cart
|
||||
by punching from inside the cart. -1 will disable this feature.
|
||||
|
||||
|
||||
License for everything
|
||||
------------------------
|
||||
CC-0, if not specified otherwise below
|
||||
|
||||
|
||||
Authors
|
||||
---------
|
||||
Various authors
|
||||
carts_rail_*.png
|
||||
|
||||
kddekadenz
|
||||
cart_bottom.png
|
||||
cart_side.png
|
||||
cart_top.png
|
||||
|
||||
klankbeeld (CC-BY 3.0)
|
||||
http://freesound.org/people/klankbeeld/sounds/174042/
|
||||
cart_rail.*.ogg
|
||||
|
||||
Zeg9
|
||||
cart.x
|
||||
cart.png
|
|
@ -0,0 +1,452 @@
|
|||
|
||||
local HAVE_MESECONS_ENABLED = minetest.global_exists("mesecon")
|
||||
|
||||
function boost_cart:on_rail_step(entity, pos, distance)
|
||||
-- Play rail sound
|
||||
if entity.sound_counter <= 0 then
|
||||
minetest.sound_play("cart_rail", {
|
||||
pos = pos,
|
||||
max_hear_distance = 40,
|
||||
gain = 0.5
|
||||
})
|
||||
entity.sound_counter = math.random(4, 15)
|
||||
end
|
||||
entity.sound_counter = entity.sound_counter - distance
|
||||
|
||||
if HAVE_MESECONS_ENABLED then
|
||||
boost_cart:signal_detector_rail(pos)
|
||||
end
|
||||
end
|
||||
|
||||
local cart_entity = {
|
||||
initial_properties = {
|
||||
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 = {}
|
||||
}
|
||||
|
||||
-- Model and textures
|
||||
if boost_cart.mtg_compat then
|
||||
cart_entity.initial_properties.mesh = "carts_cart.b3d"
|
||||
cart_entity.initial_properties.textures = {"carts_cart.png"}
|
||||
end
|
||||
|
||||
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)
|
||||
|
||||
if default.player_set_animation then
|
||||
-- player_api(/default) does not update the animation
|
||||
-- when the player is attached, reset to default animation
|
||||
default.player_set_animation(clicker, "stand")
|
||||
end
|
||||
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 type(data) ~= "table" then
|
||||
return
|
||||
end
|
||||
self.railtype = data.railtype
|
||||
self.old_dir = data.old_dir or self.old_dir
|
||||
self.old_pos = data.old_pos or self.old_pos
|
||||
-- Correct the position when the cart drives further after the last 'step()'
|
||||
if self.old_pos and boost_cart:is_rail(self.old_pos, self.railtype) then
|
||||
self.object:set_pos(self.old_pos)
|
||||
end
|
||||
end
|
||||
|
||||
function cart_entity:get_staticdata()
|
||||
return minetest.serialize({
|
||||
railtype = self.railtype,
|
||||
old_dir = self.old_dir,
|
||||
old_pos = self.old_pos
|
||||
})
|
||||
end
|
||||
|
||||
-- 0.5.x and later: When the driver leaves
|
||||
function cart_entity:on_detach_child(child)
|
||||
if child and child:get_player_name() == self.driver then
|
||||
self.driver = nil
|
||||
end
|
||||
end
|
||||
|
||||
function cart_entity:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
|
||||
local pos = self.object:get_pos()
|
||||
local vel = self.object:get_velocity()
|
||||
if not self.railtype or vector.equals(vel, {x=0, y=0, z=0}) 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:set_pos(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(pos, leftover)
|
||||
end
|
||||
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
|
||||
-- Driver punches to accelerate the cart
|
||||
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
|
||||
|
||||
local v3_len = vector.length
|
||||
function cart_entity:on_step(dtime)
|
||||
local vel = self.object:get_velocity()
|
||||
if self.punched then
|
||||
vel = vector.add(vel, self.velocity)
|
||||
self.object:set_velocity(vel)
|
||||
self.old_dir.y = 0
|
||||
elseif vector.equals(vel, {x=0, y=0, z=0}) then
|
||||
return
|
||||
end
|
||||
|
||||
local pos = self.object:get_pos()
|
||||
local cart_dir = boost_cart:velocity_to_dir(vel)
|
||||
local same_dir = vector.equals(cart_dir, self.old_dir)
|
||||
local update = {}
|
||||
|
||||
if self.old_pos and not self.punched and same_dir 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
|
||||
local distance = 1
|
||||
|
||||
-- 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
|
||||
|
||||
local stop_wiggle = false
|
||||
if self.old_pos and same_dir then
|
||||
-- Detection for "skipping" nodes (perhaps use average dtime?)
|
||||
-- It's sophisticated enough to take the acceleration in account
|
||||
local acc = self.object:get_acceleration()
|
||||
distance = dtime * (v3_len(vel) + 0.5 * dtime * v3_len(acc))
|
||||
|
||||
local new_pos, new_dir = boost_cart:pathfinder(
|
||||
pos, self.old_pos, self.old_dir, distance, ctrl,
|
||||
self.old_switch, self.railtype
|
||||
)
|
||||
|
||||
if new_pos then
|
||||
-- No rail found: set to the expected position
|
||||
pos = new_pos
|
||||
update.pos = true
|
||||
cart_dir = new_dir
|
||||
end
|
||||
elseif self.old_pos and self.old_dir.y ~= 1 and not self.punched then
|
||||
-- Stop wiggle
|
||||
stop_wiggle = true
|
||||
end
|
||||
|
||||
-- dir: New moving direction of the cart
|
||||
-- switch_keys: Currently pressed L(1) or R(2) 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 dir_changed = not vector.equals(dir, self.old_dir)
|
||||
|
||||
local acc = 0
|
||||
if stop_wiggle or vector.equals(dir, {x=0, y=0, z=0}) then
|
||||
vel = {x=0, y=0, z=0}
|
||||
local pos_r = vector.round(pos)
|
||||
if not boost_cart:is_rail(pos_r, self.railtype)
|
||||
and self.old_pos then
|
||||
pos = self.old_pos
|
||||
elseif not stop_wiggle then
|
||||
pos = pos_r
|
||||
else
|
||||
pos.y = math.floor(pos.y + 0.5)
|
||||
end
|
||||
update.pos = true
|
||||
update.vel = true
|
||||
else
|
||||
-- Direction change detected
|
||||
if dir_changed 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
|
||||
acc = nil
|
||||
|
||||
local acc_meta = minetest.get_meta(pos):get_string("cart_acceleration")
|
||||
if acc_meta == "halt" and not self.punched then
|
||||
-- Stop rail
|
||||
vel = {x=0, y=0, z=0}
|
||||
acc = false
|
||||
pos = vector.round(pos)
|
||||
update.pos = true
|
||||
update.vel = 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 ~= false then
|
||||
-- Handbrake
|
||||
if ctrl and ctrl.down then
|
||||
acc = (acc or 0) - 2
|
||||
elseif acc == nil then
|
||||
acc = -0.4
|
||||
end
|
||||
end
|
||||
|
||||
if acc then
|
||||
-- Slow down or speed up, depending on Y direction
|
||||
acc = acc + dir.y * -2.1
|
||||
else
|
||||
acc = 0
|
||||
end
|
||||
end
|
||||
|
||||
-- Limit cart speed
|
||||
local vel_len = vector.length(vel)
|
||||
if vel_len > boost_cart.speed_max then
|
||||
vel = vector.multiply(vel, boost_cart.speed_max / vel_len)
|
||||
update.vel = true
|
||||
end
|
||||
if vel_len >= boost_cart.speed_max and acc > 0 then
|
||||
acc = 0
|
||||
end
|
||||
|
||||
self.object:set_acceleration(vector.multiply(dir, acc))
|
||||
|
||||
self.old_pos = vector.round(pos)
|
||||
local old_y_dir = self.old_dir.y
|
||||
if not vector.equals(dir, {x=0, y=0, z=0}) and not stop_wiggle then
|
||||
self.old_dir = dir
|
||||
else
|
||||
-- Cart stopped, set the animation to 0
|
||||
self.old_dir.y = 0
|
||||
end
|
||||
self.old_switch = switch_keys
|
||||
|
||||
boost_cart:on_rail_step(self, self.old_pos, distance)
|
||||
|
||||
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
|
||||
-- Re-use "dir", localize self.old_dir
|
||||
dir = self.old_dir
|
||||
|
||||
local yaw = 0
|
||||
if dir.x < 0 then
|
||||
yaw = 0.5
|
||||
elseif dir.x > 0 then
|
||||
yaw = 1.5
|
||||
elseif dir.z < 0 then
|
||||
yaw = 1
|
||||
end
|
||||
self.object:set_yaw(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)
|
||||
|
||||
-- Change player model rotation, depending on the Y direction
|
||||
if player and dir.y ~= old_y_dir then
|
||||
local feet = {x=0, y=0, z=0}
|
||||
local eye = {x=0, y=-4, z=0}
|
||||
feet.y = boost_cart.old_player_model and 6 or -4
|
||||
if dir.y ~= 0 then
|
||||
-- TODO: Find a better way to calculate this
|
||||
if boost_cart.old_player_model then
|
||||
feet.y = feet.y + 2
|
||||
feet.z = -dir.y * 6
|
||||
else
|
||||
feet.y = feet.y + 4
|
||||
feet.z = -dir.y * 2
|
||||
end
|
||||
eye.z = -dir.y * 8
|
||||
end
|
||||
player:set_attach(self.object, "", feet,
|
||||
{x=dir.y * -30, y=0, z=0})
|
||||
player:set_eye_offset(eye, eye)
|
||||
end
|
||||
|
||||
if update.vel then
|
||||
self.object:set_velocity(vel)
|
||||
end
|
||||
if update.pos then
|
||||
if dir_changed then
|
||||
self.object:set_pos(pos)
|
||||
else
|
||||
self.object:move_to(pos)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
minetest.register_entity(":carts:cart", cart_entity)
|
||||
|
||||
-- Register item to place the entity
|
||||
if not boost_cart.mtg_compat then
|
||||
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.settings:get_bool("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"},
|
||||
},
|
||||
})
|
||||
end
|
|
@ -1 +1,4 @@
|
|||
default
|
||||
default
|
||||
mesecons?
|
||||
moreores?
|
||||
carts?
|
|
@ -0,0 +1 @@
|
|||
This mod offers improved minecarts and a few more rail types.
|
|
@ -0,0 +1,58 @@
|
|||
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
|
||||
minetest.swap_node(pos, {name = "boost_cart:detectorrail", param2=node.param2})
|
||||
end
|
||||
mesecon.receptor_off(pos, mesecons_rules)
|
||||
end
|
||||
end
|
||||
|
||||
function boost_cart:signal_detector_rail(pos)
|
||||
local node = minetest.get_node(pos)
|
||||
if minetest.get_item_group(node.name, "detector_rail") ~= 1 then
|
||||
return
|
||||
end
|
||||
|
||||
if node.name == "boost_cart:detectorrail" then
|
||||
minetest.swap_node(pos, {name = "boost_cart:detectorrail_on", param2=node.param2})
|
||||
end
|
||||
mesecon.receptor_on(pos, mesecons_rules)
|
||||
minetest.after(0.5, boost_cart.turnoff_detector_rail, boost_cart, pos)
|
||||
end
|
||||
|
||||
boost_cart:register_rail("boost_cart:detectorrail", {
|
||||
description = "Detector rail",
|
||||
tiles = {
|
||||
"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}),
|
||||
|
||||
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_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({
|
||||
detector_rail = 1, not_in_creative_inventory = 1
|
||||
}),
|
||||
drop = "boost_cart:detectorrail",
|
||||
|
||||
mesecons = {receptor = {state = "on", rules = mesecons_rules}},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "boost_cart:detectorrail 6",
|
||||
recipe = {
|
||||
{"default:steel_ingot", "mesecons:wire_00000000_off", "default:steel_ingot"},
|
||||
{"default:steel_ingot", "group:stick", "default:steel_ingot"},
|
||||
{"default:steel_ingot", "mesecons:wire_00000000_off", "default:steel_ingot"},
|
||||
},
|
||||
})
|
|
@ -0,0 +1,71 @@
|
|||
boost_cart API
|
||||
==============
|
||||
|
||||
This file provides information about the API of boost_cart for the use in
|
||||
mods. The API might change slightly when the development goes on, so avoid
|
||||
using internal tables or functions which are not documented here.
|
||||
|
||||
|
||||
Types
|
||||
-----
|
||||
|
||||
* `SwitchIgnore` -> `number/nil`
|
||||
* Specifies which player control was pressed. This value is used to prefer
|
||||
straight rails instead of preferring left and right rail checks.
|
||||
* `1`: Ignore left rail
|
||||
* `2`: Ignore right rail
|
||||
* `nil`: Ignore no rail
|
||||
|
||||
|
||||
Entity movement
|
||||
---------------
|
||||
These functions are grouped so that they make sense and then sorted alphabetically.
|
||||
|
||||
* `boost_cart:manage_attachment(player, obj)`
|
||||
* Attaches or detaches the player to/from an object, depending on what is
|
||||
supplied to `obj`.
|
||||
* `player`: `ObjectRef` of the player
|
||||
* `obj`: `ObjectRef` (to attach) or `nil` (to detach)
|
||||
* `boost_cart:get_sign(n)` -> `number`
|
||||
* Returns the sign for the given number. Values: `-1`, `0`, `1`
|
||||
* `n`: any `number`
|
||||
* `boost_cart:velocity_to_dir(vel)` -> `vector`
|
||||
* Returns the cart direction depending on `vel`. Each coordinate can have
|
||||
one of the `get_sign()` return values.
|
||||
* `vel`: velocity as `vector`
|
||||
* `boost_cart:boost_rail(pos, amount)`
|
||||
* Sets the rail acceleration for the given position to `amount` and punches
|
||||
carts which are at the given position.
|
||||
* `pos`: `vector`, rail position
|
||||
* `amount`: `number`, negative to brake, positive to boost
|
||||
* `boost_cart:get_rail_direction(pos, dir, ctrl, old_switch, railtype)`
|
||||
-> `vector, SwitchIgnore`
|
||||
* Returns the direction to where the next rail is, and which player control that
|
||||
should be ignored in the next call.
|
||||
* `pos`: `vector`, position of the cart
|
||||
* `dir`: `vector`, movement direction of the cart (see `velocity_to_dir()`)
|
||||
* `ctrl`: Player controls table or `nil` (no player)
|
||||
* `old_switch`: `SwitchIgnore`
|
||||
* `railtype`: (optional) `number`, gets passed indirectly to `is_rail()`
|
||||
|
||||
|
||||
Rail helper functions
|
||||
---------------------
|
||||
* `boost_cart:get_rail_groups(groups)` -> `table`
|
||||
* Returns a group table with preset values for a common rail node
|
||||
* `groups`: (optional) `table`, additional groups append (or overwrite)
|
||||
* Hint: To register an incompatible rail type, set the group
|
||||
`connect_to_raillike` to the value returned by
|
||||
`minetest.raillike_group(new_rail_type)`
|
||||
* `boost_cart:is_rail(pos, [railtype])` -> `boolean`
|
||||
* Returns whether the node at `pos` is a rail. When `railtype` is specified,
|
||||
`true` is only returned when the node is in the same rail group.
|
||||
* `pos`: `vector` of the node to check
|
||||
* `railtype`: (optional) `number`, rail group number
|
||||
* `boost_cart:register_rail(name, def)`
|
||||
* Registers a new rail with preset node definition defaults as fallback
|
||||
* `name`: `string`, node name of the new rail
|
||||
* `def`: Node definition table, containing at least the following keys:
|
||||
* `description`
|
||||
* `groups`
|
||||
* `tiles`
|
302
functions.lua
|
@ -6,98 +6,264 @@ function boost_cart:get_sign(z)
|
|||
end
|
||||
end
|
||||
|
||||
function boost_cart:velocity_to_dir(v)
|
||||
if math.abs(v.x) > math.abs(v.z) then
|
||||
return {x=boost_cart:get_sign(v.x), y=boost_cart:get_sign(v.y), z=0}
|
||||
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
|
||||
end
|
||||
default.player_attached[player_name] = status
|
||||
|
||||
if status then
|
||||
local y_pos = self.old_player_model and 6 or -4
|
||||
if player:get_properties().visual == "upright_sprite" then
|
||||
y_pos = -4
|
||||
end
|
||||
player:set_attach(obj, "", {x=0, y=y_pos, z=0}, {x=0, y=0, z=0})
|
||||
player:set_eye_offset({x=0, y=-4, z=0},{x=0, y=-4, z=0})
|
||||
else
|
||||
return {x=0, y=boost_cart:get_sign(v.y), z=boost_cart:get_sign(v.z)}
|
||||
player:set_detach()
|
||||
player:set_eye_offset({x=0, y=0, z=0},{x=0, y=0, z=0})
|
||||
-- HACK in effect! Force updating the attachment rotation
|
||||
player:set_properties({})
|
||||
end
|
||||
end
|
||||
|
||||
function boost_cart:is_rail(pos)
|
||||
local node = minetest.get_node(pos).name
|
||||
return minetest.get_item_group(node, "rail") ~= 0
|
||||
function boost_cart:velocity_to_dir(v)
|
||||
if math.abs(v.x) > math.abs(v.z) then
|
||||
return {x=self:get_sign(v.x), y=self:get_sign(v.y), z=0}
|
||||
else
|
||||
return {x=0, y=self:get_sign(v.y), z=self:get_sign(v.z)}
|
||||
end
|
||||
end
|
||||
|
||||
function boost_cart:get_rail_direction(pos_, dir_)
|
||||
local pos = vector.round(pos_)
|
||||
local get_node = minetest.get_node
|
||||
local get_item_group = minetest.get_item_group
|
||||
function boost_cart:is_rail(pos, railtype)
|
||||
local node = get_node(pos).name
|
||||
if node == "ignore" then
|
||||
local vm = minetest.get_voxel_manip()
|
||||
local emin, emax = vm:read_from_map(pos, pos)
|
||||
local area = VoxelArea:new{
|
||||
MinEdge = emin,
|
||||
MaxEdge = emax,
|
||||
}
|
||||
local data = vm:get_data()
|
||||
local vi = area:indexp(pos)
|
||||
node = minetest.get_name_from_content_id(data[vi])
|
||||
end
|
||||
if get_item_group(node, "rail") == 0 then
|
||||
return false
|
||||
end
|
||||
if not railtype then
|
||||
return true
|
||||
end
|
||||
return get_item_group(node, "connect_to_raillike") == railtype
|
||||
end
|
||||
|
||||
function boost_cart:check_front_up_down(pos, dir_, check_up, railtype)
|
||||
local dir = vector.new(dir_)
|
||||
local cur = nil
|
||||
|
||||
|
||||
-- Front
|
||||
dir.y = 0
|
||||
cur = vector.add(pos, dir)
|
||||
if boost_cart:is_rail(cur) then
|
||||
if self:is_rail(cur, railtype) then
|
||||
return dir
|
||||
end
|
||||
|
||||
-- Down
|
||||
dir.y = -1
|
||||
cur = vector.add(pos, dir)
|
||||
if boost_cart:is_rail(cur) then
|
||||
return dir
|
||||
end
|
||||
|
||||
-- Up
|
||||
dir.y = 1
|
||||
if check_up then
|
||||
dir.y = 1
|
||||
cur = vector.add(pos, dir)
|
||||
if self:is_rail(cur, railtype) then
|
||||
return dir
|
||||
end
|
||||
end
|
||||
-- Down
|
||||
dir.y = -1
|
||||
cur = vector.add(pos, dir)
|
||||
if boost_cart:is_rail(cur) then
|
||||
if self:is_rail(cur, railtype) then
|
||||
return dir
|
||||
end
|
||||
|
||||
-- Left, right
|
||||
dir.y = 0
|
||||
|
||||
return nil
|
||||
end
|
||||
|
||||
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 view, opposite, val
|
||||
|
||||
if dir.x == 0 and dir.z ~= 0 then
|
||||
view = "z"
|
||||
other = "x"
|
||||
if dir.z < 0 then
|
||||
val = {1, -1}
|
||||
else
|
||||
val = {-1, 1}
|
||||
local left = {x=0, y=0, z=0}
|
||||
local right = {x=0, y=0, z=0}
|
||||
if dir.z ~= 0 and dir.x == 0 then
|
||||
left.x = -dir.z
|
||||
right.x = dir.z
|
||||
elseif dir.x ~= 0 and dir.z == 0 then
|
||||
left.z = dir.x
|
||||
right.z = -dir.x
|
||||
end
|
||||
|
||||
local straight_priority = ctrl and dir.y ~= 0
|
||||
|
||||
-- Normal, to disallow rail switching up- & downhill
|
||||
if straight_priority then
|
||||
cur = self:check_front_up_down(pos, dir, true, railtype)
|
||||
if cur then
|
||||
return cur
|
||||
end
|
||||
elseif dir.z == 0 and dir.x ~= 0 then
|
||||
view = "x"
|
||||
other = "z"
|
||||
if dir.x > 0 then
|
||||
val = {1, -1}
|
||||
else
|
||||
val = {-1, 1}
|
||||
end
|
||||
|
||||
if ctrl then
|
||||
if old_switch == 1 then
|
||||
left_check = false
|
||||
elseif old_switch == 2 then
|
||||
right_check = false
|
||||
end
|
||||
if ctrl.left and left_check then
|
||||
cur = self:check_front_up_down(pos, left, false, railtype)
|
||||
if cur then
|
||||
return cur, 1
|
||||
end
|
||||
left_check = false
|
||||
end
|
||||
if ctrl.right and right_check then
|
||||
cur = self:check_front_up_down(pos, right, false, railtype)
|
||||
if cur then
|
||||
return cur, 2
|
||||
end
|
||||
right_check = true
|
||||
end
|
||||
else
|
||||
return {x=0, y=0, z=0}
|
||||
end
|
||||
|
||||
dir[view] = 0
|
||||
dir[other] = val[1]
|
||||
cur = vector.add(pos, dir)
|
||||
if boost_cart:is_rail(cur) then
|
||||
return dir
|
||||
|
||||
-- Normal
|
||||
if not straight_priority then
|
||||
cur = self:check_front_up_down(pos, dir, true, railtype)
|
||||
if cur then
|
||||
return cur
|
||||
end
|
||||
end
|
||||
|
||||
-- Down
|
||||
dir.y = -1
|
||||
cur = vector.add(pos, dir)
|
||||
if boost_cart:is_rail(cur) then
|
||||
return dir
|
||||
|
||||
-- Left, if not already checked
|
||||
if left_check then
|
||||
cur = self:check_front_up_down(pos, left, false, railtype)
|
||||
if cur then
|
||||
return cur
|
||||
end
|
||||
end
|
||||
dir.y = 0
|
||||
|
||||
dir[other] = val[2]
|
||||
cur = vector.add(pos, dir)
|
||||
if boost_cart:is_rail(cur) then
|
||||
return dir
|
||||
|
||||
-- Right, if not already checked
|
||||
if right_check then
|
||||
cur = self:check_front_up_down(pos, right, false, railtype)
|
||||
if cur then
|
||||
return cur
|
||||
end
|
||||
end
|
||||
|
||||
-- Down
|
||||
dir.y = -1
|
||||
cur = vector.add(pos, dir)
|
||||
if boost_cart:is_rail(cur) then
|
||||
return dir
|
||||
|
||||
-- Backwards
|
||||
if not old_switch then
|
||||
cur = self:check_front_up_down(pos, {
|
||||
x = -dir.x,
|
||||
y = dir.y,
|
||||
z = -dir.z
|
||||
}, true, railtype)
|
||||
if cur then
|
||||
return cur
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
return {x=0, y=0, z=0}
|
||||
end
|
||||
|
||||
function boost_cart:pathfinder(pos_, old_pos, old_dir, distance, ctrl,
|
||||
pf_switch, railtype)
|
||||
|
||||
local pos = vector.round(pos_)
|
||||
if vector.equals(old_pos, pos) then
|
||||
return
|
||||
end
|
||||
|
||||
local pf_pos = vector.round(old_pos)
|
||||
local pf_dir = vector.new(old_dir)
|
||||
distance = math.min(boost_cart.path_distance_max,
|
||||
math.floor(distance + 1))
|
||||
|
||||
for i = 1, distance do
|
||||
pf_dir, pf_switch = self:get_rail_direction(
|
||||
pf_pos, pf_dir, ctrl, pf_switch or 0, railtype)
|
||||
|
||||
if vector.equals(pf_dir, {x=0, y=0, z=0}) then
|
||||
-- No way forwards
|
||||
return pf_pos, pf_dir
|
||||
end
|
||||
|
||||
pf_pos = vector.add(pf_pos, pf_dir)
|
||||
|
||||
if vector.equals(pf_pos, pos) then
|
||||
-- Success! Cart moved on correctly
|
||||
return
|
||||
end
|
||||
end
|
||||
-- Not found. Put cart to predicted position
|
||||
return pf_pos, pf_dir
|
||||
end
|
||||
|
||||
function boost_cart:boost_rail(pos, amount)
|
||||
minetest.get_meta(pos):set_string("cart_acceleration", tostring(amount))
|
||||
for _,obj_ in ipairs(minetest.get_objects_inside_radius(pos, 0.5)) do
|
||||
if not obj_:is_player() and
|
||||
obj_:get_luaentity() and
|
||||
obj_:get_luaentity().name == "carts:cart" then
|
||||
obj_:get_luaentity():on_punch()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function boost_cart:register_rail(name, def_overwrite)
|
||||
local sound_func = default.node_sound_metal_defaults
|
||||
or default.node_sound_defaults
|
||||
|
||||
local def = {
|
||||
drawtype = "raillike",
|
||||
paramtype = "light",
|
||||
sunlight_propagates = true,
|
||||
is_ground_content = false,
|
||||
walkable = false,
|
||||
selection_box = {
|
||||
type = "fixed",
|
||||
fixed = {-1/2, -1/2, -1/2, 1/2, -1/2+1/16, 1/2},
|
||||
},
|
||||
sounds = sound_func()
|
||||
}
|
||||
for k, v in pairs(def_overwrite) 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
|
||||
|
||||
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 minetest.raillike_group then
|
||||
groups.connect_to_raillike = minetest.raillike_group("rail")
|
||||
end
|
||||
if type(additional_groups) == "table" then
|
||||
for k, v in pairs(additional_groups) do
|
||||
groups[k] = v
|
||||
end
|
||||
end
|
||||
return groups
|
||||
end
|
||||
|
|
234
init.lua
|
@ -1,208 +1,46 @@
|
|||
-- TODO:
|
||||
-- Fix way-up
|
||||
-- Add rail-cross switching
|
||||
-- Prevent from floating carts
|
||||
-- Speed up and brake rails
|
||||
|
||||
boost_cart = {}
|
||||
boost_cart.modpath = minetest.get_modpath("boost_cart")
|
||||
boost_cart.speed_max = 8
|
||||
|
||||
|
||||
if not minetest.settings then
|
||||
error("[boost_cart] Your Minetest version is no longer supported."
|
||||
.. " (Version <= 0.4.15)")
|
||||
end
|
||||
|
||||
local function getNum(setting)
|
||||
return tonumber(minetest.settings:get(setting))
|
||||
end
|
||||
|
||||
-- Maximal speed of the cart in m/s
|
||||
boost_cart.speed_max = getNum("boost_cart.speed_max") or 10
|
||||
-- Set to -1 to disable punching the cart from inside
|
||||
boost_cart.punch_speed_max = getNum("boost_cart.punch_speed_max") or 7
|
||||
-- Maximal distance for the path correction (for dtime peaks)
|
||||
boost_cart.path_distance_max = 3
|
||||
|
||||
|
||||
-- Support for non-default games
|
||||
if not default.player_attached then
|
||||
default.player_attached = {}
|
||||
end
|
||||
|
||||
minetest.after(0, function()
|
||||
boost_cart.old_player_model = not minetest.global_exists("player_api")
|
||||
end)
|
||||
|
||||
dofile(boost_cart.modpath.."/functions.lua")
|
||||
dofile(boost_cart.modpath.."/rails.lua")
|
||||
|
||||
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,
|
||||
punch = 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_pos = nil
|
||||
}
|
||||
|
||||
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
|
||||
clicker:set_detach()
|
||||
elseif not self.driver then
|
||||
self.driver = player_name
|
||||
clicker:set_attach(self.object, "", {x=0,y=5,z=0}, {x=0,y=0,z=0})
|
||||
end
|
||||
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_activate(staticdata, dtime_s)
|
||||
self.object:set_armor_groups({immortal=1})
|
||||
self.old_pos = self.object:getpos()
|
||||
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
|
||||
|
||||
function boost_cart.cart:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
|
||||
if not puncher or not puncher:is_player() then
|
||||
return
|
||||
end
|
||||
|
||||
if puncher:get_player_control().sneak then
|
||||
if self.driver then
|
||||
local player = minetest.get_player_by_name(self.driver)
|
||||
if player then
|
||||
player:set_detach()
|
||||
end
|
||||
end
|
||||
self.object:remove()
|
||||
puncher:get_inventory():add_item("main", "boost_cart:cart")
|
||||
return
|
||||
end
|
||||
|
||||
local vel = self.velocity
|
||||
if puncher:get_player_name() == self.driver then
|
||||
if math.abs(vel.x) > 2 or math.abs(vel.z) > 2 then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
local cart_dir = boost_cart:velocity_to_dir(direction)
|
||||
if cart_dir.x == 0 and cart_dir.z == 0 then
|
||||
local fd = minetest.dir_to_facedir(puncher:get_look_dir())
|
||||
if fd == 0 then
|
||||
cart_dir.x = 1
|
||||
elseif fd == 1 then
|
||||
cart_dir.z = -1
|
||||
elseif fd == 2 then
|
||||
cart_dir.x = -1
|
||||
elseif fd == 3 then
|
||||
cart_dir.z = 1
|
||||
end
|
||||
end
|
||||
|
||||
if time_from_last_punch > tool_capabilities.full_punch_interval then
|
||||
time_from_last_punch = tool_capabilities.full_punch_interval
|
||||
end
|
||||
local dir = boost_cart:get_rail_direction(self.object:getpos(), cart_dir)
|
||||
|
||||
local f = 3 * (time_from_last_punch / tool_capabilities.full_punch_interval)
|
||||
vel.x = dir.x * f
|
||||
vel.z = dir.y * f
|
||||
vel.z = dir.z * f
|
||||
self.velocity = vel
|
||||
self.punch = true
|
||||
end
|
||||
|
||||
function boost_cart.cart:on_step(dtime)
|
||||
local vel = self.object:getvelocity()
|
||||
if self.punch then
|
||||
vel = vector.add(vel, self.velocity)
|
||||
self.velocity = {x=0,y=0,z=0}
|
||||
elseif vector.equals(vel, {x=0,y=0,z=0}) then
|
||||
return
|
||||
end
|
||||
|
||||
local pos = self.object:getpos()
|
||||
local fpos, fold_pos = vector.round(pos), vector.round(self.old_pos)
|
||||
if vector.equals(fpos, fold_pos) and not self.punch then
|
||||
return
|
||||
end
|
||||
self.old_pos = vector.new(pos)
|
||||
|
||||
local cart_dir = {
|
||||
x = boost_cart:get_sign(vel.x),
|
||||
y = boost_cart:get_sign(vel.y),
|
||||
z = boost_cart:get_sign(vel.z)
|
||||
}
|
||||
local dir = boost_cart:get_rail_direction(pos, cart_dir)
|
||||
if vector.equals(dir, {x=0, y=0, z=0}) then
|
||||
vel = {x=0, y=0, z=0}
|
||||
self.object:setacceleration({x=0, y=0, z=0})
|
||||
self.punch = 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)
|
||||
self.punch = 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)
|
||||
self.punch = true
|
||||
end
|
||||
-- Up, down?
|
||||
if dir.y ~= self.old_dir.y then
|
||||
vel.y = dir.y * (math.abs(vel.x) + math.abs(vel.z))
|
||||
pos.y = math.floor(pos.y + 0.5)
|
||||
self.punch = true
|
||||
end
|
||||
|
||||
-- Slow down or speed up..
|
||||
local acc = -2 * dir.y - 0.4
|
||||
self.object:setacceleration({
|
||||
x = dir.x * acc,
|
||||
y = dir.y * (math.abs(dir.x) + math.abs(dir.z)) * acc,
|
||||
z = dir.z * acc
|
||||
})
|
||||
end
|
||||
|
||||
self.old_dir = vector.new(dir)
|
||||
|
||||
-- Limits
|
||||
for _,v in ipairs({"x","y","z"}) do
|
||||
if math.abs(vel[v]) > boost_cart.speed_max then
|
||||
vel[v] = boost_cart:get_sign(vel[v]) * boost_cart.speed_max
|
||||
self.punch = true
|
||||
end
|
||||
end
|
||||
|
||||
if dir.x < 0 then
|
||||
self.object:setyaw(math.pi / 2)
|
||||
elseif dir.x > 0 then
|
||||
self.object:setyaw(3 * math.pi / 2)
|
||||
elseif dir.z < 0 then
|
||||
self.object:setyaw(math.pi)
|
||||
elseif dir.z > 0 then
|
||||
self.object:setyaw(0)
|
||||
end
|
||||
|
||||
if dir.y == -1 then
|
||||
self.object:set_animation({x=1, y=1}, 1, 0)
|
||||
elseif dir.y == 1 then
|
||||
self.object:set_animation({x=2, y=2}, 1, 0)
|
||||
else
|
||||
self.object:set_animation({x=0, y=0}, 1, 0)
|
||||
end
|
||||
if self.punch then
|
||||
self.object:setvelocity(vel)
|
||||
self.object:setpos(pos)
|
||||
self.old_pos = {x=0, y=0, z=0}
|
||||
end
|
||||
self.punch = false
|
||||
end
|
||||
|
||||
minetest.register_entity("boost_cart:cart", boost_cart.cart)
|
||||
minetest.register_craftitem("boost_cart:cart", {
|
||||
description = "Cart",
|
||||
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, "boost_cart:cart")
|
||||
elseif boost_cart:is_rail(pointed_thing.above) then
|
||||
minetest.add_entity(pointed_thing.above, "boost_cart:cart")
|
||||
else return end
|
||||
|
||||
itemstack:take_item()
|
||||
return itemstack
|
||||
end,
|
||||
})
|
||||
dofile(boost_cart.modpath.."/cart_entity.lua")
|
||||
|
|
158
rails.lua
|
@ -1,16 +1,146 @@
|
|||
minetest.register_node(":default:rail", {
|
||||
-- Common rail registrations
|
||||
|
||||
local regular_rail_itemname = "default:rail"
|
||||
if minetest.registered_nodes["carts:rail"] then
|
||||
-- MTG Compatibility
|
||||
regular_rail_itemname = "carts:rail"
|
||||
end
|
||||
|
||||
boost_cart:register_rail(":"..regular_rail_itemname, {
|
||||
description = "Rail",
|
||||
drawtype = "raillike",
|
||||
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",
|
||||
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},
|
||||
tiles = {
|
||||
"carts_rail_straight.png", "carts_rail_curved.png",
|
||||
"carts_rail_t_junction.png", "carts_rail_crossing.png"
|
||||
},
|
||||
groups = {dig_immediate = 2, attached_node = 1, rail = 1, connect_to_raillike = 1},
|
||||
})
|
||||
groups = boost_cart:get_rail_groups()
|
||||
})
|
||||
|
||||
-- Moreores' copper rail
|
||||
if minetest.get_modpath("moreores") then
|
||||
minetest.register_alias("carts:copperrail", "moreores:copper_rail")
|
||||
|
||||
if minetest.raillike_group then
|
||||
-- Ensure that this rail uses the same connect_to_raillike
|
||||
local new_groups = minetest.registered_nodes["moreores:copper_rail"].groups
|
||||
new_groups.connect_to_raillike = minetest.raillike_group("rail")
|
||||
minetest.override_item("moreores:copper_rail", {
|
||||
groups = new_groups
|
||||
})
|
||||
end
|
||||
else
|
||||
boost_cart:register_rail(":carts:copperrail", {
|
||||
description = "Copper rail",
|
||||
tiles = {
|
||||
"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()
|
||||
})
|
||||
|
||||
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", "", "default:copper_ingot"},
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
-- Power rail
|
||||
boost_cart:register_rail(":carts:powerrail", {
|
||||
description = "Powered rail",
|
||||
tiles = {
|
||||
"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,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "carts:powerrail 6",
|
||||
recipe = {
|
||||
{"default:steel_ingot", "default:mese_crystal_fragment", "default:steel_ingot"},
|
||||
{"default:steel_ingot", "group:stick", "default:steel_ingot"},
|
||||
{"default:steel_ingot", "default:mese_crystal_fragment", "default:steel_ingot"},
|
||||
}
|
||||
})
|
||||
|
||||
-- Brake rail
|
||||
boost_cart:register_rail(":carts:brakerail", {
|
||||
description = "Brake rail",
|
||||
tiles = {
|
||||
"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,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
output = "carts:brakerail 6",
|
||||
recipe = {
|
||||
{"default:steel_ingot", "default:coal_lump", "default:steel_ingot"},
|
||||
{"default:steel_ingot", "group:stick", "default:steel_ingot"},
|
||||
{"default:steel_ingot", "default:coal_lump", "default:steel_ingot"},
|
||||
}
|
||||
})
|
||||
|
||||
boost_cart:register_rail("boost_cart:startstoprail", {
|
||||
description = "Start-stop rail",
|
||||
tiles = {
|
||||
"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,
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
minetest.register_craft({
|
||||
type = "shapeless",
|
||||
output = "boost_cart:startstoprail 2",
|
||||
recipe = {"carts:powerrail", "carts:brakerail"},
|
||||
})
|
||||
|
|
After Width: | Height: | Size: 154 KiB |
|
@ -0,0 +1,6 @@
|
|||
# Maximal speed of the cart in m/s (min=1, max=100)
|
||||
boost_cart.speed_max (Maximal speed) int 10 1 100
|
||||
|
||||
# Maximal speed to which the driving player can accelerate the cart by punching
|
||||
# from inside the cart. -1 will disable this feature. (min=-1, max=100)
|
||||
boost_cart.punch_speed_max (Maximal punch speed) int 7 -1 100
|
After Width: | Height: | Size: 755 B |
After Width: | Height: | Size: 765 B |
After Width: | Height: | Size: 735 B |
After Width: | Height: | Size: 823 B |
After Width: | Height: | Size: 823 B |
After Width: | Height: | Size: 847 B |
After Width: | Height: | Size: 813 B |
After Width: | Height: | Size: 750 B |
After Width: | Height: | Size: 738 B |
After Width: | Height: | Size: 691 B |
After Width: | Height: | Size: 780 B |
After Width: | Height: | Size: 780 B |
After Width: | Height: | Size: 798 B |
After Width: | Height: | Size: 832 B |
After Width: | Height: | Size: 785 B |
After Width: | Height: | Size: 789 B |
After Width: | Height: | Size: 728 B |
After Width: | Height: | Size: 830 B |
After Width: | Height: | Size: 830 B |
After Width: | Height: | Size: 836 B |
After Width: | Height: | Size: 843 B |
After Width: | Height: | Size: 789 B |
After Width: | Height: | Size: 714 B |
After Width: | Height: | Size: 715 B |
After Width: | Height: | Size: 752 B |
After Width: | Height: | Size: 808 B |
After Width: | Height: | Size: 761 B |
After Width: | Height: | Size: 813 B |
After Width: | Height: | Size: 368 B |
After Width: | Height: | Size: 400 B |
After Width: | Height: | Size: 248 B |
After Width: | Height: | Size: 323 B |