1
0
Fork 0

Make arrows stick in solid nodes propery, trigger wooden buttons

This commit is contained in:
Wuzzy 2018-05-08 14:35:15 +02:00
parent af0025debc
commit 4339c80fd8
1 changed files with 17 additions and 7 deletions

View File

@ -47,12 +47,15 @@ minetest.register_node("mcl_bows:arrow_box", {
}) })
-- FIXME: Restore arrow state properly on re-loading -- FIXME: Restore arrow state properly on re-loading
local THROWING_ARROW_ENTITY={ -- FIXME: Arrow velocity is a bit strange. If the arrow flies VERY long, the acceleration can cause the velocity to become negative
physical = false, -- and the arrow flies backwards.
local ARROW_ENTITY={
physical = true,
visual = "wielditem", visual = "wielditem",
visual_size = {x=0.4, y=0.4}, visual_size = {x=0.4, y=0.4},
textures = {"mcl_bows:arrow_box"}, textures = {"mcl_bows:arrow_box"},
collisionbox = {0,0,0,0,0,0}, collisionbox = {-0.1, -0.1, -0.1, 0.1, 0.1, 0.1},
collide_with_objects = false,
_lastpos={}, _lastpos={},
_startpos=nil, _startpos=nil,
@ -62,7 +65,7 @@ local THROWING_ARROW_ENTITY={
_shooter=nil, -- ObjectRef of player or mob who shot it _shooter=nil, -- ObjectRef of player or mob who shot it
} }
THROWING_ARROW_ENTITY.on_step = function(self, dtime) ARROW_ENTITY.on_step = function(self, dtime)
local pos = self.object:getpos() local pos = self.object:getpos()
local node = minetest.get_node(pos) local node = minetest.get_node(pos)
@ -157,19 +160,27 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
end end
end end
self.object:remove() self.object:remove()
return
end end
end end
end end
-- Check for node collision -- Check for node collision
-- FIXME: Also collides with ignore
if self._lastpos.x~=nil and not self._stuck then if self._lastpos.x~=nil and not self._stuck then
local def = minetest.registered_nodes[node.name] local def = minetest.registered_nodes[node.name]
if (def and def.walkable) or not def then local vel = self.object:get_velocity()
-- Arrow has stopped
if (math.abs(vel.x) < 0.0001) or (math.abs(vel.z) < 0.0001) or (math.abs(vel.y) < 0.00001) then
-- Arrow is stuck and no longer moves -- Arrow is stuck and no longer moves
self._stuck = true self._stuck = true
self._stucktimer = 0 self._stucktimer = 0
self.object:set_velocity({x=0, y=0, z=0}) self.object:set_velocity({x=0, y=0, z=0})
self.object:set_acceleration({x=0, y=0, z=0}) self.object:set_acceleration({x=0, y=0, z=0})
-- Push the button
if minetest.get_item_group(node.name, "button") > 0 and minetest.get_item_group(node.name, "button_push_by_arrow") == 1 and def.on_rightclick then
def.on_rightclick(pos, node)
end
elseif (def and def.liquidtype ~= "none") then elseif (def and def.liquidtype ~= "none") then
-- Slow down arrow in liquids -- Slow down arrow in liquids
local v = def.liquid_viscosity local v = def.liquid_viscosity
@ -177,7 +188,6 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
v = 0 v = 0
end end
local vpenalty = math.max(0.1, 0.98 - 0.1 * v) local vpenalty = math.max(0.1, 0.98 - 0.1 * v)
local vel = self.object:get_velocity()
if math.abs(vel.x) > 0.001 then if math.abs(vel.x) > 0.001 then
vel.x = vel.x * vpenalty vel.x = vel.x * vpenalty
end end
@ -192,7 +202,7 @@ THROWING_ARROW_ENTITY.on_step = function(self, dtime)
self._lastpos={x=pos.x, y=pos.y, z=pos.z} self._lastpos={x=pos.x, y=pos.y, z=pos.z}
end end
minetest.register_entity("mcl_bows:arrow_entity", THROWING_ARROW_ENTITY) minetest.register_entity("mcl_bows:arrow_entity", ARROW_ENTITY)
if minetest.get_modpath("mcl_core") and minetest.get_modpath("mcl_mobitems") then if minetest.get_modpath("mcl_core") and minetest.get_modpath("mcl_mobitems") then
minetest.register_craft({ minetest.register_craft({