diff --git a/README.txt b/README.txt old mode 100644 new mode 100755 diff --git a/defaults.lua b/defaults.lua old mode 100644 new mode 100755 index fbee808..54a4e96 --- a/defaults.lua +++ b/defaults.lua @@ -2,3 +2,4 @@ DISABLE_STONE_SPEAR = false DISABLE_STEEL_SPEAR = false DISABLE_DIAMOND_SPEAR = false DISABLE_OBSIDIAN_SPEAR = false +DISABLE_MITHRIL_SPEAR = false diff --git a/depends.txt b/depends.txt old mode 100644 new mode 100755 diff --git a/functions.lua b/functions.lua old mode 100644 new mode 100755 index 04f5d60..b8a1387 --- a/functions.lua +++ b/functions.lua @@ -9,20 +9,25 @@ function spears_shot (itemstack, player) obj:setvelocity({x=dir.x*sp, y=dir.y*sp, z=dir.z*sp}) obj:setacceleration({x=-dir.x*dr, y=-gravity, z=-dir.z*dr}) obj:setyaw(player:get_look_yaw()+math.pi) - minetest.sound_play("spears_sound", {pos=playerpos}) obj:get_luaentity().wear = itemstack:get_wear() + obj:get_luaentity().player = player:get_player_name() + obj:get_luaentity().lastpos = {x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z} + minetest.sound_play("spears_sound", {pos=playerpos}) return true end + function spears_set_entity(kind, eq, toughness) local SPEAR_ENTITY={ physical = false, - timer=0, visual = "wielditem", visual_size = {x=0.15, y=0.1}, textures = {"spears:spear_" .. kind}, lastpos={}, collisionbox = {0,0,0,0,0,0}, + player = "", + wear = 0, + on_punch = function(self, puncher) if puncher then if puncher:is_player() then @@ -36,42 +41,111 @@ function spears_set_entity(kind, eq, toughness) end end, } - + + SPEAR_ENTITY.on_step = function(self, dtime) - self.timer=self.timer+dtime local pos = self.object:getpos() local node = minetest.get_node(pos) if not self.wear then self.object:remove() return end - if self.lastpos.x~=nil then - if node.name ~= "air" and not (string.find(node.name, 'grass') and not string.find(node.name, 'dirt')) and not string.find(node.name, 'flowers:') and not string.find(node.name, 'farming:') then - self.object:remove() - if self.wear+65535/toughness < 65535 then - minetest.add_item(self.lastpos, {name='spears:spear_' .. kind, wear=self.wear+65535/toughness}) + local newpos = self.object:getpos() + if self.lastpos.x ~= nil then + for _, pos in pairs(spears_get_trajectoire(self, newpos)) do + local node = minetest.get_node(pos) + + if node.name ~= "air" + and not string.find(node.name, 'water_') + and not (string.find(node.name, 'grass') and not string.find(node.name, 'dirt')) + and not (string.find(node.name, 'farming:') and not string.find(node.name, 'soil')) + and not string.find(node.name, 'flowers:') + and not string.find(node.name, 'fire:') then + if self.wear+65535/toughness < 65535 then + local spear_item = minetest.add_item(self.lastpos, {name='spears:spear_' .. kind, wear=self.wear+65535/toughness}) + if spear_item then + spear_item:get_luaentity().item_drop_min_tstamp = minetest.get_us_time() + 3000000 + end + end + self.object:remove() + return end - elseif self.timer>0.2 then - local objs = minetest.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}, 2) for k, obj in pairs(objs) do - if obj:get_luaentity() ~= nil then - if obj:get_luaentity().name ~= "spears:spear_" .. kind .. "_entity" and obj:get_luaentity().name ~= "__builtin:item" then - local speed = vector.length(self.object:getvelocity()) - local damage = (speed + eq)^1.12-20 - obj:punch(self.object, 1.0, { + local objpos = obj:getpos() + if spears_is_player(self.player, obj) or spears_is_entity(obj) then + if spears_touch(pos, objpos) then + local puncher = self.object + if self.player and minetest.get_player_by_name(self.player) then + puncher = minetest.get_player_by_name(self.player) + end + --local speed = vector.length(self.object:getvelocity()) --MFF crabman(28/09/2015) damage valeur equal eq + local damage = eq --((speed + eq +5)^1.2)/10 --MFF crabman(28/09/2015) damage valeur equal eq + obj:punch(puncher, 1.0, { full_punch_interval=1.0, damage_groups={fleshy=damage}, }, nil) - self.object:remove() if self.wear+65535/toughness < 65535 then - minetest.add_item(self.lastpos, {name='spears:spear_' .. kind, wear=self.wear+65535/toughness}) + local spear_item = minetest.add_item(self.lastpos, {name='spears:spear_' .. kind, wear=self.wear+65535/toughness}) + if spear_item then + spear_item:get_luaentity().item_drop_min_tstamp = minetest.get_us_time() + 3000000 + end end + self.object:remove() + return end end end + + self.lastpos={x=pos.x, y=pos.y, z=pos.z} end end - self.lastpos={x=pos.x, y=pos.y, z=pos.z} + + self.lastpos={x=newpos.x, y=newpos.y, z=newpos.z} end return SPEAR_ENTITY end + + +function spears_is_player(name, obj) + return (obj:is_player() and obj:get_player_name() ~= name) +end + +function spears_is_entity(obj) + return (obj:get_luaentity() ~= nil + and not string.find(obj:get_luaentity().name, "spears:") + and obj:get_luaentity().name ~= "__builtin:item" + and obj:get_luaentity().name ~= "gauges:hp_bar" + and obj:get_luaentity().name ~= "signs:text") +end + + + +function spears_get_trajectoire(self, newpos) + if self.lastpos.x == nil then + return {newpos} + end + local coord = {} + local nx = (newpos["x"] - self.lastpos["x"])/3 + local ny = (newpos["y"] - self.lastpos["y"])/3 + local nz = (newpos["z"] - self.lastpos["z"])/3 + + if nx and ny and nz then + table.insert(coord, {x=self.lastpos["x"]+nx, y=self.lastpos["y"]+ny ,z=self.lastpos["z"]+nz }) + table.insert(coord, {x=newpos["x"]-nx, y=newpos["y"]-ny ,z=newpos["z"]-nz }) + end + table.insert(coord, newpos) + return coord +end + +function spears_touch(pos, objpos) + local rx = pos.x - objpos.x + local ry = pos.y - (objpos.y+1) + local rz = pos.z - objpos.z + if (ry < 1 and ry > -1) and (rx < 0.4 and rx > -0.4) and (rz < 0.4 and rz > -0.4) then + return true + end + return false +end + diff --git a/init.lua b/init.lua old mode 100644 new mode 100755 index 3a45772..842d919 --- a/init.lua +++ b/init.lua @@ -15,3 +15,11 @@ dofile(minetest.get_modpath("spears").."/tools.lua") if minetest.setting_get("log_mods") then minetest.log("action", "spears loaded") end + +--alias +minetest.register_alias("throwing:spear_stone", "spears:spear_stone") +minetest.register_alias("throwing:spear_steel", "spears:spear_steel") +minetest.register_alias("throwing:spear_diamond", "spears:spear_diamond") +minetest.register_alias("throwing:spear_obsidian", "spears:spear_obsidian") +minetest.register_alias("throwing:spear_mithril", "spears:spear_mithril") + diff --git a/screenshot.png b/screenshot.png deleted file mode 100644 index 225b1aa..0000000 Binary files a/screenshot.png and /dev/null differ diff --git a/sounds/spears_sound.ogg b/sounds/spears_sound.ogg old mode 100644 new mode 100755 index 411598c..ebebd61 Binary files a/sounds/spears_sound.ogg and b/sounds/spears_sound.ogg differ diff --git a/textures/spears_spear_diamond.png b/textures/spears_spear_diamond.png index 7a852b9..b582f2e 100644 Binary files a/textures/spears_spear_diamond.png and b/textures/spears_spear_diamond.png differ diff --git a/textures/spears_spear_mithril.png b/textures/spears_spear_mithril.png new file mode 100644 index 0000000..3794960 Binary files /dev/null and b/textures/spears_spear_mithril.png differ diff --git a/textures/spears_spear_obsidian.png b/textures/spears_spear_obsidian.png index 6ec0ab4..164104e 100644 Binary files a/textures/spears_spear_obsidian.png and b/textures/spears_spear_obsidian.png differ diff --git a/textures/spears_spear_steel.png b/textures/spears_spear_steel.png index 1fa930c..2133d4d 100644 Binary files a/textures/spears_spear_steel.png and b/textures/spears_spear_steel.png differ diff --git a/textures/spears_spear_stone.png b/textures/spears_spear_stone.png index fead8b3..65f8dc3 100644 Binary files a/textures/spears_spear_stone.png and b/textures/spears_spear_stone.png differ diff --git a/tools.lua b/tools.lua old mode 100644 new mode 100755 index 044fe22..12a870f --- a/tools.lua +++ b/tools.lua @@ -11,13 +11,6 @@ function spears_register_spear(kind, desc, eq, toughness, material) end return itemstack end, - on_place = function(itemstack, user, pointed_thing) - minetest.add_item(pointed_thing.above, itemstack) - if not minetest.setting_getbool("creative_mode") then - itemstack:take_item() - end - return itemstack - end, tool_capabilities = { full_punch_interval = 1.5, max_drop_level=1, @@ -27,18 +20,19 @@ function spears_register_spear(kind, desc, eq, toughness, material) damage_groups = {fleshy=eq}, } }) - - SPEAR_ENTITY=spears_set_entity(kind, eq, toughness) - + + + local SPEAR_ENTITY=spears_set_entity(kind, eq, toughness) + minetest.register_entity("spears:spear_" .. kind .. "_entity", SPEAR_ENTITY) - + minetest.register_craft({ output = 'spears:spear_' .. kind, recipe = { {'group:wood', 'group:wood', material}, } }) - + minetest.register_craft({ output = 'spears:spear_' .. kind, recipe = { @@ -48,17 +42,22 @@ function spears_register_spear(kind, desc, eq, toughness, material) end if not DISABLE_STONE_SPEAR then - spears_register_spear('stone', 'Stone', 4, 20, 'group:stone') + spears_register_spear('stone', 'Stone (Hunter)', 3, 25, 'group:stone') --MFF crabman(28/09/2015) damage and wear end if not DISABLE_STEEL_SPEAR then - spears_register_spear('steel', 'Steel', 6, 30, 'default:steel_ingot') -end - -if not DISABLE_OBSIDIAN_SPEAR then - spears_register_spear('obsidian', 'Obsidian', 8, 30, 'default:obsidian') + spears_register_spear('steel', 'Steel (Hunter)', 4, 30, 'default:steel_ingot') --MFF crabman(28/09/2015) damage and wear end if not DISABLE_DIAMOND_SPEAR then - spears_register_spear('diamond', 'Diamond', 8, 40, 'default:diamond') + spears_register_spear('diamond', 'Diamond (Hunter)', 7, 50, 'default:diamond') --MFF crabman(28/09/2015) damage and wear end + +if not DISABLE_OBSIDIAN_SPEAR then + spears_register_spear('obsidian', 'Obsidian (Hunter)', 5, 40, 'default:obsidian') --MFF crabman(28/09/2015) damage and wear +end + +if not DISABLE_MITHRIL_SPEAR then + spears_register_spear('mithril', 'Mithril (Hunter)', 8, 200, 'default:mithril_ingot') --MFF crabman(28/09/2015) damage and wear +end +