forked from VoxeLibre/VoxeLibre
Add Crossbows
This commit is contained in:
parent
793b5f616e
commit
7b683450f0
|
@ -31,3 +31,5 @@ mgvalleys_spflags = noaltitude_chill,noaltitude_dry,nohumid_rivers,vary_river_de
|
|||
|
||||
# MCL2-specific stuff
|
||||
keepInventory = false
|
||||
|
||||
dedicated_server_step = 0.001
|
||||
|
|
|
@ -104,6 +104,8 @@ armor.update_player_visuals = function(self, player)
|
|||
player:set_bone_position("Wield_Item", vector.new(0,3.9,1.3), vector.new(90,0,0))
|
||||
elseif string.find(wielditem:get_name(), "mcl_bows:bow") then
|
||||
player:set_bone_position("Wield_Item", vector.new(.5,4.5,-1.6), vector.new(90,0,20))
|
||||
elseif string.find(wielditem:get_name(), "mcl_bows:crossbow") or wielditem:get_name() == "mcl_bows:loaded_crossbow" then
|
||||
player:set_bone_position("Wield_Item", vector.new(-1.5,7,1.5), vector.new(170,90,90))
|
||||
else
|
||||
player:set_bone_position("Wield_Item", vector.new(-1.5,4.9,1.8), vector.new(135,0,90))
|
||||
end
|
||||
|
|
|
@ -341,7 +341,7 @@ controls.register_on_hold(function(player, key, time)
|
|||
end)
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
for _, player in ipairs(minetest.get_connected_players()) do
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
local name = player:get_player_name()
|
||||
local wielditem = player:get_wielded_item()
|
||||
local wieldindex = player:get_wield_index()
|
||||
|
|
|
@ -0,0 +1,431 @@
|
|||
local S = minetest.get_translator("mcl_bows")
|
||||
|
||||
mcl_bows = {}
|
||||
|
||||
-- local arrows = {
|
||||
-- ["mcl_bows:arrow"] = "mcl_bows:arrow_entity",
|
||||
-- }
|
||||
|
||||
local GRAVITY = 9.81
|
||||
local BOW_DURABILITY = 385
|
||||
|
||||
-- Charging time in microseconds
|
||||
local BOW_CHARGE_TIME_HALF = 500000 -- bow level 1
|
||||
local BOW_CHARGE_TIME_FULL = 1000000 -- bow level 2 (full charge)
|
||||
|
||||
-- TODO: Use Minecraft speed (ca. 53 m/s)
|
||||
-- Currently nerfed because at full speed the arrow would easily get out of the range of the loaded map.
|
||||
local BOW_MAX_SPEED = 60
|
||||
|
||||
--[[ Store the charging state of each player.
|
||||
keys: player name
|
||||
value:
|
||||
nil = not charging or player not existing
|
||||
number: currently charging, the number is the time from minetest.get_us_time
|
||||
in which the charging has started
|
||||
]]
|
||||
local bow_load = {}
|
||||
|
||||
-- Another player table, this one stores the wield index of the bow being charged
|
||||
local bow_index = {}
|
||||
|
||||
mcl_bows.shoot_arrow = function(arrow_item, pos, dir, yaw, shooter, power, damage, is_critical, bow_stack, collectable)
|
||||
local obj = minetest.add_entity({x=pos.x,y=pos.y,z=pos.z}, arrow_item.."_entity")
|
||||
if power == nil then
|
||||
power = BOW_MAX_SPEED --19
|
||||
end
|
||||
if damage == nil then
|
||||
damage = 3
|
||||
end
|
||||
local knockback
|
||||
if bow_stack then
|
||||
local enchantments = mcl_enchanting.get_enchantments(bow_stack)
|
||||
if enchantments.power then
|
||||
damage = damage + (enchantments.power + 1) / 4
|
||||
end
|
||||
if enchantments.punch then
|
||||
knockback = enchantments.punch * 3
|
||||
end
|
||||
if enchantments.flame then
|
||||
mcl_burning.set_on_fire(obj, math.huge)
|
||||
end
|
||||
end
|
||||
obj:set_velocity({x=dir.x*power, y=dir.y*power, z=dir.z*power})
|
||||
obj:set_acceleration({x=0, y=-GRAVITY, z=0})
|
||||
obj:set_yaw(yaw-math.pi/2)
|
||||
local le = obj:get_luaentity()
|
||||
le._shooter = shooter
|
||||
le._damage = damage
|
||||
le._is_critical = is_critical
|
||||
le._startpos = pos
|
||||
le._knockback = knockback
|
||||
le._collectable = collectable
|
||||
if shooter ~= nil and shooter:is_player() then
|
||||
if obj:get_luaentity().player == "" then
|
||||
obj:get_luaentity().player = shooter
|
||||
end
|
||||
obj:get_luaentity().node = shooter:get_inventory():get_stack("main", 1):get_name()
|
||||
end
|
||||
return obj
|
||||
end
|
||||
|
||||
local get_arrow = function(player)
|
||||
local inv = player:get_inventory()
|
||||
local arrow_stack, arrow_stack_id
|
||||
for i=1, inv:get_size("main") do
|
||||
local it = inv:get_stack("main", i)
|
||||
if not it:is_empty() and it:get_name() == "mcl_bows:arrow" then
|
||||
arrow_stack = it
|
||||
arrow_stack_id = i
|
||||
break
|
||||
end
|
||||
end
|
||||
return arrow_stack, arrow_stack_id
|
||||
end
|
||||
|
||||
local player_shoot_arrow = function(itemstack, player, power, damage, is_critical)
|
||||
local has_infinity_enchantment = mcl_enchanting.has_enchantment(player:get_wielded_item(), "infinity")
|
||||
local infinity_used = false
|
||||
|
||||
if has_infinity_enchantment then
|
||||
infinity_used = true
|
||||
end
|
||||
local playerpos = player:get_pos()
|
||||
local dir = player:get_look_dir()
|
||||
local yaw = player:get_look_horizontal()
|
||||
|
||||
minetest.sound_play("mcl_bows_crossbow_shoot", {pos=playerpos, max_hear_distance=16}, true)
|
||||
mcl_bows.shoot_arrow("mcl_bows:arrow", {x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, dir, yaw, player, power, damage, is_critical, player:get_wielded_item(), not infinity_used)
|
||||
return true
|
||||
end
|
||||
|
||||
-- Crossbows item, uncharged state
|
||||
minetest.register_tool("mcl_bows:crossbow", {
|
||||
description = S("Crossbow"),
|
||||
_tt_help = S("Launches arrows"),
|
||||
_doc_items_longdesc = S("Crossbows are ranged weapons to shoot arrows at your foes.").."\n"..
|
||||
S("The speed and damage of the arrow increases the longer you charge. The regular damage of the arrow is between 1 and 9. At full charge, there's also a 20% of a critical hit, dealing 11 damage instead."),
|
||||
_doc_items_usagehelp = S("To use the crossbow, you first need to have at least one arrow anywhere in your inventory (unless in Creative Mode). Hold down the right mouse button to charge, and wait for arrow to load. when the Crossbow is loaded, you will be able to tap right click to fire"),
|
||||
_doc_items_durability = BOW_DURABILITY,
|
||||
inventory_image = "mcl_bows_crossbow.png",
|
||||
wield_scale = { x = 1.8, y = 1.8, z = 1 },
|
||||
stack_max = 1,
|
||||
range = 4,
|
||||
-- Trick to disable digging as well
|
||||
on_use = function() return end,
|
||||
on_place = function(itemstack, player, pointed_thing)
|
||||
if pointed_thing and pointed_thing.type == "node" then
|
||||
-- Call on_rightclick if the pointed node defines it
|
||||
local node = minetest.get_node(pointed_thing.under)
|
||||
if player and not player:get_player_control().sneak then
|
||||
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
|
||||
return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, player, itemstack) or itemstack
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
itemstack:get_meta():set_string("active", "true")
|
||||
return itemstack
|
||||
end,
|
||||
on_secondary_use = function(itemstack)
|
||||
itemstack:get_meta():set_string("active", "true")
|
||||
return itemstack
|
||||
end,
|
||||
groups = {weapon=1,weapon_ranged=1,bow=1,enchantability=1},
|
||||
_mcl_uses = 385,
|
||||
})
|
||||
|
||||
minetest.register_tool("mcl_bows:loaded_crossbow", {
|
||||
description = S("Crossbow (loaded)"),
|
||||
_tt_help = S("Launches arrows"),
|
||||
_doc_items_durability = BOW_DURABILITY,
|
||||
inventory_image = "mcl_bows_crossbow_3.png",
|
||||
wield_scale = { x = 1.8, y = 1.8, z = 1 },
|
||||
stack_max = 1,
|
||||
range = 4,
|
||||
-- Trick to disable digging as well
|
||||
on_use = function() return end,
|
||||
on_place = function(itemstack, player, pointed_thing)
|
||||
if pointed_thing and pointed_thing.type == "node" then
|
||||
-- Call on_rightclick if the pointed node defines it
|
||||
local node = minetest.get_node(pointed_thing.under)
|
||||
if player and not player:get_player_control().sneak then
|
||||
if minetest.registered_nodes[node.name] and minetest.registered_nodes[node.name].on_rightclick then
|
||||
return minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, player, itemstack) or itemstack
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
itemstack:get_meta():set_string("active", "true")
|
||||
return itemstack
|
||||
end,
|
||||
on_secondary_use = function(itemstack)
|
||||
itemstack:get_meta():set_string("active", "true")
|
||||
return itemstack
|
||||
end,
|
||||
groups = {weapon=1,weapon_ranged=1,bow=1,enchantability=1,not_in_creative_inventory=1},
|
||||
_mcl_uses = 385,
|
||||
})
|
||||
|
||||
-- Iterates through player inventory and resets all the bows in "charging" state back to their original stage
|
||||
local reset_bows = function(player)
|
||||
local inv = player:get_inventory()
|
||||
local list = inv:get_list("main")
|
||||
for place, stack in pairs(list) do
|
||||
if stack:get_name() == "mcl_bows:crossbow" or stack:get_name() == "mcl_bows:crossbow_enchanted" then
|
||||
stack:get_meta():set_string("active", "")
|
||||
elseif stack:get_name()=="mcl_bows:crossbow_0" or stack:get_name()=="mcl_bows:crossbow_1" or stack:get_name()=="mcl_bows:crossbow_2" then
|
||||
stack:set_name("mcl_bows:crossbow")
|
||||
stack:get_meta():set_string("active", "")
|
||||
list[place] = stack
|
||||
elseif stack:get_name()=="mcl_bows:crossbow_0_enchanted" or stack:get_name()=="mcl_bows:crossbow_1_enchanted" or stack:get_name()=="mcl_bows:crossbow_2_enchanted" then
|
||||
stack:set_name("mcl_bows:crossbow_enchanted")
|
||||
stack:get_meta():set_string("active", "")
|
||||
list[place] = stack
|
||||
end
|
||||
end
|
||||
inv:set_list("main", list)
|
||||
end
|
||||
|
||||
-- Resets the bow charging state and player speed. To be used when the player is no longer charging the bow
|
||||
local reset_bow_state = function(player, also_reset_bows)
|
||||
bow_load[player:get_player_name()] = nil
|
||||
bow_index[player:get_player_name()] = nil
|
||||
if also_reset_bows then
|
||||
reset_bows(player)
|
||||
end
|
||||
end
|
||||
|
||||
-- Bow in charging state
|
||||
for level=0, 2 do
|
||||
minetest.register_tool("mcl_bows:crossbow_"..level, {
|
||||
description = S("Crossbow"),
|
||||
_doc_items_create_entry = false,
|
||||
inventory_image = "mcl_bows_crossbow_"..level..".png",
|
||||
wield_scale = { x = 1.8, y = 1.8, z = 1 },
|
||||
stack_max = 1,
|
||||
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},
|
||||
-- Trick to disable digging as well
|
||||
on_use = function() return end,
|
||||
on_drop = function(itemstack, dropper, pos)
|
||||
reset_bow_state(dropper)
|
||||
itemstack:get_meta():set_string("active", "")
|
||||
if mcl_enchanting.is_enchanted(itemstack:get_name()) then
|
||||
itemstack:set_name("mcl_bows:crossbow_enchanted")
|
||||
else
|
||||
itemstack:set_name("mcl_bows:crossbow")
|
||||
end
|
||||
minetest.item_drop(itemstack, dropper, pos)
|
||||
itemstack:take_item()
|
||||
return itemstack
|
||||
end,
|
||||
-- Prevent accidental interaction with itemframes and other nodes
|
||||
on_place = function(itemstack)
|
||||
return itemstack
|
||||
end,
|
||||
_mcl_uses = 385,
|
||||
})
|
||||
end
|
||||
|
||||
controls.register_on_release(function(player, key)
|
||||
if key~="RMB" then return end
|
||||
reset_bows(player)
|
||||
end)
|
||||
|
||||
controls.register_on_press(function(player, key)
|
||||
if key~="RMB" then return end
|
||||
local inv = minetest.get_inventory({type="player", name=player:get_player_name()})
|
||||
local wielditem = player:get_wielded_item()
|
||||
if wielditem:get_name()=="mcl_bows:loaded_crossbow" or wielditem:get_name()=="mcl_bows:loaded_crossbow_enchanted" then
|
||||
local has_shot = false
|
||||
|
||||
local enchanted = mcl_enchanting.is_enchanted(wielditem:get_name())
|
||||
local speed, damage
|
||||
local p_load = bow_load[player:get_player_name()]
|
||||
local charge
|
||||
-- Type sanity check
|
||||
if type(p_load) == "number" then
|
||||
charge = minetest.get_us_time() - p_load
|
||||
else
|
||||
-- In case something goes wrong ...
|
||||
-- Just assume minimum charge.
|
||||
charge = 0
|
||||
minetest.log("warning", "[mcl_bows] Player "..player:get_player_name().." fires arrow with non-numeric bow_load!")
|
||||
end
|
||||
charge = 1000000
|
||||
|
||||
local charge_ratio = charge / BOW_CHARGE_TIME_FULL
|
||||
charge_ratio = math.max(math.min(charge_ratio, 1), 0)
|
||||
|
||||
-- Calculate damage and speed
|
||||
-- Fully charged
|
||||
local is_critical = false
|
||||
if charge >= BOW_CHARGE_TIME_FULL then
|
||||
speed = BOW_MAX_SPEED
|
||||
local r = math.random(1,5)
|
||||
if r == 1 then
|
||||
-- 20% chance for critical hit
|
||||
damage = 11
|
||||
is_critical = true
|
||||
else
|
||||
damage = 9
|
||||
end
|
||||
-- Partially charged
|
||||
else
|
||||
-- Linear speed and damage increase
|
||||
speed = math.max(4, BOW_MAX_SPEED * charge_ratio)
|
||||
damage = math.max(1, math.floor(9 * charge_ratio))
|
||||
end
|
||||
|
||||
has_shot = player_shoot_arrow(wielditem, player, speed, damage, is_critical)
|
||||
|
||||
if enchanted then
|
||||
wielditem:set_name("mcl_bows:crossbow_enchanted")
|
||||
else
|
||||
wielditem:set_name("mcl_bows:crossbow")
|
||||
end
|
||||
|
||||
if has_shot and not minetest.is_creative_enabled(player:get_player_name()) then
|
||||
local durability = BOW_DURABILITY
|
||||
local unbreaking = mcl_enchanting.get_enchantment(wielditem, "unbreaking")
|
||||
if unbreaking > 0 then
|
||||
durability = durability * (unbreaking + 1)
|
||||
end
|
||||
wielditem:add_wear(65535/durability)
|
||||
end
|
||||
player:set_wielded_item(wielditem)
|
||||
reset_bow_state(player, true)
|
||||
end
|
||||
end)
|
||||
|
||||
controls.register_on_hold(function(player, key, time)
|
||||
playerpos = player:get_pos()
|
||||
arrow_stack = get_arrow(player)
|
||||
local name = player:get_player_name()
|
||||
local creative = minetest.is_creative_enabled(name)
|
||||
if key ~= "RMB" or not (creative or get_arrow(player)) then
|
||||
return
|
||||
end
|
||||
local inv = minetest.get_inventory({type="player", name=name})
|
||||
local wielditem = player:get_wielded_item()
|
||||
if bow_load[name] == nil and (wielditem:get_name()=="mcl_bows:crossbow" or wielditem:get_name()=="mcl_bows:crossbow_enchanted") and wielditem:get_meta():get("active") and (creative or get_arrow(player)) then
|
||||
local enchanted = mcl_enchanting.is_enchanted(wielditem:get_name())
|
||||
if enchanted then
|
||||
wielditem:set_name("mcl_bows:crossbow_0_enchanted")
|
||||
minetest.sound_play("mcl_bows_crossbow_drawback_0", {pos=playerpos, max_hear_distance=16}, true)
|
||||
else
|
||||
wielditem:set_name("mcl_bows:crossbow_0")
|
||||
minetest.sound_play("mcl_bows_crossbow_drawback_0", {pos=playerpos, max_hear_distance=16}, true)
|
||||
end
|
||||
player:set_wielded_item(wielditem)
|
||||
bow_load[name] = minetest.get_us_time()
|
||||
bow_index[name] = player:get_wield_index()
|
||||
else
|
||||
if player:get_wield_index() == bow_index[name] then
|
||||
if type(bow_load[name]) == "number" then
|
||||
if wielditem:get_name() == "mcl_bows:crossbow_0" and minetest.get_us_time() - bow_load[name] >= BOW_CHARGE_TIME_HALF then
|
||||
minetest.sound_play("mcl_bows_crossbow_drawback_1", {pos=playerpos, max_hear_distance=16}, true)
|
||||
wielditem:set_name("mcl_bows:crossbow_1")
|
||||
elseif wielditem:get_name() == "mcl_bows:crossbow_0_enchanted" and minetest.get_us_time() - bow_load[name] >= BOW_CHARGE_TIME_HALF then
|
||||
minetest.sound_play("mcl_bows_crossbow_drawback_1", {pos=playerpos, max_hear_distance=16}, true)
|
||||
wielditem:set_name("mcl_bows:crossbow_1_enchanted")
|
||||
elseif wielditem:get_name() == "mcl_bows:crossbow_1" and minetest.get_us_time() - bow_load[name] >= BOW_CHARGE_TIME_FULL then
|
||||
minetest.sound_play("mcl_bows_crossbow_drawback_2", {pos=playerpos, max_hear_distance=16}, true)
|
||||
wielditem:set_name("mcl_bows:crossbow_2")
|
||||
if minetest.get_us_time() - bow_load[name] >= 1000000 then
|
||||
minetest.sound_play("mcl_bows_crossbow_load", {pos=playerpos, max_hear_distance=16}, true)
|
||||
wielditem:set_name("mcl_bows:loaded_crossbow")
|
||||
local arrow_stack, arrow_stack_id = get_arrow(player)
|
||||
local arrow_itemstring
|
||||
local has_infinity_enchantment = mcl_enchanting.has_enchantment(player:get_wielded_item(), "infinity")
|
||||
local infinity_used = false
|
||||
|
||||
if minetest.is_creative_enabled(player:get_player_name()) then
|
||||
if arrow_stack then
|
||||
arrow_itemstring = arrow_stack:get_name()
|
||||
else
|
||||
arrow_itemstring = "mcl_bows:arrow"
|
||||
end
|
||||
else
|
||||
if not arrow_stack then
|
||||
return false
|
||||
end
|
||||
arrow_itemstring = arrow_stack:get_name()
|
||||
if has_infinity_enchantment and minetest.get_item_group(arrow_itemstring, "ammo_bow_regular") > 0 then
|
||||
infinity_used = true
|
||||
else
|
||||
arrow_stack:take_item()
|
||||
end
|
||||
local inv = player:get_inventory()
|
||||
inv:set_stack("main", arrow_stack_id, arrow_stack)
|
||||
end
|
||||
if not arrow_itemstring then
|
||||
return false
|
||||
end
|
||||
end
|
||||
elseif wielditem:get_name() == "mcl_bows:crossbow_1_enchanted" and minetest.get_us_time() - bow_load[name] >= BOW_CHARGE_TIME_FULL then
|
||||
minetest.sound_play("mcl_bows_crossbow_drawback_2", {pos=playerpos, max_hear_distance=16}, true)
|
||||
wielditem:set_name("mcl_bows:crossbow_2_enchanted")
|
||||
if minetest.get_us_time() - bow_load[name] >= 60000 then
|
||||
wielditem:set_name("mcl_bows:loaded_crossbow_enchanted")
|
||||
end
|
||||
end
|
||||
else
|
||||
if wielditem:get_name() == "mcl_bows:crossbow_0" or wielditem:get_name() == "mcl_bows:crossbow_1" or wielditem:get_name() == "mcl_bows:crossbow_2" then
|
||||
wielditem:set_name("mcl_bows:crossbow")
|
||||
elseif wielditem:get_name() == "mcl_bows:crossbow_0_enchanted" or wielditem:get_name() == "mcl_bows:crossbow_1_enchanted" or wielditem:get_name() == "mcl_bows:crossbow_2_enchanted" then
|
||||
wielditem:set_name("mcl_bows:crossbow_enchanted")
|
||||
end
|
||||
end
|
||||
player:set_wielded_item(wielditem)
|
||||
else
|
||||
reset_bow_state(player, true)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_globalstep(function(dtime)
|
||||
for _, player in pairs(minetest.get_connected_players()) do
|
||||
local name = player:get_player_name()
|
||||
local wielditem = player:get_wielded_item()
|
||||
local wieldindex = player:get_wield_index()
|
||||
local controls = player:get_player_control()
|
||||
if type(bow_load[name]) == "number" and ((wielditem:get_name()~="mcl_bows:crossbow_0" and wielditem:get_name()~="mcl_bows:crossbow_1" and wielditem:get_name()~="mcl_bows:crossbow_2" and wielditem:get_name()~="mcl_bows:crossbow_0_enchanted" and wielditem:get_name()~="mcl_bows:crossbow_1_enchanted" and wielditem:get_name()~="mcl_bows:crossbow_2_enchanted") or wieldindex ~= bow_index[name]) then
|
||||
reset_bow_state(player, true)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
minetest.register_on_joinplayer(function(player)
|
||||
reset_bows(player)
|
||||
end)
|
||||
|
||||
minetest.register_on_leaveplayer(function(player)
|
||||
reset_bow_state(player, true)
|
||||
end)
|
||||
|
||||
if minetest.get_modpath("mcl_core") and minetest.get_modpath("mcl_mobitems") then
|
||||
minetest.register_craft({
|
||||
output = 'mcl_bows:crossbow',
|
||||
recipe = {
|
||||
{'mcl_core:stick', 'mcl_core:iron_ingot', 'mcl_core:stick'},
|
||||
{'mcl_mobitems:string', 'mcl_core:iron_ingot', 'mcl_mobitems:string'},
|
||||
--TODO make this^^ trip wire (as of now no such thing exists)
|
||||
{'', 'mcl_core:stick', ''},
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
minetest.register_craft({
|
||||
type = "fuel",
|
||||
recipe = "group:bow",
|
||||
burntime = 15,
|
||||
})
|
||||
|
||||
-- Add entry aliases for the Help
|
||||
if minetest.get_modpath("doc") then
|
||||
doc.add_entry_alias("tools", "mcl_bows:crossbow", "tools", "mcl_bows:crossbow_0")
|
||||
doc.add_entry_alias("tools", "mcl_bows:crossbow", "tools", "mcl_bows:crossbow_1")
|
||||
doc.add_entry_alias("tools", "mcl_bows:crossbow", "tools", "mcl_bows:crossbow_2")
|
||||
end
|
|
@ -1,5 +1,6 @@
|
|||
dofile(minetest.get_modpath("mcl_bows") .. "/arrow.lua")
|
||||
dofile(minetest.get_modpath("mcl_bows") .. "/bow.lua")
|
||||
dofile(minetest.get_modpath("mcl_bows") .. "/crossbow.lua")
|
||||
|
||||
minetest.register_alias("mcl_throwing:bow", "mcl_bows:bow")
|
||||
minetest.register_alias("mcl_throwing:arrow", "mcl_bows:arrow")
|
||||
|
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 557 B |
Binary file not shown.
After Width: | Height: | Size: 597 B |
Binary file not shown.
After Width: | Height: | Size: 559 B |
Binary file not shown.
After Width: | Height: | Size: 575 B |
Binary file not shown.
After Width: | Height: | Size: 597 B |
|
@ -23,13 +23,35 @@ minetest.register_globalstep(function(dtime)
|
|||
local controls = player:get_player_control()
|
||||
name = player:get_player_name()
|
||||
|
||||
local player_velocity = player:get_player_velocity()
|
||||
|
||||
-- controls head bone
|
||||
local pitch = degrees(player:get_look_vertical()) * -1
|
||||
local yaw = degrees(player:get_look_horizontal()) * -1
|
||||
|
||||
if degrees(minetest.dir_to_yaw(player_velocity)) == 0 then
|
||||
player_vel_yaw = 0
|
||||
yaw = 0
|
||||
else
|
||||
player_vel_yaw = degrees(minetest.dir_to_yaw(player_velocity))
|
||||
end
|
||||
|
||||
if string.find(player:get_wielded_item():get_name(), "mcl_bows:crossbow") and controls.RMB then
|
||||
playerphysics.add_physics_factor(player, "speed", "mcl_playerplus:crossbow_walking", tonumber(minetest.settings:get("movement_speed_crouch")) / tonumber(minetest.settings:get("movement_speed_walk")))
|
||||
else
|
||||
playerphysics.remove_physics_factor(player, "speed", "mcl_playerplus:crossbow_walking")
|
||||
end
|
||||
|
||||
-- controls right and left arms pitch when shooting a bow or punching
|
||||
if string.find(player:get_wielded_item():get_name(), "mcl_bows:bow") and controls.RMB and not controls.LMB and not controls.up and not controls.down and not controls.left and not controls.right then
|
||||
if string.find(player:get_wielded_item():get_name(), "mcl_bows:bow") and controls.RMB and not controls.up and not controls.down and not controls.left and not controls.right and not minetest.get_item_group(mcl_playerinfo[name].node_stand, "water") ~= 0 then
|
||||
player:set_bone_position("Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(pitch+90,-30,pitch * -1 * .35))
|
||||
player:set_bone_position("Arm_Left_Pitch_Control", vector.new(3.5,5.785,0), vector.new(pitch+90,43,pitch * .35))
|
||||
elseif string.find(player:get_wielded_item():get_name(), "mcl_bows:crossbow") and not controls.LMB and controls.RMB and not controls.up and not controls.down and not controls.left and not controls.right and not minetest.get_item_group(mcl_playerinfo[name].node_stand, "water") ~= 0 then
|
||||
player:set_bone_position("Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(20,0,30))
|
||||
player:set_bone_position("Arm_Left_Pitch_Control", vector.new(3,5.785,0), vector.new(40,0,-40))
|
||||
elseif string.find(player:get_wielded_item():get_name(), "mcl_bows:loaded_crossbow") and not controls.LMB and not controls.up and not controls.down and not controls.left and not controls.right and not minetest.get_item_group(mcl_playerinfo[name].node_stand, "water") ~= 0 then
|
||||
player:set_bone_position("Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(pitch+90,-15,pitch * -1 * .35))
|
||||
player:set_bone_position("Arm_Left_Pitch_Control", vector.new(3.5,5.785,0), vector.new(pitch+90,55,pitch * .35))
|
||||
elseif controls.LMB then
|
||||
player:set_bone_position("Arm_Right_Pitch_Control", vector.new(-3,5.785,0), vector.new(pitch,0,0))
|
||||
player:set_bone_position("Arm_Left_Pitch_Control", vector.new(3,5.785,0), vector.new(0,0,0))
|
||||
|
@ -44,17 +66,20 @@ minetest.register_globalstep(function(dtime)
|
|||
-- sets eye height, and nametag color accordingly
|
||||
player:set_properties({collisionbox = {-0.35,0,-0.35,0.35,1.8,0.35}, eye_height = 1.35, nametag_color = { r = 225, b = 225, a = 0, g = 225 }})
|
||||
|
||||
player:set_bone_position("Body_Control", vector.new(0,6.3,0), vector.new(0,0,0))
|
||||
elseif minetest.get_item_group(mcl_playerinfo[name].node_feet, "water") ~= 0 and player:get_attach() == nil and mcl_sprint.is_sprinting(name) == true then
|
||||
-- controls head pitch when swiming
|
||||
player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch+90,0,0))
|
||||
player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch+90,yaw - player_vel_yaw * -1,0))
|
||||
-- sets eye height, and nametag color accordingly
|
||||
player:set_properties({collisionbox = {-0.35,0,-0.35,0.35,0.8,0.35}, eye_height = 0.65, nametag_color = { r = 225, b = 225, a = 225, g = 225 }})
|
||||
|
||||
player:set_bone_position("Body_Control", vector.new(0,6.3,0), vector.new(-90,player_vel_yaw * -1 - yaw + 180,0))
|
||||
else
|
||||
-- controls head pitch when not sneaking
|
||||
player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch,0,0))
|
||||
-- sets eye height, and nametag color accordingly
|
||||
player:set_properties({collisionbox = {-0.35,0,-0.35,0.35,1.8,0.35}, eye_height = 1.65, nametag_color = { r = 225, b = 225, a = 225, g = 225 }})
|
||||
player:set_bone_position("Head", vector.new(0,6.3,0), vector.new(pitch,yaw - player_vel_yaw * -1,0))
|
||||
player:set_bone_position("Body_Control", vector.new(0,6.3,0), vector.new(0,player_vel_yaw * -1 - yaw,0))
|
||||
end
|
||||
|
||||
if mcl_playerplus_internal[name].jump_cooldown > 0 then
|
||||
|
|
Loading…
Reference in New Issue