forked from VoxeLibre/VoxeLibre
update mcl_shields/init.lua
This commit is contained in:
parent
324e734fcb
commit
b89917caa0
|
@ -69,36 +69,34 @@ minetest.register_entity("mcl_shields:shield_entity", {
|
||||||
_shield_number = 2,
|
_shield_number = 2,
|
||||||
on_step = function(self, dtime, moveresult)
|
on_step = function(self, dtime, moveresult)
|
||||||
local player = self.object:get_attach()
|
local player = self.object:get_attach()
|
||||||
if player then
|
if not player then
|
||||||
local shield_texture = "mcl_shield_base_nopattern.png"
|
|
||||||
local i = self._shield_number
|
|
||||||
local item = wielded_item(player, i)
|
|
||||||
|
|
||||||
if item ~= "mcl_shields:shield" and item ~= "mcl_shields:shield_enchanted" then
|
|
||||||
local itemstack = player:get_wielded_item()
|
|
||||||
if i == 1 then
|
|
||||||
itemstack = player:get_inventory():get_stack("offhand", 1)
|
|
||||||
end
|
|
||||||
local meta_texture = itemstack:get_meta():get_string("mcl_shields:shield_custom_pattern_texture")
|
|
||||||
if meta_texture ~= "" then
|
|
||||||
shield_texture = meta_texture
|
|
||||||
else
|
|
||||||
local color = minetest.registered_items[item]._shield_color
|
|
||||||
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()
|
self.object:remove()
|
||||||
|
return
|
||||||
end
|
end
|
||||||
|
local shield_texture = "mcl_shield_base_nopattern.png"
|
||||||
|
local i = self._shield_number
|
||||||
|
local item = wielded_item(player, i)
|
||||||
|
|
||||||
|
if item ~= "mcl_shields:shield" and item ~= "mcl_shields:shield_enchanted" then
|
||||||
|
local itemstack = player:get_wielded_item()
|
||||||
|
if i == 1 then
|
||||||
|
itemstack = player:get_inventory():get_stack("offhand", 1)
|
||||||
|
end
|
||||||
|
local meta_texture = itemstack:get_meta():get_string("mcl_shields:shield_custom_pattern_texture")
|
||||||
|
if meta_texture ~= "" then
|
||||||
|
shield_texture = meta_texture
|
||||||
|
else
|
||||||
|
local color = minetest.registered_items[item]._shield_color
|
||||||
|
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}})
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -109,43 +107,50 @@ end
|
||||||
function mcl_shields.is_blocking(obj)
|
function mcl_shields.is_blocking(obj)
|
||||||
if not obj:is_player() then return end
|
if not obj:is_player() then return end
|
||||||
local blocking = mcl_shields.players[obj].blocking
|
local blocking = mcl_shields.players[obj].blocking
|
||||||
if blocking > 0 then
|
if blocking <= 0 then
|
||||||
local shieldstack = obj:get_wielded_item()
|
return
|
||||||
if blocking == 1 then
|
|
||||||
shieldstack = obj:get_inventory():get_stack("offhand", 1)
|
|
||||||
end
|
|
||||||
return blocking, shieldstack
|
|
||||||
end
|
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)
|
mcl_damage.register_modifier(function(obj, damage, reason)
|
||||||
local type = reason.type
|
local type = reason.type
|
||||||
local damager = reason.direct
|
local damager = reason.direct
|
||||||
local blocking, shieldstack = mcl_shields.is_blocking(obj)
|
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
|
||||||
local entity = damager:get_luaentity()
|
return
|
||||||
if entity and (type == "arrow" or type == "generic") then
|
end
|
||||||
damager = entity._shooter
|
|
||||||
end
|
local entity = damager:get_luaentity()
|
||||||
if vector.dot(obj:get_look_dir(), vector.subtract(damager:get_pos(), obj:get_pos())) >= 0 then
|
if entity and (type == "arrow" or type == "generic") then
|
||||||
local durability = 336
|
damager = entity._shooter
|
||||||
local unbreaking = mcl_enchanting.get_enchantment(shieldstack, mcl_shields.enchantments[2])
|
end
|
||||||
if unbreaking > 0 then
|
|
||||||
durability = durability * (unbreaking + 1)
|
if vector.dot(obj:get_look_dir(), vector.subtract(damager:get_pos(), obj:get_pos())) < 0 then
|
||||||
end
|
return
|
||||||
if not minetest.is_creative_enabled(obj:get_player_name()) and damage >= 3 then
|
end
|
||||||
shieldstack:add_wear(65535 / durability)
|
|
||||||
if blocking == 2 then
|
local durability = 336
|
||||||
obj:set_wielded_item(shieldstack)
|
local unbreaking = mcl_enchanting.get_enchantment(shieldstack, mcl_shields.enchantments[2])
|
||||||
else
|
if unbreaking > 0 then
|
||||||
obj:get_inventory():set_stack("offhand", 1, shieldstack)
|
durability = durability * (unbreaking + 1)
|
||||||
mcl_inventory.update_inventory_formspec(obj)
|
end
|
||||||
end
|
if not minetest.is_creative_enabled(obj:get_player_name()) and damage >= 3 then
|
||||||
end
|
shieldstack:add_wear(65535 / durability)
|
||||||
minetest.sound_play({name = "mcl_block"})
|
if blocking == 2 then
|
||||||
return 0
|
obj:set_wielded_item(shieldstack)
|
||||||
|
else
|
||||||
|
obj:get_inventory():set_stack("offhand", 1, shieldstack)
|
||||||
|
mcl_inventory.update_inventory_formspec(obj)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
minetest.sound_play({name = "mcl_block"})
|
||||||
|
return 0
|
||||||
end)
|
end)
|
||||||
|
|
||||||
local function modify_shield(player, vpos, vrot, i)
|
local function modify_shield(player, vpos, vrot, i)
|
||||||
|
@ -175,20 +180,23 @@ local function set_shield(player, block, i)
|
||||||
end
|
end
|
||||||
local shield = mcl_shields.players[player].shields[i]
|
local shield = mcl_shields.players[player].shields[i]
|
||||||
if not shield then return end
|
if not shield then return end
|
||||||
|
|
||||||
local luaentity = shield:get_luaentity()
|
local luaentity = shield:get_luaentity()
|
||||||
if not luaentity then return end
|
if not luaentity then return end
|
||||||
|
|
||||||
luaentity._blocking = block
|
luaentity._blocking = block
|
||||||
end
|
end
|
||||||
|
|
||||||
local function set_interact(player, interact)
|
local function set_interact(player, interact)
|
||||||
local player_name = player:get_player_name()
|
local player_name = player:get_player_name()
|
||||||
local privs = minetest.get_player_privs(player_name)
|
local privs = minetest.get_player_privs(player_name)
|
||||||
if privs.interact ~= interact then
|
if privs.interact == interact then
|
||||||
local meta = player:get_meta()
|
return
|
||||||
if meta:get_int("ineract_revoked") ~= 1 then
|
end
|
||||||
privs.interact = interact
|
local meta = player:get_meta()
|
||||||
minetest.set_player_privs(player_name, privs)
|
if meta:get_int("ineract_revoked") ~= 1 then
|
||||||
end
|
privs.interact = interact
|
||||||
|
minetest.set_player_privs(player_name, privs)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -229,39 +237,41 @@ end
|
||||||
local function handle_blocking(player)
|
local function handle_blocking(player)
|
||||||
local player_shield = mcl_shields.players[player]
|
local player_shield = mcl_shields.players[player]
|
||||||
local rmb = player:get_player_control().RMB
|
local rmb = player:get_player_control().RMB
|
||||||
if rmb then
|
if not rmb then
|
||||||
local shield_in_offhand = mcl_shields.wielding_shield(player, 1)
|
player_shield.blocking = 0
|
||||||
local shield_in_hand = mcl_shields.wielding_shield(player)
|
return
|
||||||
local not_blocking = player_shield.blocking == 0
|
end
|
||||||
|
|
||||||
local pos = player:get_pos()
|
local shield_in_offhand = mcl_shields.wielding_shield(player, 1)
|
||||||
if shield_in_hand then
|
local shield_in_hand = mcl_shields.wielding_shield(player)
|
||||||
if not_blocking then
|
local not_blocking = player_shield.blocking == 0
|
||||||
minetest.after(0.25, function()
|
|
||||||
if (not_blocking or not shield_in_offhand) and shield_in_hand and rmb then
|
local pos = player:get_pos()
|
||||||
player_shield.blocking = 2
|
if shield_in_hand then
|
||||||
set_shield(player, true, 2)
|
if not_blocking then
|
||||||
end
|
minetest.after(0.25, function()
|
||||||
end)
|
if (not_blocking or not shield_in_offhand) and shield_in_hand and rmb then
|
||||||
elseif not shield_in_offhand then
|
player_shield.blocking = 2
|
||||||
player_shield.blocking = 2
|
set_shield(player, true, 2)
|
||||||
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_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
|
|
||||||
player_shield.blocking = 1
|
|
||||||
set_shield(player, true, 1)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
elseif not shield_in_hand then
|
|
||||||
player_shield.blocking = 1
|
|
||||||
end
|
end
|
||||||
end
|
end)
|
||||||
else
|
elseif not shield_in_offhand then
|
||||||
player_shield.blocking = 0
|
player_shield.blocking = 2
|
||||||
|
end
|
||||||
|
elseif shield_in_offhand then
|
||||||
|
local offhand_can_block = (wielded_item(player) == "" or not mcl_util.get_pointed_thing(player, true))
|
||||||
|
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
|
||||||
|
player_shield.blocking = 1
|
||||||
|
set_shield(player, true, 1)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
elseif not shield_in_hand then
|
||||||
|
player_shield.blocking = 1
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
player_shield.blocking = 0
|
player_shield.blocking = 0
|
||||||
|
|
Loading…
Reference in New Issue