Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
3c174db494 | |||
00d86908d8 | |||
5a214d3b44 | |||
2c0ebde983 |
0
README.txt
Executable file → Normal file
3
defaults.lua
Executable file → Normal file
@ -1,5 +1,6 @@
|
|||||||
DISABLE_STONE_SPEAR = false
|
DISABLE_STONE_SPEAR = false
|
||||||
DISABLE_STEEL_SPEAR = false
|
DISABLE_STEEL_SPEAR = false
|
||||||
|
DISABLE_COPPER_SPEAR = false
|
||||||
|
DISABLE_BRONZE_SPEAR = false
|
||||||
DISABLE_DIAMOND_SPEAR = false
|
DISABLE_DIAMOND_SPEAR = false
|
||||||
DISABLE_OBSIDIAN_SPEAR = false
|
DISABLE_OBSIDIAN_SPEAR = false
|
||||||
DISABLE_MITHRIL_SPEAR = false
|
|
||||||
|
0
depends.txt
Executable file → Normal file
122
functions.lua
Executable file → Normal file
@ -3,35 +3,30 @@ function spears_shot (itemstack, player)
|
|||||||
local playerpos = player:getpos()
|
local playerpos = player:getpos()
|
||||||
local obj = minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, spear)
|
local obj = minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, spear)
|
||||||
local dir = player:get_look_dir()
|
local dir = player:get_look_dir()
|
||||||
local sp = 14
|
local sp = 16
|
||||||
local dr = .3
|
local dr = .3
|
||||||
local gravity = 9.8
|
local gravity = 9.8
|
||||||
obj:setvelocity({x=dir.x*sp, y=dir.y*sp, z=dir.z*sp})
|
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:setacceleration({x=-dir.x*dr, y=-gravity, z=-dir.z*dr})
|
||||||
obj:setyaw(player:get_look_yaw()+math.pi)
|
obj:setyaw(player:get_look_yaw()+math.pi)
|
||||||
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})
|
minetest.sound_play("spears_sound", {pos=playerpos})
|
||||||
|
obj:get_luaentity().wear = itemstack:get_wear()
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function spears_set_entity(spear_type, base_damage, toughness)
|
||||||
function spears_set_entity(kind, eq, toughness)
|
|
||||||
local SPEAR_ENTITY={
|
local SPEAR_ENTITY={
|
||||||
physical = false,
|
physical = false,
|
||||||
|
timer=0,
|
||||||
visual = "wielditem",
|
visual = "wielditem",
|
||||||
visual_size = {x=0.15, y=0.1},
|
visual_size = {x=0.15, y=0.1},
|
||||||
textures = {"spears:spear_" .. kind},
|
textures = {"spears:spear_" .. spear_type},
|
||||||
lastpos={},
|
lastpos={},
|
||||||
collisionbox = {0,0,0,0,0,0},
|
collisionbox = {0,0,0,0,0,0},
|
||||||
player = "",
|
|
||||||
wear = 0,
|
|
||||||
|
|
||||||
on_punch = function(self, puncher)
|
on_punch = function(self, puncher)
|
||||||
if puncher then
|
if puncher then
|
||||||
if puncher:is_player() then
|
if puncher:is_player() then
|
||||||
local stack = {name='spears:spear_' .. kind, wear=self.wear+65535/toughness}
|
local stack = {name='spears:spear_' .. spear_type, wear=self.wear+65535/toughness}
|
||||||
local inv = puncher:get_inventory()
|
local inv = puncher:get_inventory()
|
||||||
if inv:room_for_item("main", stack) then
|
if inv:room_for_item("main", stack) then
|
||||||
inv:add_item("main", stack)
|
inv:add_item("main", stack)
|
||||||
@ -41,111 +36,42 @@ function spears_set_entity(kind, eq, toughness)
|
|||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
SPEAR_ENTITY.on_step = function(self, dtime)
|
SPEAR_ENTITY.on_step = function(self, dtime)
|
||||||
|
self.timer=self.timer+dtime
|
||||||
local pos = self.object:getpos()
|
local pos = self.object:getpos()
|
||||||
local node = minetest.get_node(pos)
|
local node = minetest.get_node(pos)
|
||||||
if not self.wear then
|
if not self.wear then
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local newpos = self.object:getpos()
|
if self.lastpos.x~=nil then
|
||||||
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
|
||||||
for _, pos in pairs(spears_get_trajectoire(self, newpos)) do
|
self.object:remove()
|
||||||
local node = minetest.get_node(pos)
|
if self.wear+65535/toughness < 65535 then
|
||||||
|
minetest.add_item(self.lastpos, {name='spears:spear_' .. spear_type, wear=self.wear+65535/toughness})
|
||||||
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
|
end
|
||||||
|
elseif self.timer>0.2 then
|
||||||
local objs = minetest.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}, 1)
|
||||||
for k, obj in pairs(objs) do
|
for k, obj in pairs(objs) do
|
||||||
local objpos = obj:getpos()
|
if obj:get_luaentity() ~= nil then
|
||||||
if spears_is_player(self.player, obj) or spears_is_entity(obj) then
|
if obj:get_luaentity().name ~= "spears:spear_" .. spear_type .. "_entity" and obj:get_luaentity().name ~= "_builtin:item" then
|
||||||
if spears_touch(pos, objpos) then
|
local speed = vector.length(self.object:getvelocity())
|
||||||
local puncher = self.object
|
local damage = (speed + base_damage)^1.12-20
|
||||||
if self.player and minetest.get_player_by_name(self.player) then
|
obj:punch(self.object, 1.0, {
|
||||||
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,
|
full_punch_interval=1.0,
|
||||||
damage_groups={fleshy=damage},
|
damage_groups={fleshy=damage},
|
||||||
}, nil)
|
}, nil)
|
||||||
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()
|
self.object:remove()
|
||||||
return
|
if self.wear+65535/toughness < 65535 then
|
||||||
|
minetest.add_item(self.lastpos, {name='spears:spear_' .. spear_type, wear=self.wear+65535/toughness})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
|
|
||||||
end
|
end
|
||||||
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
|
end
|
||||||
return SPEAR_ENTITY
|
return SPEAR_ENTITY
|
||||||
end
|
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
|
|
||||||
|
|
||||||
|
8
init.lua
Executable file → Normal file
@ -15,11 +15,3 @@ dofile(minetest.get_modpath("spears").."/tools.lua")
|
|||||||
if minetest.setting_get("log_mods") then
|
if minetest.setting_get("log_mods") then
|
||||||
minetest.log("action", "spears loaded")
|
minetest.log("action", "spears loaded")
|
||||||
end
|
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")
|
|
||||||
|
|
||||||
|
BIN
screenshot.png
Normal file
After Width: | Height: | Size: 293 KiB |
BIN
sounds/spears_sound.ogg
Executable file → Normal file
6
spears.conf.example
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
DISABLE_STONE_SPEAR = true
|
||||||
|
DISABLE_STEEL_SPEAR = true
|
||||||
|
DISABLE_COPPER_SPEAR = true
|
||||||
|
DISABLE_BRONZE_SPEAR = true
|
||||||
|
DISABLE_DIAMOND_SPEAR = true
|
||||||
|
DISABLE_OBSIDIAN_SPEAR = true
|
BIN
textures/spears_spear_bronze.png
Normal file
After Width: | Height: | Size: 247 B |
BIN
textures/spears_spear_copper.png
Normal file
After Width: | Height: | Size: 256 B |
Before Width: | Height: | Size: 197 B After Width: | Height: | Size: 272 B |
Before Width: | Height: | Size: 185 B |
Before Width: | Height: | Size: 167 B After Width: | Height: | Size: 276 B |
Before Width: | Height: | Size: 192 B After Width: | Height: | Size: 273 B |
Before Width: | Height: | Size: 192 B After Width: | Height: | Size: 277 B |
47
tools.lua
Executable file → Normal file
@ -1,10 +1,11 @@
|
|||||||
function spears_register_spear(kind, desc, eq, toughness, material)
|
function spears_register_spear(spear_type, desc, base_damage, toughness, material)
|
||||||
|
|
||||||
minetest.register_tool("spears:spear_" .. kind, {
|
minetest.register_tool("spears:spear_" .. spear_type, {
|
||||||
description = desc .. " spear",
|
description = desc .. " spear",
|
||||||
inventory_image = "spears_spear_" .. kind .. ".png",
|
wield_image = "spears_spear_" .. spear_type .. ".png",
|
||||||
|
inventory_image = "spears_spear_" .. spear_type .. ".png^[transform4",
|
||||||
wield_scale= {x=2,y=1,z=1},
|
wield_scale= {x=2,y=1,z=1},
|
||||||
on_drop = function(itemstack, user, pointed_thing)
|
on_secondary_use = function(itemstack, user, pointed_thing)
|
||||||
spears_shot(itemstack, user)
|
spears_shot(itemstack, user)
|
||||||
if not minetest.setting_getbool("creative_mode") then
|
if not minetest.setting_getbool("creative_mode") then
|
||||||
itemstack:take_item()
|
itemstack:take_item()
|
||||||
@ -17,24 +18,23 @@ function spears_register_spear(kind, desc, eq, toughness, material)
|
|||||||
groupcaps={
|
groupcaps={
|
||||||
cracky = {times={[3]=2}, uses=toughness, maxlevel=1},
|
cracky = {times={[3]=2}, uses=toughness, maxlevel=1},
|
||||||
},
|
},
|
||||||
damage_groups = {fleshy=eq},
|
damage_groups = {fleshy=base_damage},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
local SPEAR_ENTITY=spears_set_entity(spear_type, base_damage, toughness)
|
||||||
local SPEAR_ENTITY=spears_set_entity(kind, eq, toughness)
|
|
||||||
|
minetest.register_entity("spears:spear_" .. spear_type .. "_entity", SPEAR_ENTITY)
|
||||||
minetest.register_entity("spears:spear_" .. kind .. "_entity", SPEAR_ENTITY)
|
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = 'spears:spear_' .. kind,
|
output = 'spears:spear_' .. spear_type,
|
||||||
recipe = {
|
recipe = {
|
||||||
{'group:wood', 'group:wood', material},
|
{'group:wood', 'group:wood', material},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = 'spears:spear_' .. kind,
|
output = 'spears:spear_' .. spear_type,
|
||||||
recipe = {
|
recipe = {
|
||||||
{material, 'group:wood', 'group:wood'},
|
{material, 'group:wood', 'group:wood'},
|
||||||
}
|
}
|
||||||
@ -42,22 +42,25 @@ function spears_register_spear(kind, desc, eq, toughness, material)
|
|||||||
end
|
end
|
||||||
|
|
||||||
if not DISABLE_STONE_SPEAR then
|
if not DISABLE_STONE_SPEAR then
|
||||||
spears_register_spear('stone', 'Stone (Hunter)', 3, 25, 'group:stone') --MFF crabman(28/09/2015) damage and wear
|
spears_register_spear('stone', 'Stone', 4, 20, 'group:stone')
|
||||||
end
|
end
|
||||||
|
|
||||||
if not DISABLE_STEEL_SPEAR then
|
if not DISABLE_STEEL_SPEAR then
|
||||||
spears_register_spear('steel', 'Steel (Hunter)', 4, 30, 'default:steel_ingot') --MFF crabman(28/09/2015) damage and wear
|
spears_register_spear('steel', 'Steel', 6, 30, 'default:steel_ingot')
|
||||||
end
|
end
|
||||||
|
|
||||||
if not DISABLE_DIAMOND_SPEAR then
|
if not DISABLE_COPPER_SPEAR then
|
||||||
spears_register_spear('diamond', 'Diamond (Hunter)', 7, 50, 'default:diamond') --MFF crabman(28/09/2015) damage and wear
|
spears_register_spear('copper', 'Copper', 5, 35, 'default:copper_ingot')
|
||||||
|
end
|
||||||
|
|
||||||
|
if not DISABLE_BRONZE_SPEAR then
|
||||||
|
spears_register_spear('bronze', 'Bronze', 6, 35, 'default:bronze_ingot')
|
||||||
end
|
end
|
||||||
|
|
||||||
if not DISABLE_OBSIDIAN_SPEAR then
|
if not DISABLE_OBSIDIAN_SPEAR then
|
||||||
spears_register_spear('obsidian', 'Obsidian (Hunter)', 5, 40, 'default:obsidian') --MFF crabman(28/09/2015) damage and wear
|
spears_register_spear('obsidian', 'Obsidian', 8, 30, 'default:obsidian')
|
||||||
end
|
end
|
||||||
|
|
||||||
if not DISABLE_MITHRIL_SPEAR then
|
if not DISABLE_DIAMOND_SPEAR then
|
||||||
spears_register_spear('mithril', 'Mithril (Hunter)', 8, 200, 'default:mithril_ingot') --MFF crabman(28/09/2015) damage and wear
|
spears_register_spear('diamond', 'Diamond', 8, 40, 'default:diamond')
|
||||||
end
|
end
|
||||||
|
|
||||||
|