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