diff options
author | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2021-10-31 09:49:42 +0800 |
---|---|---|
committer | Soopyboo32 <49228220+Soopyboo32@users.noreply.github.com> | 2021-10-31 09:49:42 +0800 |
commit | 48653ec89538f1650106a5e77463412cad4684c2 (patch) | |
tree | 09687cd579462e04d539fd4615369fa6dae13902 /utils | |
download | SoopyV2-48653ec89538f1650106a5e77463412cad4684c2.tar.gz SoopyV2-48653ec89538f1650106a5e77463412cad4684c2.tar.bz2 SoopyV2-48653ec89538f1650106a5e77463412cad4684c2.zip |
first commit
Diffstat (limited to 'utils')
-rw-r--r-- | utils/numberUtils.js | 50 | ||||
-rw-r--r-- | utils/renderLib2d.js | 147 | ||||
-rw-r--r-- | utils/renderUtils.js | 291 | ||||
-rw-r--r-- | utils/stringUtils.js | 11 | ||||
-rw-r--r-- | utils/utils.js | 116 |
5 files changed, 615 insertions, 0 deletions
diff --git a/utils/numberUtils.js b/utils/numberUtils.js new file mode 100644 index 0000000..ccc270e --- /dev/null +++ b/utils/numberUtils.js @@ -0,0 +1,50 @@ +module.exports = { + 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) { + 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) + notValue; + } + checkNum *= 10; + } + } + } else { + returnVal = this.numberWithCommas(value.toFixed(0)); + } + + return returnVal; + } +}
\ No newline at end of file diff --git a/utils/renderLib2d.js b/utils/renderLib2d.js new file mode 100644 index 0000000..b2defd1 --- /dev/null +++ b/utils/renderLib2d.js @@ -0,0 +1,147 @@ + +//-------------------------------------------------------------------------- +// CODE BY DJtheRedstoner +// IM COPYING THIS BECAUSE THE UPLOADED VERSION IS FOR +// CT 2.0.0 ONLY +//-------------------------------------------------------------------------- + +//TODO: just require the module when ct 2.0 comes out + + + +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); + +const ScaledResolution = net.minecraft.client.gui.ScaledResolution; + +register('renderWorld', () => { + Tessellator.pushMatrix(); + + let x = Player.getRenderX(); + let y = Player.getRenderY(); + let z = Player.getRenderZ(); + + Tessellator.translate(-x, -y, -z); + + GL11.glGetFloat(GL11.GL_MODELVIEW_MATRIX, modelViewMatrix); + GL11.glGetFloat(GL11.GL_PROJECTION_MATRIX, projectionMatrix); + + Tessellator.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.func_78325_e(); // getScaleFactor + let y = coords.get(1) / sr.func_78325_e(); // getScaleFactor + // OpenGL starts at bottom left, mc starts at top left + y = sr.func_78328_b() - y; // getScaledHeight + + return { x, y, z }; + } + + // 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.field_72340_a, y: box.field_72338_b, z: box.field_72339_c }); + list.push({ x: box.field_72336_d, y: box.field_72338_b, z: box.field_72339_c }); + list.push({ x: box.field_72336_d, y: box.field_72337_e, z: box.field_72339_c }); + list.push({ x: box.field_72340_a, y: box.field_72337_e, z: box.field_72339_c }); + list.push({ x: box.field_72340_a, y: box.field_72338_b, z: box.field_72334_f }); + list.push({ x: box.field_72336_d, y: box.field_72338_b, z: box.field_72334_f }); + list.push({ x: box.field_72336_d, y: box.field_72337_e, z: box.field_72334_f }); + list.push({ x: box.field_72340_a, y: box.field_72337_e, z: box.field_72334_f }); + + 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].x, projected[2].y, thickness); + if (projected[6] && projected[7]) Renderer.drawLine(color, projected[6].x, projected[6].y, projected[7].x, projected[7].y, thickness); + if (projected[1] && projected[2]) Renderer.drawLine(color, projected[1].x, projected[1].y, projected[2].x, projected[2].y, thickness); + if (projected[0] && projected[3]) Renderer.drawLine(color, projected[0].x, projected[0].y, projected[3].x, projected[3].y, thickness); + if (projected[4] && projected[7]) Renderer.drawLine(color, projected[4].x, projected[4].y, projected[7].x, projected[7].y, thickness); + if (projected[5] && projected[6]) Renderer.drawLine(color, projected[5].x, projected[5].y, projected[6].x, projected[6].y, thickness); + } +} diff --git a/utils/renderUtils.js b/utils/renderUtils.js new file mode 100644 index 0000000..1c91b6a --- /dev/null +++ b/utils/renderUtils.js @@ -0,0 +1,291 @@ + +const GlStateManager = Java.type("net.minecraft.client.renderer.GlStateManager"); +const GL11 = Java.type("org.lwjgl.opengl.GL11"); + +module.exports = { + + /* accepts parameters + * h Object = {h:x, s:y, v:z} + * OR + * h, s, v + */ + HSVtoRGB:function (h, s, v) { + var r, g, b, i, f, p, q, t; + if (arguments.length === 1) { + s = h.s, v = h.v, h = h.h; + } + i = Math.floor(h * 6); + f = h * 6 - i; + p = v * (1 - s); + q = v * (1 - f * s); + t = v * (1 - (1 - f) * s); + switch (i % 6) { + case 0: r = v, g = t, b = p; break; + case 1: r = q, g = v, b = p; break; + case 2: r = p, g = v, b = t; break; + case 3: r = p, g = q, b = v; break; + case 4: r = t, g = p, b = v; break; + case 5: r = v, g = p, b = q; break; + } + return { + r: r * 255, + g: g * 255, + b: b * 255 + }; + }, + drawLine:function (x, y, z, x2, y2, z2, r, g, b, thickness=1) { + + GL11.glBlendFunc(770, 771); + GL11.glEnable(GL11.GL_BLEND); + GL11.glLineWidth(thickness); + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glDisable(GL11.GL_DEPTH_TEST); + GL11.glDepthMask(false); + GlStateManager.func_179094_E(); + + Tessellator.begin(3).colorize(r, g, b); + + Tessellator.pos(x, y, z).tex(0, 0); + Tessellator.pos(x2, y2, z2).tex(0, 0); + + Tessellator.draw(); + + + GlStateManager.func_179121_F(); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glDepthMask(true); + GL11.glDisable(GL11.GL_BLEND); + }, + drawLineWithDepth:function (x, y, z, x2, y2, z2, r, g, b,t) { + + GL11.glBlendFunc(770, 771); + GL11.glEnable(GL11.GL_BLEND); + GL11.glLineWidth(t); + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glDepthMask(false); + GlStateManager.func_179094_E(); + + Tessellator.begin(3).colorize(r, g, b); + + Tessellator.pos(x, y, z).tex(0, 0); + Tessellator.pos(x2, y2, z2).tex(0, 0); + + Tessellator.draw(); + + + GlStateManager.func_179121_F(); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glDepthMask(true); + GL11.glDisable(GL11.GL_BLEND); + }, + drawLineSmall:function (x, y, z, x2, y2, z2, r, g, b) { + + Tessellator.begin(3).colorize(r, g, b); + + Tessellator.pos(x, y, z).tex(0, 0); + Tessellator.pos(x2, y2, z2).tex(0, 0); + + Tessellator.draw(); + }, + drawBoxAtBlockNotVisThruWalls:function (x, y, z, colorR, colorG, colorB){ + GL11.glBlendFunc(770, 771); + GL11.glEnable(GL11.GL_BLEND); + GL11.glLineWidth(3); + GL11.glDisable(GL11.GL_TEXTURE_2D); + GlStateManager.func_179094_E(); + + x -= 0.005 + y -= 0.005 + z -= 0.005 + + Tessellator.begin(3).colorize(colorR, colorG, colorB); + + Tessellator.pos(x+1.01,y+1.01,z+1.01).tex(0, 0); + Tessellator.pos(x+1.01,y+1.01,z).tex(0, 0); + Tessellator.pos(x,y+1.01,z).tex(0, 0); + Tessellator.pos(x,y+1.01,z+1.01).tex(0, 0); + Tessellator.pos(x+1.01,y+1.01,z+1.01).tex(0, 0); + Tessellator.pos(x+1.01,y,z+1.01).tex(0, 0); + Tessellator.pos(x+1.01,y,z).tex(0, 0); + Tessellator.pos(x,y,z).tex(0, 0); + Tessellator.pos(x,y,z+1.01).tex(0, 0); + Tessellator.pos(x,y,z).tex(0, 0); + Tessellator.pos(x,y+1.01,z).tex(0, 0); + Tessellator.pos(x,y,z).tex(0, 0); + Tessellator.pos(x+1.01,y,z).tex(0, 0); + Tessellator.pos(x+1.01,y+1.01,z).tex(0, 0); + Tessellator.pos(x+1.01,y,z).tex(0, 0); + Tessellator.pos(x+1.01,y,z+1.01).tex(0, 0); + Tessellator.pos(x,y,z+1.01).tex(0, 0); + Tessellator.pos(x,y+1.01,z+1.01).tex(0, 0); + Tessellator.pos(x+1.01,y+1.01,z+1.01).tex(0, 0); + + Tessellator.draw(); + + GlStateManager.func_179121_F(); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glDisable(GL11.GL_BLEND); + }, + drawBoxAtBlock:function (x, y, z, colorR, colorG, colorB){ + + GL11.glBlendFunc(770, 771); + GL11.glEnable(GL11.GL_BLEND); + GL11.glLineWidth(3); + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glDisable(GL11.GL_DEPTH_TEST); + GL11.glDepthMask(false); + GlStateManager.func_179094_E(); + + + Tessellator.begin(3).colorize(colorR, colorG, colorB); + + Tessellator.pos(x+1,y+1,z+1).tex(0, 0); + Tessellator.pos(x+1,y+1,z).tex(0, 0); + Tessellator.pos(x,y+1,z).tex(0, 0); + Tessellator.pos(x,y+1,z+1).tex(0, 0); + Tessellator.pos(x+1,y+1,z+1).tex(0, 0); + Tessellator.pos(x+1,y,z+1).tex(0, 0); + Tessellator.pos(x+1,y,z).tex(0, 0); + Tessellator.pos(x,y,z).tex(0, 0); + Tessellator.pos(x,y,z+1).tex(0, 0); + Tessellator.pos(x,y,z).tex(0, 0); + Tessellator.pos(x,y+1,z).tex(0, 0); + Tessellator.pos(x,y,z).tex(0, 0); + Tessellator.pos(x+1,y,z).tex(0, 0); + Tessellator.pos(x+1,y+1,z).tex(0, 0); + Tessellator.pos(x+1,y,z).tex(0, 0); + Tessellator.pos(x+1,y,z+1).tex(0, 0); + Tessellator.pos(x,y,z+1).tex(0, 0); + Tessellator.pos(x,y+1,z+1).tex(0, 0); + Tessellator.pos(x+1,y+1,z+1).tex(0, 0); + + Tessellator.draw(); + + GlStateManager.func_179121_F(); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glDepthMask(true); + GL11.glDisable(GL11.GL_BLEND); + }, + drawBoxAtEntity:function (entity, colorR, colorG, colorB, width, height, partialTicks, lineWidth=2, phase=false){ + let x = entity.getX() + ((entity.getX()-entity.getLastX())*partialTicks) + let y = entity.getY() + ((entity.getY()-entity.getLastY())*partialTicks) + let z = entity.getZ() + ((entity.getZ()-entity.getLastZ())*partialTicks) + + if(width === null){ + width = entity.getWidth()/2 + height = entity.getHeight() + }else{ + width = width/2 + } + + + GL11.glBlendFunc(770, 771); + GL11.glEnable(GL11.GL_BLEND); + GL11.glLineWidth(lineWidth); + if(phase) GL11.glDisable(GL11.GL_DEPTH_TEST); + GL11.glDisable(GL11.GL_TEXTURE_2D); + GlStateManager.func_179094_E(); + + + Tessellator.begin(3).colorize(colorR, colorG, colorB); + + Tessellator.pos(x+width,y+height,z+width).tex(0, 0); + Tessellator.pos(x+width,y+height,z-width).tex(0, 0); + Tessellator.pos(x-width,y+height,z-width).tex(0, 0); + Tessellator.pos(x-width,y+height,z+width).tex(0, 0); + Tessellator.pos(x+width,y+height,z+width).tex(0, 0); + Tessellator.pos(x+width,y,z+width).tex(0, 0); + Tessellator.pos(x+width,y,z-width).tex(0, 0); + Tessellator.pos(x-width,y,z-width).tex(0, 0); + Tessellator.pos(x-width,y,z+width).tex(0, 0); + Tessellator.pos(x-width,y,z-width).tex(0, 0); + Tessellator.pos(x-width,y+height,z-width).tex(0, 0); + Tessellator.pos(x-width,y,z-width).tex(0, 0); + Tessellator.pos(x+width,y,z-width).tex(0, 0); + Tessellator.pos(x+width,y+height,z-width).tex(0, 0); + Tessellator.pos(x+width,y,z-width).tex(0, 0); + Tessellator.pos(x+width,y,z+width).tex(0, 0); + Tessellator.pos(x-width,y,z+width).tex(0, 0); + Tessellator.pos(x-width,y+height,z+width).tex(0, 0); + Tessellator.pos(x+width,y+height,z+width).tex(0, 0); + + Tessellator.draw(); + + GlStateManager.func_179121_F(); + GL11.glEnable(GL11.GL_TEXTURE_2D); + if(phase) GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glDisable(GL11.GL_BLEND); + }, + drawFilledBox: function(x, y, z, w, h, red, green, blue, alpha, phase) { //FROM RENDERUTILS + GL11.glDisable(GL11.GL_CULL_FACE); + if (phase) { + GL11.glBlendFunc(770, 771); + GL11.glEnable(GL11.GL_BLEND); + GL11.glLineWidth(2.0); + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glDisable(GL11.GL_DEPTH_TEST); + GL11.glDepthMask(false); + GlStateManager.func_179094_E(); + } else { + GL11.glDisable(GL11.GL_TEXTURE_2D); + GL11.glBlendFunc(770, 771); + GL11.glEnable(GL11.GL_BLEND); + GL11.glLineWidth(2.0); + GL11.glDepthMask(false); + GlStateManager.func_179094_E(); + } + + w /= 2; + + Tessellator.begin(GL11.GL_QUADS, false); + Tessellator.colorize(red, green, blue, alpha); + + Tessellator.translate(x, y, z) + .pos(w, 0, w) + .pos(w, 0, -w) + .pos(-w, 0, -w) + .pos(-w, 0, w) + + .pos(w, h, w) + .pos(w, h, -w) + .pos(-w, h, -w) + .pos(-w, h, w) + + .pos(-w, h, w) + .pos(-w, h, -w) + .pos(-w, 0, -w) + .pos(-w, 0, w) + + .pos(w, h, w) + .pos(w, h, -w) + .pos(w, 0, -w) + .pos(w, 0, w) + + .pos(w, h, -w) + .pos(-w, h, -w) + .pos(-w, 0, -w) + .pos(w, 0, -w) + + .pos(-w, h, w) + .pos(w, h, w) + .pos(w, 0, w) + .pos(-w, 0, w) + .draw(); + + GL11.glEnable(GL11.GL_CULL_FACE); + if (phase) { + GlStateManager.func_179121_F(); + GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glEnable(GL11.GL_DEPTH_TEST); + GL11.glDepthMask(true); + GL11.glDisable(GL11.GL_BLEND); + } else { + GL11.glEnable(GL11.GL_TEXTURE_2D); + GlStateManager.func_179121_F(); + GL11.glDepthMask(true); + GL11.glDisable(GL11.GL_BLEND); + } + } +}
\ No newline at end of file diff --git a/utils/stringUtils.js b/utils/stringUtils.js new file mode 100644 index 0000000..920dd50 --- /dev/null +++ b/utils/stringUtils.js @@ -0,0 +1,11 @@ +module.exports = { + + firstLetterCapital: function (string) { + return string.substr(0, 1).toUpperCase() + string.substr(1) + }, + + firstLetterWordCapital: function (string) { + return string.split(" ").map(firstLetterCapital).join(" ") + } + +}
\ No newline at end of file diff --git a/utils/utils.js b/utils/utils.js new file mode 100644 index 0000000..b8569d9 --- /dev/null +++ b/utils/utils.js @@ -0,0 +1,116 @@ +const NBTTagList = Java.type('net.minecraft.nbt.NBTTagList'); +const NBTTagString = Java.type('net.minecraft.nbt.NBTTagString'); + +let functions = { + addLore: function(item, prefix, value){ + + const list = item + .getNBT() + .getCompoundTag("tag") + .getCompoundTag("display") + .getTagMap() + .get("Lore") + + let done = false + // Gets the current lore lines + for (let i = 0; i < list.func_74745_c(); i++) { + if (String(list.func_150307_f(i)).startsWith(prefix)){ + list.func_150304_a(i, new NBTTagString(prefix+value)); + done = true + } + } + if(!done){ + list.func_74742_a( new NBTTagString(prefix+value)) + } + + item + .getNBT() + .getCompoundTag("tag") + .getCompoundTag("display") + .getRawNBT() + .func_74782_a("Lore", list); + }, + calculateDistance: function(p1, p2) { + var a = p2[0] - p1[0]; + var b = p2[1] - p1[1]; + var c = p2[2] - p1[2]; + + let ret = Math.sqrt(a * a + b * b + c * c) + + if(ret<0){ + ret *= -1 + } + return ret; + }, + calculateDistanceQuick: function(p1, p2) { + var a = p2[0] - p1[0]; + var b = p2[1] - p1[1]; + var c = p2[2] - p1[2]; + + let ret = a * a + b * b + c * c + + if(ret<0){ + ret *= -1 + } + return ret; + }, + /** + * Please try not to use this + * it has O(n!) + * only use if points < 10 or something + * D: + * @param {*} startPoint + * @param {*} points + * @returns + */ + fastestPathThrough:function(startPoint, points){ + let ret = [] + while(ret.length<points.length){ + ret.push(ret.length) + } + + let allOrders = functions.permutation(ret) + + let lastOrder = [] + let lastOrderLength = Infinity + + allOrders.forEach((order)=>{ + let lastPoint = startPoint + let positions = order.map((a)=>{ + return points[a] + }) + let len = 0 + positions.forEach((pos)=>{ + len += functions.calculateDistance(lastPoint,pos) + lastPoint = pos + }) + + if(len < lastOrderLength){ + lastOrder = order + lastOrderLength = len + } + }) + + + return lastOrder; + }, + permutation:function(array) { + function p(array, temp) { + var i, x; + if (!array.length) { + result.push(temp); + } + for (i = 0; i < array.length; i++) { + x = array.splice(i, 1)[0]; + p(array, temp.concat(x)); + array.splice(i, 0, x); + } + } + + var result = []; + p(array, []); + return result; + } +} + +module.exports = functions
\ No newline at end of file |