tweak and tidy code

This commit is contained in:
tenplus1 2024-08-10 14:51:01 +01:00
parent 2e80d40af0
commit 543eb686c2
6 changed files with 62 additions and 77 deletions

View File

@ -1,11 +1,12 @@
-- Translation support
local S = minetest.get_translator("mobs_npc")
-- translation and mod check
local S = minetest.get_translator("mobs_npc")
local mcl = minetest.get_modpath("mcl_core") ~= nil
local def = minetest.get_modpath("default") ~= nil
-- show random message from list
mobs_npc.npc_talk = function(self, player, message_list)
local name = player:get_player_name() or ""
@ -19,8 +20,8 @@ mobs_npc.npc_talk = function(self, player, message_list)
end
end
-- drop random item from list
mobs_npc.drop_trade = function(self, player, item, item_list)
local w_inv = player:get_wielded_item()
@ -57,8 +58,8 @@ mobs_npc.drop_trade = function(self, player, item, item_list)
return true
end
-- check for simple_dialogs mod and setup
local context = {}
mobs_npc.useDialogs = "N"
@ -117,8 +118,8 @@ if minetest.get_modpath("simple_dialogs") then
end)
end
-- Kilarin's formspec functions
function mobs_npc.get_controls_formspec(name, self)
self.id = set_npc_id(self) -- make sure id is set
@ -157,8 +158,8 @@ function mobs_npc.get_controls_formspec(name, self)
return table.concat(formspec, "")
end
-- receive and do orders given through form
minetest.register_on_player_receive_fields(function(player, formname, fields)
local pname = player:get_player_name()
@ -209,8 +210,8 @@ minetest.register_on_player_receive_fields(function(player, formname, fields)
end
end)
-- check if npc has id set otherwise create one
function set_npc_id(npcself)
if not npcself.id then
@ -221,8 +222,8 @@ function set_npc_id(npcself)
return npcself.id
end
--this function finds an npcself in the luaentities list given an npcId
function get_npcself_from_id(npcId)
if npcId == nil then return nil end
@ -235,8 +236,6 @@ function get_npcself_from_id(npcId)
end
end
--This code comes almost exclusively from the trader and inventory of mobf, by Sapier.
--The copyright notice below is from mobf:
-------------------------------------------------------------------------------

View File

@ -1,10 +1,10 @@
-- Translation support
local S = minetest.get_translator("mobs_npc")
-- translation and mod check
local S = minetest.get_translator("mobs_npc")
local mcl = minetest.get_modpath("mcl_core") ~= nil
-- Igor by TenPlus1
-- right-click drops
mobs_npc.igor_drops = {
mcl and "mcl_potions:glass_bottle" or "vessels:glass_bottle",
@ -27,6 +27,7 @@ mobs_npc.igor_drops = {
mcl and "mcl_core:obsidian" or {"default:obsidian", 2}
}
-- Igor by TenPlus1
mobs:register_mob("mobs_npc:igor", {
type = "npc",
@ -78,16 +79,11 @@ mobs:register_mob("mobs_npc:igor", {
owner = "",
order = "wander",
animation = {
speed_normal = 30,
speed_run = 30,
stand_start = 0,
stand_end = 79,
walk_start = 168,
walk_end = 187,
run_start = 168,
run_end = 187,
punch_start = 189, --200
punch_end = 198 --219
speed_normal = 30, speed_run = 30,
stand_start = 0, stand_end = 79,
walk_start = 168, walk_end = 187,
run_start = 168, run_end = 187,
punch_start = 189, punch_end = 198 -- was 200 and 219
},
on_rightclick = function(self, clicker)
@ -103,6 +99,7 @@ mobs:register_mob("mobs_npc:igor", {
-- right clicking with gold lump drops random item from list
if mobs_npc.drop_trade(self, clicker, mcl and "mcl_raw_ores:raw_gold"
or "default:gold_lump", self.npc_drops or mobs_npc.igor_drops) then
return
end
@ -130,17 +127,17 @@ mobs:register_mob("mobs_npc:igor", {
end
})
-- spawn egg
-- register spawn egg
mobs:register_egg("mobs_npc:igor", S("Igor"),
mcl and "mcl_mobitems_beef_raw.png" or "mobs_meat_raw.png", 1)
-- compatibility with older mobs mod
-- this is only required for servers that used the old mobs mod
mobs:alias_mob("mobs:igor", "mobs_npc:igor")
-- spawn Igor in world
if not mobs.custom_spawn_npc then
mobs:spawn({

View File

@ -1,14 +1,13 @@
local path = minetest.get_modpath(minetest.get_current_modname()) .. "/"
-- Translation support
-- translation and get mod path
local S = minetest.get_translator("mobs_npc")
local path = minetest.get_modpath(minetest.get_current_modname()) .. "/"
-- Global
mobs_npc = {}
-- Check for custom mob spawn file
local input = io.open(path .. "spawn.lua", "r")
if input then
@ -17,26 +16,21 @@ if input then
input = nil
end
-- useful functions
dofile(path .. "functions.lua")
-- NPCs
dofile(path .. "functions.lua") -- useful functions
dofile(path .. "npc.lua") -- TenPlus1
dofile(path .. "trader.lua")
dofile(path .. "igor.lua")
-- Load custom spawning if found
-- Load custom spawning
if mobs.custom_spawn_npc then
dofile(path .. "spawn.lua")
end
-- Lucky Blocks
if minetest.get_modpath("lucky_block") then
dofile(path .. "/lucky_block.lua")
end
print ("[MOD] Mobs NPC loaded")

View File

@ -1,3 +1,6 @@
-- add lucky blocks
lucky_block:add_blocks({
{"spw", "mobs:npc", 1, true, true},
{"spw", "mobs:igor", 1, true, true, 5, "Igor"},

32
npc.lua
View File

@ -1,9 +1,10 @@
-- Translation support
local S = minetest.get_translator("mobs_npc")
-- translation and mod check
local S = minetest.get_translator("mobs_npc")
local mcl = minetest.get_modpath("mcl_core") ~= nil
-- Npc by TenPlus1
-- right-click drops
mobs_npc.npc_drops = {
{mcl and "mcl_tools:pick_iron" or "default:pick_steel", 2},
@ -26,6 +27,7 @@ mobs_npc.npc_drops = {
mcl and "mcl_core:frosted_ice" or "default:permafrost_with_moss"
}
-- Npc by TenPlus1
mobs:register_mob("mobs_npc:npc", {
type = "npc",
@ -77,16 +79,11 @@ mobs:register_mob("mobs_npc:npc", {
order = "wander",
fear_height = 3,
animation = {
speed_normal = 30,
speed_run = 30,
stand_start = 0,
stand_end = 79,
walk_start = 168,
walk_end = 187,
run_start = 168,
run_end = 187,
punch_start = 189, --200
punch_end = 198 --219
speed_normal = 30, speed_run = 30,
stand_start = 0, stand_end = 79,
walk_start = 168, walk_end = 187,
run_start = 168, run_end = 187,
punch_start = 189, punch_end = 198 -- was 200 and 219
},
on_rightclick = function(self, clicker)
@ -106,6 +103,7 @@ mobs:register_mob("mobs_npc:npc", {
-- right clicking with gold lump drops random item from list
if mobs_npc.drop_trade(self, clicker, mcl and "mcl_raw_ores:raw_gold"
or "default:gold_lump", self.npc_drops or mobs_npc.npc_drops) then
return
end
@ -134,23 +132,23 @@ mobs:register_mob("mobs_npc:npc", {
end
})
-- spawn egg
-- register spawn egg
mobs:register_egg("mobs_npc:npc", S("Npc"),
mcl and "default_stone_brick.png" or "default_brick.png", 1)
-- compatibility with older mobs mod
-- this is only needed for servers that used the old mobs mod
mobs:alias_mob("mobs:npc", "mobs_npc:npc")
-- spawn NPC in world
if not mobs.custom_spawn_npc then
mobs:spawn({
name = "mobs_npc:npc",
nodes = {mcl and "mcl_core:stonebrick" or "default:brick"},
neighbors = {mcl and "mcl_flowers:tallgrass" or "default:grass_3"},
neighbors = {mcl and "mcl_flowers:tallgrass" or "group:grass"},
min_light = 10,
chance = 10000,
active_object_count = 1,

View File

@ -1,7 +1,6 @@
-- Translation support
-- translation and mod check
local S = minetest.get_translator("mobs_npc")
local mcl = minetest.get_modpath("mcl_core") ~= nil
-- define table containing names for use and shop items for sale
@ -98,16 +97,11 @@ mobs:register_mob("mobs_npc:trader", {
order = "stand",
fear_height = 3,
animation = {
speed_normal = 30,
speed_run = 30,
stand_start = 0,
stand_end = 79,
walk_start = 168,
walk_end = 187,
run_start = 168,
run_end = 187,
punch_start = 189, --200
punch_end = 198 --219
speed_normal = 30, speed_run = 30,
stand_start = 0, stand_end = 79,
walk_start = 168, walk_end = 187,
run_start = 168, run_end = 187,
punch_start = 189, punch_end = 198 -- was 200 and 219
},
-- stop attacking on right-click and open shop
@ -127,6 +121,7 @@ mobs:register_mob("mobs_npc:trader", {
-- owner can right-click with stick to show control formspec
local item = clicker:get_wielded_item()
local name = clicker:get_player_name()
if item:get_name() == (mcl and "mcl_core:stick" or "default:stick")
and (self.owner == name or
minetest.check_player_privs(clicker, {protection_bypass = true}) )then
@ -155,19 +150,18 @@ mobs:register_mob("mobs_npc:trader", {
end
})
-- spawn egg
-- add spawn egg
mobs:register_egg("mobs_npc:trader", S("Trader"),
mcl and "mcl_core_sandstone_top.png" or "default_sandstone.png", 1)
-- this is only required for servers that previously used the old mobs mod
-- compatibility with older mobs mod
mobs:alias_mob("mobs:trader", "mobs_npc:trader")
-- make global and add functions and list
local trader_lists = {}
-- global function to add to list
mobs_npc.add_trader_list = function(def)
table.insert(trader_lists, def)
end
@ -188,8 +182,8 @@ mobs_npc.add_trader_list({
}
})
-- helper function
local function place_trader(pos, node)
local face = node.param2
@ -248,11 +242,11 @@ local function place_trader(pos, node)
-- pop sound
minetest.sound_play("default_place_node_hard", {
pos = pos, gain = 1.0, max_hear_distance = 5, pitch = 2.0})
pos = pos, gain = 1.0, max_hear_distance = 5, pitch = 2.0}, true)
end
-- trader block (punch to spawn trader)
minetest.register_node(":mobs:trader_block", {
description = S("Place this and punch to spawn Trader"),
groups = {cracky = 3},
@ -272,8 +266,8 @@ minetest.register_node(":mobs:trader_block", {
on_blast = function() end
})
-- trader block recipe
local db = mcl and "mcl_core:diamondblock" or "default:diamondblock"
local tb = mcl and "mcl_core:ironblock" or "default:tinblock"