Fix infinite grapple uses
This commit is contained in:
parent
e76dcf0563
commit
a78fdd95c5
2 changed files with 35 additions and 20 deletions
|
@ -1 +1 @@
|
|||
Subproject commit d7f6dc7c06110ca7f1eead0b15b6630d7466c649
|
||||
Subproject commit c698e3265b215285d4dd241134fee70762c18b85
|
|
@ -13,14 +13,30 @@ local function wrap_callback(name, callback, func)
|
|||
minetest.override_item(name, overrides)
|
||||
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, ...)
|
||||
if pointed_thing.type == "nothing" then
|
||||
local before = itemstack:get_wear()
|
||||
itemstack:add_wear(65536 / 16)
|
||||
return old(itemstack, ...)
|
||||
|
||||
if itemstack:get_wear() < before then
|
||||
itemstack:set_wear(65535)
|
||||
end
|
||||
end
|
||||
|
||||
return old(itemstack, user, pointed_thing, ...)
|
||||
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, ...)
|
||||
if pointed_thing.type == "nothing" then
|
||||
local before = itemstack:get_wear()
|
||||
itemstack:add_wear(65536 / 8)
|
||||
return old(itemstack, ...)
|
||||
|
||||
if itemstack:get_wear() < before then
|
||||
itemstack:set_wear(65535)
|
||||
end
|
||||
end
|
||||
|
||||
return old(itemstack, user, pointed_thing, ...)
|
||||
end)
|
||||
|
||||
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
|
||||
|
||||
-- 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)
|
||||
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
|
||||
return
|
||||
end
|
||||
|
@ -198,25 +214,24 @@ minetest.registered_entities["shooter_hook:hook"].on_step = function(self, dtime
|
|||
end
|
||||
end
|
||||
|
||||
self.timer = self.timer + dtime
|
||||
if self.timer > 0.25 then
|
||||
if moveresult.collides and (moveresult.axis == "y" or
|
||||
(moveresult.touching_ground or moveresult.standing_on_object)) then
|
||||
|
||||
local pos = self.object:get_pos()
|
||||
if minetest.get_node(pos).name ~= "air" then
|
||||
pos.y = pos.y + 1
|
||||
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 node = minetest.get_node(below)
|
||||
if node.name ~= "air" then
|
||||
local node = minetest.get_node(pos)
|
||||
|
||||
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()
|
||||
end
|
||||
self.timer = 0
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue