mirror of
https://github.com/SmallJoker/boost_cart.git
synced 2024-12-25 02:10:19 +01:00
Do not take cart from inventory in creative mode
Correct comments and move some variables
This commit is contained in:
parent
7d6132e748
commit
b741282843
@ -6,10 +6,11 @@ function boost_cart:get_sign(z)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function boost_cart:manage_attachment(player, status, obj)
|
function boost_cart:manage_attachment(player, obj)
|
||||||
if not player then
|
if not player then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
local status = obj ~= nil
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
if default.player_attached[player_name] == status then
|
if default.player_attached[player_name] == status then
|
||||||
return
|
return
|
||||||
|
43
init.lua
43
init.lua
@ -4,8 +4,8 @@ boost_cart.modpath = minetest.get_modpath("boost_cart")
|
|||||||
|
|
||||||
-- Maximal speed of the cart in m/s
|
-- Maximal speed of the cart in m/s
|
||||||
boost_cart.speed_max = 10
|
boost_cart.speed_max = 10
|
||||||
-- Set to nil to disable punching the cart from inside (min = -1)
|
-- Set to -1 to disable punching the cart from inside
|
||||||
boost_cart.punch_speed_min = 7
|
boost_cart.punch_speed_max = 7
|
||||||
|
|
||||||
|
|
||||||
if not boost_cart.modpath then
|
if not boost_cart.modpath then
|
||||||
@ -59,10 +59,10 @@ function boost_cart.cart:on_rightclick(clicker)
|
|||||||
local player_name = clicker:get_player_name()
|
local player_name = clicker:get_player_name()
|
||||||
if self.driver and player_name == self.driver then
|
if self.driver and player_name == self.driver then
|
||||||
self.driver = nil
|
self.driver = nil
|
||||||
boost_cart:manage_attachment(clicker, false)
|
boost_cart:manage_attachment(clicker, nil)
|
||||||
elseif not self.driver then
|
elseif not self.driver then
|
||||||
self.driver = player_name
|
self.driver = player_name
|
||||||
boost_cart:manage_attachment(clicker, true, self.object)
|
boost_cart:manage_attachment(clicker, self.object)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -91,8 +91,7 @@ end
|
|||||||
function boost_cart.cart:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
|
function boost_cart.cart:on_punch(puncher, time_from_last_punch, tool_capabilities, direction)
|
||||||
local pos = self.object:getpos()
|
local pos = self.object:getpos()
|
||||||
if not self.railtype then
|
if not self.railtype then
|
||||||
local bar = vector.floor(vector.add(pos, 0.1))
|
local node = minetest.get_node(pos).name
|
||||||
local node = minetest.get_node(bar).name
|
|
||||||
self.railtype = minetest.get_item_group(node, "connect_to_raillike")
|
self.railtype = minetest.get_item_group(node, "connect_to_raillike")
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -102,7 +101,6 @@ function boost_cart.cart:on_punch(puncher, time_from_last_punch, tool_capabiliti
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
self.velocity = vector.multiply(cart_dir, 3)
|
self.velocity = vector.multiply(cart_dir, 3)
|
||||||
self.old_pos = nil
|
|
||||||
self.punched = true
|
self.punched = true
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
@ -114,7 +112,7 @@ function boost_cart.cart:on_punch(puncher, time_from_last_punch, tool_capabiliti
|
|||||||
self.object:setpos(self.old_pos)
|
self.object:setpos(self.old_pos)
|
||||||
end
|
end
|
||||||
local player = minetest.get_player_by_name(self.driver)
|
local player = minetest.get_player_by_name(self.driver)
|
||||||
boost_cart:manage_attachment(player, false)
|
boost_cart:manage_attachment(player, nil)
|
||||||
end
|
end
|
||||||
for _,obj_ in ipairs(self.attached_items) do
|
for _,obj_ in ipairs(self.attached_items) do
|
||||||
if obj_ then
|
if obj_ then
|
||||||
@ -132,7 +130,7 @@ function boost_cart.cart:on_punch(puncher, time_from_last_punch, tool_capabiliti
|
|||||||
|
|
||||||
local vel = self.object:getvelocity()
|
local vel = self.object:getvelocity()
|
||||||
if puncher:get_player_name() == self.driver then
|
if puncher:get_player_name() == self.driver then
|
||||||
if math.abs(vel.x + vel.z) > boost_cart.punch_speed_min then
|
if math.abs(vel.x + vel.z) > boost_cart.punch_speed_max then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -153,7 +151,6 @@ function boost_cart.cart:on_punch(puncher, time_from_last_punch, tool_capabiliti
|
|||||||
|
|
||||||
self.velocity = vector.multiply(cart_dir, f)
|
self.velocity = vector.multiply(cart_dir, f)
|
||||||
self.old_dir = cart_dir
|
self.old_dir = cart_dir
|
||||||
self.old_pos = nil
|
|
||||||
self.punched = true
|
self.punched = true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -168,9 +165,6 @@ function boost_cart.cart:on_step(dtime)
|
|||||||
return
|
return
|
||||||
end
|
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()
|
local pos = self.object:getpos()
|
||||||
|
|
||||||
if self.old_pos and not self.punched then
|
if self.old_pos and not self.punched then
|
||||||
@ -207,12 +201,12 @@ function boost_cart.cart:on_step(dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local cart_dir = boost_cart:velocity_to_dir(vel)
|
local cart_dir = boost_cart:velocity_to_dir(vel)
|
||||||
local max_vel = boost_cart.speed_max
|
|
||||||
if not dir then
|
-- dir: New moving direction of the cart
|
||||||
dir, last_switch = boost_cart:get_rail_direction(
|
-- switch_keys: Currently pressed L/R key, used to ignore the key on the next rail node
|
||||||
pos, cart_dir, ctrl, self.old_switch, self.railtype
|
local dir, switch_keys = boost_cart:get_rail_direction(
|
||||||
)
|
pos, cart_dir, ctrl, self.old_switch, self.railtype
|
||||||
end
|
)
|
||||||
|
|
||||||
local new_acc = {x=0, y=0, z=0}
|
local new_acc = {x=0, y=0, z=0}
|
||||||
if vector.equals(dir, {x=0, y=0, z=0}) then
|
if vector.equals(dir, {x=0, y=0, z=0}) then
|
||||||
@ -285,6 +279,7 @@ function boost_cart.cart:on_step(dtime)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Limits
|
-- Limits
|
||||||
|
local max_vel = boost_cart.speed_max
|
||||||
for _,v in ipairs({"x","y","z"}) do
|
for _,v in ipairs({"x","y","z"}) do
|
||||||
if math.abs(vel[v]) > max_vel then
|
if math.abs(vel[v]) > max_vel then
|
||||||
vel[v] = boost_cart:get_sign(vel[v]) * max_vel
|
vel[v] = boost_cart:get_sign(vel[v]) * max_vel
|
||||||
@ -314,7 +309,7 @@ function boost_cart.cart:on_step(dtime)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
self.punched = false
|
self.punched = false
|
||||||
update.vel = true -- update player animation
|
update.vel = true
|
||||||
end
|
end
|
||||||
|
|
||||||
if not (update.vel or update.pos) then
|
if not (update.vel or update.pos) then
|
||||||
@ -359,9 +354,13 @@ minetest.register_craftitem(":carts:cart", {
|
|||||||
minetest.add_entity(pointed_thing.under, "carts:cart")
|
minetest.add_entity(pointed_thing.under, "carts:cart")
|
||||||
elseif boost_cart:is_rail(pointed_thing.above) then
|
elseif boost_cart:is_rail(pointed_thing.above) then
|
||||||
minetest.add_entity(pointed_thing.above, "carts:cart")
|
minetest.add_entity(pointed_thing.above, "carts:cart")
|
||||||
else return end
|
else
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
itemstack:take_item()
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
|
itemstack:take_item()
|
||||||
|
end
|
||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user