-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathProjectilesPlus.js
351 lines (263 loc) · 11 KB
/
ProjectilesPlus.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
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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
///api_version=2
//Copyright 2020 commandblock2 distributed under AGPL-3.0-or-later
(script = registerScript({
name: "ProjectilesPlus",
version: "1.0",
authors: ["commandblock2"]
})).import("Core.lib")
Color = Java.type("java.awt.Color")
GL11 = Java.type("org.lwjgl.opengl.GL11")
HashMap = Java.type("java.util.HashMap")
Material = Java.type("net.minecraft.block.material.Material")
//Idk why that happens same as REPL
//God damn fuck
entity2PositionHistorys = new HashMap()
entity2PositionPredicition = new HashMap()
playerPositionPrediction = []
dodging = null
targetPos = null
oIndex = -1
oYaw = -1
module = {
name: "ProjectilesPlus",
description: "Projectlies for Arrows that is already in air(for now)",
author: "commandblock2",
category: "misc",
values: [
arrowDodge = value.createBoolean("ArrowDodge", true
),
ticksToDodge = value.createInteger("TicksToDodge", 5, 1, 20),
renderPlayerPrediction = value.createBoolean("RenderPlayerPrediction", false),
dodgeMode = value.createList("DodgeMode", ["TeleportUp", "BlockHit", "HorizontalSpeed", "HorizontalTp", "HorizontalMotion"], "BlockHit"),
autoSwordBlockHit = value.createBoolean("AutoSword4BlockHit", true)
],
onUpdate: function () {
arrows = Java.from(mc.theWorld.loadedEntityList).filter(function (elem) {
return elem instanceof EntityArrow
})
arrows.forEach(function (arrow) {
if (!entity2PositionHistorys[arrow])
entity2PositionHistorys.put(arrow, [])
if (arrow.prevPosX == arrow.posX && arrow.prevPosY == arrow.posY && arrow.prevPosZ == arrow.posZ) {
if (entity2PositionHistorys[arrow])
entity2PositionHistorys.remove(arrow)
entity2PositionPredicition.remove(arrow)
return
}
entity2PositionHistorys[arrow].push(arrow.getPositionVector())
entity2PositionPredicition.put(arrow, predict(arrow))
})
elem4Remove = []
entity2PositionHistorys.forEach(function (elem) {
if (arrows.indexOf(elem) == -1) elem4Remove.push(elem)
})
elem4Remove.forEach(function (e) { entity2PositionHistorys.remove(e) })
playerPositionPrediction = playerPosInTicks(ticksToDodge.get())
if (dodging)
if (dodgeMode.get() == "TeleportUp") {
mc.thePlayer.setPosition(mc.thePlayer.posX, mc.thePlayer.posY + 2, mc.thePlayer.posZ)
dodging = null
}
else if (dodgeMode.get() == "BlockHit") {
if (autoSwordBlockHit.get())
for (i = 0; i < 9; i++) {
stack = mc.thePlayer.inventory.getStackInSlot(i)
if (stack && stack.getItem() instanceof ItemSword && oIndex == -1) {
oIndex = mc.thePlayer.inventory.currentItem
mc.thePlayer.inventory.currentItem = i
}
}
mc.gameSettings.keyBindUseItem.pressed = true
timeout(ticksToDodge.get() * 50, function () {
if (!dodging) {
mc.gameSettings.keyBindUseItem.pressed = false
if (oIndex != -1) {
mc.thePlayer.inventory.currentItem = oIndex
oIndex = -1
}
}
dodging = null
})
}
else if (dodgeMode.get().indexOf("Horizontal") != -1) {
if (-1 == oYaw)
oYaw = mc.thePlayer.rotationYaw
right = new Rotation(dodging - 90, mc.thePlayer.rotationPitch)
left = new Rotation(dodging + 90, mc.thePlayer.rotationPitch)
rightYaw = right.yaw / 180 * Math.PI
leftYaw = left.yaw / 180 * Math.PI
rightDis = mc.thePlayer.getPositionVector().add(RotationUtils.getVectorForRotation(right)).subtract(targetPos).lengthVector()
leftDis = mc.thePlayer.getPositionVector().add(RotationUtils.getVectorForRotation(left)).subtract(targetPos).lengthVector()
rot = (rightDis > leftDis) ? right : left
if (dodgeMode.get() == "HorizontalTp") {
mc.thePlayer.setPosition(mc.thePlayer.posX + Math.sin(Math.toRadians(rot.yaw)),
mc.thePlayer.posY,
mc.thePlayer.posZ + Math.cos(Math.toRadians(rot.yaw)))
dodging = null
return
}
if (dodgeMode.get() == "HorizontalMotion") {
mc.thePlayer.motionX = Math.sin(Math.toRadians(rot.yaw))
mc.thePlayer.motionZ = Math.cos(Math.toRadians(rot.yaw))
dodging = null
return
}
rot.toPlayer(mc.thePlayer)
SpeedModule.state = true
mc.gameSettings.keyBindForward.pressed = true
timeout(ticksToDodge.get() * 50, function () {
if (!dodging) {
if (oYaw != -1)
new Rotation(oYaw, mc.thePlayer.rotationPitch).toPlayer(mc.thePlayer)
SpeedModule.state = false
mc.gameSettings.keyBindForward.pressed = false
oYaw = -1
}
dodging = null
})
}
},
onRender3D: function (event) {
entity2PositionHistorys.forEach(function (entity) {
//Draw the history line
drawLine(entity2PositionHistorys[entity], new Color(255, 255, 0))
//Draw the prediction line
drawLine(entity2PositionPredicition[entity], new Color(86, 156, 214))
})
//Draw the Player prediction
if (!renderPlayerPrediction.get()) return
pos = playerPositionPrediction[playerPositionPrediction.length - 1]
renderMgr = mc.getRenderManager()
RenderUtils.drawAxisAlignedBB(mc.thePlayer.getEntityBoundingBox().offset(
pos.xCoord - mc.thePlayer.posX - renderMgr.renderPosX,
pos.yCoord - mc.thePlayer.posY - renderMgr.renderPosY,
pos.zCoord - mc.thePlayer.posZ - renderMgr.renderPosZ
), new Color(53, 1, 134, 30))
},
onDisable: function () {
}
}
//things below here are adapted from LiquidBounce
function playerPosInTicks(ticks) {
poses = []
poses.push(mc.thePlayer.getPositionVector())
posX = mc.thePlayer.posX;
posY = mc.thePlayer.posY;
posZ = mc.thePlayer.posZ;
motionX = mc.thePlayer.motionX;
motionY = mc.thePlayer.motionY;
motionZ = mc.thePlayer.motionZ;
yaw = mc.thePlayer.rotationYaw;
strafe = mc.thePlayer.moveStrafing;
forward = mc.thePlayer.moveForward;
//if (mc.thePlayer.onGround) {
for (index = 0; index < ticks; index++) {
multip = index + 1
poses.push(new Vec3(posX + multip * motionX, posY, posZ + multip * motionZ))
}
return poses
//}
/*for (index = 0; index < ticks; index++) {
strafe *= 0.98
forward *= 0.98
v = strafe * strafe + forward * forward
if (v > 0.0001) {
v = Math.sqrt(v)
if (v > 1.0) v = 1.0
v = mc.thePlayer.jumpMovementFactor / v
strafe *= v
forward *= v
f1 = Math.sin(yaw * Math.PI / 180.0)
f2 = Math.cos(yaw * Math.PI / 180.0)
motionX += strafe * f2 - forward * f1
motionZ += forward * f2 + strafe * f1
}
motionY -= 0.08
motionX *= 0.91
motionY *= 0.9800000190734863
motionY *= 0.91
motionZ *= 0.91
posX += motionX
posY += motionY
posZ += motionZ
poses.push(new Vec3(posX, posY, posZ))
}
return poses
*/
}
function predict(entityArrow) {
motionX = entityArrow.motionX
motionY = entityArrow.motionY
motionZ = entityArrow.motionZ
poses = []
poses.push(entityArrow.getPositionVector())
if(!poses[0]) return
//FUCK IDK WHY BUT JUST MIGHT HAPPEN
x = poses[0].xCoord
y = poses[0].yCoord
z = poses[0].zCoord
while (y > 0) {
posBefore = new Vec3(x, y, z)
posAfter = new Vec3(x + motionX, y + motionY, z + motionZ)
poses.push(posAfter)
landingPosition = mc.theWorld.rayTraceBlocks(posBefore, posAfter, false, true, false)
if (landingPosition) {
poses.push(landingPosition.hitVec)
break
}
playerBoundingBox = mc.thePlayer.getEntityBoundingBox().expand(0.3, 0.3, 0.3)
index = poses.length > ticksToDodge.get() ? ticksToDodge.get() : poses.length
pos = playerPositionPrediction[index]
if (playerBoundingBox.calculateIntercept(posBefore, posAfter) && poses.length <= ticksToDodge.get()) {
targetPos = posBefore
dodging = Math.atan2(motionZ, motionX) * 180 / Math.PI + 90
}
playerBoundingBox = playerBoundingBox.offset(pos.xCoord - mc.thePlayer.posX, pos.yCoord - mc.thePlayer.posY, pos.zCoord - mc.thePlayer.posZ)
if (playerBoundingBox.calculateIntercept(posBefore, posAfter) && poses.length <= ticksToDodge.get()) {
targetPos = posBefore
dodging = Math.atan2(motionZ, motionX) * 180 / Math.PI + 90
}
// motion thing
x += motionX
y += motionY
z += motionZ
if (mc.theWorld.getBlockState(new BlockPos(x, y, z)).getBlock()
.getMaterial() == Material.water) {
// Update motion
motionX *= 0.6
motionY *= 0.6
motionZ *= 0.6
} else { // Update motion
motionX *= 0.99
motionY *= 0.99
motionZ *= 0.99
}
motionY -= 0.05
}
return poses
}
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();
}