forked from VoxeLibre/VoxeLibre
update mcl_shields/init.lua
This commit is contained in:
parent
324e734fcb
commit
b89917caa0
|
@ -69,7 +69,10 @@ minetest.register_entity("mcl_shields:shield_entity", {
|
|||
_shield_number = 2,
|
||||
on_step = function(self, dtime, moveresult)
|
||||
local player = self.object:get_attach()
|
||||
if player then
|
||||
if not player then
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
local shield_texture = "mcl_shield_base_nopattern.png"
|
||||
local i = self._shield_number
|
||||
local item = wielded_item(player, i)
|
||||
|
@ -87,18 +90,13 @@ minetest.register_entity("mcl_shields:shield_entity", {
|
|||
if color then
|
||||
shield_texture = "mcl_shield_base_nopattern.png^(mcl_shield_pattern_base.png^[colorize:" .. color .. ")"
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
if shield_is_enchanted(player, i) then
|
||||
shield_texture = shield_texture .. overlay
|
||||
end
|
||||
|
||||
self.object:set_properties({textures = {shield_texture}})
|
||||
else
|
||||
self.object:remove()
|
||||
end
|
||||
end,
|
||||
})
|
||||
|
||||
|
@ -109,25 +107,34 @@ end
|
|||
function mcl_shields.is_blocking(obj)
|
||||
if not obj:is_player() then return end
|
||||
local blocking = mcl_shields.players[obj].blocking
|
||||
if blocking > 0 then
|
||||
if blocking <= 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local shieldstack = obj:get_wielded_item()
|
||||
if blocking == 1 then
|
||||
shieldstack = obj:get_inventory():get_stack("offhand", 1)
|
||||
end
|
||||
return blocking, shieldstack
|
||||
end
|
||||
end
|
||||
|
||||
mcl_damage.register_modifier(function(obj, damage, reason)
|
||||
local type = reason.type
|
||||
local damager = reason.direct
|
||||
local blocking, shieldstack = mcl_shields.is_blocking(obj)
|
||||
if obj:is_player() and blocking and mcl_shields.types[type] and damager then
|
||||
if not (obj:is_player() and blocking and mcl_shields.types[type] and damager) then
|
||||
return
|
||||
end
|
||||
|
||||
local entity = damager:get_luaentity()
|
||||
if entity and (type == "arrow" or type == "generic") then
|
||||
damager = entity._shooter
|
||||
end
|
||||
if vector.dot(obj:get_look_dir(), vector.subtract(damager:get_pos(), obj:get_pos())) >= 0 then
|
||||
|
||||
if vector.dot(obj:get_look_dir(), vector.subtract(damager:get_pos(), obj:get_pos())) < 0 then
|
||||
return
|
||||
end
|
||||
|
||||
local durability = 336
|
||||
local unbreaking = mcl_enchanting.get_enchantment(shieldstack, mcl_shields.enchantments[2])
|
||||
if unbreaking > 0 then
|
||||
|
@ -144,8 +151,6 @@ mcl_damage.register_modifier(function(obj, damage, reason)
|
|||
end
|
||||
minetest.sound_play({name = "mcl_block"})
|
||||
return 0
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
local function modify_shield(player, vpos, vrot, i)
|
||||
|
@ -175,21 +180,24 @@ local function set_shield(player, block, i)
|
|||
end
|
||||
local shield = mcl_shields.players[player].shields[i]
|
||||
if not shield then return end
|
||||
|
||||
local luaentity = shield:get_luaentity()
|
||||
if not luaentity then return end
|
||||
|
||||
luaentity._blocking = block
|
||||
end
|
||||
|
||||
local function set_interact(player, interact)
|
||||
local player_name = player:get_player_name()
|
||||
local privs = minetest.get_player_privs(player_name)
|
||||
if privs.interact ~= interact then
|
||||
if privs.interact == interact then
|
||||
return
|
||||
end
|
||||
local meta = player:get_meta()
|
||||
if meta:get_int("ineract_revoked") ~= 1 then
|
||||
privs.interact = interact
|
||||
minetest.set_player_privs(player_name, privs)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local shield_hud = {}
|
||||
|
@ -229,7 +237,11 @@ end
|
|||
local function handle_blocking(player)
|
||||
local player_shield = mcl_shields.players[player]
|
||||
local rmb = player:get_player_control().RMB
|
||||
if rmb then
|
||||
if not rmb then
|
||||
player_shield.blocking = 0
|
||||
return
|
||||
end
|
||||
|
||||
local shield_in_offhand = mcl_shields.wielding_shield(player, 1)
|
||||
local shield_in_hand = mcl_shields.wielding_shield(player)
|
||||
local not_blocking = player_shield.blocking == 0
|
||||
|
@ -248,7 +260,9 @@ local function handle_blocking(player)
|
|||
end
|
||||
elseif shield_in_offhand then
|
||||
local offhand_can_block = (wielded_item(player) == "" or not mcl_util.get_pointed_thing(player, true))
|
||||
if offhand_can_block then
|
||||
if not offhand_can_block then
|
||||
return
|
||||
end
|
||||
if not_blocking then
|
||||
minetest.after(0.25, function()
|
||||
if (not_blocking or not shield_in_hand) and shield_in_offhand and rmb and offhand_can_block then
|
||||
|
@ -259,10 +273,6 @@ local function handle_blocking(player)
|
|||
elseif not shield_in_hand then
|
||||
player_shield.blocking = 1
|
||||
end
|
||||
end
|
||||
else
|
||||
player_shield.blocking = 0
|
||||
end
|
||||
else
|
||||
player_shield.blocking = 0
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue