1
0
mirror of https://gitlab.com/echoes91/spears.git synced 2025-06-29 22:20:24 +02:00

9 Commits
v1.1 ... 2.0

Author SHA1 Message Date
b5ce10d157 Version 2.0 2020-04-25 17:04:01 +02:00
7d2ae76dcb Refinements 2020-04-20 23:50:20 +02:00
6966f7f8b6 New textures 2020-04-20 23:50:00 +02:00
07a5f951c0 Refinements and new textures 2020-04-19 22:06:25 +02:00
fc1fd99541 Refinements and new textures 2020-04-19 21:53:10 +02:00
119116b89e Sticking great into nodes 2020-04-19 18:50:54 +02:00
bb6c36d7e5 Merge branch 'master' of https://gitlab.com/echoes91/spears 2020-04-19 12:05:14 +02:00
cdc548ecd5 Moving towards 2.0 2020-04-19 11:55:40 +02:00
7f9973400e Update 1.1 2020-04-18 13:41:26 +00:00
14 changed files with 163 additions and 73 deletions

View File

@ -1,12 +1,47 @@
=== SPEARS for MINETEST === === SPEARS for MINETEST by Echoes91 ===
This mod adds spears to Minetest. It aims at improving the ones introduced within throwing enhanced. This mod adds spears to Minetest.
How to download:
If you have this file, you already know
Forum topic:
https://forum.minetest.net/viewtopic.php?f=11&t=13367
How to install: How to install:
http://wiki.minetest.com/wiki/Installing_Mods http://wiki.minetest.com/wiki/Installing_Mods
How to use the mod: How to use the mod:
Spear work similarly to other tools such as swords, even if being a little slower. Moreover, a spear can be thrown using the drop key ('Q') or placed on a node using the place key ('right click'); they have also limited digging capabilities. Craft a spear with | stick | stick | (material) |, works also mirrored.
Spears can be thrown using right mouse button, they either hurt someone or stick where they land on; damage depends on speed and material, flight trajectory is ballistic with (unrealistic) drag.
Spears can be used to fight, but are slower and weaker than swords.
Spears can be used to dig, but are slower and weaker and pickaxes.
If you miss the target it's your fault, the spear is fine.
You can grab a spear on the fly (or maybe wait until it falls?).
You can stick a spear into a block, but if you remove the block then the spear falls (obviously).
This mod contains the word "spear" more than 100 times, if you want the exact number count them yourself.
If you feel clever, throw a spear right above you and look at it to see what happens.
You can even throw a spear from above down to your foes, it's even easier to hit.
Someone once reported to have hit its own foot but it takes practice to do that.
CHANGELOG
2.0:
- Cleaner, streamlined code without deprecated functions
- Spears hurt players
- Spears animated in flight
- Spears stick into nodes
- New textures
- New sound when hitting flesh
- New receipt to fit with default tools
- Drag depends on fluid
- Improved instructions
- New gold-plated spear to celebrate
1.1:
- Make use of new on_secondary_use API, requires Minetest 5.2.0
License: License:
Sourcecode: LGPLv2.1 (see http://www.gnu.org/licenses/lgpl-2.1.html) Sourcecode: LGPLv2.1 (see http://www.gnu.org/licenses/lgpl-2.1.html)

View File

@ -1,77 +1,119 @@
function spears_shot (itemstack, player) function spears_throw (itemstack, player, pointed_thing)
local spear = itemstack:get_name() .. '_entity' local spear = itemstack:get_name() .. '_entity'
local playerpos = player:getpos() local player_pos = player:get_pos()
local obj = minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, spear) local head_pos = vector.new(player_pos.x, player_pos.y + player:get_properties().eye_height, player_pos.z)
local dir = player:get_look_dir() local direction = player:get_look_dir()
local sp = 16 local throw_pos = vector.add(head_pos, vector.multiply(direction,0.5))
local dr = .3 local pitch = player:get_look_vertical()
local gravity = 9.8 local yaw = player:get_look_horizontal()
obj:setvelocity({x=dir.x*sp, y=dir.y*sp, z=dir.z*sp}) local rotation = vector.new(0, yaw + math.pi/2, pitch + math.pi/6)
obj:setacceleration({x=-dir.x*dr, y=-gravity, z=-dir.z*dr}) -- Plant into node
obj:setyaw(player:get_look_yaw()+math.pi) if pointed_thing.type == "node" then
minetest.sound_play("spears_sound", {pos=playerpos}) local node = minetest.get_node(pointed_thing.under)
obj:get_luaentity().wear = itemstack:get_wear() if minetest.registered_nodes[node.name].walkable and vector.distance(pointed_thing.above, throw_pos) < 1 then
local spear_object = minetest.add_entity(vector.divide(vector.add(pointed_thing.above, pointed_thing.under), 2), spear)
spear_object:set_rotation(rotation)
minetest.sound_play("default_place_node", {pos = throw_pos}, true)
spear_object:get_luaentity()._wear = itemstack:get_wear()
spear_object:get_luaentity()._stickpos = pointed_thing.under
return
end
end
-- Avoid hitting yourself and throw
local throw_speed = 12
while vector.distance(player_pos, throw_pos) < 1 do
throw_pos = vector.add(throw_pos, vector.multiply(direction,0.1))
end
local spear_object = minetest.add_entity(throw_pos, spear)
spear_object:set_velocity(vector.multiply(direction, throw_speed))
spear_object:set_rotation(rotation)
minetest.sound_play("spears_throw", {pos = player_pos}, true)
spear_object:get_luaentity()._wear = itemstack:get_wear()
spear_object:get_luaentity()._stickpos = nil
return true return true
end end
function spears_set_entity(spear_type, base_damage, toughness) function spears_set_entity(spear_type, base_damage, toughness)
local SPEAR_ENTITY={ local SPEAR_ENTITY={
initial_properties = {
physical = false, physical = false,
timer=0, visual = "item",
visual = "wielditem", visual_size = {x = 0.3, y = 0.3, z = 0.3},
visual_size = {x=0.15, y=0.1}, wield_item = "spears:spear_" .. spear_type,
textures = {"spears:spear_" .. spear_type}, collisionbox = {-0.3, -0.3, -0.3, 0.3, 0.3, 0.3},
lastpos={}, },
collisionbox = {0,0,0,0,0,0},
on_activate = function (self, staticdata, dtime_s)
self.object:set_armor_groups({immortal = 1})
end,
on_punch = function (self, puncher) on_punch = function (self, puncher)
if puncher then if puncher:is_player() then -- Grab the spear
if puncher:is_player() then local stack = {name='spears:spear_' .. spear_type, wear = self._wear}
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)
self.object:remove() self.object:remove()
end end
end end
end
end, end,
}
SPEAR_ENTITY.on_step = function(self, dtime) on_step = function(self, dtime)
self.timer=self.timer+dtime if not self._wear then
local pos = self.object:getpos()
local node = minetest.get_node(pos)
if not self.wear then
self.object:remove() self.object:remove()
return return
end end
if self.lastpos.x~=nil then local velocity = self.object:get_velocity()
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 local speed = vector.length(velocity)
-- Spear is stuck ?
if self._stickpos then
local node = minetest.get_node(self._stickpos)
if not node or not minetest.registered_nodes[node.name].walkable then -- Fall when node is removed
self.object:remove() self.object:remove()
if self.wear+65535/toughness < 65535 then minetest.add_item(self.object:get_pos(), {name='spears:spear_' .. spear_type, wear = self._wear})
minetest.add_item(self.lastpos, {name='spears:spear_' .. spear_type, wear=self.wear+65535/toughness}) return
end end
elseif self.timer>0.2 then else -- Spear is flying
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1) local direction = vector.normalize(velocity)
for k, obj in pairs(objs) do local yaw = minetest.dir_to_yaw(velocity)
if obj:get_luaentity() ~= nil then local pitch = math.acos(velocity.y/speed) - math.pi/3
if obj:get_luaentity().name ~= "spears:spear_" .. spear_type .. "_entity" and obj:get_luaentity().name ~= "_builtin:item" then local pos = vector.add(self.object:get_pos(), vector.multiply(velocity, dtime))
local speed = vector.length(self.object:getvelocity()) local node = minetest.get_node(pos)
local damage = (speed + base_damage)^1.12-20 self.object:set_rotation({x = 0, y = yaw + math.pi/2, z = pitch})
obj:punch(self.object, 1.0, { -- Hit someone?
full_punch_interval=1.0, local objects_in_radius = minetest.get_objects_inside_radius(pos, 0.5)
damage_groups={fleshy=damage}, for _,object in ipairs(objects_in_radius) do
}, nil) if object:get_luaentity() ~= self and object:get_armor_groups().fleshy then
local damage = (speed + base_damage)^1.15 - 20
object:punch(self.object, 1.0, {full_punch_interval = 1.0, damage_groups = {fleshy=damage},}, direction)
self.object:remove() self.object:remove()
if self.wear+65535/toughness < 65535 then minetest.sound_play("spears_hit", {pos = pos}, true)
minetest.add_item(self.lastpos, {name='spears:spear_' .. spear_type, wear=self.wear+65535/toughness}) minetest.add_item(pos, {name='spears:spear_' .. spear_type, wear = self._wear + 65535/toughness})
return
end
end
-- Hit a node?
if node then
if minetest.registered_nodes[node.name].walkable then -- Stick
self.object:set_acceleration({x = 0, y = 0, z = 0})
self.object:set_velocity({x = 0, y = 0, z = 0})
minetest.sound_play("default_place_node", {pos = pos}, true)
self._wear = self._wear + 65535/toughness
if self._wear >= 65535 then
minetest.sound_play("default_tool_breaks", {pos = pos}, true)
self.object:remove()
return
end
self._stickpos = pos
else -- Get drag
local drag = math.max(minetest.registered_nodes[node.name].liquid_viscosity, 0.1)
local acceleration = vector.multiply(velocity, -drag)
acceleration.y = acceleration.y - 10 * ((7 - drag) / 7)
self.object:set_acceleration(acceleration)
end end
end end
end end
end end,
end }
end
self.lastpos={x=pos.x, y=pos.y, z=pos.z}
end
return SPEAR_ENTITY return SPEAR_ENTITY
end end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 293 KiB

