diff options
| author | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-09-17 19:39:05 +0800 |
|---|---|---|
| committer | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2022-09-17 19:39:05 +0800 |
| commit | 431e4fc9d1657a50ebc34b8ac24f9bfaea06417f (patch) | |
| tree | 5987bb14f38d2999c682970429f34b41eb3e5826 /src/utils | |
| parent | e73f2efdf0f50aa775c540317394d46428e9704f (diff) | |
| download | SoopyV2-431e4fc9d1657a50ebc34b8ac24f9bfaea06417f.tar.gz SoopyV2-431e4fc9d1657a50ebc34b8ac24f9bfaea06417f.tar.bz2 SoopyV2-431e4fc9d1657a50ebc34b8ac24f9bfaea06417f.zip | |
Initial move to babel + change fetch to use async/await
Diffstat (limited to 'src/utils')
| -rw-r--r-- | src/utils/delayUtils.js | 29 | ||||
| -rw-r--r-- | src/utils/networkUtils.js | 185 | ||||
| -rw-r--r-- | src/utils/nonPooledThread.js | 14 | ||||
| -rw-r--r-- | src/utils/numberUtils.js | 102 | ||||
| -rw-r--r-- | src/utils/renderJavaUtils.js | 413 | ||||
| -rw-r--r-- | src/utils/renderLib2d.js | 172 | ||||
| -rw-r--r-- | src/utils/renderUtils.js | 407 | ||||
| -rw-r--r-- | src/utils/statUtils.js | 1204 | ||||
| -rw-r--r-- | src/utils/stringUtils.js | 15 | ||||
| -rw-r--r-- | src/utils/utils.js | 141 |
10 files changed, 2682 insertions, 0 deletions
diff --git a/src/utils/delayUtils.js b/src/utils/delayUtils.js new file mode 100644 index 0000000..3ec6d95 --- /dev/null +++ b/src/utils/delayUtils.js @@ -0,0 +1,29 @@ +const { default: FlatQueue } = require("../datastructures/flatqueue") + +if (!global.delayThingSoopy) { + + let functionQueue = new FlatQueue() + let functions = new Map() + let functionId = 0 + + function delay(time, callback) { + let id = functionId++ + functions.set(id, callback) + functionQueue.push(id, Date.now() + time) + } + + register("tick", () => { + while (functionQueue.length > 0 && Date.now() > functionQueue.peekValue()) { + let id = functionQueue.pop() + + functions.get(id)() + functions.delete(id) + } + }) + + global.delayThingSoopy = { + delay: delay + } +} + +module.exports = global.delayThingSoopy diff --git a/src/utils/networkUtils.js b/src/utils/networkUtils.js new file mode 100644 index 0000000..ca3270a --- /dev/null +++ b/src/utils/networkUtils.js @@ -0,0 +1,185 @@ +if (!global.networkUtilsThingSoopyPromise) { + + let jURL = Java.type("java.net.URL") + let jStandardCharsets = Java.type("java.nio.charset.StandardCharsets") + let jCollectors = Java.type("java.util.stream.Collectors") + let jBufferedReader = Java.type("java.io.BufferedReader") + let jInputStreamReader = Java.type("java.io.InputStreamReader") + let jString = Java.type("java.lang.String") + + function getUrlContent(theUrl, { userAgent = "Mozilla/5.0", includeConnection = false, postData = undefined } = {}) { + + if (global.soopyv2loggerthing) { + global.soopyv2loggerthing.logMessage("Loading API: " + theUrl, 4) + } + + // if(theUrl.includes("soopy.dev")){ + // throw new Error("Testing to ensure the module works when my server is down") + // } + // Thread.sleep(1000) //simulating high ping + + let conn = new jURL(theUrl).openConnection() + conn.setRequestProperty("User-Agent", userAgent) + + if (postData) { + conn.setRequestMethod("POST"); + conn.setRequestProperty("Content-Type", "application/json"); + conn.setDoOutput(true); + + let jsonInputString = new jString(JSON.stringify(postData)) + + let os + try { + os = conn.getOutputStream() + input = jsonInputString.getBytes("utf-8"); + os.write(input, 0, input.length); + } finally { + os.close() + } + } + + let stringData + + if (conn.getResponseCode() < 400) { + stringData = new jBufferedReader( + new jInputStreamReader(conn.getInputStream(), jStandardCharsets.UTF_8)) + .lines() + .collect(jCollectors.joining("\n")); + + conn.getInputStream().close() + } else { + stringData = new jBufferedReader( + new jInputStreamReader(conn.getErrorStream(), jStandardCharsets.UTF_8)) + .lines() + .collect(jCollectors.joining("\n")); + + conn.getErrorStream().close() + } + + if (includeConnection) { + return { stringData, connection: conn } + } + + return stringData + } + + function fetch(url, options = { userAgent: "Mozilla/5.0" }) { + let loadedConnection = undefined + let loadedString = undefined + let loadedJSON = undefined + + let ret = { + loadSync() { + if (loadedString === undefined) { + options.includeConnection = true + + try { + let data = getUrlContent(url, options) + loadedString = data.stringData + loadedConnection = data.connection + } catch (e) { + errorData = e + loadedString = null + } + } + + return ret + }, + async load(_ifError = false) { + if (loadedString === undefined) { + options.includeConnection = true + + await new Promise((res, rej) => { + pendingRequests.push({ + callback: (data) => { + loadedString = data.stringData + loadedConnection = data.connection + res() + }, + errcallback: (e) => { + rej(e) + }, + url: url, + options: options + }) + }) + } + }, + textSync() { + ret.loadSync() + + return loadedString + }, + async text() { + await ret.load() + + return loadedString + }, + jsonSync() { + if (loadedJSON === undefined) { + let str = ret.textSync() + + loadedJSON = JSON.parse(str) + } + + return loadedJSON + }, + async json() { + if (loadedJSON === undefined) { + let str = await ret.text() + + loadedJSON = JSON.parse(str) + } + + return loadedJSON + }, + responseCode() { + return loadedConnection?.getResponseCode() || -1 + } + } + return ret + } + + let pendingRequests = [] + let pendingResolves = [] + let runningThread = false + + register("tick", () => { + try { + while (pendingResolves.length > 0) { + let [callback, data] = pendingResolves.shift() + + callback(data) + } + } catch (e) { + console.log(JSON.stringify(e, undefined, 2)) + console.log(e.stack) + } + + if (pendingRequests.length > 0 && !runningThread) { + runningThread = true + new Thread(() => { + while (pendingRequests.length > 0) { + let req = pendingRequests.shift() + + try { + let data = getUrlContent(req.url, req.options) + + pendingResolves.push([req.callback, data]) + } catch (e) { + pendingResolves.push([req.errcallback, e]) + } + } + + runningThread = false + }).start() + } + }) + + global.networkUtilsThingSoopyPromise = { + getUrlContent: getUrlContent, + fetch: fetch + } +} + +module.exports = global.networkUtilsThingSoopyPromise diff --git a/src/utils/nonPooledThread.js b/src/utils/nonPooledThread.js new file mode 100644 index 0000000..4720700 --- /dev/null +++ b/src/utils/nonPooledThread.js @@ -0,0 +1,14 @@ +let Executors = Java.type("java.util.concurrent.Executors") + +class NonPooledThread { + constructor(fun) { + this.fun = fun + this.executor = Executors.newSingleThreadExecutor() + } + + start() { + this.executor.execute(this.fun) + } +} + +export default NonPooledThread
\ No newline at end of file diff --git a/src/utils/numberUtils.js b/src/utils/numberUtils.js new file mode 100644 index 0000000..8d5e7c3 --- /dev/null +++ b/src/utils/numberUtils.js @@ -0,0 +1,102 @@ +let utils = { + numberWithCommas: function (x) { + if (x === undefined) { return "" } + var parts = x.toString().split("."); + parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ","); + return parts.join("."); + }, + addNotation: function (type, value, joiner = "") { + let returnVal = value; + let notList = []; + if (type === "shortScale") { + //notation type + //do notation stuff here + notList = [ + " Thousand", + " Million", + " Billion", + " Trillion", + " Quadrillion", + " Quintillion" + ]; + } + + if (type === "oneLetters") { + notList = [" K", " M", " B", " T"]; + } + + let checkNum = 1000; + + if (type !== "none" && type !== "commas") { + let notValue = notList[notList.length - 1]; + for (let u = notList.length; u >= 1; u--) { + notValue = notList.shift(); + for (let o = 3; o >= 1; o--) { + if (value >= checkNum) { + returnVal = value / (checkNum / 100); + returnVal = Math.floor(returnVal); + returnVal = (returnVal / Math.pow(10, o)) * 10; + returnVal = +returnVal.toFixed(o - 1) + joiner + notValue; + } + checkNum *= 10; + } + } + } else { + returnVal = this.numberWithCommas(value.toFixed(0)); + } + + return returnVal; + }, + timeSince: function (date) { + if (typeof date !== 'object') { + date = new Date(date); + } + + var seconds = Math.floor((new Date() - date) / 1000); + var intervalType; + + var interval = Math.floor(seconds / 31536000); + interval = Math.floor(seconds / 86400); + if (interval >= 1) { + intervalType = 'd'; + } else { + interval = Math.floor(seconds / 3600); + if (interval >= 1) { + intervalType = "h"; + } else { + interval = Math.floor(seconds / 60); + if (interval >= 1) { + intervalType = "m"; + } else { + interval = seconds; + intervalType = "s"; + } + } + } + + return interval + '' + intervalType; + }, + timeSince2: (date) => { + let time = Date.now() - date + + if (time > 30 * 60000) { + return utils.timeNumber2(time) + } + return utils.timeNumber(time) + }, + timeNumber: (time, secondDecimals = 0) => { + let mins = Math.floor(time / 1000 / 60) + let secs = (time / 1000) % 60 + + if (mins === 0) return `${secs.toFixed(secondDecimals)}s` + return `${mins}m ${secs.toFixed(secondDecimals)}s` + }, + timeNumber2: (time) => { + let hours = Math.floor(time / 1000 / 60 / 60) + let mins = Math.floor(time / 1000 / 60) % 60 + + if (hours === 0) return mins + "m" + return `${hours}h ${mins}m` + } +} +module.exports = utils diff --git a/src/utils/renderJavaUtils.js b/src/utils/renderJavaUtils.js new file mode 100644 index 0000000..6a16cda --- /dev/null +++ b/src/utils/renderJavaUtils.js @@ -0,0 +1,413 @@ +import { m } from "../../mappings/mappings" +import { numberWithCommas } from "./numberUtils" + +let SoopyV2Forge = Java.type("me.soopyboo32.soopyv2forge.SoopyV2Forge").INSTANCE + +let LASTEST_SOOPYFORGE_VER = "1.1" // uncomment out on new soopyv2forge version +let canUseForgeRendering = net.minecraftforge.fml.common.Loader.isModLoaded("soopyv2forge")// && SoopyV2Forge.getVersion() === LASTEST_SOOPYFORGE_VER + +let ArrayList = Java.type("java.util.ArrayList") + +let Vec3 = Java.type("net.minecraft.util.Vec3") +let Vector2f = Java.type("javax.vecmath.Vector2f") +let RenderPointsC = Java.type("me.soopyboo32.soopyv2forge.RenderTypes.Points") +let RenderWorldTextC = Java.type("me.soopyboo32.soopyv2forge.RenderTypes.WorldText") +let RenderBeaconC = Java.type("me.soopyboo32.soopyv2forge.RenderTypes.Beacon") +let HudPointsC = Java.type("me.soopyboo32.soopyv2forge.RenderTypes.HudPoints") +let HudTextC = Java.type("me.soopyboo32.soopyv2forge.RenderTypes.HudText") + +let addFix = false +if (!global.soopyv2RenderWorldThings) { + global.soopyv2RenderWorldThings = new Set() + addFix = true +} +if (!global.soopyv2RenderHudThings) global.soopyv2RenderHudThings = new Set() + +register("gameUnload", () => { + global.soopyv2RenderWorldThings.clear() + SoopyV2Forge.setRenderWorldList(new ArrayList([])) + global.soopyv2RenderHudThings.clear() + SoopyV2Forge.setRenderHudList(new ArrayList([])) +}) + +let currentlyRendering = true +export function setRendering(rendering) { + if (!rendering) { + setRenderWorldList(new ArrayList([])) + setRenderHudList(new ArrayList([])) + } + currentlyRendering = rendering + if (rendering) { + setRenderWorldList(new ArrayList([...global.soopyv2RenderWorldThings])) + setRenderHudList(new ArrayList([...global.soopyv2RenderHudThings])) + } +} + +function setRenderWorldList(data) { + if (currentlyRendering) SoopyV2Forge.setRenderWorldList(data) +} +function setRenderHudList(data) { + if (currentlyRendering) SoopyV2Forge.setRenderHudList(data) +} + +class RenderWorldAble { + startRender(isBatched) { + if (!canUseForgeRendering) return + if (global.soopyv2RenderWorldThings.has(this.javaObj)) return this + global.soopyv2RenderWorldThings.add(this.javaObj) + if (!isBatched) setRenderWorldList(new ArrayList([...global.soopyv2RenderWorldThings])) + return this + } + stopRender(isBatched) { + if (!canUseForgeRendering) return + if (!global.soopyv2RenderWorldThings.has(this.javaObj)) return this + global.soopyv2RenderWorldThings.delete(this.javaObj) + if (!isBatched) setRenderWorldList(new ArrayList([...global.soopyv2RenderWorldThings])) + return this + } +} +class RenderHudAble { + startRender() { + if (!canUseForgeRendering) return + if (global.soopyv2RenderHudThings.has(this.javaObj)) return this + global.soopyv2RenderHudThings.add(this.javaObj) + setRenderHudList(new ArrayList([...global.soopyv2RenderHudThings])) + return this + } + stopRender() { + if (!canUseForgeRendering) return + if (!global.soopyv2RenderHudThings.has(this.javaObj)) return this + global.soopyv2RenderHudThings.delete(this.javaObj) + setRenderHudList(new ArrayList([...global.soopyv2RenderHudThings])) + return this + } +} + +export class Points extends RenderWorldAble { + constructor(points, r, g, b, a, thickness, depth) { + this.javaObj = new RenderPointsC(new ArrayList(points.map(a => new Vec3(...a))), r, g, b, a, thickness, depth) + } + + setPoints(points) { + this.javaObj.points = new ArrayList(points.map(a => new Vec3(...a))) + return this + } + setRGBA(r, g, b, a) { + this.javaObj.red = r + this.javaObj.green = g + this.javaObj.blue = b + this.javaObj.alpha = a + return this + } + setThickness(thickness) { + this.javaObj.thickness = thickness + return this + } + setDepth(depth) { + this.javaObj.depthtest = depth + return this + } + setDisableCullFace(disable) { + this.javaObj.disableCullFace = disable + return this + } + setGLMode(glMode) { + this.javaObj.glmode = glMode + return this + } +} +export class FilledPoints extends Points { + constructor(points, r, g, b, a, thickness, depth) { + super(points, r, g, b, a, thickness, depth) + + this.setGLMode(GL11.GL_QUADS) + this.setDisableCullFace(true) + } +} +export class Box extends Points { + constructor(location, size, r, g, b, a, thickness, depth) { + super(Box.getPointsFromLocationSize(location, size), r, g, b, a, thickness, depth) + } + + setLocationSize(location, size) { + this.setPoints(Box.getPointsFromLocationSize(location, size)) + return this + } + + static getPointsFromLocationSize(location, size) { + let [x, y, z] = location + let [width, height, width2] = size + + return [[x + width, y + height, z + width2], + [x + width, y + height, z], + [x, y + height, z], + [x, y + height, z + width2], + [x + width, y + height, z + width2], + [x + width, y, z + width2], + [x + width, y, z], + [x, y, z], + [x, y, z + width2], + [x, y, z], + [x, y + height, z], + [x, y, z], + [x + width, y, z], + [x + width, y + height, z], + [x + width, y, z], + [x + width, y, z + width2], + [x, y, z + width2], + [x, y + height, z + width2], + [x + width, y + height, z + width2]] + } +} +export class FilledBox extends FilledPoints { + constructor(location, size, r, g, b, a, thickness, depth) { + super(FilledBox.getPointsFromLocationSize(location, size), r, g, b, a, thickness, depth) + } + + setLocationSize(location, size) { + this.setPoints(FilledBox.getPointsFromLocationSize(location, size)) + return this + } + + static getPointsFromLocationSize(location, size) { + let [x, y, z] = location + let [w, h, w2] = size + + return [ + [x + w, y + 0, z + w2], + [x + w, y + 0, z], + [x, y + 0, z], + [x, y + 0, z + w2], + + [x + w, y + h, z + w2], + [x + w, y + h, z], + [x, y + h, z], + [x, y + h, z + w2], + + [x, y + h, z + w2], + [x, y + h, z], + [x, y + 0, z], + [x, y + 0, z + w2], + + [x + w, y + h, z + w2], + [x + w, y + h, z], + [x + w, y + 0, z], + [x + w, y + 0, z + w2], + + [x + w, y + h, z], + [x, y + h, z], + [x, y + 0, z], + [x + w, y + 0, z], + + [x, y + h, z + w2], + [x + w, y + h, z + w2], + [x + w, y + 0, z + w2], + [x, y + 0, z + w2] + ] + } +} +export class WorldText extends RenderWorldAble { + constructor(location, text, depth, scale) { + this.javaObj = new RenderWorldTextC(new Vec3(...location), text, depth, scale) + } + + setLocation(location) { + this.javaObj.location = new Vec3(...location) + return this + } + setText(text) { + this.javaObj.text = text + return this + } + setDepthtest(depthtest) { + this.javaObj.depthtest = depthtest + return this + } + setScale(scale) { + this.javaObj.scale = scale + return this + } + setShadow(shadow) { + this.javaObj.shadow = shadow + return this + } +} + +export class Beacon extends RenderWorldAble { + constructor(location, r, g, b, a, depth) { + this.javaObj = new RenderBeaconC(new Vec3(...location), r, g, b, a, depth) + } + + setLocation(location) { + this.javaObj.location = new Vec3(...location) + return this + } + setRGBA(r, g, b, a) { + this.javaObj.red = r + this.javaObj.green = g + this.javaObj.blue = b + this.javaObj.alpha = a + return this + } + setDepthtest(depthtest) { + this.javaObj.depthtest = depthtest + return this + } + +} +export class HudPoints extends RenderHudAble { + constructor(points, r, g, b, a, thickness) { + this.javaObj = new HudPointsC(new ArrayList(points.map(a => new Vector2f(...a))), r, g, b, a, thickness) + } + + setPoints(points) { + this.javaObj.points = new ArrayList(points.map(a => new Vec3(...a))) + return this + } + setRGBA(r, g, b, a) { + this.javaObj.colorR = r + this.javaObj.colorG = g + this.javaObj.colorB = b + this.javaObj.colorA = a + return this + } + setThickness(thickness) { + this.javaObj.thickness = thickness + return this + } + setGlmode(glmode) { + this.javaObj.glmode = glmode + return this + } +} +export class HudText extends RenderHudAble { + constructor(text, x, y, shadow) { + this.javaObj = new HudTextC(text, x, y, shadow) + } + + setText(text) { + this.javaObj.textLines = text + return this + } + setX(x) { + this.javaObj.x = x + return this + } + setY(y) { + this.javaObj.y = y + return this + } + setScale(scale) { + this.javaObj.scale = scale + return this + } + setShadow(shadow) { + this.javaObj.shadow = shadow + return this + } +} + +export class Waypoint extends FilledBox { + constructor(x, y, z, r, g, b, { name = "", showDist = !!name, phase = false }) { + this.rendering = false + + let distToPlayerSq = (x - Player.getRenderX()) ** 2 + (y - (Player.getRenderY() + Player.getPlayer()[m.getEyeHeight]())) ** 2 + (z - Player.getRenderZ()) ** 2 + + let alpha = Math.min(1, Math.max(0, 1 - (distToPlayerSq - 10000) / 12500)) + + super([x - 0.001, y - 0.001, z - 0.001], [1.002, 1.002, 1.002], r, g, b, 0.25 * alpha, 1, !phase) + + this.params = { x, y, z, r, g, b, name, showDist, phase } + + this.outLine = new Box([x - 0.002, y - 0.002, z - 0.002], [1.004, 1.004, 1.004], r, g, b, alpha, 3, !phase) + this.beam = new Beacon([x, y + 1, z], r, g, b, Math.min(1, Math.max(0, (distToPlayerSq - 25) / 100)) * alpha, true) + + let distToPlayer = Math.sqrt(distToPlayerSq) + + let distRender = Math.min(distToPlayer, 50) + + let loc5 = [Player.getRenderX() + (x + 0.5 - Player.getRenderX()) / (distToPlayer / distRender), (Player.getRenderY() + Player.getPlayer()[m.getEyeHeight]()) + (y + 2 + 20 * distToPlayer / 300 - (Player.getRenderY() + Player.getPlayer()[m.getEyeHeight]())) / (distToPlayer / distRender), Player.getRenderZ() + (z + 0.5 - Player.getRenderZ()) / (distToPlayer / distRender)] + let loc6 = [Player.getRenderX() + (x + 0.5 - Player.getRenderX()) / (distToPlayer / distRender), (Player.getRenderY() + Player.getPlayer()[m.getEyeHeight]()) + (y + 2 + 20 * distToPlayer / 300 - 10 * distToPlayer / 300 - (Player.getRenderY() + Player.getPlayer()[m.getEyeHeight]())) / (distToPlayer / distRender), Player.getRenderZ() + (z + 0.5 - Player.getRenderZ()) / (distToPlayer / distRender)] + + this.textLine1 = new WorldText([loc5[0], loc5[1], loc5[2]], "§a" + name, false, distRender / 12) + this.textLine2 = new WorldText([(name ? loc6[0] : loc5[0]), (name ? loc6[1] : loc5[1]), (name ? loc6[2] : loc5[2])], "§b(" + numberWithCommas(Math.round(distToPlayer)) + "m)", false, distRender / 12) + } + + update() { + let { x, y, z, r, g, b, name, showDist } = this.params + + let distToPlayerSq = (x - Player.getRenderX()) ** 2 + (y - (Player.getRenderY() + Player.getPlayer()[m.getEyeHeight]())) ** 2 + (z - Player.getRenderZ()) ** 2 + + let alpha = Math.min(1, Math.max(0, 1 - (distToPlayerSq - 10000) / 12500)) + + this.setRGBA(r, g, b, 0.25 * alpha) + this.outLine.setRGBA(r, g, b, alpha) + this.beam.setRGBA(r, g, b, Math.min(1, Math.max(0, (distToPlayerSq - 25) / 100)) * alpha) + + if (name || showDist) { + let distToPlayer = Math.sqrt(distToPlayerSq) + + let distRender = Math.min(distToPlayer, 100) + + let loc5 = [Player.getRenderX() + (x + 0.5 - Player.getRenderX()) / (distToPlayer / distRender), (Player.getRenderY() + Player.getPlayer()[m.getEyeHeight]()) + (y + 2 + 20 * distToPlayer / 300 - (Player.getRenderY() + Player.getPlayer()[m.getEyeHeight]())) / (distToPlayer / distRender), Player.getRenderZ() + (z + 0.5 - Player.getRenderZ()) / (distToPlayer / distRender)] + let loc6 = [Player.getRenderX() + (x + 0.5 - Player.getRenderX()) / (distToPlayer / distRender), (Player.getRenderY() + Player.getPlayer()[m.getEyeHeight]()) + (y + 2 + 20 * distToPlayer / 300 - 10 * distToPlayer / 300 - (Player.getRenderY() + Player.getPlayer()[m.getEyeHeight]())) / (distToPlayer / distRender), Player.getRenderZ() + (z + 0.5 - Player.getRenderZ()) / (distToPlayer / distRender)] + + this.textLine1.setLocation([loc5[0], loc5[1], loc5[2]]).setScale(distRender / 12) + this.textLine2.setLocation([(name ? loc6[0] : loc5[0]), (name ? loc6[1] : loc5[1]), (name ? loc6[2] : loc5[2])]).setScale(distRender / 12).setText("§b(" + numberWithCommas(Math.round(distToPlayer)) + "m)") + } + } + + startRender(isBatched) { + if (this.rendering) return this + this.rendering = true + + super.startRender(true) + this.outLine.startRender(true) + this.beam.startRender(true) + if (this.params.name) this.textLine1.startRender(true) + if (this.params.showDist) this.textLine2.startRender(true) + + if (!isBatched) setRenderWorldList(new ArrayList([...global.soopyv2RenderWorldThings])) + return this + } + + stopRender(isBatched) { + if (!this.rendering) return this + this.rendering = false + + super.stopRender(true) + this.outLine.stopRender(true) + this.beam.stopRender(true) + this.textLine1.stopRender(true) + this.textLine2.stopRender(true) + + if (!isBatched) setRenderWorldList(new ArrayList([...global.soopyv2RenderWorldThings])) + return this + } +} + +register("worldLoad", () => { + if (!net.minecraftforge.fml.common.Loader.isModLoaded("soopyv2forge")) { + ChatLib.chat("&1" + ChatLib.getChatBreak("-").trim()) + ChatLib.chat("§cWARNING: You dont have the forge mod for soopyv2 installed") + ChatLib.chat("§cWARNING: -> almost nothing can be rendered") + new TextComponent(" &e[CLICK] &7- Download").setHover("show_text", "&2Download").setClick("open_url", "https://github.com/Soopyboo32/SoopyV2Forge/releases").chat() + ChatLib.chat("Or if u want to remove soopyv2 run /ct delete soopyv2") + ChatLib.chat("&1" + ChatLib.getChatBreak("-").trim()) + } + if (SoopyV2Forge.getVersion() !== LASTEST_SOOPYFORGE_VER) { + ChatLib.chat("&1" + ChatLib.getChatBreak("-").trim()) + ChatLib.chat("§cWARNING: Your forge version of soopyv2 is outdated") + if (LASTEST_SOOPYFORGE_VER === "1.1") { + ChatLib.chat("§cWARNING: this does not affect much at the moment, but has an incorect download url") + } else { + ChatLib.chat("§cWARNING: -> almost nothing can be rendered") + } + new TextComponent(" &e[CLICK] &7- Download").setHover("show_text", "&2Download update").setClick("open_url", "https://github.com/Soopyboo32/SoopyV2Forge/releases").chat() + ChatLib.chat("&1" + ChatLib.getChatBreak("-").trim()) + } +}) + +if (addFix) { + new Box([-1000000000, 0, 0], 0, 0, 0, 0, 0, 1, false).startRender() +}
\ No newline at end of file diff --git a/src/utils/renderLib2d.js b/src/utils/renderLib2d.js new file mode 100644 index 0000000..30ac28f --- /dev/null +++ b/src/utils/renderLib2d.js @@ -0,0 +1,172 @@ + +//-------------------------------------------------------------------------- +// CODE BY DJtheRedstoner +// IM COPYING THIS BECAUSE THE UPLOADED VERSION IS FOR +// CT 2.0.0 ONLY +// +// Edit: iv added some features to this so might keep as is +//-------------------------------------------------------------------------- + +import { f, m } from "../../mappings/mappings"; + + +const BufferUtils = org.lwjgl.BufferUtils; +const Project = org.lwjgl.util.glu.Project; + +const modelViewMatrix = BufferUtils.createFloatBuffer(16); +const projectionMatrix = BufferUtils.createFloatBuffer(16); +const viewportDims = BufferUtils.createIntBuffer(16); + +if(!GlStateManager){ + var GL11 = Java.type("org.lwjgl.opengl.GL11"); //using var so it goes to global scope + var GlStateManager = Java.type("net.minecraft.client.renderer.GlStateManager"); +} + +const ScaledResolution = net.minecraft.client.gui.ScaledResolution; + +const AxisAlignedBB = Java.type("net.minecraft.util.AxisAlignedBB") + +register('renderWorld', () => { + GlStateManager[m.pushMatrix](); + + let x = Player.getX(); + let y = Player.getY(); + let z = Player.getZ(); + + Tessellator.translate(-x, -y, -z); + + GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelViewMatrix); + GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projectionMatrix); + + GlStateManager[m.popMatrix](); + + GL11.glGetInteger(GL11.GL_VIEWPORT, viewportDims); +}); + +export default class RenderLib2D { + // Utils + + // Original made by DJtheRedstoner + static projectPoint = (posX, posY, posZ) => { + const coords = BufferUtils.createFloatBuffer(3); + const success = Project.gluProject( + posX, + posY, + posZ, + modelViewMatrix, + projectionMatrix, + viewportDims, + coords + ); + + const z = coords.get(2); + if (!success || !(z > 0 && z < 1)) return null; + + const sr = new ScaledResolution(Client.getMinecraft()); + + const x = coords.get(0) / sr[m.getScaleFactor](); // getScaleFactor + let y = coords.get(1) / sr[m.getScaleFactor](); // getScaleFactor + // OpenGL starts at bottom left, mc starts at top left + y = sr[m.getScaledHeight]() - y; // getScaledHeight + + return { x, y, z }; + } + + static drawLine(x1, y1, z1, x2, y2, z2, color, thickness=1) { + let pos1 = RenderLib2D.projectPoint(x1, y1, z1); + let pos2 = RenderLib2D.projectPoint(x2, y2, z2); + + if(!pos1 || !pos2) return; + + let {x, y} = pos1 + let {x:ox, y:oy} = pos2 + + // console.log(x, y, ox, oy, thickness) + Renderer.drawLine(color, x, y, ox, oy, thickness); + } + + // Original made by DJtheRedstoner + static calculateBoundingBox = (box) => { + let vertices = RenderLib2D.getVertices(box); + + let x1 = java.lang.Float.MAX_VALUE; + let x2 = 0; + let y1 = java.lang.Float.MAX_VALUE; + let y2 = 0; + + vertices.forEach(vertex => { + let vec = RenderLib2D.projectPoint(vertex.x, vertex.y, vertex.z); + if (vec == null) return null; + + let x = vec.x; + let y = vec.y; + + if (x < x1) x1 = x; + if (x > x2) x2 = x; + if (y < y1) y1 = y; + if (y > y2) y2 = y; + }); + + return { x1, y1, x2, y2 }; + } + + static getVertices = (box) => { + let list = []; + + list.push({ x: box[f.minX.AxisAlignedBB], y: box[f.minY.AxisAlignedBB], z: box[f.minZ.AxisAlignedBB] }); + list.push({ x: box[f.maxX.AxisAlignedBB], y: box[f.minY.AxisAlignedBB], z: box[f.minZ.AxisAlignedBB] }); + list.push({ x: box[f.maxX.AxisAlignedBB], y: box[f.maxY.AxisAlignedBB], z: box[f.minZ.AxisAlignedBB] }); + list.push({ x: box[f.minX.AxisAlignedBB], y: box[f.maxY.AxisAlignedBB], z: box[f.minZ.AxisAlignedBB] }); + list.push({ x: box[f.minX.AxisAlignedBB], y: box[f.minY.AxisAlignedBB], z: box[f.maxZ.AxisAlignedBB] }); + list.push({ x: box[f.maxX.AxisAlignedBB], y: box[f.minY.AxisAlignedBB], z: box[f.maxZ.AxisAlignedBB] }); + list.push({ x: box[f.maxX.AxisAlignedBB], y: box[f.maxY.AxisAlignedBB], z: box[f.maxZ.AxisAlignedBB] }); + list.push({ x: box[f.minX.AxisAlignedBB], y: box[f.maxY.AxisAlignedBB], z: box[f.maxZ.AxisAlignedBB] }); + + return list; + } + + // Rendering Functions + + static drawNameTag = (vec, string) => { + if (vec === null) return; + + Renderer.drawStringWithShadow(string, vec.x - Renderer.getStringWidth(string) / 2, vec.y); + } + + static draw2DESP = (aabb, color, thickness) => { + let bb = RenderLib2D.calculateBoundingBox(aabb); + + Renderer.drawLine(color, bb.x1, bb.y1, bb.x1, bb.y2, thickness); + Renderer.drawLine(color, bb.x1, bb.y1, bb.x2, bb.y1, thickness); + Renderer.drawLine(color, bb.x2, bb.y2, bb.x2, bb.y1, thickness); + Renderer.drawLine(color, bb.x2, bb.y2, bb.x1, bb.y2, thickness); + } + + static draw3DESP = (aabb, color, thickness) => { + let vertices = RenderLib2D.getVertices(aabb); + let projected = []; + + vertices.forEach(vertex => { + let vec = RenderLib2D.projectPoint(vertex.x, vertex.y, vertex.z); + if (vec == null) return null; + projected.push(vec); + }); + + if (projected[0] && projected[1]) Renderer.drawLine(color, projected[0].x, projected[0].y, projected[1].x, projected[1].y, thickness); + if (projected[0] && projected[4]) Renderer.drawLine(color, projected[0].x, projected[0].y, projected[4].x, projected[4].y, thickness); + if (projected[5] && projected[1]) Renderer.drawLine(color, projected[5].x, projected[5].y, projected[1].x, projected[1].y, thickness); + if (projected[5] && projected[4]) Renderer.drawLine(color, projected[5].x, projected[5].y, projected[4].x, projected[4].y, thickness); + if (projected[3] && projected[2]) Renderer.drawLine(color, projected[3].x, projected[3].y, projected[2].x, projected[2].y, thickness); + if (projected[3] && projected[7]) Renderer.drawLine(color, projected[3].x, projected[3].y, projected[7].x, projected[7].y, thickness); + if (projected[6] && projected[2]) Renderer.drawLine(color, projected[6].x, projected[6].y, projected[2] |
