Use new API command add_player_velocity
1
README.txt
Normal file → Executable file
@ -1,4 +1,5 @@
|
|||||||
Mod for Minetest game "Climbing pick"
|
Mod for Minetest game "Climbing pick"
|
||||||
|
Starting from version 5.1
|
||||||
Climbing pick - allow to jump over more than one block.
|
Climbing pick - allow to jump over more than one block.
|
||||||
Meant to partially replace "sneak glitch" feature.
|
Meant to partially replace "sneak glitch" feature.
|
||||||
|
|
||||||
|
0
depends.txt
Normal file → Executable file
100
init.lua
Normal file → Executable file
@ -1,6 +1,7 @@
|
|||||||
-- Climbing tool mod
|
-- Climbing tool mod
|
||||||
|
|
||||||
climbing_pick = {}
|
climbing_pick = {}
|
||||||
|
climbing_pick.jump2 = {}
|
||||||
|
|
||||||
climbing_pick.effect = function(pos)
|
climbing_pick.effect = function(pos)
|
||||||
-- visual effect
|
-- visual effect
|
||||||
@ -115,25 +116,23 @@ climbing_pick.pick_on_use = function(itemstack, user, pointed_thing)
|
|||||||
local tool_capabilities = tool_definition.tool_capabilities
|
local tool_capabilities = tool_definition.tool_capabilities
|
||||||
-- local punch_interval = tool_capabilities.full_punch_interval -- not sure how to use correctly
|
-- 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
|
-- sound effect
|
||||||
minetest.sound_play("default_metal_footstep", {pos = pos, gain = 0.5, })
|
minetest.sound_play("default_metal_footstep", {pos = pos, gain = 0.5, })
|
||||||
climbing_pick.effect(target_pos)
|
climbing_pick.effect(target_pos)
|
||||||
|
|
||||||
-- no way to set speed of player
|
-- minetest API now allows to set speed of player
|
||||||
-- emulate it in ugly way
|
local jump2_speed = 3.25 + tool_capabilities.groupcaps.climbing.maxlevel
|
||||||
-- https://github.com/minetest/minetest/issues/1176 :(
|
-- Limit jump speed to default 6.5
|
||||||
local repetitions = 5
|
if (current_jump_speed + jump2_speed) > 6.5 then
|
||||||
if tool_capabilities.groupcaps.climbing.maxlevel > 1 then
|
jump2_speed = 6.5 - current_jump_speed
|
||||||
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)
|
|
||||||
end
|
end
|
||||||
|
user:add_player_velocity({x=0, y=jump2_speed, z=0})
|
||||||
|
|
||||||
-- wear tool
|
-- wear tool
|
||||||
local uses = tool_capabilities.groupcaps.climbing.uses * 2 -- there was still not enough uses
|
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},
|
climbing = {times={[3]=1.60}, uses=40, maxlevel=1},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
groups = {flammable = 2},
|
groups = {flammable = 2, climbing = 1},
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
return climbing_pick.pick_on_use(itemstack, user, pointed_thing)
|
return climbing_pick.pick_on_use(itemstack, user, pointed_thing)
|
||||||
end,
|
end,
|
||||||
@ -173,6 +172,7 @@ minetest.register_tool("climbing_pick:pick_stone", {
|
|||||||
climbing = {times={[2]=2.0, [3]=1.00}, uses=80, maxlevel=1},
|
climbing = {times={[2]=2.0, [3]=1.00}, uses=80, maxlevel=1},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
groups = {climbing = 1},
|
||||||
on_use = function(itemstack, user, pointed_thing)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
return climbing_pick.pick_on_use(itemstack, user, pointed_thing)
|
return climbing_pick.pick_on_use(itemstack, user, pointed_thing)
|
||||||
end,
|
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},
|
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)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
return climbing_pick.pick_on_use(itemstack, user, pointed_thing)
|
return climbing_pick.pick_on_use(itemstack, user, pointed_thing)
|
||||||
end,
|
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},
|
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)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
return climbing_pick.pick_on_use(itemstack, user, pointed_thing)
|
return climbing_pick.pick_on_use(itemstack, user, pointed_thing)
|
||||||
end,
|
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},
|
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)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
return climbing_pick.pick_on_use(itemstack, user, pointed_thing)
|
return climbing_pick.pick_on_use(itemstack, user, pointed_thing)
|
||||||
end,
|
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},
|
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)
|
on_use = function(itemstack, user, pointed_thing)
|
||||||
return climbing_pick.pick_on_use(itemstack, user, pointed_thing)
|
return climbing_pick.pick_on_use(itemstack, user, pointed_thing)
|
||||||
end,
|
end,
|
||||||
@ -302,3 +306,67 @@ minetest.register_craft({
|
|||||||
{'group:stick', '', ''},
|
{'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
Before Width: | Height: | Size: 224 B After Width: | Height: | Size: 224 B |
0
textures/handholds_tool_diamond.png
Normal file → Executable file
Before Width: | Height: | Size: 225 B After Width: | Height: | Size: 225 B |
0
textures/handholds_tool_mese.png
Normal file → Executable file
Before Width: | Height: | Size: 224 B After Width: | Height: | Size: 224 B |
0
textures/handholds_tool_steel.png
Normal file → Executable file
Before Width: | Height: | Size: 224 B After Width: | Height: | Size: 224 B |
0
textures/handholds_tool_stone.png
Normal file → Executable file
Before Width: | Height: | Size: 224 B After Width: | Height: | Size: 224 B |
0
textures/handholds_tool_wood.png
Normal file → Executable file
Before Width: | Height: | Size: 224 B After Width: | Height: | Size: 224 B |