2019-09-10 19:09:51 +02:00
|
|
|
-- carts/cart_entity.lua
|
|
|
|
|
|
|
|
-- support for MT game translation.
|
|
|
|
local S = carts.get_translator
|
|
|
|
|
2016-11-26 09:09:35 +01:00
|
|
|
local cart_entity = {
|
2018-07-30 01:32:18 +02:00
|
|
|
initial_properties = {
|
|
|
|
physical = false, -- otherwise going uphill breaks
|
|
|
|
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
|
|
|
|
visual = "mesh",
|
|
|
|
mesh = "carts_cart.b3d",
|
|
|
|
visual_size = {x=1, y=1},
|
|
|
|
textures = {"carts_cart.png"},
|
|
|
|
},
|
2016-11-26 09:09:35 +01:00
|
|
|
|
|
|
|
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 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
|
|
|
|
carts:manage_attachment(clicker, nil)
|
|
|
|
elseif not self.driver then
|
|
|
|
carts:manage_attachment(clicker, self.object)
|
2021-05-11 21:15:47 +02:00
|
|
|
self.driver = player_name
|
2016-11-26 09:09:35 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function cart_entity: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)
|
2018-07-07 03:08:36 +02:00
|
|
|
if type(data) ~= "table" then
|
2016-11-26 09:09:35 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
self.railtype = data.railtype
|
2022-05-09 20:44:06 +02:00
|
|
|
self.old_dir = data.old_dir or self.old_dir
|
2016-11-26 09:09:35 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
function cart_entity:get_staticdata()
|
|
|
|
return minetest.serialize({
|
|
|
|
railtype = self.railtype,
|
2017-10-15 12:05:31 +02:00
|
|
|
old_dir = self.old_dir
|
2016-11-26 09:09:35 +01:00
|
|
|
})
|
|
|
|
end
|
|
|
|
|
2018-07-07 03:08:36 +02:00
|
|
|
-- 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
|
2021-05-11 21:15:47 +02:00
|
|
|
-- Clean up eye height
|
2020-05-15 19:04:34 +02:00
|
|
|
carts:manage_attachment(child, nil)
|
2021-05-11 21:15:47 +02:00
|
|
|
self.driver = nil
|
2018-07-07 03:08:36 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-26 09:09:35 +01:00
|
|
|
function cart_entity:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
|
2017-10-15 11:49:48 +02:00
|
|
|
local pos = self.object:get_pos()
|
|
|
|
local vel = self.object:get_velocity()
|
2017-07-02 10:32:10 +02:00
|
|
|
if not self.railtype or vector.equals(vel, {x=0, y=0, z=0}) then
|
2016-11-26 09:09:35 +01:00
|
|
|
local node = minetest.get_node(pos).name
|
|
|
|
self.railtype = minetest.get_item_group(node, "connect_to_raillike")
|
|
|
|
end
|
2016-11-29 03:28:55 +01:00
|
|
|
-- Punched by non-player
|
2016-11-26 09:09:35 +01:00
|
|
|
if not puncher or not puncher:is_player() then
|
|
|
|
local cart_dir = carts: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
|
2016-11-29 03:28:55 +01:00
|
|
|
self.velocity = vector.multiply(cart_dir, 2)
|
2016-11-26 09:09:35 +01:00
|
|
|
self.punched = true
|
|
|
|
return
|
|
|
|
end
|
2016-11-29 03:28:55 +01:00
|
|
|
-- Player digs cart by sneak-punch
|
2016-11-26 09:09:35 +01:00
|
|
|
if puncher:get_player_control().sneak then
|
|
|
|
if self.sound_handle then
|
|
|
|
minetest.sound_stop(self.sound_handle)
|
|
|
|
end
|
2016-11-29 03:28:55 +01:00
|
|
|
-- Detach driver and items
|
2016-11-26 09:09:35 +01:00
|
|
|
if self.driver then
|
|
|
|
if self.old_pos then
|
2017-10-15 11:49:48 +02:00
|
|
|
self.object:set_pos(self.old_pos)
|
2016-11-26 09:09:35 +01:00
|
|
|
end
|
|
|
|
local player = minetest.get_player_by_name(self.driver)
|
|
|
|
carts:manage_attachment(player, nil)
|
|
|
|
end
|
2018-07-07 03:08:36 +02:00
|
|
|
for _, obj_ in ipairs(self.attached_items) do
|
2016-11-26 09:09:35 +01:00
|
|
|
if obj_ then
|
|
|
|
obj_:set_detach()
|
|
|
|
end
|
|
|
|
end
|
2016-11-29 03:28:55 +01:00
|
|
|
-- Pick up cart
|
2016-11-27 07:02:38 +01:00
|
|
|
local inv = puncher:get_inventory()
|
2020-12-13 18:59:19 +01:00
|
|
|
if not minetest.is_creative_enabled(puncher:get_player_name())
|
2016-11-27 07:02:38 +01:00
|
|
|
or not inv:contains_item("main", "carts:cart") then
|
|
|
|
local leftover = inv:add_item("main", "carts:cart")
|
2016-11-29 03:28:55 +01:00
|
|
|
-- If no room in inventory add a replacement cart to the world
|
2016-11-27 07:02:38 +01:00
|
|
|
if not leftover:is_empty() then
|
2017-10-15 11:49:48 +02:00
|
|
|
minetest.add_item(self.object:get_pos(), leftover)
|
2016-11-27 07:02:38 +01:00
|
|
|
end
|
2016-11-26 09:09:35 +01:00
|
|
|
end
|
|
|
|
self.object:remove()
|
|
|
|
return
|
|
|
|
end
|
2016-11-29 03:28:55 +01:00
|
|
|
-- Player punches cart to alter velocity
|
2016-11-26 09:09:35 +01:00
|
|
|
if puncher:get_player_name() == self.driver then
|
|
|
|
if math.abs(vel.x + vel.z) > carts.punch_speed_max then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local punch_dir = carts:velocity_to_dir(puncher:get_look_dir())
|
|
|
|
punch_dir.y = 0
|
|
|
|
local cart_dir = carts: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
|
2021-05-02 14:53:09 +02:00
|
|
|
-- Faulty tool registrations may cause the interval to be set to 0 !
|
|
|
|
if tool_capabilities and (tool_capabilities.full_punch_interval or 0) > 0 then
|
2016-11-26 09:09:35 +01:00
|
|
|
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 = 2 * (time_from_last_punch / punch_interval)
|
|
|
|
|
|
|
|
self.velocity = vector.multiply(cart_dir, f)
|
|
|
|
self.old_dir = cart_dir
|
|
|
|
self.punched = true
|
|
|
|
end
|
|
|
|
|
|
|
|
local function rail_on_step_event(handler, obj, dtime)
|
|
|
|
if handler then
|
|
|
|
handler(obj, dtime)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- sound refresh interval = 1.0sec
|
|
|
|
local function rail_sound(self, dtime)
|
|
|
|
if not self.sound_ttl then
|
|
|
|
self.sound_ttl = 1.0
|
|
|
|
return
|
|
|
|
elseif self.sound_ttl > 0 then
|
|
|
|
self.sound_ttl = self.sound_ttl - dtime
|
|
|
|
return
|
|
|
|
end
|
|
|
|
self.sound_ttl = 1.0
|
|
|
|
if self.sound_handle then
|
|
|
|
local handle = self.sound_handle
|
|
|
|
self.sound_handle = nil
|
|
|
|
minetest.after(0.2, minetest.sound_stop, handle)
|
|
|
|
end
|
2017-10-15 11:49:48 +02:00
|
|
|
local vel = self.object:get_velocity()
|
2016-11-26 09:09:35 +01:00
|
|
|
local speed = vector.length(vel)
|
|
|
|
if speed > 0 then
|
|
|
|
self.sound_handle = minetest.sound_play(
|
|
|
|
"carts_cart_moving", {
|
|
|
|
object = self.object,
|
|
|
|
gain = (speed / carts.speed_max) / 2,
|
|
|
|
loop = true,
|
|
|
|
})
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-11-26 09:48:24 +01:00
|
|
|
local function get_railparams(pos)
|
2016-11-26 09:09:35 +01:00
|
|
|
local node = minetest.get_node(pos)
|
2016-11-26 09:48:24 +01:00
|
|
|
return carts.railparams[node.name] or {}
|
|
|
|
end
|
2016-11-26 09:09:35 +01:00
|
|
|
|
2018-07-07 03:08:36 +02:00
|
|
|
local v3_len = vector.length
|
2016-11-26 09:48:24 +01:00
|
|
|
local function rail_on_step(self, dtime)
|
2017-10-15 11:49:48 +02:00
|
|
|
local vel = self.object:get_velocity()
|
2016-11-26 09:09:35 +01:00
|
|
|
if self.punched then
|
|
|
|
vel = vector.add(vel, self.velocity)
|
2017-10-15 11:49:48 +02:00
|
|
|
self.object:set_velocity(vel)
|
2016-11-26 09:09:35 +01:00
|
|
|
self.old_dir.y = 0
|
|
|
|
elseif vector.equals(vel, {x=0, y=0, z=0}) then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
2017-10-15 11:49:48 +02:00
|
|
|
local pos = self.object:get_pos()
|
2022-05-09 20:44:06 +02:00
|
|
|
local dir = carts:velocity_to_dir(vel)
|
|
|
|
local dir_changed = not vector.equals(dir, self.old_dir)
|
2016-11-26 09:48:24 +01:00
|
|
|
local update = {}
|
|
|
|
|
2022-05-09 20:44:06 +02:00
|
|
|
if self.old_pos and not self.punched and not dir_changed then
|
2016-11-26 09:09:35 +01:00
|
|
|
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
|
|
|
|
|
2017-10-15 12:05:31 +02:00
|
|
|
local stop_wiggle = false
|
2022-05-09 20:44:06 +02:00
|
|
|
if self.old_pos and not dir_changed then
|
2018-07-07 03:08:36 +02:00
|
|
|
-- Detection for "skipping" nodes (perhaps use average dtime?)
|
|
|
|
-- It's sophisticated enough to take the acceleration in account
|
|
|
|
local acc = self.object:get_acceleration()
|
|
|
|
local distance = dtime * (v3_len(vel) + 0.5 * dtime * v3_len(acc))
|
|
|
|
|
|
|
|
local new_pos, new_dir = carts:pathfinder(
|
|
|
|
pos, self.old_pos, self.old_dir, distance, ctrl,
|
|
|
|
self.old_switch, self.railtype
|
2016-11-26 09:09:35 +01:00
|
|
|
)
|
|
|
|
|
2018-07-07 03:08:36 +02:00
|
|
|
if new_pos then
|
|
|
|
-- No rail found: set to the expected position
|
|
|
|
pos = new_pos
|
2016-11-26 09:09:35 +01:00
|
|
|
update.pos = true
|
2022-05-09 20:44:06 +02:00
|
|
|
dir = new_dir
|
2016-11-26 09:09:35 +01:00
|
|
|
end
|
2018-07-07 03:08:36 +02:00
|
|
|
elseif self.old_pos and self.old_dir.y ~= 1 and not self.punched then
|
2017-10-15 12:05:31 +02:00
|
|
|
-- Stop wiggle
|
|
|
|
stop_wiggle = true
|
2016-11-26 09:09:35 +01:00
|
|
|
end
|
|
|
|
|
2016-11-26 09:48:24 +01:00
|
|
|
local railparams
|
2016-11-26 09:09:35 +01:00
|
|
|
|
|
|
|
-- dir: New moving direction of the cart
|
2022-05-09 20:44:06 +02:00
|
|
|
-- switch_keys: Currently pressed L(1) or R(2) key,
|
|
|
|
-- used to ignore the key on the next rail node
|
|
|
|
local switch_keys
|
|
|
|
dir, switch_keys = carts:get_rail_direction(
|
|
|
|
pos, dir, ctrl, self.old_switch, self.railtype
|
2016-11-26 09:09:35 +01:00
|
|
|
)
|
2022-05-09 20:44:06 +02:00
|
|
|
dir_changed = not vector.equals(dir, self.old_dir)
|
2016-11-26 09:09:35 +01:00
|
|
|
|
2022-05-09 20:44:06 +02:00
|
|
|
local acc = 0
|
2017-10-15 12:05:31 +02:00
|
|
|
if stop_wiggle or vector.equals(dir, {x=0, y=0, z=0}) then
|
2022-05-09 20:44:06 +02:00
|
|
|
dir = vector.new(self.old_dir)
|
2016-11-26 09:48:24 +01:00
|
|
|
vel = {x = 0, y = 0, z = 0}
|
2017-10-15 12:05:31 +02:00
|
|
|
local pos_r = vector.round(pos)
|
2018-07-07 03:08:36 +02:00
|
|
|
if not carts:is_rail(pos_r, self.railtype)
|
|
|
|
and self.old_pos then
|
2017-10-15 12:05:31 +02:00
|
|
|
pos = self.old_pos
|
|
|
|
elseif not stop_wiggle then
|
2022-05-09 20:44:06 +02:00
|
|
|
-- End of rail: Smooth out.
|
2017-10-15 12:05:31 +02:00
|
|
|
pos = pos_r
|
2022-05-09 20:44:06 +02:00
|
|
|
dir_changed = false
|
|
|
|
dir.y = 0
|
2017-10-15 12:05:31 +02:00
|
|
|
else
|
|
|
|
pos.y = math.floor(pos.y + 0.5)
|
|
|
|
end
|
2016-11-26 09:09:35 +01:00
|
|
|
update.pos = true
|
|
|
|
update.vel = true
|
|
|
|
else
|
2016-11-26 09:48:24 +01:00
|
|
|
-- Direction change detected
|
2018-07-07 03:08:36 +02:00
|
|
|
if dir_changed then
|
2016-11-26 09:48:24 +01:00
|
|
|
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
|
2016-11-26 09:09:35 +01:00
|
|
|
end
|
2016-11-26 09:48:24 +01:00
|
|
|
-- Center on the rail
|
|
|
|
if dir.z ~= 0 and math.floor(pos.x + 0.5) ~= pos.x then
|
2016-11-26 09:09:35 +01:00
|
|
|
pos.x = math.floor(pos.x + 0.5)
|
|
|
|
update.pos = true
|
|
|
|
end
|
2016-11-26 09:48:24 +01:00
|
|
|
if dir.x ~= 0 and math.floor(pos.z + 0.5) ~= pos.z then
|
|
|
|
pos.z = math.floor(pos.z + 0.5)
|
2016-11-26 09:09:35 +01:00
|
|
|
update.pos = true
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Slow down or speed up..
|
2022-05-09 20:44:06 +02:00
|
|
|
acc = dir.y * -4.0
|
2016-11-26 09:09:35 +01:00
|
|
|
|
2016-11-26 09:48:24 +01:00
|
|
|
-- Get rail for corrected position
|
|
|
|
railparams = get_railparams(pos)
|
|
|
|
|
2016-11-26 09:09:35 +01:00
|
|
|
-- no need to check for railparams == nil since we always make it exist.
|
|
|
|
local speed_mod = railparams.acceleration
|
|
|
|
if speed_mod and speed_mod ~= 0 then
|
|
|
|
-- Try to make it similar to the original carts mod
|
|
|
|
acc = acc + speed_mod
|
|
|
|
else
|
2016-12-07 04:23:03 +01:00
|
|
|
-- Handbrake or coast
|
2016-11-26 09:09:35 +01:00
|
|
|
if ctrl and ctrl.down then
|
2016-12-07 04:23:03 +01:00
|
|
|
acc = acc - 3
|
2016-11-26 09:09:35 +01:00
|
|
|
else
|
|
|
|
acc = acc - 0.4
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-05-09 20:44:06 +02:00
|
|
|
-- Limit cart speed
|
|
|
|
local vel_len = vector.length(vel)
|
|
|
|
if vel_len > carts.speed_max then
|
|
|
|
vel = vector.multiply(vel, carts.speed_max / vel_len)
|
|
|
|
update.vel = true
|
|
|
|
end
|
|
|
|
if vel_len >= carts.speed_max and acc > 0 then
|
|
|
|
acc = 0
|
2016-11-26 09:09:35 +01:00
|
|
|
end
|
|
|
|
|
2022-05-09 20:44:06 +02:00
|
|
|
self.object:set_acceleration(vector.multiply(dir, acc))
|
|
|
|
|
2018-07-07 03:08:36 +02:00
|
|
|
self.old_pos = vector.round(pos)
|
2022-05-09 20:44:06 +02:00
|
|
|
self.old_dir = vector.new(dir)
|
2016-11-26 09:09:35 +01:00
|
|
|
self.old_switch = switch_keys
|
|
|
|
|
|
|
|
if self.punched then
|
|
|
|
-- Collect dropped items
|
2016-11-26 09:48:24 +01:00
|
|
|
for _, obj_ in pairs(minetest.get_objects_inside_radius(pos, 1)) do
|
2020-05-29 22:54:47 +02:00
|
|
|
local ent = obj_:get_luaentity()
|
|
|
|
-- Careful here: physical_state and disable_physics are item-internal APIs
|
|
|
|
if ent and ent.name == "__builtin:item" and ent.physical_state then
|
|
|
|
ent:disable_physics()
|
2016-11-26 09:09:35 +01:00
|
|
|
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
|
|
|
|
|
2016-11-26 09:48:24 +01:00
|
|
|
railparams = railparams or get_railparams(pos)
|
|
|
|
|
2016-11-26 09:09:35 +01:00
|
|
|
if not (update.vel or update.pos) then
|
|
|
|
rail_on_step_event(railparams.on_step, self, dtime)
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local yaw = 0
|
2022-05-09 20:44:06 +02:00
|
|
|
if dir.x < 0 then
|
2016-11-26 09:09:35 +01:00
|
|
|
yaw = 0.5
|
2022-05-09 20:44:06 +02:00
|
|
|
elseif dir.x > 0 then
|
2016-11-26 09:09:35 +01:00
|
|
|
yaw = 1.5
|
2022-05-09 20:44:06 +02:00
|
|
|
elseif dir.z < 0 then
|
2016-11-26 09:09:35 +01:00
|
|
|
yaw = 1
|
|
|
|
end
|
2017-10-15 12:05:31 +02:00
|
|
|
self.object:set_yaw(yaw * math.pi)
|
2016-11-26 09:09:35 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
|
2018-07-07 03:08:36 +02:00
|
|
|
if update.vel then
|
|
|
|
self.object:set_velocity(vel)
|
|
|
|
end
|
2016-11-26 09:09:35 +01:00
|
|
|
if update.pos then
|
2018-07-07 03:08:36 +02:00
|
|
|
if dir_changed then
|
|
|
|
self.object:set_pos(pos)
|
|
|
|
else
|
|
|
|
self.object:move_to(pos)
|
|
|
|
end
|
2016-11-26 09:09:35 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
-- call event handler
|
|
|
|
rail_on_step_event(railparams.on_step, self, dtime)
|
|
|
|
end
|
|
|
|
|
|
|
|
function cart_entity:on_step(dtime)
|
|
|
|
rail_on_step(self, dtime)
|
|
|
|
rail_sound(self, dtime)
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.register_entity("carts:cart", cart_entity)
|
|
|
|
|
|
|
|
minetest.register_craftitem("carts:cart", {
|
2019-09-12 19:03:10 +02:00
|
|
|
description = S("Cart") .. "\n" .. S("(Sneak+Click to pick up)"),
|
2020-04-30 19:51:39 +02:00
|
|
|
inventory_image = minetest.inventorycube("carts_cart_top.png", "carts_cart_front.png", "carts_cart_side.png"),
|
2020-07-24 17:59:42 +02:00
|
|
|
wield_image = "carts_cart_front.png",
|
2016-11-26 09:09:35 +01:00
|
|
|
on_place = function(itemstack, placer, pointed_thing)
|
2017-02-12 01:23:43 +01:00
|
|
|
local under = pointed_thing.under
|
|
|
|
local node = minetest.get_node(under)
|
|
|
|
local udef = minetest.registered_nodes[node.name]
|
|
|
|
if udef and udef.on_rightclick and
|
2017-10-01 15:41:58 +02:00
|
|
|
not (placer and placer:is_player() and
|
|
|
|
placer:get_player_control().sneak) then
|
2017-02-12 01:23:43 +01:00
|
|
|
return udef.on_rightclick(under, node, placer, itemstack,
|
|
|
|
pointed_thing) or itemstack
|
|
|
|
end
|
|
|
|
|
2022-03-26 19:55:12 +01:00
|
|
|
if pointed_thing.type ~= "node" then
|
2016-11-26 09:09:35 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
if carts:is_rail(pointed_thing.under) then
|
|
|
|
minetest.add_entity(pointed_thing.under, "carts:cart")
|
|
|
|
elseif carts:is_rail(pointed_thing.above) then
|
|
|
|
minetest.add_entity(pointed_thing.above, "carts:cart")
|
|
|
|
else
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
minetest.sound_play({name = "default_place_node_metal", gain = 0.5},
|
2020-01-25 23:45:09 +01:00
|
|
|
{pos = pointed_thing.above}, true)
|
2016-11-26 09:09:35 +01:00
|
|
|
|
2024-01-11 15:50:36 +01:00
|
|
|
local player_name = placer and placer:get_player_name() or ""
|
|
|
|
if not minetest.is_creative_enabled(player_name) then
|
2016-11-26 09:09:35 +01:00
|
|
|
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"},
|
|
|
|
},
|
|
|
|
})
|