Commit a70acb23 authored by Aaron Suen's avatar Aaron Suen

New project, first working version.

parents
Pipeline #54337954 failed with stages
in 1 minute and 18 seconds
Copyright (C)2019 by Aaron Suen <warr1024@gmail.com>
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-- LUALOCALS < ---------------------------------------------------------
local minetest, pairs, table
= minetest, pairs, table
local table_sort
= table.sort
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
local cmd = "rs"
minetest.register_privilege(modname, {
description = "Can create replica nodes",
give_to_singleplayer = false,
})
local db = {}
for k, v in pairs(minetest.registered_nodes) do
if v.liquidtype ~= "flowing" then
if k:sub(1, #modname + 1) == modname .. ":" then
for s in v.description
:lower()
:gsub("replica ", "")
:gmatch("%w+") do
local x = db[s]
if not x then x = {} db[s] = x end
x[k] = 1
end
end
end
end
local results = {}
local function search(name, param)
local u = {}
local need = 0
for s in param:lower():gmatch("%w+") do
need = need + 1
for k, v in pairs(db) do
if k:find(s, 1, true) then
for x in pairs(v) do
u[x] = (u[x] or 0) + 1
end
end
end
end
for k, v in pairs(u) do
if v < need then
u[k] = nil
end
end
t = {}
for k in pairs(u) do
local r = minetest.registered_nodes[k]
local o = minetest.registered_nodes[r.replica_original] or r
t[#t + 1] = {
name = k,
orig = o.name,
desc = o.description
}
end
if #t < 1 then
return false, "No results found."
end
if #t == 1 then
return minetest.registered_chatcommands
.giveme.func(name, t[1].name)
end
while #t > 8 do t[#t] = nil end
table_sort(t, function(a, b)
if a.desc == b.desc then
return a.orig < b.orig
end
return a.desc < b.desc
end)
results[name] = t
for i, v in pairs(t) do
minetest.chat_send_player(name, "/" .. cmd .. " " .. i
.. " -> " .. v.desc .. " (" .. v.orig .. ")")
end
end
minetest.register_chatcommand(cmd, {
params = "<search>",
description = "Replica node search",
privs = {[modname] = true},
func = function(name, param)
local res = results[name]
if res then
local num = tonumber(param)
if res[num] then
return minetest.registered_chatcommands
.giveme.func(name, res[num].name)
end
end
return search(name, param)
end
})
nc_api
nc_api_craft
nc_fire?
nc_items?
nc_lode?
nc_optics?
nc_sponge?
nc_stonework?
nc_terrain?
nc_tote?
nc_tree?
nc_woodwork?
\ No newline at end of file
include("nodes")
include("command")
-- LUALOCALS < ---------------------------------------------------------
local ItemStack, ipairs, minetest, pairs
= ItemStack, ipairs, minetest, pairs
-- LUALOCALS > ---------------------------------------------------------
local modname = minetest.get_current_modname()
local function regnode(name, def)
def.on_drop = function() return "" end
def.on_place = function(stack, ...)
local s = minetest.item_place(ItemStack(stack), ...)
return s:is_empty() and stack or s
end
def.on_dig = function(a, b, digger, ...)
if digger and digger:is_player()
and minetest.check_player_privs(digger, modname) then
return minetest.node_dig(a, b, digger, ...)
end
end
return minetest.register_node(name, def)
end
local function cname(k)
if not k then return k end
if k:sub(1, 3) == "nc_" then k = k:sub(4) end
return modname .. ":" .. k:gsub("%W", "_")
end
local deferred = {}
for k, v in pairs(minetest.registered_nodes) do
if (not v.virtual_item) and (not v.groups.is_stack_only) then
local def = {
replica_original = v.name,
description = "Replica " .. v.description,
drawtype = v.drawtype,
visual_scale = v.visual_scale,
wield_scale = v.wield_scale,
tiles = v.tiles,
special_tiles = v.special_tiles,
alpha = v.alpha,
node_box = v.node_box,
collison_box = v.collision_box,
selection_box = v.selection_box,
inventory_image = v.inventory_image,
wield_image = v.wield_image,
paramtype2 = v.paramtype2,
paramtype = v.paramtype,
light_source = v.light_source,
sunlight_propagates = v.sunlight_propagates,
groups = {snappy = 1},
pointable = true,
buildable_to = false,
liquidtype = v.liquidtype,
liquid_renewable = false,
liquid_range = 2,
liquid_alternative_flowing = cname(v.liquid_alternative_flowing),
liquid_alternative_source = cname(v.liquid_alternative_source),
}
if v.paramtype2 == "facedir" then
def.on_rightclick = v.on_rightclick
end
deferred[#deferred + 1] = function()
regnode(cname(k), def)
end
end
end
for _, v in ipairs(deferred) do v() end
regnode(modname .. ":smoke", {
replica_original = true,
description = "Smoke Generator",
drawtype = "airlike",
inventory_image = "nc_api_craft_smoke.png",
wield_image = "nc_api_craft_smoke.png",
walkable = false,
pointable = true,
paramtype = "light",
sunlight_propagates = true,
groups = {snappy = 1}
})
nodecore.register_limited_abm({
label = "Smoke Source",
nodenames = {modname .. ":smoke"},
interval = 1,
chance = 1,
action = function(pos)
pos.y = pos.y - 1
nodecore.smokefx(pos, 1)
end
})
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment