Handle lag better in drill
authorZefram <zefram@fysh.org>
Fri, 20 Jun 2014 21:35:56 +0000 (22:35 +0100)
committerRealBadAngel <maciej.kasatkin@o2.pl>
Fri, 20 Jun 2014 23:22:40 +0000 (01:22 +0200)
If a mining drill is apparently applied to a non-pointable node, do
nothing rather than drilling as normal.  This situation usually arises
from lag, where the news of a node having been drilled didn't reach the
user quickly enough and the user thereby applied the drill twice to the
same node.  The second drill attempt would formerly consume charge and
then find that all the nodes it wanted to dig had already been removed.

technic/tools/mining_drill.lua

index 202123db795f7dcb8f2d5b457856839d7dfdae55..ac22098e88990f60a93b154a6cd6a04efc793af1 100644 (file)
@@ -229,6 +229,12 @@ local function drill_dig_it(pos, player, mode)
        minetest.sound_play("mining_drill", {pos = pos, gain = 1.0, max_hear_distance = 10,})
 end
 
+local function pos_is_pointable(pos)
+       local node = minetest.env:get_node(pos)
+       local nodedef = minetest.registered_nodes[node.name]
+       return nodedef and nodedef.pointable
+end
+
 local function mining_drill_mk2_setmode(user,itemstack)
        local player_name=user:get_player_name()
        local item=itemstack:to_table()
@@ -285,7 +291,7 @@ local function mining_drill_mk2_handler(itemstack, user, pointed_thing)
        if not meta or not meta.mode or keys.sneak then
                return mining_drill_mk2_setmode(user, itemstack)
        end
-       if pointed_thing.type ~= "node" or not meta.charge then
+       if pointed_thing.type ~= "node" or not pos_is_pointable(pointed_thing.under) or not meta.charge then
                return
        end
        local charge_to_take = cost_to_use(2, meta.mode)
@@ -306,7 +312,7 @@ local function mining_drill_mk3_handler(itemstack, user, pointed_thing)
        if not meta or not meta.mode or keys.sneak then
                return mining_drill_mk3_setmode(user, itemstack)
        end
-       if pointed_thing.type ~= "node" or not meta.charge then
+       if pointed_thing.type ~= "node" or not pos_is_pointable(pointed_thing.under) or not meta.charge then
                return
        end
        local charge_to_take = cost_to_use(3, meta.mode)
@@ -329,7 +335,7 @@ minetest.register_tool("technic:mining_drill", {
        wear_represents = "technic_RE_charge",
        on_refill = technic.refill_RE_charge,
        on_use = function(itemstack, user, pointed_thing)
-               if pointed_thing.type ~= "node" then
+               if pointed_thing.type ~= "node" or not pos_is_pointable(pointed_thing.under) then
                        return itemstack
                end
                local meta = minetest.deserialize(itemstack:get_metadata())