Fix infinite grapple uses

This commit is contained in:
LoneWolfHT 2020-07-09 17:55:29 -07:00
parent e76dcf0563
commit a78fdd95c5
2 changed files with 35 additions and 20 deletions

@ -1 +1 @@
Subproject commit d7f6dc7c06110ca7f1eead0b15b6630d7466c649 Subproject commit c698e3265b215285d4dd241134fee70762c18b85

View file

@ -13,14 +13,30 @@ local function wrap_callback(name, callback, func)
minetest.override_item(name, overrides) minetest.override_item(name, overrides)
end end
wrap_callback("shooter_hook:grapple_hook", "on_use", function(old, itemstack, ...) wrap_callback("shooter_hook:grapple_hook", "on_use", function(old, itemstack, user, pointed_thing, ...)
itemstack:add_wear(65536 / 16) if pointed_thing.type == "nothing" then
return old(itemstack, ...) local before = itemstack:get_wear()
itemstack:add_wear(65536 / 16)
if itemstack:get_wear() < before then
itemstack:set_wear(65535)
end
end
return old(itemstack, user, pointed_thing, ...)
end) end)
wrap_callback("shooter_hook:grapple_gun_loaded", "on_use", function(old, itemstack, ...) wrap_callback("shooter_hook:grapple_gun_loaded", "on_use", function(old, itemstack, user, pointed_thing, ...)
itemstack:add_wear(65536 / 8) if pointed_thing.type == "nothing" then
return old(itemstack, ...) local before = itemstack:get_wear()
itemstack:add_wear(65536 / 8)
if itemstack:get_wear() < before then
itemstack:set_wear(65535)
end
end
return old(itemstack, user, pointed_thing, ...)
end) end)
wrap_callback("shooter_hook:grapple_gun", "on_use", function(old, itemstack, user, pointed_thing) wrap_callback("shooter_hook:grapple_gun", "on_use", function(old, itemstack, user, pointed_thing)
@ -178,12 +194,12 @@ local function check_grapple(self, node, pos, above)
end end
-- Drop remaining stack -- Drop remaining stack
if not self.itemstack:is_empty() and minetest.get_item_group(node.name, "lava") == 0 then if self.itemstack and not self.itemstack:is_empty() and minetest.get_item_group(node.name, "lava") == 0 then
minetest.add_item(pos, self.itemstack) minetest.add_item(pos, self.itemstack)
end end
end end
minetest.registered_entities["shooter_hook:hook"].on_step = function(self, dtime) minetest.registered_entities["shooter_hook:hook"].on_step = function(self, dtime, moveresult)
if not self.user then if not self.user then
return return
end end
@ -198,25 +214,24 @@ minetest.registered_entities["shooter_hook:hook"].on_step = function(self, dtime
end end
end end
self.timer = self.timer + dtime if moveresult.collides and (moveresult.axis == "y" or
if self.timer > 0.25 then (moveresult.touching_ground or moveresult.standing_on_object)) then
local pos = self.object:get_pos() local pos = self.object:get_pos()
if minetest.get_node(pos).name ~= "air" then if minetest.get_node(pos).name ~= "air" then
pos.y = pos.y + 1 pos.y = pos.y + 1
end end
local below = {x=pos.x, y=pos.y - 1, z=pos.z}
local above = {x=pos.x, y=pos.y + 1, z=pos.z} local above = {x=pos.x, y=pos.y + 1, z=pos.z}
local node = minetest.get_node(below) local node = minetest.get_node(pos)
if node.name ~= "air" then
self.object:set_velocity({x=0, y=-10, z=0})
self.object:set_acceleration({x=0, y=0, z=0})
check_grapple(self, node, pos, above) self.object:set_velocity({x=0, y=-10, z=0})
self.object:set_acceleration({x=0, y=0, z=0})
check_grapple(self, node, pos, above)
self.object:remove()
self.object:remove()
end
self.timer = 0
end end
end end