Compare commits
4 Commits
549693ff97
...
ea229e8dbc
Author | SHA1 | Date |
---|---|---|
teknomunk | ea229e8dbc | |
teknomunk | baa5fb5952 | |
teknomunk | 53a34747da | |
teknomunk | b8a115753e |
|
@ -27,6 +27,11 @@ minetest.register_node("mcl_target:target_off", {
|
|||
rules = mesecon.rules.alldirs,
|
||||
},
|
||||
},
|
||||
_vl_projectile = {
|
||||
on_collide = function(projectile, pos, node, node_def)
|
||||
mcl_target.hit(pos, 1) --10 redstone ticks
|
||||
end
|
||||
},
|
||||
_mcl_blast_resistance = 0.5,
|
||||
_mcl_hardness = 0.5,
|
||||
})
|
||||
|
@ -67,4 +72,4 @@ if mod_farming then
|
|||
{"", "mesecons:redstone", ""},
|
||||
},
|
||||
})
|
||||
end
|
||||
end
|
||||
|
|
|
@ -151,6 +151,20 @@ function mesecon.register_button(basename, description, texture, recipeitem, sou
|
|||
}},
|
||||
_mcl_button_basename = basename,
|
||||
_mcl_button_timer = button_timer,
|
||||
_vl_projectile = {
|
||||
on_collide = function(projectile, pos, node, node_def)
|
||||
pos = vector.round(pos)
|
||||
|
||||
-- Push the button! Push, push, push the button!
|
||||
if node_def.groups.button_push_by_arrow == 1 then
|
||||
minetest.log("hit"..dump({
|
||||
pos = pos,
|
||||
node = node,
|
||||
}))
|
||||
mesecon.push_button(pos, node)
|
||||
end
|
||||
end
|
||||
},
|
||||
|
||||
_mcl_blast_resistance = 0.5,
|
||||
_mcl_hardness = 0.5,
|
||||
|
|
|
@ -36,65 +36,6 @@ S("Arrows might get stuck on solid blocks and can be retrieved again. They are a
|
|||
})
|
||||
|
||||
-- Destroy arrow entity self at pos and drops it as an item
|
||||
local function replace_with_item_drop(self, pos)
|
||||
if not minetest.is_creative_enabled("") then
|
||||
local item = minetest.add_item(pos, "mcl_bows:arrow")
|
||||
item:set_velocity(vector.zero())
|
||||
item:set_yaw(self.object:get_yaw())
|
||||
end
|
||||
|
||||
mcl_burning.extinguish(self.object)
|
||||
self._removed = true
|
||||
self.object:remove()
|
||||
end
|
||||
|
||||
local function stuck_arrow_on_step(self, dtime)
|
||||
self._stucktimer = self._stucktimer + dtime
|
||||
self._stuckrechecktimer = self._stuckrechecktimer + dtime
|
||||
if self._stucktimer > ARROW_TIMEOUT then
|
||||
mcl_burning.extinguish(self.object)
|
||||
self._removed = true
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
|
||||
local pos = self.object:get_pos()
|
||||
if not pos then return end
|
||||
|
||||
-- Drop arrow as item when it is no longer stuck
|
||||
-- FIXME: Arrows are a bit slow to react and continue to float in mid air for a few seconds.
|
||||
if self._stuckrechecktimer > STUCK_RECHECK_TIME then
|
||||
local stuckin_def = self._stuckin and minetest.registered_nodes[minetest.get_node(self._stuckin).name]
|
||||
-- TODO: In MC, arrow just falls down without turning into an item
|
||||
if stuckin_def and stuckin_def.walkable == false then
|
||||
replace_with_item_drop(self, pos)
|
||||
return
|
||||
end
|
||||
self._stuckrechecktimer = 0
|
||||
end
|
||||
|
||||
-- Pickup arrow if player is nearby (not in Creative Mode)
|
||||
local objects = minetest.get_objects_inside_radius(pos, 1)
|
||||
for _,obj in ipairs(objects) do
|
||||
if obj:is_player() then
|
||||
if self._collectable and not minetest.is_creative_enabled(obj:get_player_name()) then
|
||||
local arrow_item = self._arrow_item
|
||||
if arrow_item and minetest.registered_items[arrow_item] and obj:get_inventory():room_for_item("main", arrow_item) then
|
||||
obj:get_inventory():add_item("main", arrow_item)
|
||||
minetest.sound_play("item_drop_pickup", {
|
||||
pos = pos,
|
||||
max_hear_distance = 16,
|
||||
gain = 1.0,
|
||||
}, true)
|
||||
end
|
||||
end
|
||||
mcl_burning.extinguish(self.object)
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local arrow_entity = {
|
||||
physical = true,
|
||||
pointable = false,
|
||||
|
@ -132,7 +73,33 @@ local arrow_entity = {
|
|||
damage_groups = function(self)
|
||||
return { fleshy = self._damage }
|
||||
end,
|
||||
hide_tracer = function(self)
|
||||
return self._stuck or self._damage < 9 or self._in_player
|
||||
end,
|
||||
tracer_texture = "mobs_mc_arrow_particle.png",
|
||||
behaviors = {
|
||||
vl_projectile.sticks,
|
||||
vl_projectile.burns,
|
||||
vl_projectile.has_tracer,
|
||||
|
||||
-- Custom arrow behaviors
|
||||
function(self, dtime)
|
||||
local pos = self.object:get_pos()
|
||||
self._allow_punch = self._allow_punch or not self._owner or not self._startpos or pos and vector.distance(self._startpos, pos) > 1.5
|
||||
|
||||
-- Give the arrows a maximum flight time
|
||||
self._time_in_air = (self._time_in_air or 0) + dtime
|
||||
if self._time_in_air > ARROW_TIMEOUT then
|
||||
self._removed = true
|
||||
self.object:remove()
|
||||
return true
|
||||
end
|
||||
|
||||
if self._deflection_cooloff > 0 then
|
||||
self._deflection_cooloff = self._deflection_cooloff - dtime
|
||||
end
|
||||
end,
|
||||
|
||||
vl_projectile.collides_with_solids,
|
||||
vl_projectile.raycast_collides_with_entities,
|
||||
},
|
||||
|
@ -153,74 +120,6 @@ local arrow_entity = {
|
|||
return {{name="mcl_bows_hit_other", gain=0.3}, {pos=self.object:get_pos(), max_hear_distance=16}, true}
|
||||
end
|
||||
},
|
||||
on_collide_with_solid = function(self, pos, node, node_def)
|
||||
local vel = self.object:get_velocity()
|
||||
local dpos = vector.round(pos) -- digital pos
|
||||
|
||||
-- Check for the node to which the arrow is pointing
|
||||
local dir
|
||||
if math.abs(vel.y) < 0.00001 then
|
||||
if self._last_pos.y < pos.y then
|
||||
dir = vector.new(0, 1, 0)
|
||||
else
|
||||
dir = vector.new(0, -1, 0)
|
||||
end
|
||||
else
|
||||
dir = minetest.facedir_to_dir(minetest.dir_to_facedir(minetest.yaw_to_dir(self.object:get_yaw()-YAW_OFFSET)))
|
||||
end
|
||||
self._stuckin = vector.add(dpos, dir)
|
||||
|
||||
local snode = minetest.get_node(self._stuckin)
|
||||
local sdef = minetest.registered_nodes[snode.name]
|
||||
|
||||
-- If node is non-walkable, unknown or ignore, don't make arrow stuck.
|
||||
-- This causes a deflection in the engine.
|
||||
if not sdef or sdef.walkable == false or snode.name == "ignore" then
|
||||
self._stuckin = nil
|
||||
if self._deflection_cooloff <= 0 then
|
||||
-- Lose 1/3 of velocity on deflection
|
||||
local newvel = vector.multiply(vel, 0.6667)
|
||||
|
||||
self.object:set_velocity(newvel)
|
||||
-- Reset deflection cooloff timer to prevent many deflections happening in quick succession
|
||||
self._deflection_cooloff = 1.0
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
-- Node was walkable, make arrow stuck
|
||||
self._stuck = true
|
||||
self._stucktimer = 0
|
||||
self._stuckrechecktimer = 0
|
||||
|
||||
self.object:set_velocity(vector.zero())
|
||||
self.object:set_acceleration(vector.zero())
|
||||
|
||||
minetest.sound_play({name="mcl_bows_hit_other", gain=0.3}, {pos=self.object:get_pos(), max_hear_distance=16}, true)
|
||||
|
||||
if mcl_burning.is_burning(self.object) and snode.name == "mcl_tnt:tnt" then
|
||||
tnt.ignite(self._stuckin)
|
||||
end
|
||||
|
||||
-- Ignite Campfires
|
||||
if mod_campfire and mcl_burning.is_burning(self.object) and minetest.get_item_group(snode.name, "campfire") ~= 0 then
|
||||
mcl_campfires.light_campfire(self._stuckin)
|
||||
end
|
||||
|
||||
-- Activate target
|
||||
if mod_target and snode.name == "mcl_target:target_off" then
|
||||
mcl_target.hit(self._stuckin, 1) --10 redstone ticks
|
||||
end
|
||||
|
||||
-- Push the button! Push, push, push the button!
|
||||
if mod_button and minetest.get_item_group(node.name, "button") > 0 and minetest.get_item_group(node.name, "button_push_by_arrow") == 1 then
|
||||
local bdir = minetest.wallmounted_to_dir(node.param2)
|
||||
-- Check the button orientation
|
||||
if vector.equals(vector.add(dpos, bdir), self._stuckin) then
|
||||
mesecon.push_button(dpos, node)
|
||||
end
|
||||
end
|
||||
end,
|
||||
on_collide_with_entity = function(self, pos, obj)
|
||||
local is_player = obj:is_player()
|
||||
local lua = obj:get_luaentity()
|
||||
|
@ -231,7 +130,6 @@ local arrow_entity = {
|
|||
end
|
||||
|
||||
if obj:get_hp() > 0 then
|
||||
-- Check if there is no solid node between arrow and object
|
||||
if lua then
|
||||
local entity_name = lua.name
|
||||
-- Achievement for hitting skeleton, wither skeleton or stray (TODO) with an arrow at least 50 meters away
|
||||
|
@ -262,55 +160,6 @@ local arrow_entity = {
|
|||
self.object:remove()
|
||||
end
|
||||
},
|
||||
on_step = function(self, dtime)
|
||||
mcl_burning.tick(self.object, dtime, self)
|
||||
|
||||
-- mcl_burning.tick may remove object immediately
|
||||
if not self.object:get_pos() then return end
|
||||
|
||||
self._time_in_air = (self._time_in_air or 0) + dtime
|
||||
|
||||
-- Give the arrows a maximum flight time
|
||||
if self._time_in_air > ARROW_TIMEOUT then
|
||||
self._removed = true
|
||||
self.object:remove()
|
||||
end
|
||||
|
||||
local pos = self.object:get_pos()
|
||||
self._allow_punch = self._allow_punch or not self._owner or not self._startpos or pos and vector.distance(self._startpos, pos) > 1.5
|
||||
|
||||
if self._stuck then
|
||||
return stuck_arrow_on_step(self, dtime)
|
||||
end
|
||||
|
||||
-- Add tracer
|
||||
if self._damage >= 9 and self._in_player == false then
|
||||
minetest.add_particlespawner({
|
||||
amount = 20,
|
||||
time = .2,
|
||||
minpos = vector.zero(),
|
||||
maxpos = vector.zero(),
|
||||
minvel = vector.new(-0.1,-0.1,-0.1),
|
||||
maxvel = vector.new(0.1,0.1,0.1),
|
||||
minexptime = 0.5,
|
||||
maxexptime = 0.5,
|
||||
minsize = 2,
|
||||
maxsize = 2,
|
||||
attached = self.object,
|
||||
collisiondetection = false,
|
||||
vertical = false,
|
||||
texture = "mobs_mc_arrow_particle.png",
|
||||
glow = 1,
|
||||
})
|
||||
end
|
||||
|
||||
if self._deflection_cooloff > 0 then
|
||||
self._deflection_cooloff = self._deflection_cooloff - dtime
|
||||
end
|
||||
|
||||
-- Process as projectile
|
||||
vl_projectile.update_projectile(self, dtime)
|
||||
end,
|
||||
|
||||
-- Force recheck of stuck arrows when punched.
|
||||
-- Otherwise, punching has no effect.
|
||||
|
|
|
@ -261,6 +261,14 @@ function mcl_campfires.register_campfire(name, def)
|
|||
},
|
||||
_mcl_blast_resistance = 2,
|
||||
_mcl_hardness = 2,
|
||||
_vl_projectile = {
|
||||
on_collide = function(projectile, pos, node, node_def)
|
||||
-- Ignite Campfires
|
||||
if mcl_burning.is_burning(projectile) then
|
||||
mcl_campfires.light_campfire(pos)
|
||||
end
|
||||
end
|
||||
},
|
||||
after_dig_node = function(pos, node, oldmeta, digger)
|
||||
campfire_drops(pos, digger, def.drops, name.."_lit")
|
||||
end,
|
||||
|
|
|
@ -110,6 +110,13 @@ minetest.register_node("mcl_tnt:tnt", {
|
|||
tnt.ignite(droppos)
|
||||
end
|
||||
end,
|
||||
_vl_projectile = {
|
||||
on_collide = function(projectile, pos, node, node_def)
|
||||
if mcl_burning.is_burning(projectile) then
|
||||
tnt.ignite(pos)
|
||||
end
|
||||
end
|
||||
},
|
||||
sounds = sounds,
|
||||
})
|
||||
|
||||
|
|
|
@ -62,8 +62,13 @@ Arguments:
|
|||
The projectile API supports specifying the behaviors that a projectile will exhibit. There are several
|
||||
standard behaviors provided with the API:
|
||||
|
||||
* `vl_projectile.burns`: projectile can be set on fire
|
||||
* `vl_projectile.collides_with_solids`: handles collisions between projectiles and solid nodes
|
||||
* `vl_projectile.collides_with_entities`: handles collisions between projectiles and entities by checking nearby entities
|
||||
* `vl_projectile.has_tracer`: projectile will have a tracer trail when thrown/shot. Projectile can define
|
||||
`_vl_projectile.hide_tracer = function(self)` to conditionally hide the tracer.
|
||||
* `vl_projectile.sticks`: projectile will stick into nodes. Forces `_vl_projectile.sticks_in_nodes = true`
|
||||
and `_vl_projectile.survive_collision = true`.
|
||||
* `vl_projectile.raycast_collides_with_entities`: handles collisions between projectils and entities by performing a raycast
|
||||
check along the path of movement.
|
||||
|
||||
|
|
|
@ -6,10 +6,14 @@ local vl_physics_path = minetest.get_modpath("vl_physics")
|
|||
local DEBUG = false
|
||||
local YAW_OFFSET = -math.pi/2
|
||||
local GRAVITY = tonumber(minetest.settings:get("movement_gravity"))
|
||||
local STUCK_TIMEOUT = 60
|
||||
local STUCK_RECHECK_TIME = 0.25
|
||||
local enable_pvp = minetest.settings:get_bool("enable_pvp")
|
||||
|
||||
function mod.projectile_physics(obj, entity_def, v, a)
|
||||
local le = obj:get_luaentity()
|
||||
if not le then return end
|
||||
|
||||
local entity_def = minetest.registered_entities[le.name]
|
||||
local pos = obj:get_pos()
|
||||
if not pos then return end
|
||||
|
@ -85,7 +89,9 @@ function mod.update_projectile(self, dtime)
|
|||
end
|
||||
end
|
||||
|
||||
mod.projectile_physics(self.object, entity_def)
|
||||
if not self._stuck then
|
||||
mod.projectile_physics(self.object, entity_def)
|
||||
end
|
||||
end
|
||||
|
||||
local function damage_particles(pos, is_critical)
|
||||
|
@ -186,6 +192,126 @@ local function handle_player_sticking(self, entity_def, projectile_def, entity)
|
|||
)
|
||||
end
|
||||
|
||||
function mod.burns(self, dtime, entity_def, projectile_def)
|
||||
mcl_burning.tick(self.object, dtime, self)
|
||||
|
||||
-- mcl_burning.tick may remove object immediately
|
||||
local pos = self.object:get_pos()
|
||||
if not pos then return true end
|
||||
|
||||
-- Handle getting set on fire
|
||||
local node = minetest.get_node(vector.round(pos))
|
||||
if not node or node.name == "ignore" then return end
|
||||
|
||||
local set_on_fire = minetest.get_item_group(node.name, "set_on_fire")
|
||||
if set_on_fire ~= 0 then
|
||||
mcl_burning.set_on_fire(self.object, set_on_fire)
|
||||
end
|
||||
end
|
||||
|
||||
function mod.has_tracer(self, dtime, entity_def, projectile_def)
|
||||
local hide_tracer = projectile_def.hide_tracer
|
||||
if hide_tracer and hide_tracer(self) then return end
|
||||
|
||||
-- Add tracer
|
||||
minetest.add_particlespawner({
|
||||
amount = 20,
|
||||
time = .2,
|
||||
minpos = vector.zero(),
|
||||
maxpos = vector.zero(),
|
||||
minvel = vector.new(-0.1,-0.1,-0.1),
|
||||
maxvel = vector.new(0.1,0.1,0.1),
|
||||
minexptime = 0.5,
|
||||
maxexptime = 0.5,
|
||||
minsize = 2,
|
||||
maxsize = 2,
|
||||
attached = self.object,
|
||||
collisiondetection = false,
|
||||
vertical = false,
|
||||
texture = projectile_def.tracer_texture or "mobs_mc_arrow_particle.png",
|
||||
glow = 1,
|
||||
})
|
||||
end
|
||||
|
||||
function mod.replace_with_item_drop(self, pos, entity_def, projectile_def)
|
||||
local item = self._arrow_item or projectile_def.item
|
||||
|
||||
if self._collectable and not minetest.is_creative_enabled("") then
|
||||
local item = minetest.add_item(pos, item)
|
||||
item:set_velocity(vector.zero())
|
||||
item:set_yaw(self.object:get_yaw())
|
||||
end
|
||||
|
||||
mcl_burning.extinguish(self.object)
|
||||
self._removed = true
|
||||
self.object:remove()
|
||||
end
|
||||
|
||||
local function stuck_on_step(self, dtime, entity_def, projectile_def)
|
||||
-- Don't process objects that have been removed
|
||||
local pos = self.object:get_pos()
|
||||
if not pos then return true end
|
||||
|
||||
self._stucktimer = self._stucktimer + dtime
|
||||
if self._stucktimer > STUCK_TIMEOUT then
|
||||
mcl_burning.extinguish(self.object)
|
||||
self._removed = true
|
||||
self.object:remove()
|
||||
return true
|
||||
end
|
||||
|
||||
-- Drop arrow as item when it is no longer stuck
|
||||
-- TODO: revist after observer rework
|
||||
self._stuckrechecktimer = self._stuckrechecktimer + dtime
|
||||
if self._stuckrechecktimer > 1 then
|
||||
self._stuckrechecktimer = 0
|
||||
if self._stuckin then
|
||||
local node = minetest.get_node(self._stuckin)
|
||||
local node_def = minetest.registered_nodes[node.name]
|
||||
if node_def and node_def.walkable == false then
|
||||
mod.replace_with_item_drop(self, pos, entity_def, projectile_def)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Pickup arrow if player is nearby (not in Creative Mode)
|
||||
local objects = minetest.get_objects_inside_radius(pos, 1)
|
||||
for i = 1,#objects do
|
||||
obj = objects[i]
|
||||
if obj:is_player() then
|
||||
if self._collectable and not minetest.is_creative_enabled(obj:get_player_name()) then
|
||||
local arrow_item = self._arrow_item
|
||||
if arrow_item and minetest.registered_items[arrow_item] and obj:get_inventory():room_for_item("main", arrow_item) then
|
||||
obj:get_inventory():add_item("main", arrow_item)
|
||||
|
||||
minetest.sound_play("item_drop_pickup", {
|
||||
pos = pos,
|
||||
max_hear_distance = 16,
|
||||
gain = 1.0,
|
||||
}, true)
|
||||
end
|
||||
end
|
||||
mcl_burning.extinguish(self.object)
|
||||
self.object:remove()
|
||||
return
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
function mod.sticks(self, dtime, entity_def, projectile_def)
|
||||
-- Force the projectile to survive collisions (Otherwise, the projectile can't stick in nodes)
|
||||
projectile_def.survive_collision = true
|
||||
projectile_def.sticks_in_nodes = true
|
||||
|
||||
-- Stuck handling
|
||||
if self._stuck then
|
||||
return stuck_on_step(self, dtime, entity_def, projectile_def)
|
||||
end
|
||||
end
|
||||
|
||||
function mod.collides_with_solids(self, dtime, entity_def, projectile_def)
|
||||
local pos = self.object:get_pos()
|
||||
if not pos then return end
|
||||
|
@ -221,6 +347,55 @@ function mod.collides_with_solids(self, dtime, entity_def, projectile_def)
|
|||
end
|
||||
end
|
||||
|
||||
-- Handle sticking in nodes
|
||||
if projectile_def.sticks_in_nodes then
|
||||
local vel = self.object:get_velocity()
|
||||
local dpos = vector.round(pos) -- digital pos
|
||||
|
||||
-- Check for the node to which the arrow is pointing
|
||||
local dir
|
||||
if math.abs(vel.y) < 0.00001 then
|
||||
if self._last_pos.y < pos.y then
|
||||
dir = vector.new(0, 1, 0)
|
||||
else
|
||||
dir = vector.new(0, -1, 0)
|
||||
end
|
||||
else
|
||||
dir = minetest.facedir_to_dir(minetest.dir_to_facedir(minetest.yaw_to_dir(self.object:get_yaw()-YAW_OFFSET)))
|
||||
end
|
||||
self._stuckin = vector.add(dpos, dir)
|
||||
|
||||
local snode = minetest.get_node(self._stuckin)
|
||||
local sdef = minetest.registered_nodes[snode.name]
|
||||
|
||||
-- If node is non-walkable, unknown or ignore, don't make arrow stuck.
|
||||
-- This causes a deflection in the engine.
|
||||
if not sdef or sdef.walkable == false or snode.name == "ignore" then
|
||||
self._stuckin = nil
|
||||
if self._deflection_cooloff <= 0 then
|
||||
-- Lose 1/3 of velocity on deflection
|
||||
local newvel = vector.multiply(vel, 0.6667)
|
||||
|
||||
self.object:set_velocity(newvel)
|
||||
-- Reset deflection cooloff timer to prevent many deflections happening in quick succession
|
||||
self._deflection_cooloff = 1.0
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
-- Node was walkable, make arrow stuck
|
||||
self._stuck = true
|
||||
self._stucktimer = 0
|
||||
self._stuckrechecktimer = 0
|
||||
|
||||
self.object:set_velocity(vector.zero())
|
||||
self.object:set_acceleration(vector.zero())
|
||||
|
||||
-- Trigger hits on the node the projectile hit
|
||||
local hook = sdef._vl_projectile and sdef._vl_projectile.on_collide
|
||||
if hook then hook(self, self._stuckin, snode, sdef) end
|
||||
end
|
||||
|
||||
-- Call entity collied hook
|
||||
local hook = projectile_def.on_collide_with_solid
|
||||
if hook then hook(self, pos, node, node_def) end
|
||||
|
@ -363,6 +538,8 @@ function mod.raycast_collides_with_entities(self, dtime, entity_def, projectile_
|
|||
local closest_object, closest_distance
|
||||
|
||||
local pos = self.object:get_pos()
|
||||
if not pos then return end
|
||||
|
||||
local arrow_dir = self.object:get_velocity()
|
||||
|
||||
--create a raycast from the arrow based on the velocity of the arrow to deal with lag
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
name = vl_projectile
|
||||
depends = mcl_util
|
||||
optional_depends = vl_physics, mcl_shields, mcl_burning
|
||||
optional_depends = vl_physics, mcl_shields, mcl_burning, mcl_util
|
||||
|
|
Loading…
Reference in New Issue