BIN
sounds/spears_hit.ogg Normal file

Binary file not shown.

Binary file not shown.

BIN
sounds/spears_throw.ogg Normal file

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 247 B

After

Width:  |  Height:  |  Size: 234 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 256 B

After

Width:  |  Height:  |  Size: 247 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 272 B

After

Width:  |  Height:  |  Size: 202 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 276 B

After

Width:  |  Height:  |  Size: 193 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 273 B

After

Width:  |  Height:  |  Size: 200 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 277 B

After

Width:  |  Height:  |  Size: 226 B

View File

@ -2,11 +2,18 @@ function spears_register_spear(spear_type, desc, base_damage, toughness, materia
minetest.register_tool("spears:spear_" .. spear_type, { minetest.register_tool("spears:spear_" .. spear_type, {
description = desc .. " spear", description = desc .. " spear",
wield_image = "spears_spear_" .. spear_type .. ".png", wield_image = "spears_spear_" .. spear_type .. ".png^[transform4",
inventory_image = "spears_spear_" .. spear_type .. ".png^[transform4", inventory_image = "spears_spear_" .. spear_type .. ".png",
wield_scale= {x=2,y=1,z=1}, wield_scale= {x = 1.5, y = 1.5, z = 1.5},
on_secondary_use = function(itemstack, user, pointed_thing) on_secondary_use = function(itemstack, user, pointed_thing)
spears_shot(itemstack, user) spears_throw(itemstack, user, pointed_thing)
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
end
return itemstack
end,
on_place = function(itemstack, user, pointed_thing)
spears_throw(itemstack, user, pointed_thing)
if not minetest.setting_getbool("creative_mode") then if not minetest.setting_getbool("creative_mode") then
itemstack:take_item() itemstack:take_item()
end end
@ -19,7 +26,9 @@ function spears_register_spear(spear_type, desc, base_damage, toughness, materia
cracky = {times={[3]=2}, uses=toughness, maxlevel=1}, cracky = {times={[3]=2}, uses=toughness, maxlevel=1},
}, },
damage_groups = {fleshy=base_damage}, damage_groups = {fleshy=base_damage},
} },
sound = {breaks = "default_tool_breaks"},
groups = {flammable = 1}
}) })
local SPEAR_ENTITY = spears_set_entity(spear_type, base_damage, toughness) local SPEAR_ENTITY = spears_set_entity(spear_type, base_damage, toughness)
@ -29,14 +38,14 @@ function spears_register_spear(spear_type, desc, base_damage, toughness, materia
minetest.register_craft({ minetest.register_craft({
output = 'spears:spear_' .. spear_type, output = 'spears:spear_' .. spear_type,
recipe = { recipe = {
{'group:wood', 'group:wood', material}, {'group:stick', 'group:stick', material},
} }
}) })
minetest.register_craft({ minetest.register_craft({
output = 'spears:spear_' .. spear_type, output = 'spears:spear_' .. spear_type,
recipe = { recipe = {
{material, 'group:wood', 'group:wood'}, {material, 'group:stick', 'group:stick'},
} }
}) })
end end
@ -64,3 +73,7 @@ end
if not DISABLE_DIAMOND_SPEAR then if not DISABLE_DIAMOND_SPEAR then
spears_register_spear('diamond', 'Diamond', 8, 40, 'default:diamond') spears_register_spear('diamond', 'Diamond', 8, 40, 'default:diamond')
end end
if not DISABLE_GOLD_SPEAR then
spears_register_spear('gold', 'Golden', 5, 40, 'default:gold_ingot')
end