forked from PrismarineJS/flying-squid
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathportal.test.js
More file actions
260 lines (230 loc) · 8.72 KB
/
Copy pathportal.test.js
File metadata and controls
260 lines (230 loc) · 8.72 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
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/* eslint-env mocha */
globalThis.isMocha = true
const squid = require('flying-squid')
const PortalDetector = require('../src/lib/portal_detector')
const expect = require('expect').default
squid.testedVersions.forEach((testedVersion, i) => {
const registry = require('prismarine-registry')(testedVersion)
const version = registry.version
const {
detectFrame,
findPotentialLines,
findBorder,
getAir,
generateLine,
generatePortal,
makeWorldWithPortal
} = PortalDetector(registry)
const { Vec3 } = require('vec3')
describe('generate portal ' + testedVersion + 'v', () => {
it('generate a line', () => {
expect(generateLine(new Vec3(3, 1, 1), new Vec3(1, 0, 0), 2)).toEqual([new Vec3(3, 1, 1), new Vec3(4, 1, 1)])
})
it('generate a portal', () => {
expect(generatePortal(new Vec3(2, 1, 1), new Vec3(1, 0, 0), 4, 5)).toEqual({
bottom: generateLine(new Vec3(3, 1, 1), new Vec3(1, 0, 0), 2),
left: generateLine(new Vec3(2, 2, 1), new Vec3(0, 1, 0), 3),
right: generateLine(new Vec3(5, 2, 1), new Vec3(0, 1, 0), 3),
top: generateLine(new Vec3(3, 5, 1), new Vec3(1, 0, 0), 2),
air: generateLine(new Vec3(3, 2, 1), new Vec3(0, 1, 0), 3).concat(generateLine(new Vec3(4, 2, 1), new Vec3(0, 1, 0), 3))
})
})
})
describe('detect portal ' + version.minecraftVersion, () => {
const portalData = []
portalData.push({
name: 'simple portal frame x',
bottomLeft: new Vec3(2, 1, 1),
direction: new Vec3(1, 0, 0),
width: 4,
height: 5,
additionalAir: [],
additionalObsidian: []
})
portalData.push({
name: 'simple portal frame z',
bottomLeft: new Vec3(2, 1, 1),
direction: new Vec3(0, 0, 1),
width: 4,
height: 5,
additionalAir: [],
additionalObsidian: []
})
portalData.push({
name: 'big simple portal frame x',
bottomLeft: new Vec3(2, 1, 1),
direction: new Vec3(1, 0, 0),
width: 10,
height: 10,
additionalAir: [],
additionalObsidian: []
})
portalData.push({
name: 'simple portal frame x with borders',
bottomLeft: new Vec3(2, 1, 1),
direction: new Vec3(1, 0, 0),
width: 4,
height: 5,
additionalAir: [],
additionalObsidian: [new Vec3(2, 1, 1), new Vec3(5, 1, 1), new Vec3(2, 6, 1), new Vec3(5, 6, 1)]
})
const { bottom, left, right, top, air } = generatePortal(new Vec3(2, 1, 2), new Vec3(1, 0, 0), 4, 5)
portalData.push({
name: '2 portals',
bottomLeft: new Vec3(2, 1, 1),
direction: new Vec3(1, 0, 0),
width: 4,
height: 5,
additionalAir: air,
additionalObsidian: [].concat(bottom, left, right, top)
})
portalData.push({
name: 'huge simple portal frame z',
bottomLeft: new Vec3(2, 1, 1),
direction: new Vec3(0, 0, 1),
width: 50,
height: 50,
additionalAir: [],
additionalObsidian: []
})
portalData.forEach(({ name, bottomLeft, direction, width, height, additionalAir, additionalObsidian }) => {
const portal = generatePortal(bottomLeft, direction, width, height)
const { bottom, left, right, top, air } = portal
describe('Detect ' + name, () => {
const expectedBorder = { bottom, left, right, top }
let world
before(async function () {
world = await makeWorldWithPortal(portal, additionalAir, additionalObsidian)
})
describe('detect potential first lines', () => {
it('detect potential first lines from bottom left', async () => {
const potentialLines = await findPotentialLines(world, bottom[0], new Vec3(0, 1, 0))
expect(potentialLines).toContainEqual({
direction,
line: bottom
})
})
it('detect potential first lines from bottom right', async () => {
const potentialLines = await findPotentialLines(world, bottom[bottom.length - 1], new Vec3(0, 1, 0))
expect(potentialLines).toContainEqual({
direction,
line: bottom
})
})
it('detect potential first lines from top left', async () => {
const potentialLines = await findPotentialLines(world, top[0], new Vec3(0, -1, 0))
expect(potentialLines).toContainEqual({
direction,
line: top
})
})
it('detect potential first lines from top right', async () => {
const potentialLines = await findPotentialLines(world, top[top.length - 1], new Vec3(0, -1, 0))
expect(potentialLines).toContainEqual({
direction,
line: top
})
})
it('detect potential first lines from left top', async () => {
const potentialLines = await findPotentialLines(world, left[left.length - 1], direction)
expect(potentialLines).toEqual([{
direction: new Vec3(0, 1, 0),
line: left
}])
})
it('detect potential first lines from right bottom', async () => {
const potentialLines = await findPotentialLines(world, right[0], direction.scaled(-1))
expect(potentialLines).toEqual([{
direction: new Vec3(0, 1, 0),
line: right
}])
})
})
describe('find borders', () => {
it('find borders from bottom', async () => {
const border = await findBorder(world, {
direction,
line: bottom
}, new Vec3(0, 1, 0))
expect(border).toEqual(expectedBorder)
})
it('find borders from top', async () => {
const border = await findBorder(world, {
direction,
line: top
}, new Vec3(0, -1, 0))
expect(border).toEqual(expectedBorder)
})
it('find borders from left', async () => {
const border = await findBorder(world, {
direction: new Vec3(0, 1, 0),
line: left
}, direction)
expect(border).toEqual(expectedBorder)
})
it('find borders from right', async () => {
const border = await findBorder(world, {
direction: new Vec3(0, 1, 0),
line: right
}, direction.scaled(-1))
expect(border).toEqual(expectedBorder)
})
})
describe('detect portals', () => {
it('detect portals from bottom left', async () => {
const portals = await detectFrame(world, bottom[0], new Vec3(0, 1, 0))
expect(portals).toEqual([portal])
})
it('detect portals from top left', async () => {
const portals = await detectFrame(world, top[0], new Vec3(0, -1, 0))
expect(portals).toEqual([portal])
})
it('detect portals from right top', async () => {
const portals = await detectFrame(world, right[right.length - 1], direction.scaled(-1))
expect(portals).toEqual([portal])
})
})
it('get air', () => {
const foundAir = getAir(expectedBorder)
expect(foundAir).toEqual(air)
})
})
})
}).timeout(120 * 1000)
describe("doesn't detect non-portal " + version.minecraftVersion, () => {
const portalData = []
portalData.push({
name: 'simple portal frame x with one obsidian in the middle',
bottomLeft: new Vec3(2, 1, 1),
direction: new Vec3(1, 0, 0),
width: 5,
height: 5,
additionalAir: [],
additionalObsidian: [new Vec3(4, 3, 1)]
})
portalData.forEach(({ name, bottomLeft, direction, width, height, additionalAir, additionalObsidian }) => {
const portal = generatePortal(bottomLeft, direction, width, height)
const { bottom, right, top } = portal
describe("doesn't detect detect " + name, () => {
let world
before(async function () {
world = await makeWorldWithPortal(portal, additionalAir, additionalObsidian)
})
describe("doesn't detect portals", () => {
it("doesn't detect portals from bottom left", async () => {
const portals = await detectFrame(world, bottom[0], new Vec3(0, 1, 0))
expect(portals).toEqual([])
})
it("doesn't detect portals from top left", async () => {
const portals = await detectFrame(world, top[0], new Vec3(0, -1, 0))
expect(portals).toEqual([])
})
it("doesn't detect portals from right top", async () => {
const portals = await detectFrame(world, right[right.length - 1], direction.scaled(-1))
expect(portals).toEqual([])
})
})
})
})
})
})