diff --git a/bows.lua b/bows.lua index 0f9857d..36c38d1 100644 --- a/bows.lua +++ b/bows.lua @@ -36,7 +36,6 @@ local throwing_shoot_arrow = function(itemstack, player) end obj:get_luaentity().stack = player:get_inventory():get_stack("main", player:get_wield_index()+2) obj:get_luaentity().inventory = player:get_inventory() - obj:get_luaentity().breaks = math.random() return true end end @@ -228,3 +227,83 @@ if not DISABLE_STEEL_BOW then } }) end + +if not DISABLE_ROYAL_BOW then + minetest.register_tool("throwing:bow_royal", { + description = "Royal Bow", + inventory_image = "throwing_bow_royal.png", + wield_scale = {x=1, y=1.4, z=0.5}, + stack_max = 1, + on_use = function(itemstack, user, pointed_thing) + stiffness = 16 + reload = 1.6 + if throwing_shoot_arrow(itemstack, user, pointed_thing) then + reloading(user) + if not minetest.setting_getbool("creative_mode") then + itemstack:add_wear(65535/1000) + end + end + return itemstack + end, + }) + + minetest.register_craft({ + output = 'throwing:bow_royal', + recipe = { + {'farming:string', 'group:wood', 'default:diamond'}, + {'farming:string', '', 'default:gold_ingot'}, + {'farming:string', 'group:wood', 'default:diamond'}, + } + }) + + minetest.register_craft({ + output = 'throwing:bow_royal', + recipe = { + {'default:diamond', 'group:wood', 'farming:string'}, + {'default:gold_ingot', '', 'farming:string'}, + {'default:diamond', 'group:wood', 'farming:string'}, + } + }) +end + +if not DISABLE_CROSSBOW then + minetest.register_tool("throwing:crossbow", { + description = "Crossbow", + inventory_image = "throwing_crossbow.png", + wield_scale = {x=1, y=1, z=1}, + stack_max = 1, + on_use = function(itemstack, user, pointed_thing) + minetest.sound_play("throwing_crossbow_sound", {pos=playerpos}) + stiffness = 27 + reload = 8 + if throwing_shoot_arrow(itemstack, user, pointed_thing) then + if not minetest.setting_getbool("creative_mode") then + itemstack:add_wear(65535/100) + end + end + return itemstack + end, + on_place = function(itemstack, placer, pointed_thing) + reloading(placer) + return itemstack + end, + }) + + minetest.register_craft({ + output = 'throwing:crossbow', + recipe = { + {'group:wood', 'farming:string', ''}, + {'default:steel_ingot', 'farming:string', 'group:wood'}, + {'group:wood', 'farming:string', ''}, + } + }) + + minetest.register_craft({ + output = 'throwing:crossbow', + recipe = { + {'', 'farming:string', 'group:wood'}, + {'group:wood', 'farming:string', 'default:steel_ingot'}, + {'', 'farming:string', 'group:wood'}, + } + }) +end diff --git a/build_arrow.lua b/build_arrow.lua index 37a5051..0f3b173 100644 --- a/build_arrow.lua +++ b/build_arrow.lua @@ -46,7 +46,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) local node = minetest.get_node(pos) if self.timer>0.2 then - local objs = minetest.env:get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1) + local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1) for k, obj in pairs(objs) do if obj:get_luaentity() ~= nil then if obj:get_luaentity().name ~= "throwing:arrow_build_entity" and obj:get_luaentity().name ~= "__builtin:item" then @@ -56,7 +56,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) end minetest.add_item(self.lastpos, {name=self.stack:get_name()}) local toughness = 0.95 - if self.breaks < toughness then + if math.random() < toughness then minetest.add_item(self.lastpos, 'throwing:arrow_build') else minetest.add_item(self.lastpos, 'default:stick') diff --git a/diamond_arrow.lua b/diamond_arrow.lua index b931d28..358fd22 100644 --- a/diamond_arrow.lua +++ b/diamond_arrow.lua @@ -45,7 +45,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) local node = minetest.get_node(pos) if self.timer>0.2 then - local objs = minetest.env:get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2) + local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 2) for k, obj in pairs(objs) do if obj:get_luaentity() ~= nil then if obj:get_luaentity().name ~= "throwing:arrow_diamond_entity" and obj:get_luaentity().name ~= "__builtin:item" then @@ -57,7 +57,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) }, nil) self.object:remove() local toughness = 0.97 - if self.breaks < toughness then + if math.random() < toughness then minetest.add_item(self.lastpos, 'throwing:arrow_diamond') else minetest.add_item(self.lastpos, 'default:stick') @@ -71,7 +71,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) if node.name ~= "air" then self.object:remove() local toughness = 0.95 - if self.breaks < toughness then + if math.random() < toughness then minetest.add_item(self.lastpos, 'throwing:arrow_diamond') else minetest.add_item(self.lastpos, 'default:stick') diff --git a/dig_arrow.lua b/dig_arrow.lua index 8ad2e7e..4e7cf9b 100644 --- a/dig_arrow.lua +++ b/dig_arrow.lua @@ -56,7 +56,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) }, nil) self.object:remove() local toughness = 0.9 - if self.breaks < toughness then + if math.random() < toughness then minetest.add_item(self.lastpos, 'throwing:arrow_dig') else minetest.add_item(self.lastpos, 'default:stick') @@ -73,7 +73,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) minetest.dig_node(pos) end local toughness = 0.65 - if self.breaks < toughness then + if math.random() < toughness then minetest.add_item(self.lastpos, 'default:pick_steel') else minetest.add_item(self.lastpos, 'default:stick') diff --git a/obsidian_arrow.lua b/obsidian_arrow.lua index db26542..ea45eef 100644 --- a/obsidian_arrow.lua +++ b/obsidian_arrow.lua @@ -57,7 +57,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) }, nil) self.object:remove() local toughness = 0.94 - if self.breaks < toughness then + if math.random() < toughness then minetest.add_item(self.lastpos, 'throwing:arrow_obsidian') else minetest.add_item(self.lastpos, 'default:stick') @@ -71,7 +71,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) if node.name ~= "air" then self.object:remove() local toughness = 0.88 - if self.breaks < toughness then + if math.random() < toughness then minetest.add_item(self.lastpos, 'throwing:arrow_obsidian') else minetest.add_item(self.lastpos, 'default:stick') diff --git a/sounds/throwing_bow_sound.ogg b/sounds/throwing_bow_sound.ogg index de4e22b..411598c 100644 Binary files a/sounds/throwing_bow_sound.ogg and b/sounds/throwing_bow_sound.ogg differ diff --git a/steel_arrow.lua b/steel_arrow.lua index a4d2eb0..6aa8c64 100644 --- a/steel_arrow.lua +++ b/steel_arrow.lua @@ -57,7 +57,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) }, nil) self.object:remove() local toughness = 0.95 - if self.breaks < toughness then + if math.random() < toughness then minetest.add_item(self.lastpos, 'throwing:arrow_steel') else minetest.add_item(self.lastpos, 'default:stick') @@ -71,7 +71,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) if node.name ~= "air" then self.object:remove() local toughness = 0.9 - if self.breaks < toughness then + if math.random() < toughness then minetest.add_item(self.lastpos, 'throwing:arrow_steel') else minetest.add_item(self.lastpos, 'default:stick') diff --git a/stone_arrow.lua b/stone_arrow.lua index 66d522b..da00e78 100644 --- a/stone_arrow.lua +++ b/stone_arrow.lua @@ -57,7 +57,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) }, nil) self.object:remove() local toughness = 0.94 - if self.breaks < toughness then + if math.random() < toughness then minetest.add_item(self.lastpos, 'throwing:arrow_stone') else minetest.add_item(self.lastpos, 'default:stick') @@ -71,7 +71,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) if node.name ~= "air" then self.object:remove() local toughness = 0.88 - if self.breaks < toughness then + if math.random() < toughness then minetest.add_item(self.lastpos, 'throwing:arrow_stone') else minetest.add_item(self.lastpos, 'default:stick') diff --git a/torch_arrow.lua b/torch_arrow.lua index 8165ea3..004b73d 100644 --- a/torch_arrow.lua +++ b/torch_arrow.lua @@ -57,8 +57,8 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) }, nil) self.object:remove() local toughness = 0.9 - if self.breaks < toughness then - minetest.add_item(self.lastpos, 'throwing:arrow_diamond') + if math.random() < toughness then + minetest.add_item(self.lastpos, 'throwing:arrow_torch') else minetest.add_item(self.lastpos, 'default:stick') end @@ -74,46 +74,9 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime) local dir=vector.direction(self.lastpos, pos) local wall=minetest.dir_to_wallmounted(dir) minetest.add_node(self.lastpos, {name="default:torch", param2 = wall}) - --~ if wall == 0 then Check doesn't help :( - --~ local check_pos={self.lastpos.x, self.lastpos.y+0.5, self.lastpos.z} - --~ if minetest.get_node(check_pos).name ~= "air" then - --~ minetest.add_node(self.lastpos, {name="default:torch", param2 = wall}) - --~ self.object:remove() - --~ end - --~ elseif wall == 1 then - --~ local check_pos={self.lastpos.x, self.lastpos.y-0.5, self.lastpos.z} - --~ if minetest.get_node(check_pos).name ~= "air" then - --~ minetest.add_node(self.lastpos, {name="default:torch", param2 = wall}) - --~ self.object:remove() - --~ end - --~ elseif wall == 2 then - --~ local check_pos={self.lastpos.x+0.5, self.lastpos.y, self.lastpos.z} - --~ if minetest.get_node(check_pos).name ~= "air" then - --~ minetest.add_node(self.lastpos, {name="default:torch", param2 = wall}) - --~ self.object:remove() - --~ end - --~ elseif wall == 3 then - --~ local check_pos={self.lastpos.x-0.5, self.lastpos.y, self.lastpos.z} - --~ if minetest.get_node(check_pos).name ~= "air" then - --~ minetest.add_node(self.lastpos, {name="default:torch", param2 = wall}) - --~ self.object:remove() - --~ end - --~ elseif wall == 4 then - --~ local check_pos={self.lastpos.x, self.lastpos.y, self.lastpos.z+0.5} - --~ if minetest.get_node(check_pos).name ~= "air" then - --~ minetest.add_node(self.lastpos, {name="default:torch", param2 = wall}) - --~ self.object:remove() - --~ end - --~ elseif wall == 5 then - --~ local check_pos={self.lastpos.x, self.lastpos.y, self.lastpos.z-0.5} - --~ if minetest.get_node(check_pos).name ~= "air" then - --~ minetest.add_node(self.lastpos, {name="default:torch", param2 = wall}) - --~ self.object:remove() - --~ end - --~ end else local toughness = 0.9 - if self.breaks < toughness then + if math.random() < toughness then minetest.add_item(self.lastpos, 'throwing:arrow_torch') else minetest.add_item(self.lastpos, 'default:stick')