mirror of
https://git.minetest.land/MineClone2/MineClone2.git
synced 2024-12-12 12:43:15 +01:00
Break long lines, add space between functions in vl_projectile/init.lua
This commit is contained in:
parent
429b55b9c6
commit
430cd8dffa
@ -179,7 +179,8 @@ end
|
|||||||
---Allow to bypass the `buildable_to` node field in a `on_place` callback.
|
---Allow to bypass the `buildable_to` node field in a `on_place` callback.
|
||||||
---
|
---
|
||||||
---You have to make sure that the nodes you return true for have `buildable_to = true`.
|
---You have to make sure that the nodes you return true for have `buildable_to = true`.
|
||||||
---@param func fun(node_name: string): boolean Return `true` if node must not replace the buildable_to node which have `node_name`
|
---@param func fun(node_name: string): boolean Return `true` if node must not replace the buildable_to node
|
||||||
|
--- which have `node_name`
|
||||||
---@return fun(itemstack: ItemStack, placer: ObjectRef, pointed_thing: pointed_thing, param2: integer): ItemStack?
|
---@return fun(itemstack: ItemStack, placer: ObjectRef, pointed_thing: pointed_thing, param2: integer): ItemStack?
|
||||||
function mcl_util.bypass_buildable_to(func)
|
function mcl_util.bypass_buildable_to(func)
|
||||||
-- Copied from minetest builtin
|
-- Copied from minetest builtin
|
||||||
@ -406,7 +407,8 @@ function mcl_util.get_palette_indexes_from_pos(pos)
|
|||||||
local biome = biome_data.biome
|
local biome = biome_data.biome
|
||||||
local biome_name = core.get_biome_name(biome)
|
local biome_name = core.get_biome_name(biome)
|
||||||
local reg_biome = core.registered_biomes[biome_name]
|
local reg_biome = core.registered_biomes[biome_name]
|
||||||
if reg_biome and reg_biome._mcl_grass_palette_index and reg_biome._mcl_foliage_palette_index and reg_biome._mcl_water_palette_index then
|
if reg_biome and reg_biome._mcl_grass_palette_index and reg_biome._mcl_foliage_palette_index
|
||||||
|
and reg_biome._mcl_water_palette_index then
|
||||||
return {
|
return {
|
||||||
grass_palette_index = reg_biome._mcl_grass_palette_index,
|
grass_palette_index = reg_biome._mcl_grass_palette_index,
|
||||||
foliage_palette_index = reg_biome._mcl_foliage_palette_index,
|
foliage_palette_index = reg_biome._mcl_foliage_palette_index,
|
||||||
@ -432,7 +434,9 @@ function mcl_util.match_node_to_filter(node_name, filters)
|
|||||||
local filter = filters[i]
|
local filter = filters[i]
|
||||||
if node_name == filter then return true end
|
if node_name == filter then return true end
|
||||||
|
|
||||||
if string.sub(filter,1,6) == "group:" and core.get_item_group(node_name, string.sub(filter,7)) ~= 0 then return true end
|
if string.sub(filter,1,6) == "group:" and core.get_item_group(node_name, string.sub(filter,7)) ~= 0 then
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return false
|
return false
|
||||||
|
@ -266,7 +266,8 @@ functions needed for the mob to work properly which contains the following:
|
|||||||
|
|
||||||
mobs:gopath(self,target,callback_arrived) pathfind a way to target and run callback on arrival
|
mobs:gopath(self,target,callback_arrived) pathfind a way to target and run callback on arrival
|
||||||
'_vl_projectile' Table with Projectile API behaviors. Current members are:
|
'_vl_projectile' Table with Projectile API behaviors. Current members are:
|
||||||
'can_punch(self, projectile_luaentity)' return 'false' from this function to prevent the provided projectile from colliding with the mob
|
'can_punch(self, projectile_luaentity)' return 'false' from this function to prevent the provided projectile
|
||||||
|
from colliding with the mob
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -486,7 +487,8 @@ This function registers a arrow for mobs with the attack type shoot.
|
|||||||
'rotate' integer value in degrees to rotate arrow
|
'rotate' integer value in degrees to rotate arrow
|
||||||
'on_step' is a custom function when arrow is active, nil for
|
'on_step' is a custom function when arrow is active, nil for
|
||||||
default.
|
default.
|
||||||
'_vl_projectile' table with Projectile API properties. Refer to mods/ITEMS/vl_projectile/api.md for documentation.
|
'_vl_projectile' table with Projectile API properties. Refer to mods/ITEMS/vl_projectile/api.md
|
||||||
|
for documentation.
|
||||||
|
|
||||||
|
|
||||||
Spawn Eggs
|
Spawn Eggs
|
||||||
|
@ -415,8 +415,11 @@ function mcl_mobs.register_arrow(name, def)
|
|||||||
ignore_gravity = true,
|
ignore_gravity = true,
|
||||||
damages_players = true,
|
damages_players = true,
|
||||||
allow_punching = function(self, entity_def, projectile_def, object)
|
allow_punching = function(self, entity_def, projectile_def, object)
|
||||||
if def.allow_punching and not def.allow_punching(self, entity_def, projectile_def, object) then return false end
|
if def.allow_punching and not def.allow_punching(self, entity_def, projectile_def, object) then
|
||||||
if self.timer < 2 and self._owner and mcl_util.get_entity_id(object) == self._owner then return false end
|
return false
|
||||||
|
elseif self.timer < 2 and self._owner and mcl_util.get_entity_id(object) == self._owner then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end,
|
end,
|
||||||
|
@ -128,7 +128,8 @@ mcl_mobs.register_arrow("mobs_mc:fireball", {
|
|||||||
local name = mob:get_luaentity().name
|
local name = mob:get_luaentity().name
|
||||||
mcl_mobs.mob_class.boom(self,self.object:get_pos(), 1, true)
|
mcl_mobs.mob_class.boom(self,self.object:get_pos(), 1, true)
|
||||||
local ent = mob:get_luaentity()
|
local ent = mob:get_luaentity()
|
||||||
if (not ent or ent.health <= 0) and self._owner and core.get_player_by_name(self._owner) and name == "mobs_mc:ghast" then
|
if (not ent or ent.health <= 0) and self._owner and core.get_player_by_name(self._owner)
|
||||||
|
and name == "mobs_mc:ghast" then
|
||||||
awards.unlock(self._owner, "mcl:fireball_redir_serv")
|
awards.unlock(self._owner, "mcl:fireball_redir_serv")
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
|
@ -108,12 +108,14 @@ local arrow_entity = {
|
|||||||
if obj:get_hp() > 0 then
|
if obj:get_hp() > 0 then
|
||||||
if lua then
|
if lua then
|
||||||
local entity_name = lua.name
|
local entity_name = lua.name
|
||||||
-- Achievement for hitting skeleton, wither skeleton or stray (TODO) with an arrow at least 50 meters away
|
-- Achievement for hitting skeleton, wither skeleton or stray (TODO) with an arrow at least 50
|
||||||
|
-- meters away
|
||||||
-- NOTE: Range has been reduced because mobs unload much earlier than that ... >_>
|
-- NOTE: Range has been reduced because mobs unload much earlier than that ... >_>
|
||||||
-- TODO: This achievement should be given for the kill, not just a hit
|
-- TODO: This achievement should be given for the kill, not just a hit
|
||||||
local shooter = self._vl_projectile.owner
|
local shooter = self._vl_projectile.owner
|
||||||
if shooter and shooter:is_player() and vector.distance(pos, self._startpos) >= 20 then
|
if shooter and shooter:is_player() and vector.distance(pos, self._startpos) >= 20 then
|
||||||
if mod_awards and (entity_name == "mobs_mc:skeleton" or entity_name == "mobs_mc:stray" or entity_name == "mobs_mc:witherskeleton") then
|
if mod_awards and (entity_name == "mobs_mc:skeleton" or entity_name == "mobs_mc:stray"
|
||||||
|
or entity_name == "mobs_mc:witherskeleton") then
|
||||||
awards.unlock(shooter:get_player_name(), "mcl:snipeSkeleton")
|
awards.unlock(shooter:get_player_name(), "mcl:snipeSkeleton")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -130,8 +132,8 @@ local arrow_entity = {
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Because arrows are flagged to survive collisions to allow sticking into blocks, manually remove it now that it
|
-- Because arrows are flagged to survive collisions to allow sticking into blocks, manually remove it
|
||||||
-- has collided with an entity
|
-- now that it has collided with an entity
|
||||||
if not is_player then
|
if not is_player then
|
||||||
mcl_util.remove_entity(self)
|
mcl_util.remove_entity(self)
|
||||||
end
|
end
|
||||||
|
@ -9,31 +9,37 @@ Arguments:
|
|||||||
* `entity_name`: The name the entity will be refered to by the Luanti engine
|
* `entity_name`: The name the entity will be refered to by the Luanti engine
|
||||||
* `def`: Projectile defintion. Supports all fields that standard Luanti entities support.
|
* `def`: Projectile defintion. Supports all fields that standard Luanti entities support.
|
||||||
Must include the field `_vl_projectile` for projectile-specific behaviors. These are the supported
|
Must include the field `_vl_projectile` for projectile-specific behaviors. These are the supported
|
||||||
fields:
|
fields:
|
||||||
* `ignore_gravity`: if true, the projectile will not be affected by gravity
|
* `ignore_gravity`: if true, the projectile will not be affected by gravity
|
||||||
* `liquid_drag`: if true, apply drag from liquid nodes to the projectile
|
* `liquid_drag`: if true, apply drag from liquid nodes to the projectile
|
||||||
* `survive_collision`: if this field is `false` or `nil`, the projectile will be removed after a collision.
|
* `survive_collision`: if this field is `false` or `nil`, the projectile will be removed after a collision.
|
||||||
* `sticks_in_players`: if true, the projectile will stick into players after colliding with them.
|
* `sticks_in_players`: if true, the projectile will stick into players after colliding with them.
|
||||||
* `damages_players`: if true, the projectile will deal damage to players.
|
* `damages_players`: if true, the projectile will deal damage to players.
|
||||||
* `damage_groups`: damage group information to use for `punch()`. May be a function of type `function(projectile, entity_def, projectile_def, obj)`
|
* `damage_groups`: damage group information to use for `punch()`. May be a function of type `function(projectile,
|
||||||
that returns dynamic damange group information.
|
entity_def, projectile_def, obj)` that returns dynamic damange group information.
|
||||||
* `allow_punching`: will the projectile punch entities it collides with. May be either a boolean or a function of type `function(projectile, entity_def, projectile_def, obj)`.
|
* `allow_punching`: will the projectile punch entities it collides with. May be either a boolean or a function
|
||||||
* `survive_collision`: will the projectile surive collisions. May be either a boolean or a fnction of type `function(projectile, entity_def, projectile_def, type, ...)`.
|
of type `function(projectile, entity_def, projectile_def, obj)`.
|
||||||
|
* `survive_collision`: will the projectile surive collisions. May be either a boolean or a function of type
|
||||||
|
`function(projectile, entity_def, projectile_def, type, ...)`.
|
||||||
* If `type` is "node" then the additional parameters `node, node_def` will be provided.
|
* If `type` is "node" then the additional parameters `node, node_def` will be provided.
|
||||||
* If `type` is "entity" then the additional parameter `objet` will be provided.
|
* If `type` is "entity" then the additional parameter `objet` will be provided.
|
||||||
* `behaviors`: a list of behavior callbacks that define the projectile's behavior. This mod provides the following
|
* `behaviors`: a list of behavior callbacks that define the projectile's behavior. This mod provides the following
|
||||||
behaviors: `vl_projectiles.collides_with_solids`, `vl_projectiles.collides_with_entities` and `vl_projectiles.raycast_collides_with_entities`
|
behaviors: `vl_projectiles.collides_with_solids`, `vl_projectiles.collides_with_entities`
|
||||||
|
and `vl_projectiles.raycast_collides_with_entities`
|
||||||
* `maximum_time`: number of seconds until projectiles are removed.
|
* `maximum_time`: number of seconds until projectiles are removed.
|
||||||
* `sounds`: sounds for this projectile. All fields take a table with three parameters corresponding to the
|
* `sounds`: sounds for this projectile. All fields take a table with three parameters corresponding to the
|
||||||
three parameters for `core.play_sound()`. Supported sounds are:
|
three parameters for `core.play_sound()`. Supported sounds are:
|
||||||
* `on_collision`: played when no other more specific sound is defined. May be a function of type `function(projectile, entity_def, projectile_def, type, ...)`
|
* `on_collision`: played when no other more specific sound is defined. May be a function of type
|
||||||
|
`function(projectile, entity_def, projectile_def, type, ...)`
|
||||||
* `on_solid_collision`: played when the projectile collides with a solid node. May be a function of type
|
* `on_solid_collision`: played when the projectile collides with a solid node. May be a function of type
|
||||||
`funciton(projectile, entity_def, projectile_def, type, pos, node, node_def)` with `type = "node"`
|
`funciton(projectile, entity_def, projectile_def, type, pos, node, node_def)` with `type = "node"`
|
||||||
* `on_entity_collision`: played when the projectile collides with another entity. May be a function of type
|
* `on_entity_collision`: played when the projectile collides with another entity. May be a function of type
|
||||||
`function(projectile, entity_def, projectile_def, type, entity)` with `type = "entity"`
|
`function(projectile, entity_def, projectile_def, type, entity)` with `type = "entity"`
|
||||||
* `on_collide_with_solid`: callback of type `function(projectile, pos, node, node_def)` used when the projectile collides with a solid node. Requires
|
* `on_collide_with_solid`: callback of type `function(projectile, pos, node, node_def)` used when the projectile
|
||||||
|
collides with a solid node. Requires
|
||||||
`vl_projectile.collides_with_solids` in `behaviors` list.
|
`vl_projectile.collides_with_solids` in `behaviors` list.
|
||||||
* `on_collide_with_entity`: callback of type `function(projectile, pos, obj)` used when the projectile collides with an entity. Requires
|
* `on_collide_with_entity`: callback of type `function(projectile, pos, obj)` used when the projectile collides
|
||||||
|
with an entity. Requires
|
||||||
`vl_projectile.collides_with_entities` in `behaviors` list.
|
`vl_projectile.collides_with_entities` in `behaviors` list.
|
||||||
|
|
||||||
## `vl_projectile.update_projectile(self, dtime)`
|
## `vl_projectile.update_projectile(self, dtime)`
|
||||||
|
@ -123,6 +123,7 @@ local function damage_particles(pos, is_critical)
|
|||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function random_hit_positions(positions, placement)
|
local function random_hit_positions(positions, placement)
|
||||||
if positions == "x" then
|
if positions == "x" then
|
||||||
return math.random(-4, 4)
|
return math.random(-4, 4)
|
||||||
@ -138,6 +139,7 @@ local function random_hit_positions(positions, placement)
|
|||||||
|
|
||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
local function check_hitpoint(hitpoint)
|
local function check_hitpoint(hitpoint)
|
||||||
if hitpoint.type ~= "object" then return false end
|
if hitpoint.type ~= "object" then return false end
|
||||||
|
|
||||||
@ -157,6 +159,7 @@ local function check_hitpoint(hitpoint)
|
|||||||
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local function handle_player_sticking(self, entity_def, projectile_def, entity)
|
local function handle_player_sticking(self, entity_def, projectile_def, entity)
|
||||||
if self._in_player or self._blocked then return end
|
if self._in_player or self._blocked then return end
|
||||||
if not projectile_def.sticks_in_players then return end
|
if not projectile_def.sticks_in_players then return end
|
||||||
@ -225,6 +228,7 @@ function mod.has_owner_grace_distance(self, dtime, entity_def, projectile_def)
|
|||||||
not self._owner or not self._startpos or
|
not self._owner or not self._startpos or
|
||||||
pos and vector.distance(self._startpos, pos) > ( projectile_def.grace_distance or 1.5 )
|
pos and vector.distance(self._startpos, pos) > ( projectile_def.grace_distance or 1.5 )
|
||||||
end
|
end
|
||||||
|
|
||||||
function mod.has_tracer(self, dtime, entity_def, projectile_def)
|
function mod.has_tracer(self, dtime, entity_def, projectile_def)
|
||||||
local hide_tracer = projectile_def.hide_tracer
|
local hide_tracer = projectile_def.hide_tracer
|
||||||
if hide_tracer and hide_tracer(self) then return end
|
if hide_tracer and hide_tracer(self) then return end
|
||||||
@ -310,7 +314,8 @@ local function stuck_on_step(self, dtime, entity_def, projectile_def)
|
|||||||
local creative = core.is_creative_enabled(player_name)
|
local creative = core.is_creative_enabled(player_name)
|
||||||
if self._collectable and not creative then
|
if self._collectable and not creative then
|
||||||
local arrow_item = self._itemstring or self._arrow_item
|
local arrow_item = self._itemstring or self._arrow_item
|
||||||
if arrow_item and core.registered_items[arrow_item] and obj:get_inventory():room_for_item("main", arrow_item) then
|
if arrow_item and core.registered_items[arrow_item]
|
||||||
|
and obj:get_inventory():room_for_item("main", arrow_item) then
|
||||||
obj:get_inventory():add_item("main", arrow_item)
|
obj:get_inventory():add_item("main", arrow_item)
|
||||||
self._picked_up = true
|
self._picked_up = true
|
||||||
end
|
end
|
||||||
@ -655,4 +660,3 @@ function mod.register(name, def)
|
|||||||
|
|
||||||
core.register_entity(name, def)
|
core.register_entity(name, def)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user