Moving towards 2.0

This commit is contained in:
echoes91 2020-04-19 11:55:40 +02:00
parent 3c174db494
commit cdc548ecd5
5 changed files with 78 additions and 61 deletions

View File

@ -1,13 +1,16 @@
=== 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 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) |, 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 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.
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)
Grahpics & sounds: CC-BY 3.0 (see http://creativecommons.org/licenses/by/3.0/legalcode) Grahpics & sounds: CC-BY 3.0 (see http://creativecommons.org/licenses/by/3.0/legalcode)

View File

@ -1,77 +1,82 @@
function spears_shot (itemstack, player) function spears_shot (itemstack, player)
local spear = itemstack:get_name() .. '_entity' local spear = itemstack:get_name() .. '_entity'
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 spear_object = minetest.add_entity({x=playerpos.x,y=playerpos.y+1.5,z=playerpos.z}, spear)
local dir = player:get_look_dir() local direction = player:get_look_dir()
local sp = 16 local pitch = player:get_look_vertical()
local dr = .3 local yaw = player:get_look_horizontal()
local throw_speed = 15
local drag = 0.3
local gravity = 9.8 local gravity = 9.8
obj:setvelocity({x=dir.x*sp, y=dir.y*sp, z=dir.z*sp}) spear_object:set_velocity({x = direction.x*throw_speed, y = direction.y*throw_speed, z = direction.z*throw_speed})
obj:setacceleration({x=-dir.x*dr, y=-gravity, z=-dir.z*dr}) spear_object:set_acceleration({x = -direction.x*drag, y = -gravity, z = -direction.z*drag})
obj:setyaw(player:get_look_yaw()+math.pi) spear_object:set_rotation({x = 0, y = yaw + math.pi/2, z = pitch + math.pi/6})
minetest.sound_play("spears_sound", {pos=playerpos}) minetest.sound_play("spears_throw", {pos = playerpos}, true)
obj:get_luaentity().wear = itemstack:get_wear() spear_object: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(spear_type, base_damage, toughness)
local SPEAR_ENTITY={ local SPEAR_ENTITY={
physical = false, initial_properties = {
timer=0, physical = false,
visual = "wielditem", visual = "item",
visual_size = {x=0.15, y=0.1}, visual_size = {x = 0.3, y = 0.3, z = 0.3},
textures = {"spears:spear_" .. spear_type}, wield_item = "spears:spear_" .. spear_type,
lastpos={}, collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
collisionbox = {0,0,0,0,0,0}, },
on_punch = function(self, puncher) on_punch = function(self, puncher)
if puncher then if puncher:is_player() then
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,
}
on_step = function(self, dtime)
SPEAR_ENTITY.on_step = function(self, dtime) if not self._wear then
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() self.object:remove()
if self.wear+65535/toughness < 65535 then return
minetest.add_item(self.lastpos, {name='spears:spear_' .. spear_type, wear=self.wear+65535/toughness}) end
end local acceleration = self.object:get_acceleration()
elseif self.timer>0.2 then local velocity = self.object:get_velocity()
local objs = minetest.get_objects_inside_radius({x=pos.x,y=pos.y,z=pos.z}, 1) local speed = vector.length(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 if speed > 0 then
obj:punch(self.object, 1.0, { if node.name ~= "air" and minetest.get_item_group(node.name, 'attached_node') < 1 then
full_punch_interval=1.0, self.object:set_acceleration({x = 0, y = 0, z = 0})
damage_groups={fleshy=damage}, self.object:set_velocity({x = 0, y = 0, z = 0})
}, nil) minetest.sound_play("default_place_node.2", {pos = pos}, true)
self._wear = self._wear + 65535/toughness
if self._wear >= 65535 then
self.object:remove()
return
end
else
self.object:set_rotation({x = 0, y = yaw + math.pi/2, z = pitch})
local objects_in_radius = minetest.get_objects_inside_radius(pos, 1)
for _,object in ipairs(objects_in_radius) do
if object:is_player() or (object:get_luaentity().name ~= self.name and object:get_luaentity().name ~= "_builtin:item") then
local direction = vector.normalize(velocity)
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}) if self._wear + 65535/toughness < 65535 then
minetest.add_item(pos, {name='spears:spear_' .. spear_type, wear = self._wear + 65535/toughness})
end end
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

BIN
sounds/spears_hit.ogg Normal file

Binary file not shown.

View File

@ -12,6 +12,13 @@ function spears_register_spear(spear_type, desc, base_damage, toughness, materia
end end
return itemstack return itemstack
end, end,
on_place = function(itemstack, user, pointed_thing)
spears_shot(itemstack, user)
if not minetest.setting_getbool("creative_mode") then
itemstack:take_item()
end
return itemstack
end,
tool_capabilities = { tool_capabilities = {
full_punch_interval = 1.5, full_punch_interval = 1.5,
max_drop_level=1, max_drop_level=1,
@ -19,10 +26,12 @@ 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)
minetest.register_entity("spears:spear_" .. spear_type .. "_entity", SPEAR_ENTITY) minetest.register_entity("spears:spear_" .. spear_type .. "_entity", SPEAR_ENTITY)