Skip to content

Commit

Permalink
Add the slow_down node (early development) (#70)
Browse files Browse the repository at this point in the history
  • Loading branch information
Panquesito7 committed Feb 9, 2023
1 parent b471ee1 commit 983e781
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 12 deletions.
52 changes: 40 additions & 12 deletions mods/pk/lib_mount/init.lua
Expand Up @@ -67,11 +67,6 @@ local function node_is(pos)
return "special_asphalt"
elseif node.name == "pk_nodes:lava_node" then
return "special_lava"
-- Grass nodes
elseif node.name == "maptools:grass" then
return "maptools_grass"
elseif node.name == "default:dirt_with_grass" then
return "default_grass"
end
if minetest.get_item_group(node.name, "liquid") ~= 0 then
Expand Down Expand Up @@ -222,6 +217,25 @@ local function slow_down_on_grass(entity, max_spd) -- luacheck: ignore
end
end
local function slow_down(entity, max_spd, nodename, value) -- luacheck: ignore
if not entity or not entity.object then return end -- Safety check
local pos = entity.object:get_pos() or {x = 0, y = 0, z = 0}
pos.y = pos.y - 0.5
local node = minetest.get_node(pos)
-- Slow down speed when standing on certain node.
if node.name == nodename then
max_spd = entity.max_speed_reverse / value
if get_sign(entity.v) >= 0 then
max_spd = entity.max_speed_forward / value
end
if math.abs(entity.v) > max_spd then
entity.v = entity.v - get_sign(entity.v)
end
end
end
-------------------------------------------------------------------------------
minetest.register_on_leaveplayer(function(player)
Expand Down Expand Up @@ -498,7 +512,9 @@ function lib_mount.drive(entity, dtime, is_mob, moving_anim, stand_anim, jump_he
if math.abs(entity.v) > max_spd then
entity.v = entity.v - get_sign(entity.v)
end
slow_down_on_grass(entity, max_spd)
slow_down(entity, max_spd, "default:dirt_with_grass", 2)
slow_down(entity, max_spd, "maptools:grass", 2)
slow_down(entity, max_spd, "pk_nodes:slow_down", 3)
else
local max_spd = entity.max_speed_reverse
if get_sign(entity.v) >= 0 then
Expand All @@ -507,7 +523,9 @@ function lib_mount.drive(entity, dtime, is_mob, moving_anim, stand_anim, jump_he
if math.abs(entity.v) > max_spd then
entity.v = entity.v - get_sign(entity.v)
end
slow_down_on_grass(entity, max_spd)
slow_down(entity, max_spd, "default:dirt_with_grass", 2)
slow_down(entity, max_spd, "maptools:grass", 2)
slow_down(entity, max_spd, "pk_nodes:slow_down", 3)
end
else
local max_spd = entity.max_speed_reverse
Expand All @@ -517,7 +535,9 @@ function lib_mount.drive(entity, dtime, is_mob, moving_anim, stand_anim, jump_he
if math.abs(entity.v) > max_spd then
entity.v = entity.v - get_sign(entity.v)
end
slow_down_on_grass(entity, max_spd)
slow_down(entity, max_spd, "default:dirt_with_grass", 2)
slow_down(entity, max_spd, "maptools:grass", 2)
slow_down(entity, max_spd, "pk_nodes:slow_down", 3)
end
else
Expand All @@ -538,7 +558,9 @@ function lib_mount.drive(entity, dtime, is_mob, moving_anim, stand_anim, jump_he
if math.abs(entity.v) > max_spd then
entity.v = entity.v - get_sign(entity.v)
end
slow_down_on_grass(entity, max_spd)
slow_down(entity, max_spd, "default:dirt_with_grass", 2)
slow_down(entity, max_spd, "maptools:grass", 2)
slow_down(entity, max_spd, "pk_nodes:slow_down", 3)
else
-- enforce speed limit forward and reverse
local max_spd = entity.max_speed_reverse
Expand All @@ -548,7 +570,9 @@ function lib_mount.drive(entity, dtime, is_mob, moving_anim, stand_anim, jump_he
if math.abs(entity.v) > max_spd then
entity.v = entity.v - get_sign(entity.v)
end
slow_down_on_grass(entity, max_spd)
slow_down(entity, max_spd, "default:dirt_with_grass", 2)
slow_down(entity, max_spd, "maptools:grass", 2)
slow_down(entity, max_spd, "pk_nodes:slow_down", 3)
end
end
end
Expand All @@ -561,6 +585,10 @@ function lib_mount.drive(entity, dtime, is_mob, moving_anim, stand_anim, jump_he
if math.abs(entity.v) > max_spd then
entity.v = entity.v - get_sign(entity.v)
end
slow_down(entity, max_spd, "default:dirt_with_grass", 2)
slow_down(entity, max_spd, "maptools:grass", 2)
slow_down(entity, max_spd, "pk_nodes:slow_down", 3)
end
-- Stop!
Expand Down Expand Up @@ -665,14 +693,14 @@ function lib_mount.drive(entity, dtime, is_mob, moving_anim, stand_anim, jump_he
-- new_acce.y = 1
end
-- Set the variable to true if on grass
--[[ Set the variable to true if on grass
if entity.driver then
if ni == "maptools_grass" or ni == "default_grass" then
is_on_grass[entity.driver] = true
elseif ni ~= "maptools_grass" or ni ~= "default_grass" then
is_on_grass[entity.driver] = false
end
end
end--]]

-- Teleport the player 35 nodes back when touching this node.
if entity.driver and ni == "special_lava" and not core_game.is_end[entity.driver] then
Expand Down
33 changes: 33 additions & 0 deletions mods/pk/pk_nodes/init.lua
Expand Up @@ -108,6 +108,39 @@ if minetest.get_modpath("wool") then
})
end
-- Based off from `streets_solid_center_line_wide` node registration. Thanks!
minetest.register_node("pk_nodes:slow_down", {
description = "Slows down an entity when on top",
tiles = {"pk_nodes_invisible.png"},
inventory_image = "default_cobble.png",
paramtype = "light",
sunlight_propagates = true,
paramtype2 = "facedir",
is_ground_content = false,
walkable = true,
pointable = false,
buildable_to = false,
drawtype = "nodebox",
groups = {not_in_creative_inventory = 1, unbreakable = 1},
use_texture_alpha = "clip",
node_box = {
type = "fixed",
fixed = { -0.5, -0.5, -0.5, 0.5, -0.499, 0.5 }
},
selection_box = {
type = "fixed",
fixed = { -1 / 2, -1 / 2, -1 / 2, 1 / 2, -1 / 2 + 1 / 16, 1 / 2 }
},
on_place = function(itemstack, placer, pointed_thing)
if minetest.check_player_privs(placer, { core_admin = true }) or minetest.check_player_privs(placer, { builder = true }) then
return minetest.item_place(itemstack, placer, pointed_thing)
else
minetest.chat_send_player(placer:get_player_name(), S2("You don't have sufficient permissions to interact with this node. Missing privileges: core_admin"))
return itemstack
end
end,
})
-- In case the user doesn't install the `mobs` mod, make an alias for the fence node.
-- Start: code taken from https://notabug.org/TenPlus1/mobs_redo/src/master/crafts.lua#L157-L171
if not minetest.get_modpath("mobs") then
Expand Down
Binary file added mods/pk/pk_nodes/textures/pk_nodes_invisible.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 983e781

Please sign in to comment.