-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFindMobs.groovy
More file actions
64 lines (54 loc) · 2.22 KB
/
FindMobs.groovy
File metadata and controls
64 lines (54 loc) · 2.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import groovy.transform.Field
import net.querz.mcaselector.io.mca.ChunkData
import net.querz.nbt.CompoundTag
import net.querz.nbt.DoubleTag
import net.querz.nbt.ListTag
import net.querz.nbt.NBTUtil
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Logger
@Field Logger LOGGER = LogManager.getLogger("FindEntities")
@Field List<String> foundEntities = Collections.synchronizedList(new ArrayList<String>())
@Field List<CompoundTag> entity_types
void before() {
entity_types = entities.collect {
var compound = NBTUtil.fromSNBT(it) as CompoundTag
var id = compound.getStringOrDefault("id", ":")
if (!id.contains(":")) compound.putString("id", "minecraft:$id")
return compound
}
}
boolean filter(ChunkData data) {
var foundAny = false
for (entity in data.entities?.data?.getListOrDefault("Entities", new ListTag()) as List<CompoundTag>) {
if (!entity_types.any { it.partOf(entity) }) continue
var intPos = (entity.getList("Pos") as List<DoubleTag>).collect { it.asInt() }
foundEntities.addLast("${intPos.join(" ")} | ${entity.getString("id")}")
foundAny = true
}
return foundAny
}
void after() {
println("FindEntities: There have been ${foundEntities.size()} matching foundEntities found in the world.")
LOGGER.info("There have been ${foundEntities.size()} matching foundEntities found in the world.")
fileName = fileName.replaceFirst("^~/*", System.getProperty("user.home"))
var file = new File(fileName)
if (!file.exists()) file.createNewFile()
file.write(foundEntities.join("\n"))
}
/** !! CODE ABOVE !! **/
/** Usually, you don't need to edit anything here. **/
/**
* Selects all chunks that contain any of the specified entity types.
* Additionally, it outputs the coordinates and id of every matching entity to a file.
*
* @type Chunk Filter (Ctrl + F)
* @version 1.17+
*/
// The file to write the output to, relative to the mca directory
// Use `~` to refer to the user's home directory instead
@Field String fileName = "Entities.txt"
// entities to check for, as snbt strings
@Field List<String> entities = [
'{"id": "donkey", "ChestedHorse": true}',
// more entity types ...
]