-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathEndPortalLocate.js
More file actions
126 lines (100 loc) · 4 KB
/
EndPortalLocate.js
File metadata and controls
126 lines (100 loc) · 4 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
///api_version=2
//Copyright 2020 commandblock2 distributed under AGPL-3.0-or-later
(script = registerScript({
name: "EndPortalLocate",
version: "1.0",
authors: ["commandblock2"]
})).import("Core.lib")
Color = Java.type("java.awt.Color")
GL11 = Java.type("org.lwjgl.opengl.GL11")
firstPoses = []
secondPoses = []
first = true
detected = null
lastLocation = null
module = {
name: "EndPortalLocate",
description: "Locate end portal with 2 eyes (not that accurate but within the xray distance)",
author: "commandblock2",
category: "misc",
values: [
],
onUpdate: function () {
pearl = Java.from(mc.theWorld.loadedEntityList).filter(function (elem) {
return elem instanceof EntityEnderEye
})
if (!pearl.length && first && firstPoses.length)
first = false
if (pearl.length == 1) {
if (first)
firstPoses.push(pearl[0].getPositionVector())
else
secondPoses.push(pearl[0].getPositionVector())
}
if (!pearl.length && firstPoses.length && secondPoses.length) {
firstBeginXZ = { x: firstPoses[0].xCoord, z: firstPoses[0].zCoord }
firstEndXZ = { x: firstPoses[firstPoses.length - 1].xCoord, z: firstPoses[firstPoses.length - 1].zCoord }
secondBeginXZ = { x: secondPoses[0].xCoord, z: secondPoses[0].zCoord }
secondEndXZ = { x: secondPoses[secondPoses.length - 1].xCoord, z: secondPoses[secondPoses.length - 1].zCoord }
//I hate this
//line is represented as a * x + b * z = c
firstAB = { a: firstEndXZ.z - firstBeginXZ.z, b: firstBeginXZ.x - firstEndXZ.x }
firstC = firstAB.a * firstBeginXZ.x + firstAB.b * firstBeginXZ.z
secondAB = { a: secondEndXZ.z - secondBeginXZ.z, b: secondBeginXZ.x - secondEndXZ.x }
secondC = secondAB.a * secondBeginXZ.x + secondAB.b * secondBeginXZ.z
det = firstAB.a * secondAB.b - firstAB.b * secondAB.a
intersectX = (secondAB.b * firstC - firstAB.b * secondC) / det
intersectZ = (firstAB.a * secondC - secondAB.a * firstC) / det
if (!detected)
detected = timeout(0, function () {
chat.print("The portal is around X = " + intersectX + " Z = " + intersectZ)
lastLocation = [intersectX, intersectZ]
timeout(1000 * 5, function () {
resetState()
chat.print("State reset")
detected = null
})
})
}
},
onRender3D: function (event) {
drawLine(firstPoses, new Color(86, 156, 214))
drawLine(secondPoses, new Color(255, 255, 0))
if (lastLocation)
drawLine([new Vec3(lastLocation[0], 0, lastLocation[1]), new Vec3(lastLocation[0], 255, lastLocation[1])], new Color(53, 1 , 134))
},
onDisable: function () {
resetState()
lastLocation = null
}
}
function resetState() {
first = true
firstPoses = []
secondPoses = []
}
function drawLine(poses, color) {
GL11.glPushMatrix();
GL11.glDisable(GL11.GL_TEXTURE_2D);
GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA);
GL11.glLineWidth(4)
GL11.glEnable(GL11.GL_LINE_SMOOTH);
GL11.glEnable(GL11.GL_BLEND);
GL11.glDisable(GL11.GL_DEPTH_TEST);
mc.entityRenderer.disableLightmap();
GL11.glBegin(GL11.GL_LINE_STRIP);
RenderUtils.glColor(color);
renderPosX = mc.getRenderManager().viewerPosX;
renderPosY = mc.getRenderManager().viewerPosY;
renderPosZ = mc.getRenderManager().viewerPosZ;
poses.forEach(function (pos) {
GL11.glVertex3d(pos.xCoord - renderPosX, pos.yCoord - renderPosY, pos.zCoord - renderPosZ);
})
GL11.glColor4d(1, 1, 1, 1);
GL11.glEnd();
GL11.glEnable(GL11.GL_DEPTH_TEST);
GL11.glDisable(GL11.GL_LINE_SMOOTH);
GL11.glDisable(GL11.GL_BLEND);
GL11.glEnable(GL11.GL_TEXTURE_2D);
GL11.glPopMatrix();
}