-
Notifications
You must be signed in to change notification settings - Fork 35
/
500ise_cuboid_replace.js
59 lines (51 loc) · 1.7 KB
/
500ise_cuboid_replace.js
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
var WAITING_FOR_FIRST_POS = 0;
var WAITING_FOR_SECOND_POS = 1;
var WAITING_FOR_REPLACE_MATERIAL = 2;
var WAITING_FOR_MATERIAL = 3;
var selectionStage = WAITING_FOR_FIRST_POS;
var firstPoint = [0, 0, 0];
var secondPoint = [0, 0, 0];
function useItem(x, y, z, itemId, blockId) {
if (selectionStage == WAITING_FOR_MATERIAL) {
//itemId is the material we want
var material = itemId > 0xff? 0 : itemId;
createCuboid(firstPoint, secondPoint, replaceMaterial, material);
selectionStage = WAITING_FOR_FIRST_POS;
preventDefault();
} else if (selectionStage == WAITING_FOR_REPLACE_MATERIAL) {
replaceMaterial = itemId > 0xff? blockId: itemId;
selectionStage = WAITING_FOR_MATERIAL;
print("Replace block set to " + replaceMaterial);
preventDefault();
} else {
if (itemId == 292) { //iron hoe
var newpoint = [x, y, z];
if (selectionStage == WAITING_FOR_FIRST_POS) {
firstPoint = newpoint;
print("First point set to " + newpoint.join(","));
} else {
secondPoint = newpoint;
print("Second point set to " + newpoint.join(","));
}
selectionStage++;
preventDefault();
}
}
}
function createCuboid(firstPoint, secondPoint, replaceMaterial, material) {
var minX = Math.min(firstPoint[0], secondPoint[0]);
var minY = Math.min(firstPoint[1], secondPoint[1]);
var minZ = Math.min(firstPoint[2], secondPoint[2]);
var maxX = Math.max(firstPoint[0], secondPoint[0]);
var maxY = Math.max(firstPoint[1], secondPoint[1]);
var maxZ = Math.max(firstPoint[2], secondPoint[2]);
for (var x = minX; x <= maxX; ++x) {
for (var z = minZ; z <= maxZ; ++z) {
for (var y = minY; y <= maxY; ++y) {
if (getTile(x, y, z) == replaceMaterial) {
setTile(x, y, z, material);
}
}
}
}
}