Update 2.3

This commit is contained in:
echoes91 2022-09-28 23:44:35 +02:00
parent a6ca632829
commit a523aff826
9 changed files with 33 additions and 15 deletions

View File

@ -1,3 +1,8 @@
Version 2.3:
- Updated to Minetest 5.6.0 API
- Changed receipts to avoid being confused with arrows
- Various cleansing and fixes
Version 2.2:
- "Hit detection" based on spearhead position
- Spears go through buildable_to nodes (snow)

2
README
View File

@ -19,7 +19,7 @@ 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.
This mod contains the word "spear" more than 100 times, if you want the exact number you can count them.
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.

View File

@ -4,3 +4,4 @@ DISABLE_COPPER_SPEAR = false
DISABLE_BRONZE_SPEAR = false
DISABLE_DIAMOND_SPEAR = false
DISABLE_OBSIDIAN_SPEAR = false
DISABLE_GOLD_SPEAR = false

View File

@ -1 +0,0 @@
default

View File

@ -7,7 +7,7 @@ function spears_throw (itemstack, player, pointed_thing)
local pitch = player:get_look_vertical()
local yaw = player:get_look_horizontal()
local rotation = vector.new(0, yaw + math.pi/2, pitch + math.pi/6)
-- Plant into node
-- Stick into node
if pointed_thing.type == "node" then
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
@ -23,7 +23,7 @@ function spears_throw (itemstack, player, pointed_thing)
while vector.distance(player_pos, throw_pos) < 1.2 do
throw_pos = vector.add(throw_pos, vector.multiply(direction, 0.1))
end
local player_vel = player:get_player_velocity()
local player_vel = player:get_velocity()
local spear_object = minetest.add_entity(throw_pos, spear)
spear_object:set_velocity(vector.add(player_vel, vector.multiply(direction, throw_speed)))
spear_object:set_rotation(rotation)
@ -63,6 +63,7 @@ function spears_set_entity(spear_type, base_damage, toughness)
self.object:remove()
return
end
local pos = self.object:get_pos()
local velocity = self.object:get_velocity()
local speed = vector.length(velocity)
-- Spear is stuck ?
@ -72,21 +73,20 @@ function spears_set_entity(spear_type, base_damage, toughness)
if node_cracky and node_cracky < 3 then
minetest.sound_play("default_metal_footstep", {pos = pos}, true)
self.object:remove()
minetest.add_item(self.object:get_pos(), {name='spears:spear_' .. spear_type, wear = self._wear})
minetest.add_item(pos, {name='spears:spear_' .. spear_type, wear = self._wear})
elseif not self._node_walkable then
minetest.sound_play("default_place_node", {pos = throw_pos}, true)
minetest.sound_play("default_place_node", {pos = pos}, true)
end
self._node_walkable = minetest.registered_nodes[node.name].walkable
if not node or not self._node_walkable then -- Fall when node is removed
self.object:remove()
minetest.add_item(self.object:get_pos(), {name='spears:spear_' .. spear_type, wear = self._wear})
minetest.add_item(pos, {name='spears:spear_' .. spear_type, wear = self._wear})
return
end
else -- Spear is flying
local direction = vector.normalize(velocity)
local yaw = minetest.dir_to_yaw(direction)
local pitch = math.acos(velocity.y/speed) - math.pi/3
local pos = self.object:get_pos()
local spearhead_pos = vector.add(pos, vector.multiply(direction, 0.5))
local node = minetest.get_node(spearhead_pos)
self.object:set_rotation({x = 0, y = yaw + math.pi/2, z = pitch})

View File

@ -11,7 +11,8 @@ dofile(minetest.get_modpath("spears").."/functions.lua")
dofile(minetest.get_modpath("spears").."/tools.lua")
local log_mods = minetest.settings:get_bool("log_mods")
if minetest.setting_get("log_mods") then
minetest.log("action", "spears loaded")
if minetest.settings:get_bool("log_mods") then
minetest.log("action", "[MOD] Spears loaded")
end

7
mod.conf Normal file
View File

@ -0,0 +1,7 @@
name = spears
depends = default
description = Add spears to Minetest, versatile weapons that can be thrown
release = 2.3
author = Echoes91
title = Spears

View File

@ -3,4 +3,5 @@ DISABLE_STEEL_SPEAR = true
DISABLE_COPPER_SPEAR = true
DISABLE_BRONZE_SPEAR = true
DISABLE_DIAMOND_SPEAR = true
DISABLE_OBSIDIAN_SPEAR = true
DISABLE_OBSIDIAN_SPEAR = true
DISABLE_GOLD_SPEAR = true

View File

@ -7,14 +7,14 @@ function spears_register_spear(spear_type, desc, base_damage, toughness, materia
wield_scale= {x = 1.5, y = 1.5, z = 1.5},
on_secondary_use = function(itemstack, user, pointed_thing)
spears_throw(itemstack, user, pointed_thing)
if not minetest.setting_getbool("creative_mode") then
if not minetest.settings:get_bool("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.settings:get_bool("creative_mode") then
itemstack:take_item()
end
return itemstack
@ -38,14 +38,18 @@ function spears_register_spear(spear_type, desc, base_damage, toughness, materia
minetest.register_craft({
output = 'spears:spear_' .. spear_type,
recipe = {
{'group:stick', 'group:stick', material},
{"", "", material},
{"", "group:stick", ""},
{"group:stick", "", ""}
}
})
minetest.register_craft({
output = 'spears:spear_' .. spear_type,
recipe = {
{material, 'group:stick', 'group:stick'},
{material, "", ""},
{"", "group:stick", ""},
{"", "", "group:stick"}
}
})
end