diff options
-rw-r--r-- | datastructures/flatqueue.js | 83 | ||||
-rw-r--r-- | features/dataLoader/index.js | 2 | ||||
-rw-r--r-- | features/events/index.js | 2 | ||||
-rw-r--r-- | features/hud/HudTextElement.js | 5 | ||||
-rw-r--r-- | features/settings/helpDataLoader.js | 4 | ||||
-rw-r--r-- | features/settings/index.js | 109 | ||||
-rw-r--r-- | features/settings/locationSettingHolder.js | 23 | ||||
-rw-r--r-- | features/settings/settingThings/imageLocation.js | 9 | ||||
-rw-r--r-- | features/settings/settingThings/location.js | 9 | ||||
-rw-r--r-- | features/waypoints/index.js | 42 | ||||
-rw-r--r-- | features/waypoints/pathfind.js | 96 | ||||
-rw-r--r-- | utils/renderUtils.js | 2 |
12 files changed, 317 insertions, 69 deletions
diff --git a/datastructures/flatqueue.js b/datastructures/flatqueue.js new file mode 100644 index 0000000..a011476 --- /dev/null +++ b/datastructures/flatqueue.js @@ -0,0 +1,83 @@ + +//SEE https://github.com/mourner/flatqueue + +export default class FlatQueue { + + constructor() { + this.ids = []; + this.values = []; + this.length = 0; + } + + clear() { + this.length = 0; + } + + push(id, value) { + let pos = this.length++; + + while (pos > 0) { + let parent = ((pos + 1) >>> 1) - 1; + let parentValue = this.values[parent]; + if (value >= parentValue) break; + this.ids[pos] = this.ids[parent]; + this.values[pos] = parentValue; + pos = parent; + } + + this.ids[pos] = id; + this.values[pos] = value; + } + + pop() { + if (this.length === 0) return undefined; + + let top = this.ids[0]; + this.length--; + + if (this.length > 0) { + let id = this.ids[0] = this.ids[this.length]; + let value = this.values[0] = this.values[this.length]; + let halfLength = this.length >> 1; + let pos = 0; + + while (pos < halfLength) { + let left = (pos << 1) + 1; + let right = left + 1; + let bestIndex = this.ids[left]; + let bestValue = this.values[left]; + let rightValue = this.values[right]; + + if (right < this.length && rightValue < bestValue) { + left = right; + bestIndex = this.ids[right]; + bestValue = rightValue; + } + if (bestValue >= value) break; + + this.ids[pos] = bestIndex; + this.values[pos] = bestValue; + pos = left; + } + + this.ids[pos] = id; + this.values[pos] = value; + } + + return top; + } + + peek() { + if (this.length === 0) return undefined; + return this.ids[0]; + } + + peekValue() { + if (this.length === 0) return undefined; + return this.values[0]; + } + + shrink() { + this.ids.length = this.values.length = this.length; + } +}
\ No newline at end of file diff --git a/features/dataLoader/index.js b/features/dataLoader/index.js index e06925c..dbaf841 100644 --- a/features/dataLoader/index.js +++ b/features/dataLoader/index.js @@ -14,6 +14,7 @@ class DataLoader extends Feature { this.stats = {} this.area = undefined + this.areaFine = undefined this.isInSkyblock = false @@ -39,6 +40,7 @@ class DataLoader extends Feature { worldLoad(){ this.area = undefined + this.areaFine = undefined this.worldLoaded = true } diff --git a/features/events/index.js b/features/events/index.js index cc2c3e5..77fe1ae 100644 --- a/features/events/index.js +++ b/features/events/index.js @@ -266,7 +266,7 @@ class Events extends Feature { spawnParticle(particle, type, event){ - if(this.shinyBlockOverlayEnabled.getValue()){ + if(this.shinyBlockOverlayEnabled.getValue() && this.FeatureManager.features["dataLoader"].class.areaFine === "The End"){ if(particle.toString().startsWith("EntitySpellParticleFX,")){ if(particle.getUnderlyingEntity().func_70534_d()===particle.getUnderlyingEntity().func_70535_g()){ let arr = [particle.getX(), particle.getY(), particle.getZ()] diff --git a/features/hud/HudTextElement.js b/features/hud/HudTextElement.js index 2acbe67..be9e4ee 100644 --- a/features/hud/HudTextElement.js +++ b/features/hud/HudTextElement.js @@ -48,6 +48,11 @@ class HudTextElement{ return this } + isEnabled(){ + if(!this.toggleSetting) return true + return this.locationSetting && this.toggleSetting.getValue() + } + render(){ if(this.toggleSetting && !this.toggleSetting.getValue() || !this.locationSetting) return if(Date.now()-this.tempDisableTime < 100) return diff --git a/features/settings/helpDataLoader.js b/features/settings/helpDataLoader.js index aadbd93..3a2e8f5 100644 --- a/features/settings/helpDataLoader.js +++ b/features/settings/helpDataLoader.js @@ -41,6 +41,10 @@ class HelpDataLoader { if(!global.helpDataLoader){ global.helpDataLoader = new HelpDataLoader(); + + register("gameUnload", ()=>{ + global.helpDataLoader = undefined + }) } export default global.helpDataLoader;
\ No newline at end of file diff --git a/features/settings/index.js b/features/settings/index.js index 2ce076d..6888f8a 100644 --- a/features/settings/index.js +++ b/features/settings/index.js @@ -4,86 +4,101 @@ import Feature from "../../featureClass/class"; import SoopyGuiElement from "../../../guimanager/GuiElement/SoopyGuiElement"; import SoopyTextElement from "../../../guimanager/GuiElement/SoopyTextElement"; import SoopyBoxElement from "../../../guimanager/GuiElement/SoopyBoxElement"; -import TextWithArrow from "../../../guimanager/GuiElement/TextWithArrow"; -import ButtonWithArrow from "../../../guimanager/GuiElement/ButtonWithArrow"; import BoxWithToggleAndDescription from "../../../guimanager/GuiElement/BoxWithToggleAndDescription"; import ButtonWithArrowAndDescription from "../../../guimanager/GuiElement/ButtonWithArrowAndDescription"; import SoopyMouseClickEvent from "../../../guimanager/EventListener/SoopyMouseClickEvent"; import SoopyContentChangeEvent from "../../../guimanager/EventListener/SoopyContentChangeEvent"; -import SoopyOpenGuiEvent from "../../../guimanager/EventListener/SoopyOpenGuiEvent"; import settingsCommunicator from "./settingsCommunicator"; import GuiPage from "../soopyGui/GuiPage" -import { SoopyRenderEvent } from "../../../guimanager"; +import { SoopyGui, SoopyRenderEvent } from "../../../guimanager"; import TextBox from "../../../guimanager/GuiElement/TextBox"; +import locationSettingHolder from "./locationSettingHolder"; class SettingsRenderer extends Feature { constructor() { super() - - this.gui = undefined - - this.pages = [] - this.currentPage = 0 - this.backButton = undefined - this.settingsCategoryArea = undefined - this.settingsTitle = undefined - this.settingsArea = undefined - this.modifyingFeature = false - this.featureLoadedTextBox = undefined - - this.SettingPage = undefined } onEnable(){ - this.SettingPage = new SettingPage() + this.EditLocationsPage = new EditLocationsPage() this.SettingPage.FeatureManager = this.FeatureManager - return; + this.registerStep(true, 1, ()=>{ + if(!this.EditLocationsPage) return + + if(this.EditLocationsPage.needsExitPage){ + this.EditLocationsPage.goToPage(0, 500) + this.EditLocationsPage.needsExitPage = false + } + }) + } onDisable(){ + this.EditLocationsPage = undefined this.SettingPage = undefined - return; - this.gui.delete() - - this.pages = [] - this.currentPage = 0 - this.backButton = undefined - this.settingsArea = undefined - this.settingsTitle = undefined - this.settingsCategoryArea = undefined - this.modifyingFeature = false - this.featureLoadedTextBox = undefined } +} - clickedOpenSettings(){ +class EditLocationsPage extends GuiPage { + + constructor(){ + super(9) + + this.name = "Edit GUI Locations" + this.needsExitPage = false - this.goToPage(1) - } + this.soopyGui = new SoopyGui() + this.soopyGui._renderBackground = ()=>{} //remove background darkening - clickedBackButton(){ - this.goToPage(this.currentPage-1) - } - goToPage(pageNum, animate=true){ - pageNum = Math.max(0, Math.min(pageNum, this.pages.length-1)) - if(pageNum == this.currentPage){ - return + this.soopyGui.ctGui.registerDraw((mouseX, mouseY, partialTicks)=>{ + this.renderGui(mouseX, mouseY) + this.soopyGui._render(mouseX, mouseY, partialTicks) + }) + this.soopyGui.ctGui.registerClicked((mouseX, mouseY, button)=>{ + this.clicked(mouseX, mouseY) + this.soopyGui._onClick(mouseX, mouseY, button) + }) + this.soopyGui.ctGui.registerMouseReleased((mouseX, mouseY)=>{ + this.released(mouseX, mouseY) + }) + + this.finaliseLoading() + } + + renderGui(mouseX, mouseY){ + for(let setting of locationSettingHolder.getData()){ + if(setting.parent){ + if(setting.parent.isEnabled()){ + setting.renderGui(mouseX, mouseY) + } + }else{ + setting.renderGui(mouseX, mouseY) + } + } + } + + clicked(mouseX, mouseY){ + for(let setting of locationSettingHolder.getData()){ + if(setting.clicked(mouseX, mouseY)) return //dont allow the user to drag 2 locations at once } + } - this.currentPage = pageNum + released(mouseX, mouseY){ + for(let setting of locationSettingHolder.getData()){ + setting.released(mouseX, mouseY) + } + } - this.pages.forEach((p, i)=>{ - p.forEach(e=>{ - e.location.location.x.set(i-pageNum, animate?1000:0) - }) - }) + onOpen(){ + this.needsExitPage = true - this.backButton.location.location.y.set(pageNum === 0?-0.2:0, animate?1000:0) + this.soopyGui.open() } } diff --git a/features/settings/locationSettingHolder.js b/features/settings/locationSettingHolder.js new file mode 100644 index 0000000..14256d3 --- /dev/null +++ b/features/settings/locationSettingHolder.js @@ -0,0 +1,23 @@ +class LocationSettingHolder { + constructor() { + this.data = []; + } + + addLocationSetting(setting){ + this.data.push(setting) + } + + getData(){ + return this.data + } +} + +if(!global.LocationSettingHolder){ + global.LocationSettingHolder = new LocationSettingHolder(); + + register("gameUnload", ()=>{ + global.LocationSettingHolder = undefined + }) +} + +export default global.LocationSettingHolder;
\ No newline at end of file diff --git a/features/settings/settingThings/imageLocation.js b/features/settings/settingThings/imageLocation.js index adb6725..c8f37ed 100644 --- a/features/settings/settingThings/imageLocation.js +++ b/features/settings/settingThings/imageLocation.js @@ -7,8 +7,7 @@ import ButtonWithArrow from "../../../../guimanager/GuiElement/ButtonWithArrow" import SoopyMouseClickEvent from "../../../../guimanager/EventListener/SoopyMouseClickEvent" import NumberTextBox from "../../../../guimanager/GuiElement/NumberTextBox" import SoopyContentChangeEvent from "../../../../guimanager/EventListener/SoopyContentChangeEvent" - -let allLocations = [] +import locationSettingHolder from "../locationSettingHolder" class ImageLocationSetting extends ButtonSetting { constructor(name, description, settingId, module, defaultLocation, image, imageWBase, imageHBase){ @@ -123,7 +122,7 @@ class ImageLocationSetting extends ButtonSetting { this.released(mouseX, mouseY) }) - allLocations.push(this) + locationSettingHolder.addLocationSetting(this) } requires(toggleSetting){ @@ -174,7 +173,9 @@ class ImageLocationSetting extends ButtonSetting { && mouseY>this.y && mouseY<this.y+height*this.scale){ this.dragging = true; this.dragOffset = [this.x-mouseX, this.y-mouseY] + return true } + return false } released(mouseX, mouseY){ this.updateLocation(mouseX, mouseY) @@ -201,7 +202,7 @@ class ImageLocationSetting extends ButtonSetting { this.y = mouseY+this.dragOffset[1] let snapPoints = [] - allLocations.forEach(loc=>{ + locationSettingHolder.getData().forEach(loc=>{ if(loc === this) return; snapPoints.push([loc.x, loc.y]) snapPoints.push([loc.x+loc.getWidth()*loc.scale, loc.y]) diff --git a/features/settings/settingThings/location.js b/features/settings/settingThings/location.js index b158e03..b5a6f1c 100644 --- a/features/settings/settingThings/location.js +++ b/features/settings/settingThings/location.js @@ -7,8 +7,7 @@ import ButtonWithArrow from "../../../../guimanager/GuiElement/ButtonWithArrow" import SoopyMouseClickEvent from "../../../../guimanager/EventListener/SoopyMouseClickEvent" import NumberTextBox from "../../../../guimanager/GuiElement/NumberTextBox" import SoopyContentChangeEvent from "../../../../guimanager/EventListener/SoopyContentChangeEvent" - -let allLocations = [] +import locationSettingHolder from "../locationSettingHolder" class LocationSetting extends ButtonSetting { constructor(name, description, settingId, module, defaultLocation){ @@ -124,7 +123,7 @@ class LocationSetting extends ButtonSetting { this.released(mouseX, mouseY) }) - allLocations.push(this) + locationSettingHolder.addLocationSetting(this) } requires(toggleSetting){ @@ -184,7 +183,9 @@ class LocationSetting extends ButtonSetting { && mouseY>this.y && mouseY<this.y+height*this.scale){ this.dragging = true; this.dragOffset = [this.x-mouseX, this.y-mouseY] + return true } + return false } released(mouseX, mouseY){ this.updateLocation(mouseX, mouseY) @@ -207,7 +208,7 @@ class LocationSetting extends ButtonSetting { this.y = mouseY+this.dragOffset[1] let snapPoints = [] - allLocations.forEach(loc=>{ + locationSettingHolder.getData().forEach(loc=>{ if(loc === this) return; snapPoints.push([loc.x, loc.y]) snapPoints.push([loc.x+loc.getWidth()*loc.scale, loc.y]) diff --git a/features/waypoints/index.js b/features/waypoints/index.js index 755780d..d13a897 100644 --- a/features/waypoints/index.js +++ b/features/waypoints/index.js @@ -15,18 +15,20 @@ class Waypoints extends Feature { onEnable(){ this.initVariables() - new SettingBase("/addwaypoint [name] [x] [y] [z] [r?] [g?] [b?]", "Allows you to create a waypoint", undefined, "create_waypoint", this) + new SettingBase("/addwaypoint [name] [x] [y] [z] [r?] [g?] [b?] [area?]", "Allows you to create a waypoint", undefined, "create_waypoint", this) new SettingBase("/delwaypoint [name]", "Allows you to delete a waypoint", undefined, "delete_waypoint", this) new SettingBase("/clearwaypoints", "Allows you to clear all the waypoints", undefined, "clear_waypoints", this) new SettingBase("/savewaypoints", "Copys the waypoints to your clipboard", undefined, "save_waypoints", this) new SettingBase("/loadwaypoints", "Loads waypoints from your clipboard", undefined, "load_waypoints", this) this.waypoints = [] - this.userWaypoints = {} + this.userWaypoints = JSON.parse(FileLib.read("soopyAddonsData", "soopyv2userwaypoints.json") || "{}") + this.userWaypointsArr = Object.values(this.userWaypoints) + this.waypointsChanged = false this.registerForge(RenderWorldLastEvent, this.renderWorldLast) - this.registerCommand("addwaypoint", (name, x=Math.floor(Player.getX()).toString(), y=Math.floor(Player.getY()).toString(), z=Math.floor(Player.getZ()).toString(), r="0", g="255", b="0")=>{ + this.registerCommand("addwaypoint", (name, x=Math.floor(Player.getX()).toString(), y=Math.floor(Player.getY()).toString(), z=Math.floor(Player.getZ()).toString(), r="0", g="255", b="0", area)=>{ let lx = 0 let ly = 0 let lz = 0 @@ -43,23 +45,31 @@ class Waypoints extends Feature { } this.userWaypoints[name] = { - x: parseFloat(x.replace("l", lx)), - y: parseFloat(y.replace("l", ly)), - z: parseFloat(z.replace("l", lz)), - r: parseInt(r), - g: parseInt(g), - b: parseInt(b), + x: parseFloat(x.replace("l", lx).replace('p', Math.floor(Player.getX()))), + y: parseFloat(y.replace("l", ly).replace('p', Math.floor(Player.getY()))), + z: parseFloat(z.replace("l", lz).replace('p', Math.floor(Player.getZ()))), + r: parseInt(r)/255, + g: parseInt(g)/255, + b: parseInt(b)/255, + area: area==="a"?this.FeatureManager.features["dataLoader"].class.area:area.replace(/_/g," "), options: {name: ChatLib.addColor(name.replace(/_/g," "))} } + + this.userWaypointsArr = Object.values(this.userWaypoints) + this.waypointsChanged = true ChatLib.chat(this.FeatureManager.messagePrefix + "Added waypoint "+ name + "!") }) this.registerCommand("delwaypoint", (name)=>{ delete this.userWaypoints[name] + this.userWaypointsArr = Object.values(this.userWaypoints) + this.waypointsChanged = true ChatLib.chat(this.FeatureManager.messagePrefix + "Deleted waypoint "+ name + "!") }) this.registerCommand("clearwaypoints", ()=>{ this.userWaypoints = {} + this.userWaypointsArr = [] + this.waypointsChanged = true ChatLib.chat(this.FeatureManager.messagePrefix + "Cleared waypoints!") }) this.registerCommand("savewaypoints", ()=>{ @@ -69,6 +79,9 @@ class Waypoints extends Feature { this.registerCommand("loadwaypoints", ()=>{ try{ this.userWaypoints = JSON.parse(Java.type("net.minecraft.client.gui.GuiScreen")[m.getClipboardString]()) + + this.userWaypointsArr = Object.values(this.userWaypoints) + this.waypointsChanged = true ChatLib.chat(this.FeatureManager.messagePrefix + "Loaded waypoints from clipboard!") }catch(e){ ChatLib.chat(this.FeatureManager.messagePrefix + "Error loading from clipboard!") @@ -92,9 +105,10 @@ class Waypoints extends Feature { for(let waypoint of this.waypoints){ drawCoolWaypoint(waypoint.x, waypoint.y, waypoint.z, waypoint.r, waypoint.g, waypoint.b, waypoint.options) } - let waypoints2 = Object.values(this.userWaypoints) - for(let waypoint of waypoints2){ - drawCoolWaypoint(waypoint.x, waypoint.y, waypoint.z, waypoint.r, waypoint.g, waypoint.b, {...waypoint.options}) + for(let waypoint of this.userWaypointsArr){ //TODO: Make hash from waypoint.area -> waypoints[] + if(!waypoint.area || this.FeatureManager.features["dataLoader"].class.area === waypoint.area){ + drawCoolWaypoint(waypoint.x, waypoint.y, waypoint.z, waypoint.r, waypoint.g, waypoint.b, {...waypoint.options}) + } } } @@ -103,6 +117,10 @@ class Waypoints extends Feature { } onDisable(){ + if(this.waypointsChanged){ + FileLib.write("soopyAddonsData", "soopyv2userwaypoints.json", JSON.stringify(this.userWaypoints)) + } + this.initVariables() } } diff --git a/features/waypoints/pathfind.js b/features/waypoints/pathfind.js new file mode 100644 index 0000000..42135d8 --- /dev/null +++ b/features/waypoints/pathfind.js @@ -0,0 +1,96 @@ +import FlatQueue from "../../datastructures/flatqueue" + +const directions = [ + [1,0,0,1], + [0,1,0,1], + [0,0,1,1], + [-1,0,0,1], + [0,-1,0,1], + [0,0,-1,1], + [1,1,0,Math.SQRT2], + [1,-1,0,Math.SQRT2], + [-1,1,0,Math.SQRT2], + [-1,-1,0,Math.SQRT2], + [1,0,1,Math.SQRT2], + [1,0,-1,Math.SQRT2], + [-1,0,1,Math.SQRT2], + [-1,0,-1,Math.SQRT2], + [0,1,1,Math.SQRT2], + [0,1,-1,Math.SQRT2], + [0,-1,1,Math.SQRT2], + [0,-1,-1,Math.SQRT2] +] + +class Path{ + constructor(startLocation, endLocation){ + this.startLocation = startLocation + this.endLocation = endLocation + + this.points = [] + } + + getPoints(){ + return this.points + } + + calculate(){ + this.locs = {} + this.points = [] + this.locs[this.startLocation.x+","+this.startLocation.y+","+this.startLocation.z]= { + location: this.startLocation, + parent: null, + distance: 0, + huristic: (Math.abs(this.startLocation.x-this.endLocation.x)+Math.abs(this.startLocation.y-this.endLocation.y)+Math.abs(this.startLocation.z-this.endLocation.z)) + } + + this.heap = new FlatQueue() + + this.heap.push(this.startLocation.x+","+this.startLocation.y+","+this.startLocation.z, this.locs[this.startLocation.x+","+this.startLocation.y+","+this.startLocation.z].huristic) + + let i = 0 + while(!this._iterate() && i<100000){ + i++ + } + } + + _iterate(){ + let currentKey = this.heap.pop() + let current = this.locs[currentKey] + if(current.location.x === this.endLocation.x && current.location.y === this.endLocation.y && current.location.z === this.endLocation.z){ + this.points.push([current.location.x, current.location.y, current.location.z]) + while(current.parent){ + current = this.locs[current.parent] + + this.points.push([current.location.x, current.location.y, current.location.z]) + } + return true + } + + for(let dir of directions){ + + let newLoc = { + x: current.location.x + dir[0], + y: current.location.y + dir[1], + z: current.location.z + dir[2] + } + + if(!this.locs[newLoc.x + "," + newLoc.y + "," + newLoc.z]){ + + if(World.getBlockAt(newLoc.x, newLoc.y, newLoc.z).getType().getID() === 0 && World.getBlockAt(newLoc.x, newLoc.y+1, newLoc.z).getType().getID() === 0){ + this.locs[newLoc.x + "," + newLoc.y + "," + newLoc.z] = { + location: newLoc, + parent: currentKey, + distance: current.distance+1, + huristic: Math.hypot((newLoc.x-this.endLocation.x),(newLoc.y-this.endLocation.y),(newLoc.z-this.endLocation.z))+(current.distance+dir[3])/2 + } + + this.heap.push(newLoc.x + "," + newLoc.y + "," + newLoc.z, this.locs[newLoc.x + "," + newLoc.y + "," + newLoc.z].huristic) + } + } + } + + return false + } +} + +export default Path
\ No newline at end of file diff --git a/utils/renderUtils.js b/utils/renderUtils.js index c437254..4398b19 100644 --- a/utils/renderUtils.js +++ b/utils/renderUtils.js @@ -341,7 +341,7 @@ let ret = { let alpha = Math.min(1,Math.max(0,1-(distToPlayerSq-10000)/12500)) ret[phase?"drawBoxAtBlock":"drawBoxAtBlockNotVisThruWalls"](x-0.005, y-0.005, z-0.005, r, g, b, 1.01, 1.01, alpha) - ret.drawFilledBox(x+0.5, y, z+0.5, 1.02, 1.02, r, g, b, 0.25*alpha, phase) + ret.drawFilledBox(x+0.5, y, z+0.5, 1.02, 1.01, r, g, b, 0.25*alpha, phase) ret.renderBeaconBeam(x, y+1, z, r, g, b, Math.min(1,Math.max(0,(distToPlayerSq-25)/100))*alpha, false) if(name || showDist){ |