fix deployer issue nalc/nalc-server-mods#104
fix deprecated function
fix bad/Nonexistent collision detection on mobs/players, use collision box for very good detection
add translation client side
This commit is contained in:
Crabman77 2022-07-21 17:35:07 +02:00
parent e2182ca004
commit b888cda310
4 changed files with 122 additions and 41 deletions

View File

@ -23,12 +23,18 @@ 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
if player.is_fake_player then
player_vel = {x=0,y=0,z=0}
else
player_vel = player:get_velocity()
end
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)
minetest.sound_play("spears_throw", {pos = player_pos}, true)
spear_object:get_luaentity()._wear = itemstack:get_wear()
spear_object:get_luaentity().lastpos = throw_pos
spear_object:get_luaentity()._stickpos = nil
return true
end
@ -41,6 +47,7 @@ function spears_set_entity(spear_type, base_damage, toughness)
visual_size = {x = 0.3, y = 0.3, z = 0.3},
wield_item = "spears:spear_" .. spear_type,
collisionbox = {-0.3, -0.3, -0.3, 0.3, 0.3, 0.3},
lastpos={},
},
on_activate = function (self, staticdata, dtime_s)
@ -75,7 +82,7 @@ function spears_set_entity(spear_type, base_damage, toughness)
self.object:remove()
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 = self._stickpos}, 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
@ -84,47 +91,91 @@ function spears_set_entity(spear_type, base_damage, toughness)
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})
-- Hit someone?
local objects_in_radius = minetest.get_objects_inside_radius(spearhead_pos, 0.6)
for _,object in ipairs(objects_in_radius) do
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()
minetest.sound_play("spears_hit", {pos = pos}, true)
minetest.add_item(pos, {name='spears:spear_' .. spear_type, wear = self._wear + 65535/toughness})
local newpos = self.object:get_pos()
for _, pos in pairs(spears_get_trajectoire(self, newpos)) do
local direction = vector.normalize(velocity)
local yaw = minetest.dir_to_yaw(direction)
local pitch = math.acos(velocity.y/speed) - math.pi/3
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})
-- Hit someone?
local objects_in_radius = minetest.get_objects_inside_radius(spearhead_pos, 2.5)
for _,object in ipairs(objects_in_radius) do
if object:get_luaentity() ~= self and object:get_armor_groups().fleshy then
local objpos = object:get_pos()
local collisionbox = object:get_properties().collisionbox or {-0.5, -0.5, -0.5, 0.5, 0.5, 0.5}
if spears_touch(spearhead_pos, objpos, collisionbox) 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()
minetest.sound_play("spears_hit", {pos = pos}, true)
minetest.add_item(pos, {name='spears:spear_' .. spear_type, wear = self._wear + 65535/toughness})
return
end
end
end
-- Hit a node?
if node and minetest.registered_nodes[node.name].walkable
and not minetest.registered_nodes[node.name].buildable_to
and not (minetest.registered_nodes[node.name].groups.slab and spearhead_pos.y % 1 < 0.5)
then -- Stick
self.object:set_acceleration({x = 0, y = 0, z = 0})
self.object:set_velocity({x = 0, y = 0, z = 0})
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 = spearhead_pos
self.lastpos = pos
return
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
-- Hit a node?
if node and minetest.registered_nodes[node.name].walkable
and not minetest.registered_nodes[node.name].buildable_to
and not (minetest.registered_nodes[node.name].groups.slab and spearhead_pos.y % 1 < 0.5)
then -- Stick
self.object:set_acceleration({x = 0, y = 0, z = 0})
self.object:set_velocity({x = 0, y = 0, z = 0})
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 = spearhead_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
self.lastpos = newpos
end
end,
}
return SPEAR_ENTITY
end
function spears_get_trajectoire(self, newpos)
if self.lastpos.x == nil then
return {newpos}
end
local coord = {}
local dx = vector.distance({x=newpos["x"], y=0, z=0}, {x=self.lastpos["x"], y=0, z=0} )/2
local dy = vector.distance({x=0, y=newpos["y"], z=0}, {x=0, y=self.lastpos["y"], z=0} )/2
local dz = vector.distance({x=0, y=0, z=newpos["z"]}, {x=0, y=0, z=self.lastpos["z"]} )/2
if newpos["x"] < self.lastpos["x"] then
dx = -dx
end
if newpos["y"] < self.lastpos["y"] then
dy = -dy
end
if newpos["z"] < self.lastpos["z"] then
dz = -dz
end
table.insert(coord, {x=self.lastpos["x"]+dx, y=self.lastpos["y"]+dy ,z=self.lastpos["z"]+dz })
table.insert(coord, newpos)
return coord
end
function spears_touch(pos, objpos, cbox)
--colbox format {x1, y1, z1, x2, y2, z2}
if (pos.x < objpos.x + math.max(cbox[1], cbox[4]) and pos.x > objpos.x + math.min(cbox[1], cbox[4]))
and (pos.y < objpos.y + math.max(cbox[2], cbox[5]) and pos.y > objpos.y + math.min(cbox[2], cbox[5]))
and (pos.z < objpos.z + math.max(cbox[3], cbox[6]) and pos.z > objpos.z + math.min(cbox[3], cbox[6])) then
return true
end
return false
end

9
locale/spears.fr.tr Normal file
View File

@ -0,0 +1,9 @@
# textdomain: spears
Stone spear=Lance en pierre
Steel spear=Lance en acier
Copper spear=Lance en cuivre
Bronze spear=Lance en bronze
Obsidian spear=Lance en obsidienne
Diamond spear=Lance en diamant
Golden spear=Lance en or

11
locale/template.txt Normal file
View File

@ -0,0 +1,11 @@
# textdomain: spears
Stone spear=
Steel spear=
Copper spear=
Bronze spear=
Obsidian spear=
Diamond spear=
Golden spear=

View File

@ -1,20 +1,30 @@
local S = minetest.get_translator("spears")
function spears_register_spear(spear_type, desc, base_damage, toughness, material)
minetest.register_tool("spears:spear_" .. spear_type, {
description = desc .. " spear",
description = S(desc .. " spear"),
wield_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},
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)
if pointed_thing.type == "node" then
local node = minetest.get_node(pointed_thing.under)
if minetest.registered_nodes[node.name] and (node.name == "itemframes:pedestal" or node.name == "itemframes:frame") then
minetest.registered_nodes[node.name].on_rightclick(pointed_thing.under, node, user, itemstack)
return itemstack
end
end
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