mirror of
https://gitlab.com/echoes91/spears.git
synced 2025-01-22 05:30:22 +01:00
Refinements
This commit is contained in:
parent
6966f7f8b6
commit
7d2ae76dcb
24
README.txt
24
README.txt
@ -2,30 +2,38 @@
|
|||||||
|
|
||||||
This mod adds spears to Minetest.
|
This mod adds spears to Minetest.
|
||||||
|
|
||||||
|
How to download:
|
||||||
|
If you have this file, you already know
|
||||||
|
|
||||||
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:
|
||||||
Craft a spear with | stick | stick | (material) |, also mirrored.
|
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 drag.
|
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 fight, but are slower and weaker than swords.
|
||||||
Spears can be used to dig, but are slower and weaker and pickaxes.
|
Spears can be used to dig, but are slower and weaker and pickaxes.
|
||||||
You can grab a spear on the fly (or maybe wait until it falls).
|
If you miss the target it's your fault, the spear is fine.
|
||||||
If you feel even clever, throw a spear right above you and look at it to see what happens.
|
You can grab a spear on the fly (or maybe wait until it falls?).
|
||||||
Someone once reported to have hit its own foot but it takes practice.
|
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
|
CHANGELOG
|
||||||
|
|
||||||
2.0:
|
2.0:
|
||||||
- Cleaned, streamlined code without deprecated functions
|
- Cleaner, streamlined code without deprecated functions
|
||||||
- Spears hurt players
|
- Spears hurt players
|
||||||
- Spears animated in flight
|
- Spears animated in flight
|
||||||
- Spears stick into nodes
|
- Spears stick into nodes
|
||||||
- New sound when hitting flesh
|
|
||||||
- Changed receipt to fit with default tools
|
|
||||||
- New textures
|
- New textures
|
||||||
|
- New sound when hitting flesh
|
||||||
|
- New receipt to fit with default tools
|
||||||
- Drag depends on fluid
|
- Drag depends on fluid
|
||||||
|
- Improved instructions
|
||||||
- New gold-plated spear to celebrate
|
- New gold-plated spear to celebrate
|
||||||
|
|
||||||
1.1:
|
1.1:
|
||||||
|
@ -6,13 +6,12 @@ function spears_throw (itemstack, player, pointed_thing)
|
|||||||
local throw_pos = vector.add(head_pos, vector.multiply(direction,0.5))
|
local throw_pos = vector.add(head_pos, vector.multiply(direction,0.5))
|
||||||
local pitch = player:get_look_vertical()
|
local pitch = player:get_look_vertical()
|
||||||
local yaw = player:get_look_horizontal()
|
local yaw = player:get_look_horizontal()
|
||||||
local throw_speed = 15
|
|
||||||
local rotation = vector.new(0, yaw + math.pi/2, pitch + math.pi/6)
|
local rotation = vector.new(0, yaw + math.pi/2, pitch + math.pi/6)
|
||||||
-- Stick into node
|
-- Plant into node
|
||||||
if pointed_thing.type == "node" then
|
if pointed_thing.type == "node" then
|
||||||
local node = minetest.get_node(pointed_thing.under)
|
local node = minetest.get_node(pointed_thing.under)
|
||||||
if minetest.registered_nodes[node.name].walkable and vector.distance(pointed_thing.above, throw_pos) < 1 then
|
if minetest.registered_nodes[node.name].walkable and vector.distance(pointed_thing.above, throw_pos) < 1 then
|
||||||
local spear_object = minetest.add_entity(vector.add(throw_pos, vector.multiply(direction,0.5)), spear)
|
local spear_object = minetest.add_entity(vector.divide(vector.add(pointed_thing.above, pointed_thing.under), 2), spear)
|
||||||
spear_object:set_rotation(rotation)
|
spear_object:set_rotation(rotation)
|
||||||
minetest.sound_play("default_place_node", {pos = throw_pos}, true)
|
minetest.sound_play("default_place_node", {pos = throw_pos}, true)
|
||||||
spear_object:get_luaentity()._wear = itemstack:get_wear()
|
spear_object:get_luaentity()._wear = itemstack:get_wear()
|
||||||
@ -21,6 +20,7 @@ function spears_throw (itemstack, player, pointed_thing)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Avoid hitting yourself and throw
|
-- Avoid hitting yourself and throw
|
||||||
|
local throw_speed = 12
|
||||||
while vector.distance(player_pos, throw_pos) < 1 do
|
while vector.distance(player_pos, throw_pos) < 1 do
|
||||||
throw_pos = vector.add(throw_pos, vector.multiply(direction,0.1))
|
throw_pos = vector.add(throw_pos, vector.multiply(direction,0.1))
|
||||||
end
|
end
|
||||||
@ -38,9 +38,9 @@ function spears_set_entity(spear_type, base_damage, toughness)
|
|||||||
initial_properties = {
|
initial_properties = {
|
||||||
physical = false,
|
physical = false,
|
||||||
visual = "item",
|
visual = "item",
|
||||||
visual_size = {x = 0.25, y = 0.25, z = 0.25},
|
visual_size = {x = 0.3, y = 0.3, z = 0.3},
|
||||||
wield_item = "spears:spear_" .. spear_type,
|
wield_item = "spears:spear_" .. spear_type,
|
||||||
collisionbox = {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5},
|
collisionbox = {-0.3, -0.3, -0.3, 0.3, 0.3, 0.3},
|
||||||
},
|
},
|
||||||
|
|
||||||
on_activate = function (self, staticdata, dtime_s)
|
on_activate = function (self, staticdata, dtime_s)
|
||||||
@ -48,7 +48,7 @@ function spears_set_entity(spear_type, base_damage, toughness)
|
|||||||
end,
|
end,
|
||||||
|
|
||||||
on_punch = function (self, puncher)
|
on_punch = function (self, puncher)
|
||||||
if puncher:is_player() then
|
if puncher:is_player() then -- Grab the spear
|
||||||
local stack = {name='spears:spear_' .. spear_type, wear = self._wear}
|
local stack = {name='spears:spear_' .. spear_type, wear = self._wear}
|
||||||
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
|
||||||
@ -65,14 +65,15 @@ function spears_set_entity(spear_type, base_damage, toughness)
|
|||||||
end
|
end
|
||||||
local velocity = self.object:get_velocity()
|
local velocity = self.object:get_velocity()
|
||||||
local speed = vector.length(velocity)
|
local speed = vector.length(velocity)
|
||||||
|
-- Spear is stuck ?
|
||||||
if self._stickpos then
|
if self._stickpos then
|
||||||
local node = minetest.get_node(self._stickpos)
|
local node = minetest.get_node(self._stickpos)
|
||||||
if not node or not minetest.registered_nodes[node.name].walkable then
|
if not node or not minetest.registered_nodes[node.name].walkable then -- Fall when node is removed
|
||||||
self.object:remove()
|
self.object:remove()
|
||||||
minetest.add_item(self.object:get_pos(), {name='spears:spear_' .. spear_type, wear = self._wear})
|
minetest.add_item(self.object:get_pos(), {name='spears:spear_' .. spear_type, wear = self._wear})
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
else
|
else -- Spear is flying
|
||||||
local direction = vector.normalize(velocity)
|
local direction = vector.normalize(velocity)
|
||||||
local yaw = minetest.dir_to_yaw(velocity)
|
local yaw = minetest.dir_to_yaw(velocity)
|
||||||
local pitch = math.acos(velocity.y/speed) - math.pi/3
|
local pitch = math.acos(velocity.y/speed) - math.pi/3
|
||||||
@ -91,9 +92,9 @@ function spears_set_entity(spear_type, base_damage, toughness)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Stick or get drag
|
-- Hit a node?
|
||||||
if node then
|
if node then
|
||||||
if minetest.registered_nodes[node.name].walkable then
|
if minetest.registered_nodes[node.name].walkable then -- Stick
|
||||||
self.object:set_acceleration({x = 0, y = 0, z = 0})
|
self.object:set_acceleration({x = 0, y = 0, z = 0})
|
||||||
self.object:set_velocity({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)
|
minetest.sound_play("default_place_node", {pos = pos}, true)
|
||||||
@ -104,10 +105,10 @@ function spears_set_entity(spear_type, base_damage, toughness)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
self._stickpos = pos
|
self._stickpos = pos
|
||||||
else
|
else -- Get drag
|
||||||
local drag = math.max(minetest.registered_nodes[node.name].liquid_viscosity, 0.1)
|
local drag = math.max(minetest.registered_nodes[node.name].liquid_viscosity, 0.1)
|
||||||
local acceleration = vector.multiply(velocity, -drag)
|
local acceleration = vector.multiply(velocity, -drag)
|
||||||
acceleration.y = acceleration.y - 10 * ((7 - drag) / 7)^2
|
acceleration.y = acceleration.y - 10 * ((7 - drag) / 7)
|
||||||
self.object:set_acceleration(acceleration)
|
self.object:set_acceleration(acceleration)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -2,8 +2,8 @@ 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 = 1.5, y = 1.5, z = 1.5},
|
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_throw(itemstack, user, pointed_thing)
|
spears_throw(itemstack, user, pointed_thing)
|
||||||
|
Loading…
Reference in New Issue
Block a user