This repository has been archived by the owner on Dec 30, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathminecraft.c
95 lines (77 loc) · 2.36 KB
/
minecraft.c
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
minecraft.c
Core module definition plus functionality that doesn't really fit anywhere else
*/
#include <Python.h>
#include <structmember.h>
#include <regex.h>
#include <stdbool.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "minecraft.h"
// Get information from the filename
void region_information( int *coords, char *filename )
{
regmatch_t matches[3];
regex_t regex;
int reti;
coords[0] = -1;
coords[1] = -1;
reti = regcomp(®ex, "^.*\\.([^.]*)\\.([^.]*)\\.mca$", REG_EXTENDED);
if ( reti )
{
printf("Could not compile expression");
return;
}
reti = regexec(®ex, filename, 3, matches, 0);
if ( !reti )
{
char coord[20];
strncpy ( coord, filename + matches[1].rm_so, matches[1].rm_eo - matches[1].rm_eo + 1 );
coords[0] = atoi(coord);
strncpy ( coord, filename + matches[2].rm_so, matches[2].rm_eo - matches[2].rm_eo + 1 );
coords[1]= atoi(coord);
printf("\nx: %d | z: %d\n", coords[0], coords[1]);
}
else
{
printf("NO MATCH!");
}
}
/*
Python module set-up
*/
static PyMethodDef MinecraftMethods[] = {
// {"get_chunk", get_chunk, METH_VARARGS, "Get a specified chunk."},
{NULL, NULL, 0, NULL} /* Sentinel */
};
PyMODINIT_FUNC initminecraft(void)
{
PyObject *m;
m = Py_InitModule3("minecraft", MinecraftMethods, "Minecraft module");
// Block
minecraft_BlockType.tp_new = PyType_GenericNew;
if( PyType_Ready(&minecraft_BlockType) < 0 )
return;
Py_INCREF(&minecraft_BlockType);
PyModule_AddObject(m, "Block", (PyObject *) &minecraft_BlockType);
// Chunk
minecraft_ChunkType.tp_new = PyType_GenericNew;
if( PyType_Ready(&minecraft_ChunkType) < 0 )
return;
Py_INCREF(&minecraft_ChunkType);
PyModule_AddObject(m, "Chunk", (PyObject *) &minecraft_ChunkType);
// World
minecraft_WorldType.tp_new = PyType_GenericNew;
if( PyType_Ready(&minecraft_WorldType) < 0 )
return;
Py_INCREF(&minecraft_WorldType);
PyModule_AddObject(m, "World", (PyObject *) &minecraft_WorldType);
// Block
minecraft_GeneratorType.tp_new = PyType_GenericNew;
if( PyType_Ready(&minecraft_GeneratorType) < 0 )
return;
Py_INCREF(&minecraft_GeneratorType);
PyModule_AddObject(m, "Generator", (PyObject *) &minecraft_GeneratorType);
}