From d26fdce2678624fa32d0d35a79bcf14e73f75d74 Mon Sep 17 00:00:00 2001 From: Andrey Date: Thu, 1 Jul 2021 10:46:53 +0300 Subject: [PATCH] Use new API command add_player_velocity --- LICENSE | 0 README.txt | 1 + depends.txt | 0 init.lua | 100 +++++++++++++++++++++++----- textures/handholds_tool_bronze.png | Bin textures/handholds_tool_diamond.png | Bin textures/handholds_tool_mese.png | Bin textures/handholds_tool_steel.png | Bin textures/handholds_tool_stone.png | Bin textures/handholds_tool_wood.png | Bin 10 files changed, 85 insertions(+), 16 deletions(-) mode change 100644 => 100755 LICENSE mode change 100644 => 100755 README.txt mode change 100644 => 100755 depends.txt mode change 100644 => 100755 init.lua mode change 100644 => 100755 textures/handholds_tool_bronze.png mode change 100644 => 100755 textures/handholds_tool_diamond.png mode change 100644 => 100755 textures/handholds_tool_mese.png mode change 100644 => 100755 textures/handholds_tool_steel.png mode change 100644 => 100755 textures/handholds_tool_stone.png mode change 100644 => 100755 textures/handholds_tool_wood.png diff --git a/LICENSE b/LICENSE old mode 100644 new mode 100755 diff --git a/README.txt b/README.txt old mode 100644 new mode 100755 index 8cf0383..52b15e3 --- a/README.txt +++ b/README.txt @@ -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. diff --git a/depends.txt b/depends.txt old mode 100644 new mode 100755 diff --git a/init.lua b/init.lua old mode 100644 new mode 100755 index 53b6218..bd948b6 --- a/init.lua +++ b/init.lua @@ -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) diff --git a/textures/handholds_tool_bronze.png b/textures/handholds_tool_bronze.png old mode 100644 new mode 100755 diff --git a/textures/handholds_tool_diamond.png b/textures/handholds_tool_diamond.png old mode 100644 new mode 100755 diff --git a/textures/handholds_tool_mese.png b/textures/handholds_tool_mese.png old mode 100644 new mode 100755 diff --git a/textures/handholds_tool_steel.png b/textures/handholds_tool_steel.png old mode 100644 new mode 100755 diff --git a/textures/handholds_tool_stone.png b/textures/handholds_tool_stone.png old mode 100644 new mode 100755 diff --git a/textures/handholds_tool_wood.png b/textures/handholds_tool_wood.png old mode 100644 new mode 100755