See first post.keyxmakerx wrote:Any news when the download will be fixed?
[Mod] Delete unknown blocks and objects [1] [clean]
-
- Member
- Posts: 104
- Joined: Mon Apr 08, 2013 23:53
- BrandonReese
- Member
- Posts: 839
- Joined: Wed Sep 12, 2012 00:44
- GitHub: bremaweb
- IRC: BrandonReese
- In-game: BrandonReese
- Location: USA
Dig one and watch the console it will say <Player> digs <node name> at <position>keyxmakerx wrote:Sorry I'm not understanding. What if I don't know what the unknown blocks were?PilzAdam wrote:See first post.keyxmakerx wrote:Any news when the download will be fixed?
Last edited by BrandonReese on Sun Jun 09, 2013 03:49, edited 1 time in total.
My Twitch Channel - https://www.twitch.tv/brandonreese81/profile
-
- Member
- Posts: 104
- Joined: Mon Apr 08, 2013 23:53
- JPRuehmann
- Member
- Posts: 334
- Joined: Fri Mar 21, 2014 21:40
- Location: Germany
- Contact:
- hoodedice
- Member
- Posts: 1374
- Joined: Sat Jul 06, 2013 06:33
- GitHub: hoodedice
- IRC: hoodedice
- In-game: hoodedice
- Location: world
- Contact:
1. Make a folder called 'clean'. (Without quotes)JPRuehmann wrote:link is broken
2. Right click, scroll to 'New'. Click 'Text files' in the context menu.
3. Rename text file to 'init.lua' (Without quotes). Open it.
4. Go to first link in thread, copy entire stuff in the code box.
5. Paste stuff into new text file you made.
6. Just to be sure, click 'File', 'Save As...' and type "init.lua" (WITH Quotes) and save.
7. ???
8. Only if everyone used GitHub...
7:42 PM - Bauglio: I think if you go to staples you could steal firmware from a fax machine that would run better than win10 does on any platform
7:42 PM - Bauglio: so fudge the stable build
7:43 PM - Bauglio: get the staple build
7:42 PM - Bauglio: so fudge the stable build
7:43 PM - Bauglio: get the staple build
- JPRuehmann
- Member
- Posts: 334
- Joined: Fri Mar 21, 2014 21:40
- Location: Germany
- Contact:
Re: [Mod] Delete unknown blocks and objects [1] [clean]
This mod dates from almost two years ago. Surely, there must be more efficient ways of removing unknown nodes now. First, there would have to be a way to detect them...
[BitChute: https://www.bitchute.com/channel/fCcBQxrYQjNX/] [Rumble: https://rumble.com/user/HPoorHMagentaHChildH]
-
- Member
- Posts: 647
- Joined: Thu Feb 21, 2013 23:54
Re: [Mod] Delete unknown blocks and objects [1] [clean]
I THINK this would do the trick without manual configuration, but it's obviously a lot less simple. See what you think. The code is WTFPL.
There's a caveat: at the moment it will keep a table entry in memory for every 80x80x80 block nearby positions connected players visit. That's a bit of a "memory leak", but if it's not acceptable that could be fixed relatively easily by keeping some kind of freshness value and ousting old entries once the size gets too big.
There's a caveat: at the moment it will keep a table entry in memory for every 80x80x80 block nearby positions connected players visit. That's a bit of a "memory leak", but if it's not acceptable that could be fixed relatively easily by keeping some kind of freshness value and ousting old entries once the size gets too big.
Code: Select all
local CLEANUP_PERIOD__S = 10.0;
local ENTITY_CLEANUP_RADIUS = 80.0;
local NODES_PER_BLOCK = 80;
local function hashPos(pos)
return 32*pos.z + 16*pos.y + pos.x;
end
local function posEqual(ap, bp)
return (ap.x == bp.x) and (ap.y == bp.y) and (ap.z == bp.z);
end
local function nodePosToBlockPos(pos)
return {
x = math.floor(pos.x / NODES_PER_BLOCK),
y = math.floor(pos.y / NODES_PER_BLOCK),
z = math.floor(pos.z / NODES_PER_BLOCK)
};
end
local function blockPosToNodePos(pos)
return {
x = NODES_PER_BLOCK * pos.x,
y = NODES_PER_BLOCK * pos.y,
z = NODES_PER_BLOCK * pos.z
};
end
local function cleanupEntitiesNear(pos)
local objs = minetest.get_objects_inside_radius(pos, ENTITY_CLEANUP_RADIUS);
for _, obj in ipairs(objs) do
local pname = obj.get_player_name and obj:get_player_name();
local entity = obj.get_luaentity and obj:get_luaentity();
if entity then
if entity.name == "__builtin:item" then
local istr = entity.itemstring;
local itemName = istr and ItemStack(istr):get_name();
local def = itemName and itemName ~= "" and
(minetest.registered_entities[itemName] or
minetest.registered_items[itemName] or
minetest.registered_nodes[itemName] or
minetest.registered_craftitems[itemName] or
minetest.registered_tools[itemName]);
if not def then
obj:remove();
end
end
elseif not pname or pname == "" then
obj:remove();
end
end
end
local addCache;
do
local cache = {};
addCache = function(pos)
local h = hashPos(pos);
local parr = cache[h];
if not parr then
cache[h] = { pos };
return true;
else
for _, p in ipairs(parr) do
if posEqual(pos, p) then
return false;
end
end
table.insert(parr, pos);
return true;
end
end
end
local addToDo;
local removeToDo;
do
local head = nil;
local tail = nil;
addToDo = function(pos)
local n = { pos = pos };
if tail then
tail.next = n;
tail = n;
else
head = n;
tail = n;
end
end
removeToDo = function()
if not head then return nil; end
local n = head;
head = n.next;
return n.pos;
end
end
local function markClean(minp, maxp)
local bpmin = nodePosToBlockPos(minp);
local bpmax = nodePosToBlockPos(maxp);
for x = bpmin.x, bpmax.x do
for y = bpmin.y, bpmax.y do
for z = bpmin.z, bpmax.z do
addCache({ x = x, y = y, z = z });
end
end
end
end
local function registerCleanupBlocks(pos)
local bp = nodePosToBlockPos(pos);
for x = bp.x-1, bp.x+1 do
for y = bp.y-1, bp.y+1 do
for z = bp.z-1, bp.z+1 do
local bp = { x = x, y = y, z = z };
if addCache(bp) then
addToDo(bp);
end
end
end
end
end
local function cleanupBlock()
local bp = removeToDo();
if not bp then return; end
local pmin = blockPosToNodePos(bp);
local pmax = blockPosToNodePos({ x = bp.x+1, y = bp.y+1, z = bp.z+1 });
pmax.x = pmax.x-1; -- make inclusive
pmax.y = pmax.y-1;
pmax.z = pmax.z-1;
local vm = VoxelManip();
pmin, pmax = vm:read_from_map(pmin, pmax);
local va = VoxelArea:new({ MinEdge = pmin, MaxEdge = pmax });
local data = vm:get_data();
local airCid = minetest.get_content_id("air");
local replaced = 0;
for i, cid in ipairs(data) do
local nodeName = minetest.get_name_from_content_id(cid);
if not minetest.registered_nodes[nodeName] then
data[i] = airCid;
replaced = replaced + 1;
end
end
if replaced > 0 then
vm:set_data(data);
vm:write_to_map();
vm:update_map();
vm:update_liquids();
end
end
local function cleanup()
for _, player in ipairs(minetest.get_connected_players()) do
local pos = player:getpos();
cleanupEntitiesNear(pos);
registerCleanupBlocks(pos);
end
cleanupBlock();
end
do
local elapsedTime_s = 0;
minetest.register_globalstep(
function(dt_s)
elapsedTime_s = elapsedTime_s + dt_s;
if elapsedTime_s >= CLEANUP_PERIOD__S then
elapsedTime_s = 0;
cleanup();
end
end);
end
minetest.register_on_generated(
function(minp, maxp, blockSeed)
markClean(minp, maxp);
end);
-
- Member
- Posts: 647
- Joined: Thu Feb 21, 2013 23:54
Re: [Mod] Delete unknown blocks and objects [1] [clean]
Okay. Realized I could do a little better. This version uses node metadata and a maximum TODO queue size to avoid the "memory leak". Again, WTFPL.
(EDIT, 2014-07-18: Fixed small bug on list add/remove.)
Code: Select all
local MOD_NAME = minetest.get_current_modname();
local CLEANUP_PERIOD__S = 10.0;
local ENTITY_CLEANUP_RADIUS = 80.0;
local NODES_PER_BLOCK = 80;
local FRESHNESS_META_KEY = MOD_NAME..":freshness";
local MAX_TODO_SIZE = 100;
local BATCH_SIZE = 3;
local startTime = minetest.get_gametime();
local function nodePosToBlockPos(pos)
return {
x = math.floor(pos.x / NODES_PER_BLOCK),
y = math.floor(pos.y / NODES_PER_BLOCK),
z = math.floor(pos.z / NODES_PER_BLOCK)
};
end
local function blockPosToNodePos(pos)
return {
x = NODES_PER_BLOCK * pos.x,
y = NODES_PER_BLOCK * pos.y,
z = NODES_PER_BLOCK * pos.z
};
end
local function cleanupEntitiesNear(pos)
local objs = minetest.get_objects_inside_radius(pos, ENTITY_CLEANUP_RADIUS);
for _, obj in ipairs(objs) do
local pname = obj.get_player_name and obj:get_player_name();
local entity = obj.get_luaentity and obj:get_luaentity();
if entity then
if entity.name == "__builtin:item" then
local istr = entity.itemstring;
local itemName = istr and ItemStack(istr):get_name();
local def = itemName and itemName ~= "" and
(minetest.registered_entities[itemName] or
minetest.registered_items[itemName] or
minetest.registered_nodes[itemName] or
minetest.registered_craftitems[itemName] or
minetest.registered_tools[itemName]);
if not def then
obj:remove();
end
end
elseif not pname or pname == "" then
obj:remove();
end
end
end
local function isBlockFresh(blockPos)
local pos = blockPosToNodePos(blockPos);
return minetest.get_meta(pos):get_int(FRESHNESS_META_KEY) == startTime;
end
local function setBlockFresh(blockPos)
local pos = blockPosToNodePos(blockPos);
minetest.get_meta(pos):set_int(FRESHNESS_META_KEY, startTime);
end
local addToDo;
local removeToDo;
do
local size = 0;
local head = nil;
local tail = nil;
addToDo = function(pos)
if size >= MAX_TODO_SIZE then return false; end
local n = { pos = pos };
if head then
tail.next = n;
tail = n;
else
head = n;
tail = n;
end
size = size + 1;
return true;
end
removeToDo = function()
if not head then return nil; end
local n = head;
head = n.next;
if not head then tail = nil; end
size = size - 1;
return n.pos;
end
end
local function markNodesClean(minp, maxp)
local bpmin = nodePosToBlockPos(minp);
local bpmax = nodePosToBlockPos(maxp);
for x = bpmin.x, bpmax.x do
for y = bpmin.y, bpmax.y do
for z = bpmin.z, bpmax.z do
setBlockFresh({ x = x, y = y, z = z });
end
end
end
end
local function registerCleanupBlocks(pos)
local bp = nodePosToBlockPos(pos);
for x = bp.x-1, bp.x+1 do
for y = bp.y-1, bp.y+1 do
for z = bp.z-1, bp.z+1 do
local bp = { x = x, y = y, z = z };
if not isBlockFresh(bp) then
local willDo = addToDo(bp);
if willDo then setBlockFresh(bp); end
end
end
end
end
end
local function cleanupBlock()
local bp = removeToDo();
if not bp then return false; end
local pmin = blockPosToNodePos(bp);
local pmax = blockPosToNodePos({ x = bp.x+1, y = bp.y+1, z = bp.z+1 });
pmax.x = pmax.x-1; -- make inclusive
pmax.y = pmax.y-1;
pmax.z = pmax.z-1;
local vm = VoxelManip();
pmin, pmax = vm:read_from_map(pmin, pmax);
local va = VoxelArea:new({ MinEdge = pmin, MaxEdge = pmax });
local data = vm:get_data();
local airCid = minetest.get_content_id("air");
local replaced = 0;
for i, cid in ipairs(data) do
local nodeName = minetest.get_name_from_content_id(cid);
if not minetest.registered_nodes[nodeName] then
data[i] = airCid;
replaced = replaced + 1;
end
end
if replaced > 0 then
vm:set_data(data);
vm:write_to_map();
vm:update_map();
vm:update_liquids();
end
return true;
end
local function cleanup()
for _, player in ipairs(minetest.get_connected_players()) do
local pos = player:getpos();
cleanupEntitiesNear(pos);
registerCleanupBlocks(pos);
end
for i = 1, BATCH_SIZE do
if not cleanupBlock() then break; end
end
end
do
local elapsedTime_s = 0;
minetest.register_globalstep(
function(dt_s)
elapsedTime_s = elapsedTime_s + dt_s;
if elapsedTime_s >= CLEANUP_PERIOD__S then
elapsedTime_s = 0;
cleanup();
end
end);
end
minetest.register_on_generated(
function(minp, maxp, blockSeed)
markNodesClean(minp, maxp);
end);
-
- Member
- Posts: 249
- Joined: Mon Jul 14, 2014 17:13
- In-game: Mazal
- Location: Cullinan, South-Africa
Re: [Mod] Delete unknown blocks and objects [1] [clean]
This works brilliantly , thanx
- Linuxdirk
- Member
- Posts: 3219
- Joined: Wed Sep 17, 2014 11:21
- In-game: Linuxdirk
- Location: Germany
- Contact:
Re: [Mod] Delete unknown blocks and objects [1] [clean]
Do you know a way to remove all unknown entities/nodes (even if currently not loaded) from a world?prestidigitator wrote:This version uses node metadata and a maximum TODO queue size to avoid the "memory leak".
Re: [Mod] Delete unknown blocks and objects [1] [clean]
This should be a part of minetest. Should be added to server commands.
Many of my mods are now a part of Minetest-mods. A place where you know they are maintained!
A list of my mods can be found here
A list of my mods can be found here
-
- Member
- Posts: 647
- Joined: Thu Feb 21, 2013 23:54
Re: [Mod] Delete unknown blocks and objects [1] [clean]
It would probably require operating directly on the database file for the world. I haven't taken a look at the schema, but I seriously doubt that would be fun. I suspect it might even involve mirroring how Minetest parses BLOBs of node data....Linuxdirk wrote:Do you know a way to remove all unknown entities/nodes (even if currently not loaded) from a world?prestidigitator wrote:This version uses node metadata and a maximum TODO queue size to avoid the "memory leak".
- 12Me21
- Member
- Posts: 873
- Joined: Tue Mar 05, 2013 00:36
- GitHub: 12Me21
- Location: (Ignore all of my posts before 2018)
Re:
No, you need to do:PilzAdam wrote:rubenwardy wrote:How to use?
local old_nodes = {xpanes:pane} does not workCode: Select all
local old_nodes = {"xpanes:pane"}
local old_nodes = {"{"{"{"{"xpanes:pane"}"}"}"}"}
Re: [Mod] Delete unknown blocks and objects [1] [clean]
Just letting future viewers know to try this when /clearobjects just keeps on segmentation fault (incrementing but who knows how many times until all is finally cleared).
I created a directory called clean with depends.txt containing default and init.lua containg the code posted by prestidigitator.
Thanks for the code!
I created a directory called clean with depends.txt containing default and init.lua containg the code posted by prestidigitator.
Thanks for the code!
Re: [Mod] Delete unknown blocks and objects [1] [clean]
+1
as a Newbie to modding, this was very Useful.
as a Newbie to modding, this was very Useful.
Re:
Calling it new_name, old_name confused me for a while--I looked it up and https://dev.minetest.net/minetest.register_alias explains that it is actually (name, convert_to)PilzAdam wrote:From lua-api.txtmauvebic wrote:Feature request: renaming/migration
Say when you change the name of your mod, or the node, that you could do something likeexample use: i have a map that uses staircase, which ive updated and renamed since then to nbu, along with some of the nodenames. I cant switch the old mod for the new mod without ruining my map and i dont want to remove the UB's, just switch 'em :-)Code: Select all
nodeswitch('teacup:teacup','tea:cup')
After that you can use both in code and game, new_name and old_name.Code: Select all
minetest.register_alias(new_name, old_name)
such that if mod providing "name" doesn't exist (is "old") then mod "convert_to" will be used instead. So in some usages such as that, case name, convert_to param names are more clear.
- QwertyDragon
- Member
- Posts: 20
- Joined: Sat Dec 24, 2016 15:37
- Contact:
Re: [Mod] Delete unknown blocks and objects [1] [clean]
+1Don wrote:This should be a part of minetest. Should be added to server commands.
Maybe:
https://github.com/indriApollo/remove_unknown
My GitLab, and Obior pages, and YouTube as QuixoticalPig, and Twitter as vuvvobUd. irc as QwertyDragon
- ManElevation
- Member
- Posts: 896
- Joined: Tue Aug 02, 2016 22:04
- GitHub: ManElevation
- IRC: ManElevation
- In-game: ManElevation
- Location: Madrid,Spain
Re: [Mod] Delete unknown blocks and objects [1] [clean]
what am i doing wrong?
Code: Select all
local old_nodes = {"moreores:mineral_tin"}
local old_nodes = {"magmatools:stone_with_magma_crystal"}
local old_nodes = {"mod:a", "mod:b"}
local old_entities = {}
local old_entities = {"magmatools:stone_with_magma_crystal","moreores:mineral_tin","icetools:stone_with_ice_crystal"}
for _,node_name in ipairs(old_nodes) do
minetest.register_node(":"..node_name, {
groups = {old=1},
})
end
minetest.register_abm({
nodenames = {"group:old"},
interval = 1,
chance = 1,
action = function(pos, node)
minetest.env:remove_node(pos)
end,
})
for _,entity_name in ipairs(old_entities) do
minetest.register_entity(":"..entity_name, {
on_activate = function(self, staticdata)
self.object:remove()
end,
})
end
My Public Mods! Discord: Rottweiler Games#3368
-
- Member
- Posts: 845
- Joined: Fri Jan 08, 2016 21:17
- In-game: Ghost
Re: [Mod] Delete unknown blocks and objects [1] [clean]
try this mod
https://github.com/indriApollo/remove_unknown
coupled with world edit
https://github.com/Uberi/Minetest-WorldEdit
and it works tricky to learn at first
but easy and you don't have learn lines of code
https://github.com/indriApollo/remove_unknown
coupled with world edit
https://github.com/Uberi/Minetest-WorldEdit
and it works tricky to learn at first
but easy and you don't have learn lines of code
- AntumDeluge
- Member
- Posts: 213
- Joined: Sun Aug 07, 2016 05:42
- GitHub: AntumDeluge
- IRC: AntumDeluge
- Contact:
Re: [Mod] Delete unknown blocks and objects [1] [clean]
Wanted to post a fork I created: Cleaner
Major changes:
Major changes:
- Changed license to CC0.
- Reads entities to be cleaned from clean_entities.txt file in world path.
- Reads nodes to be cleaned from clean_nodes.txt file in world path.
Re: [Mod] Delete unknown blocks and objects [1] [clean]
I just wanted to add some information regarding converting old blocks.
In the moreblocks mod inside stairsplus folder you might find find two files:
- aliases.lua
- conversion.lua
they are not loaded by current versions of this mod, but are there just in case.
Those could be a good examples how one could set aliases to many old blocks or replace them when the map is loaded.
It would be great if this mod could be accessible via github and implement those two options (alias and replace) also.
https://github.com/codexp/moreblocks/bl ... liases.lua
https://github.com/codexp/moreblocks/bl ... ersion.lua
In the moreblocks mod inside stairsplus folder you might find find two files:
- aliases.lua
- conversion.lua
they are not loaded by current versions of this mod, but are there just in case.
Those could be a good examples how one could set aliases to many old blocks or replace them when the map is loaded.
It would be great if this mod could be accessible via github and implement those two options (alias and replace) also.
https://github.com/codexp/moreblocks/bl ... liases.lua
https://github.com/codexp/moreblocks/bl ... ersion.lua
Re: [Mod] Delete unknown blocks and objects [1] [clean]
I think, Minetest should have a delete-unknown-things feature built in.
Who is online
Users browsing this forum: No registered users and 29 guests