tweak & tidy
This commit is contained in:
parent
d61557d670
commit
e382ece1f3
24
arrow.lua
24
arrow.lua
@ -1,5 +1,9 @@
|
||||
|
||||
local on_hit_remove = function(self)
|
||||
local math_random = math.random
|
||||
|
||||
-- helper to remove or maybe drop arrow item
|
||||
|
||||
local function on_hit_remove(self)
|
||||
|
||||
minetest.sound_play(
|
||||
bows.registered_arrows[self.name].on_hit_sound, {
|
||||
@ -12,7 +16,7 @@ local on_hit_remove = function(self)
|
||||
local chance = minetest.registered_items[self.name].drop_chance or 10
|
||||
local pos = self.object:get_pos()
|
||||
|
||||
if pos and math.random(chance) == 1 then
|
||||
if pos and math_random(chance) == 1 then
|
||||
|
||||
pos.y = pos.y + 0.5
|
||||
|
||||
@ -24,18 +28,19 @@ local on_hit_remove = function(self)
|
||||
return self
|
||||
end
|
||||
|
||||
-- when arrow hits an entity
|
||||
|
||||
local on_hit_object = function(self, target, hp, user, lastpos)
|
||||
local function on_hit_object(self, target, hp, user, lastpos)
|
||||
|
||||
target:punch(user, 0.1, {
|
||||
full_punch_interval = 0.1,
|
||||
target:punch(user, 1.0, {
|
||||
--full_punch_interval = 1.0,
|
||||
damage_groups = {fleshy = hp},
|
||||
}, nil)
|
||||
|
||||
if bows.registered_arrows[self.name].on_hit_object then
|
||||
|
||||
bows.registered_arrows[self.name].on_hit_object(
|
||||
self, target, hp, user, lastpos)
|
||||
self, target, hp, user, lastpos)
|
||||
end
|
||||
|
||||
on_hit_remove(self)
|
||||
@ -43,6 +48,7 @@ local on_hit_object = function(self, target, hp, user, lastpos)
|
||||
return self
|
||||
end
|
||||
|
||||
-- arrow entity
|
||||
|
||||
minetest.register_entity("bows:arrow",{
|
||||
|
||||
@ -61,8 +67,7 @@ minetest.register_entity("bows:arrow",{
|
||||
on_activate = function(self, staticdata)
|
||||
|
||||
if not self then
|
||||
self.object:remove()
|
||||
return
|
||||
self.object:remove() ; return
|
||||
end
|
||||
|
||||
if bows.tmp and bows.tmp.arrow ~= nil then
|
||||
@ -85,8 +90,7 @@ minetest.register_entity("bows:arrow",{
|
||||
self.timer = self.timer - dtime
|
||||
|
||||
if self.timer < 0 then
|
||||
self.object:remove()
|
||||
return
|
||||
self.object:remove() ; return
|
||||
end
|
||||
|
||||
local pos = self.object:get_pos() ; self.oldpos = self.oldpos or pos
|
||||
|
24
init.lua
24
init.lua
@ -1,5 +1,5 @@
|
||||
|
||||
-- Bows Mod by UjEdwin
|
||||
-- Bows Mod by UjEdwin (edited by TenPlus1)
|
||||
|
||||
bows = {
|
||||
pvp = minetest.settings:get_bool("enable_pvp"),
|
||||
@ -7,6 +7,7 @@ bows = {
|
||||
registered_bows = {}
|
||||
}
|
||||
|
||||
-- creative check
|
||||
|
||||
local creative_mode_cache = minetest.settings:get_bool("creative_mode")
|
||||
|
||||
@ -14,8 +15,9 @@ function bows.is_creative(name)
|
||||
return creative_mode_cache or minetest.check_player_privs(name, {creative = true})
|
||||
end
|
||||
|
||||
-- register arrow
|
||||
|
||||
bows.register_arrow = function(name, def)
|
||||
function bows.register_arrow(name, def)
|
||||
|
||||
if name == nil or name == "" then
|
||||
return false
|
||||
@ -46,8 +48,9 @@ bows.register_arrow = function(name, def)
|
||||
end
|
||||
end
|
||||
|
||||
-- register bow
|
||||
|
||||
bows.register_bow = function(name, def)
|
||||
function bows.register_bow(name, def)
|
||||
|
||||
if name == nil or name == "" then
|
||||
return false
|
||||
@ -63,14 +66,14 @@ bows.register_bow = function(name, def)
|
||||
description = def.description or name,
|
||||
inventory_image = def.texture or "bows_bow.png",
|
||||
on_use = bows.load,
|
||||
groups = {bow = 1},
|
||||
groups = {bow = 1}
|
||||
})
|
||||
|
||||
minetest.register_tool(":" .. def.replace, {
|
||||
description = def.description or name,
|
||||
inventory_image = def.texture_loaded or "bows_bow_loaded.png",
|
||||
on_use = bows.shoot,
|
||||
groups = {bow = 1, not_in_creative_inventory = 1},
|
||||
groups = {bow = 1, not_in_creative_inventory = 1}
|
||||
})
|
||||
|
||||
if def.craft then
|
||||
@ -78,8 +81,9 @@ bows.register_bow = function(name, def)
|
||||
end
|
||||
end
|
||||
|
||||
-- load bow
|
||||
|
||||
bows.load = function(itemstack, user, pointed_thing)
|
||||
function bows.load(itemstack, user, pointed_thing)
|
||||
|
||||
local inv = user:get_inventory()
|
||||
local index = user:get_wield_index() - 1
|
||||
@ -107,8 +111,9 @@ bows.load = function(itemstack, user, pointed_thing)
|
||||
return itemstack
|
||||
end
|
||||
|
||||
-- shoot bow
|
||||
|
||||
bows.shoot = function(itemstack, user, pointed_thing)
|
||||
function bows.shoot(itemstack, user, pointed_thing)
|
||||
|
||||
local item = itemstack:to_table()
|
||||
local meta = minetest.deserialize(item.metadata)
|
||||
@ -148,7 +153,7 @@ bows.shoot = function(itemstack, user, pointed_thing)
|
||||
pos.y = pos.y + height
|
||||
end
|
||||
|
||||
local e = minetest.add_entity({ x = pos.x, y = pos.y, z = pos.z }, "bows:arrow")
|
||||
local e = minetest.add_entity({x = pos.x, y = pos.y, z = pos.z}, "bows:arrow")
|
||||
|
||||
e:set_velocity({x = dir.x * level, y = dir.y * level, z = dir.z * level})
|
||||
e:set_acceleration({x = dir.x * -3, y = -10, z = dir.z * -3})
|
||||
@ -163,12 +168,15 @@ bows.shoot = function(itemstack, user, pointed_thing)
|
||||
return itemstack
|
||||
end
|
||||
|
||||
-- register items
|
||||
|
||||
local path = minetest.get_modpath("bows")
|
||||
|
||||
dofile(path .. "/arrow.lua")
|
||||
dofile(path .. "/items.lua")
|
||||
|
||||
-- add lucky blocks
|
||||
|
||||
if minetest.get_modpath("lucky_block") then
|
||||
dofile(path .. "/lucky_block.lua")
|
||||
end
|
||||
|
44
items.lua
44
items.lua
@ -1,7 +1,8 @@
|
||||
|
||||
-- detect feather item to use
|
||||
|
||||
local feather = "default:leaves"
|
||||
|
||||
-- detect feather item to use
|
||||
if minetest.get_modpath("animalia") then
|
||||
feather = "animalia:feather"
|
||||
elseif minetest.get_modpath("mobs_animal") then
|
||||
@ -11,6 +12,7 @@ elseif minetest.get_modpath("xanadu") then
|
||||
end
|
||||
|
||||
-- helpful recipes
|
||||
|
||||
minetest.register_craft({
|
||||
output = "default:flint",
|
||||
recipe = {{"default:gravel"}}
|
||||
@ -22,6 +24,7 @@ minetest.register_craft({
|
||||
})
|
||||
|
||||
-- wooden bow
|
||||
|
||||
bows.register_bow("bow_wood",{
|
||||
description = "Wooden bow",
|
||||
texture = "bows_bow.png",
|
||||
@ -42,47 +45,51 @@ minetest.register_craft({
|
||||
})
|
||||
|
||||
-- steel bow
|
||||
|
||||
bows.register_bow("bow_steel",{
|
||||
description = "Steel bow",
|
||||
texture = "bows_bow_steel.png",
|
||||
texture_loaded = "bows_bow_loaded_steel.png",
|
||||
uses = 280, --140,
|
||||
level = 5, --8,
|
||||
uses = 280,
|
||||
level = 5,
|
||||
craft = {
|
||||
{"", "default:steel_ingot", "farming:string"},
|
||||
{"default:steel_ingot", "", "farming:string"},
|
||||
{"", "default:steel_ingot", "farming:string"}
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
-- bronze bow
|
||||
|
||||
bows.register_bow("bow_bronze",{
|
||||
description = "Bronze bow",
|
||||
texture = "bows_bow_bronze.png",
|
||||
texture_loaded = "bows_bow_loaded_bronze.png",
|
||||
uses = 140, --280,
|
||||
level = 3, --10,
|
||||
uses = 140,
|
||||
level = 3,
|
||||
craft = {
|
||||
{"", "default:bronze_ingot", "farming:string"},
|
||||
{"default:bronze_ingot", "", "farming:string"},
|
||||
{"", "default:bronze_ingot", "farming:string"}
|
||||
},
|
||||
}
|
||||
})
|
||||
|
||||
-- special David BOWie (lucky block drop)
|
||||
|
||||
bows.register_bow("bow_bowie",{
|
||||
description = "David BOWie",
|
||||
texture = "bows_bow_bowie.png",
|
||||
texture_loaded = "bows_bow_loaded_bowie.png",
|
||||
uses = 500,
|
||||
level = 7,
|
||||
level = 7
|
||||
})
|
||||
|
||||
-- wooden arrow
|
||||
|
||||
bows.register_arrow("arrow",{
|
||||
description = "Arrow",
|
||||
texture = "bows_arrow_wood.png",
|
||||
damage = 5,
|
||||
damage = 2,
|
||||
craft_count = 4,
|
||||
drop_chance = 10,
|
||||
craft = {
|
||||
@ -108,16 +115,17 @@ bows.register_arrow("arrow",{
|
||||
minetest.register_craft({
|
||||
type = "fuel",
|
||||
recipe = "bows:arrow",
|
||||
burntime = 1,
|
||||
burntime = 1
|
||||
})
|
||||
|
||||
-- steel arrow
|
||||
|
||||
bows.register_arrow("arrow_steel",{
|
||||
description = "Steel arrow",
|
||||
texture = "bows_arrow_wood.png^[colorize:#FFFFFFcc",
|
||||
damage = 8,
|
||||
damage = 6,
|
||||
craft_count = 4,
|
||||
drop_chance = 8,
|
||||
drop_chance = 9,
|
||||
craft = {
|
||||
{"default:steel_ingot", "group:stick", feather}
|
||||
},
|
||||
@ -136,12 +144,13 @@ bows.register_arrow("arrow_steel",{
|
||||
})
|
||||
|
||||
-- mese arrow (enables node mesecons when hit)
|
||||
|
||||
bows.register_arrow("arrow_mese",{
|
||||
description = "Mese arrow",
|
||||
texture = "bows_arrow_wood.png^[colorize:#e3ff00cc",
|
||||
damage = 12,
|
||||
damage = 7,
|
||||
craft_count = 4,
|
||||
drop_chance = 6,
|
||||
drop_chance = 8,
|
||||
craft = {
|
||||
{"default:mese_crystal", "group:stick", feather}
|
||||
},
|
||||
@ -162,12 +171,13 @@ bows.register_arrow("arrow_mese",{
|
||||
})
|
||||
|
||||
-- diamond arrow (breaks glass node when hit)
|
||||
|
||||
bows.register_arrow("arrow_diamond",{
|
||||
description = "Diamond arrow",
|
||||
texture = "bows_arrow_wood.png^[colorize:#15d7c2cc",
|
||||
damage = 15,
|
||||
damage = 8,
|
||||
craft_count = 4,
|
||||
drop_chance = 4,
|
||||
drop_chance = 7,
|
||||
craft = {
|
||||
{"default:diamond", "group:stick", feather}
|
||||
},
|
||||
@ -180,5 +190,5 @@ bows.register_arrow("arrow_diamond",{
|
||||
minetest.remove_node(pos)
|
||||
minetest.add_item(pos, "vessels:glass_fragments")
|
||||
end
|
||||
end,
|
||||
end
|
||||
})
|
||||
|
@ -1,11 +1,14 @@
|
||||
|
||||
-- add lucky blocks
|
||||
|
||||
lucky_block:add_blocks({
|
||||
{"dro", {"bows:bow_wood"}},
|
||||
{"dro", {"bows:bow_steel"}},
|
||||
{"dro", {"bows:bow_bronze"}},
|
||||
{"dro", {"bows:arrow"}, 5},
|
||||
{"dro", {"bows:arrow_steel"}, 5},
|
||||
{"dro", {"bows:arrow_mese"}, 5},
|
||||
{"dro", {"bows:arrow_diamond"}, 5},
|
||||
{"dro", {"bows:arrow"}, 10},
|
||||
{"dro", {"bows:arrow_steel"}, 8},
|
||||
{"dro", {"bows:arrow_mese"}, 7},
|
||||
{"dro", {"bows:arrow_diamond"}, 6},
|
||||
{"nod", "default:chest", 0, {
|
||||
{name = "default:stick", max = 5},
|
||||
{name = "default:flint", max = 5},
|
||||
|
Loading…
x
Reference in New Issue
Block a user