Use new API command add_player_velocity

This commit is contained in:
Andrey 2021-07-01 10:46:53 +03:00 committed by Andrejs
parent 39d60c6657
commit d26fdce267
10 changed files with 85 additions and 16 deletions

0
LICENSE Normal file → Executable file
View File

1
README.txt Normal file → Executable file
View File

@ -1,4 +1,5 @@
Mod for Minetest game "Climbing pick"
Starting from version 5.1
Climbing pick - allow to jump over more than one block.
Meant to partially replace "sneak glitch" feature.

0
depends.txt Normal file → Executable file
View File

100
init.lua Normal file → Executable file
View File

@ -1,6 +1,7 @@
-- Climbing tool mod
climbing_pick = {}
climbing_pick.jump2 = {}
climbing_pick.effect = function(pos)
-- visual effect
@ -115,25 +116,23 @@ climbing_pick.pick_on_use = function(itemstack, user, pointed_thing)
local tool_capabilities = tool_definition.tool_capabilities
-- local punch_interval = tool_capabilities.full_punch_interval -- not sure how to use correctly
-- Limit how fast up player can go
local current_jump_speed = user:get_player_velocity()["y"]
if current_jump_speed > (tool_capabilities.groupcaps.climbing.maxlevel) then
return
end
-- sound effect
minetest.sound_play("default_metal_footstep", {pos = pos, gain = 0.5, })
climbing_pick.effect(target_pos)
-- no way to set speed of player
-- emulate it in ugly way
-- https://github.com/minetest/minetest/issues/1176 :(
local repetitions = 5
if tool_capabilities.groupcaps.climbing.maxlevel > 1 then
repetitions = repetitions + 2
end
if tool_capabilities.groupcaps.climbing.maxlevel > 2 then
repetitions = repetitions + 2
end
for i = 1, repetitions do
pos.y = pos.y + 0.2
user:moveto(pos, true)
-- minetest API now allows to set speed of player
local jump2_speed = 3.25 + tool_capabilities.groupcaps.climbing.maxlevel
-- Limit jump speed to default 6.5
if (current_jump_speed + jump2_speed) > 6.5 then
jump2_speed = 6.5 - current_jump_speed
end
user:add_player_velocity({x=0, y=jump2_speed, z=0})
-- wear tool
local uses = tool_capabilities.groupcaps.climbing.uses * 2 -- there was still not enough uses
@ -156,7 +155,7 @@ minetest.register_tool("climbing_pick:pick_wood", {
climbing = {times={[3]=1.60}, uses=40, maxlevel=1},
},
},
groups = {flammable = 2},
groups = {flammable = 2, climbing = 1},
on_use = function(itemstack, user, pointed_thing)
return climbing_pick.pick_on_use(itemstack, user, pointed_thing)
end,
@ -173,6 +172,7 @@ minetest.register_tool("climbing_pick:pick_stone", {
climbing = {times={[2]=2.0, [3]=1.00}, uses=80, maxlevel=1},
},
},
groups = {climbing = 1},
on_use = function(itemstack, user, pointed_thing)
return climbing_pick.pick_on_use(itemstack, user, pointed_thing)
end,
@ -189,6 +189,7 @@ minetest.register_tool("climbing_pick:pick_steel", {
climbing = {times={[1]=4.00, [2]=1.60, [3]=0.80}, uses=80, maxlevel=2},
},
},
groups = {climbing = 1},
on_use = function(itemstack, user, pointed_thing)
return climbing_pick.pick_on_use(itemstack, user, pointed_thing)
end,
@ -205,6 +206,7 @@ minetest.register_tool("climbing_pick:pick_bronze", {
climbing = {times={[1]=4.00, [2]=1.60, [3]=0.80}, uses=120, maxlevel=2},
},
},
groups = {climbing = 1},
on_use = function(itemstack, user, pointed_thing)
return climbing_pick.pick_on_use(itemstack, user, pointed_thing)
end,
@ -221,6 +223,7 @@ minetest.register_tool("climbing_pick:pick_mese", {
climbing = {times={[1]=2.4, [2]=1.2, [3]=0.60}, uses=80, maxlevel=3},
},
},
groups = {climbing = 1},
on_use = function(itemstack, user, pointed_thing)
return climbing_pick.pick_on_use(itemstack, user, pointed_thing)
end,
@ -237,6 +240,7 @@ minetest.register_tool("climbing_pick:pick_diamond", {
climbing = {times={[1]=2.0, [2]=1.0, [3]=0.50}, uses=120, maxlevel=3},
},
},
groups = {climbing = 1},
on_use = function(itemstack, user, pointed_thing)
return climbing_pick.pick_on_use(itemstack, user, pointed_thing)
end,
@ -302,3 +306,67 @@ minetest.register_craft({
{'group:stick', '', ''},
},
})
local on_step = function (dtime)
local players = minetest.get_connected_players()
for i = 1, #players do
local player_name = players[i]:get_player_name()
local jump2 = climbing_pick.jump2[player_name] or 0
local player_controls = players[i]:get_player_control_bits()
local player_jump = math.floor(player_controls%32/16)
local itemstack = players[i]:get_wielded_item()
local pick = minetest.get_item_group(itemstack:get_name(), "climbing") > 0
local current_jump_speed = players[i]:get_player_velocity()["y"]
local standing = current_jump_speed == 0
local falling = current_jump_speed < 0
if standing and jump2 > 0 then
climbing_pick.jump2[player_name] = jump2 - 1
elseif not standing and jump2 < 3 then
climbing_pick.jump2[player_name] = jump2 + 1
end
if player_jump == 1 and pick and jump2 == 3 and falling then
climbing_pick.jump2[player_name] = 6
local pos = players[i]:get_pos()
local tool_definition = itemstack:get_definition()
local tool_capabilities = tool_definition.tool_capabilities
local uses = tool_capabilities.groupcaps.climbing.uses
itemstack:add_wear(65535/(uses-1))
players[i]:set_wielded_item(itemstack)
minetest.sound_play("default_metal_footstep", {pos = pos, gain = 0.5, })
climbing_pick.effect(pos)
-- tool break sound
if itemstack:get_count() == 0 and tool_definition.sound and tool_definition.sound.breaks then
minetest.sound_play(tool_definition.sound.breaks, {pos = pos, gain = 0.5})
end
local jump2_speed = 6.5 + tool_capabilities.groupcaps.climbing.maxlevel
if (current_jump_speed + jump2_speed) > 6.5 then
jump2_speed = 6.5 - current_jump_speed
end
players[i]:add_player_velocity({x=0, y=jump2_speed, z=0})
end
end
end
minetest.register_globalstep(on_step)

0
textures/handholds_tool_bronze.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 224 B

After

Width:  |  Height:  |  Size: 224 B

0
textures/handholds_tool_diamond.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 225 B

After

Width:  |  Height:  |  Size: 225 B

0
textures/handholds_tool_mese.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 224 B

After

Width:  |  Height:  |  Size: 224 B

0
textures/handholds_tool_steel.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 224 B

After

Width:  |  Height:  |  Size: 224 B

0
textures/handholds_tool_stone.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 224 B

After

Width:  |  Height:  |  Size: 224 B

0
textures/handholds_tool_wood.png Normal file → Executable file
View File

Before

Width:  |  Height:  |  Size: 224 B

After

Width:  |  Height:  |  Size: 224 B