mirror of
https://git.minetest.land/VoxeLibre/VoxeLibre.git
synced 2024-11-24 19:41:08 +01:00
Improve shield block code and unhardcode offhand group
This commit is contained in:
parent
084741b733
commit
f86a641dfa
3 changed files with 21 additions and 22 deletions
|
@ -168,7 +168,7 @@ S("The speed and damage of the arrow increases the longer you charge. The regula
|
||||||
itemstack:get_meta():set_string("active", "true")
|
itemstack:get_meta():set_string("active", "true")
|
||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end,
|
||||||
groups = {weapon=1,weapon_ranged=1,bow=1,enchantability=1},
|
groups = {weapon=1,weapon_ranged=1,bow=1,cannot_block=1,enchantability=1},
|
||||||
_mcl_uses = 385,
|
_mcl_uses = 385,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -216,7 +216,7 @@ for level=0, 2 do
|
||||||
wield_scale = mcl_vars.tool_wield_scale,
|
wield_scale = mcl_vars.tool_wield_scale,
|
||||||
stack_max = 1,
|
stack_max = 1,
|
||||||
range = 0, -- Pointing range to 0 to prevent punching with bow :D
|
range = 0, -- Pointing range to 0 to prevent punching with bow :D
|
||||||
groups = {not_in_creative_inventory=1, not_in_craft_guide=1, bow=1, enchantability=1},
|
groups = {not_in_creative_inventory=1, not_in_craft_guide=1, bow=1, cannot_block=1, enchantability=1},
|
||||||
-- Trick to disable digging as well
|
-- Trick to disable digging as well
|
||||||
on_use = function() return end,
|
on_use = function() return end,
|
||||||
on_drop = function(itemstack, dropper, pos)
|
on_drop = function(itemstack, dropper, pos)
|
||||||
|
|
|
@ -158,7 +158,7 @@ S("The speed and damage of the arrow increases the longer you charge. The regula
|
||||||
itemstack:get_meta():set_string("active", "true")
|
itemstack:get_meta():set_string("active", "true")
|
||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end,
|
||||||
groups = {weapon=1,weapon_ranged=1,crossbow=1,enchantability=1},
|
groups = {weapon=1,weapon_ranged=1,crossbow=1,cannot_block=1,enchantability=1},
|
||||||
_mcl_uses = 326,
|
_mcl_uses = 326,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ S("The speed and damage of the arrow increases the longer you charge. The regula
|
||||||
itemstack:get_meta():set_string("active", "true")
|
itemstack:get_meta():set_string("active", "true")
|
||||||
return itemstack
|
return itemstack
|
||||||
end,
|
end,
|
||||||
groups = {weapon=1,weapon_ranged=1,crossbow=1,enchantability=1,not_in_creative_inventory=1},
|
groups = {weapon=1,weapon_ranged=1,crossbow=1,cannot_block=1,enchantability=1,not_in_creative_inventory=1},
|
||||||
_mcl_uses = 326,
|
_mcl_uses = 326,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ for level=0, 2 do
|
||||||
wield_scale = mcl_vars.tool_wield_scale,
|
wield_scale = mcl_vars.tool_wield_scale,
|
||||||
stack_max = 1,
|
stack_max = 1,
|
||||||
range = 0, -- Pointing range to 0 to prevent punching with bow :D
|
range = 0, -- Pointing range to 0 to prevent punching with bow :D
|
||||||
groups = {not_in_creative_inventory=1, not_in_craft_guide=1, bow=1, enchantability=1},
|
groups = {not_in_creative_inventory=1, not_in_craft_guide=1, cannot_block=1, bow=1, enchantability=1},
|
||||||
-- Trick to disable digging as well
|
-- Trick to disable digging as well
|
||||||
on_use = function() return end,
|
on_use = function() return end,
|
||||||
on_drop = function(itemstack, dropper, pos)
|
on_drop = function(itemstack, dropper, pos)
|
||||||
|
|
|
@ -270,7 +270,7 @@ local function remove_shield_entity(player, i)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function is_rmb_conflicting_node(nodename)
|
local function is_rmb_conflicting_node(nodename)
|
||||||
nodedef = minetest.registered_nodes[nodename] or {}
|
local nodedef = minetest.registered_nodes[nodename] or {}
|
||||||
return nodedef.on_rightclick
|
return nodedef.on_rightclick
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -282,11 +282,22 @@ local function handle_blocking(player)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local pointed_thing = mcl_util.get_pointed_thing(player, true)
|
||||||
|
local wielded_stack = player:get_wielded_item()
|
||||||
|
|
||||||
local shield_in_offhand = mcl_shields.wielding_shield(player, 1)
|
local shield_in_offhand = mcl_shields.wielding_shield(player, 1)
|
||||||
local shield_in_hand = mcl_shields.wielding_shield(player)
|
local shield_in_hand = mcl_shields.wielding_shield(player)
|
||||||
local not_blocking = player_shield.blocking == 0
|
local not_blocking = player_shield.blocking == 0
|
||||||
|
|
||||||
local pos = player:get_pos()
|
if pointed_thing and pointed_thing.type == "node" then
|
||||||
|
local pointed_node = minetest.get_node(pointed_thing.under)
|
||||||
|
if minetest.get_item_group(pointed_node.name, "container") > 1
|
||||||
|
or is_rmb_conflicting_node(pointed_node.name)
|
||||||
|
or wielded_stack:get_definition().type == "node" then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if shield_in_hand then
|
if shield_in_hand then
|
||||||
if not_blocking then
|
if not_blocking then
|
||||||
minetest.after(0.05, function()
|
minetest.after(0.05, function()
|
||||||
|
@ -299,27 +310,15 @@ local function handle_blocking(player)
|
||||||
player_shield.blocking = 2
|
player_shield.blocking = 2
|
||||||
end
|
end
|
||||||
elseif shield_in_offhand then
|
elseif shield_in_offhand then
|
||||||
local pointed_thing = mcl_util.get_pointed_thing(player, true)
|
local offhand_can_block = minetest.get_item_group(wielded_item(player), "cannot_block") ~= 1
|
||||||
local wielded_stack = player:get_wielded_item()
|
|
||||||
local offhand_can_block = (minetest.get_item_group(wielded_item(player), "bow") ~= 1
|
|
||||||
and minetest.get_item_group(wielded_item(player), "crossbow") ~= 1)
|
|
||||||
|
|
||||||
if pointed_thing and pointed_thing.type == "node" then
|
|
||||||
local pointed_node = minetest.get_node(pointed_thing.under)
|
|
||||||
if minetest.get_item_group(pointed_node.name, "container") > 1
|
|
||||||
or is_rmb_conflicting_node(pointed_node.name)
|
|
||||||
or wielded_stack:get_definition().type == "node"
|
|
||||||
then
|
|
||||||
return
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if not offhand_can_block then
|
if not offhand_can_block then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if not_blocking then
|
if not_blocking then
|
||||||
minetest.after(0.05, function()
|
minetest.after(0.05, function()
|
||||||
if (not_blocking or not shield_in_hand) and shield_in_offhand and rmb and offhand_can_block then
|
if (not_blocking or not shield_in_hand) and shield_in_offhand
|
||||||
|
and rmb and offhand_can_block then
|
||||||
player_shield.blocking = 1
|
player_shield.blocking = 1
|
||||||
set_shield(player, true, 1)
|
set_shield(player, true, 1)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue