From 430cd8dffae257a3187efe253de65c877ba848c6 Mon Sep 17 00:00:00 2001 From: teknomunk Date: Thu, 5 Dec 2024 10:56:59 -0600 Subject: [PATCH] Break long lines, add space between functions in vl_projectile/init.lua --- mods/CORE/mcl_util/nodes.lua | 10 +++++++--- mods/ENTITIES/mcl_mobs/api.txt | 6 ++++-- mods/ENTITIES/mcl_mobs/init.lua | 7 +++++-- mods/ENTITIES/mobs_mc/ghast.lua | 3 ++- mods/ITEMS/mcl_bows/arrow.lua | 10 ++++++---- mods/ITEMS/vl_projectile/api.md | 24 +++++++++++++++--------- mods/ITEMS/vl_projectile/init.lua | 8 ++++++-- 7 files changed, 45 insertions(+), 23 deletions(-) diff --git a/mods/CORE/mcl_util/nodes.lua b/mods/CORE/mcl_util/nodes.lua index 07010e4a7..96ec3260b 100644 --- a/mods/CORE/mcl_util/nodes.lua +++ b/mods/CORE/mcl_util/nodes.lua @@ -179,7 +179,8 @@ end ---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`. ----@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? function mcl_util.bypass_buildable_to(func) -- Copied from minetest builtin @@ -406,7 +407,8 @@ function mcl_util.get_palette_indexes_from_pos(pos) local biome = biome_data.biome local biome_name = core.get_biome_name(biome) 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 { grass_palette_index = reg_biome._mcl_grass_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] 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 return false diff --git a/mods/ENTITIES/mcl_mobs/api.txt b/mods/ENTITIES/mcl_mobs/api.txt index bf903ded0..69bccf15b 100644 --- a/mods/ENTITIES/mcl_mobs/api.txt +++ b/mods/ENTITIES/mcl_mobs/api.txt @@ -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 '_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 'on_step' is a custom function when arrow is active, nil for 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 diff --git a/mods/ENTITIES/mcl_mobs/init.lua b/mods/ENTITIES/mcl_mobs/init.lua index ccb7eaade..a507a9e68 100644 --- a/mods/ENTITIES/mcl_mobs/init.lua +++ b/mods/ENTITIES/mcl_mobs/init.lua @@ -415,8 +415,11 @@ function mcl_mobs.register_arrow(name, def) ignore_gravity = true, damages_players = true, 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 self.timer < 2 and self._owner and mcl_util.get_entity_id(object) == self._owner then return false end + if def.allow_punching and not def.allow_punching(self, entity_def, projectile_def, object) then + return false + elseif self.timer < 2 and self._owner and mcl_util.get_entity_id(object) == self._owner then + return false + end return true end, diff --git a/mods/ENTITIES/mobs_mc/ghast.lua b/mods/ENTITIES/mobs_mc/ghast.lua index 93e12f320..8cbad4eb4 100644 --- a/mods/ENTITIES/mobs_mc/ghast.lua +++ b/mods/ENTITIES/mobs_mc/ghast.lua @@ -128,7 +128,8 @@ mcl_mobs.register_arrow("mobs_mc:fireball", { local name = mob:get_luaentity().name mcl_mobs.mob_class.boom(self,self.object:get_pos(), 1, true) 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") end end, diff --git a/mods/ITEMS/mcl_bows/arrow.lua b/mods/ITEMS/mcl_bows/arrow.lua index 14ada2d98..1e260443b 100644 --- a/mods/ITEMS/mcl_bows/arrow.lua +++ b/mods/ITEMS/mcl_bows/arrow.lua @@ -108,12 +108,14 @@ local arrow_entity = { if obj:get_hp() > 0 then 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 + -- 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 ... >_> -- TODO: This achievement should be given for the kill, not just a hit local shooter = self._vl_projectile.owner 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") end end @@ -130,8 +132,8 @@ local arrow_entity = { return end - -- Because arrows are flagged to survive collisions to allow sticking into blocks, manually remove it now that it - -- has collided with an entity + -- Because arrows are flagged to survive collisions to allow sticking into blocks, manually remove it + -- now that it has collided with an entity if not is_player then mcl_util.remove_entity(self) end diff --git a/mods/ITEMS/vl_projectile/api.md b/mods/ITEMS/vl_projectile/api.md index 614c18e18..393102637 100644 --- a/mods/ITEMS/vl_projectile/api.md +++ b/mods/ITEMS/vl_projectile/api.md @@ -9,31 +9,37 @@ Arguments: * `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. 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 * `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. * `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. - * `damage_groups`: damage group information to use for `punch()`. May be a function of type `function(projectile, 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)`. - * `survive_collision`: will the projectile surive collisions. May be either a boolean or a fnction of type `function(projectile, entity_def, projectile_def, type, ...)`. + * `damage_groups`: damage group information to use for `punch()`. May be a function of type `function(projectile, + 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)`. + * `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 "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: `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. * `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: - * `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 `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 `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. - * `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.update_projectile(self, dtime)` diff --git a/mods/ITEMS/vl_projectile/init.lua b/mods/ITEMS/vl_projectile/init.lua index 9dd9bbcb5..d800ec191 100644 --- a/mods/ITEMS/vl_projectile/init.lua +++ b/mods/ITEMS/vl_projectile/init.lua @@ -123,6 +123,7 @@ local function damage_particles(pos, is_critical) }) end end + local function random_hit_positions(positions, placement) if positions == "x" then return math.random(-4, 4) @@ -138,6 +139,7 @@ local function random_hit_positions(positions, placement) return 0 end + local function check_hitpoint(hitpoint) if hitpoint.type ~= "object" then return false end @@ -157,6 +159,7 @@ local function check_hitpoint(hitpoint) return false end + local function handle_player_sticking(self, entity_def, projectile_def, entity) if self._in_player or self._blocked 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 pos and vector.distance(self._startpos, pos) > ( projectile_def.grace_distance or 1.5 ) 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 @@ -310,7 +314,8 @@ local function stuck_on_step(self, dtime, entity_def, projectile_def) local creative = core.is_creative_enabled(player_name) if self._collectable and not creative then 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) self._picked_up = true end @@ -655,4 +660,3 @@ function mod.register(name, def) core.register_entity(name, def) end -