Skip to content

Commit

Permalink
blood helper
Browse files Browse the repository at this point in the history
  • Loading branch information
soshimee committed Aug 3, 2024
1 parent 204c3b5 commit 180b998
Show file tree
Hide file tree
Showing 5 changed files with 215 additions and 24 deletions.
2 changes: 1 addition & 1 deletion config.js
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ class Settings {

@SwitchProperty({
name: "Blood Helper",
description: "WIP, does not work",
description: "Highlights where the mobs will spawn in the blood room",
category: "SkyBlock",
subcategory: "Blood Helper"
})
Expand Down
110 changes: 110 additions & 0 deletions events/dungeonRoom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/// <reference types="../../CTAutocomplete" />

import Dungeon from "../../BloomCore/dungeons/Dungeon";

global.soshimee ??= {};
global.soshimee.events ??= {};
global.soshimee.events.dungeonRoom ??= {};

const listeners = global.soshimee.events.dungeonRoom.listeners ??= [];

let roomX = -1;
let roomZ = -1;
let notified = false;

const trigger = global.soshimee.events.dungeonRoom.trigger ??= register("tick", () => {
if (!Dungeon.inDungeon) {
if (!notified) {
for (let listener of listeners) {
listener(0);
}
roomX = -1;
roomZ = -1;
notified = true;
}
return;
}

const prevRoomX = roomX;
const prevRoomZ = roomZ;
const x = Player.getX();
const z = Player.getZ();
if (x < -200 || z < -200 || x > 0 || z > 0) {
if (!notified) {
for (let listener of listeners) {
listener(0);
}
roomX = -1;
roomZ = -1;
notified = true;
}
return;
}
roomX = Math.floor((x + 200) / 32);
roomZ = Math.floor((z + 200) / 32);

if (prevRoomX != roomX || prevRoomZ != roomZ) {
const cx = -185 + roomX * 32;
const cz = -185 + roomZ * 32;

const roofHeight = getHighestBlock(cx, cz);

for (let listener of listeners) {
listener(getCore(cx, cz), getRotation(cx, roofHeight, cz));
}

notified = false;
}
}).unregister();

const offsets = [[-15, -15], [15, -15], [15, 15], [-15, 15]];
const blacklisted = [5, 54];
function hashCode(s) {
return s.split("").reduce((a, b) => {
a = ((a << 5) - a) + b.charCodeAt(0);
return a & a;
}, 0);
}
function getCore(x, z) {
let blockIds = ""
for (let y = 140; y >= 12; --y) {
let block = World.getBlockAt(x, y, z);
if (blacklisted.includes(block.type.getID())) continue;
blockIds += block.type.getID();
}
return hashCode(blockIds);
};
function getHighestBlock(x, z) {
for (let y = 255; y > 0; --y) {
let id = World.getBlockAt(x, y, z)?.type?.getID();
if (id == 0 || id == 41) continue;
return y;
}
return null;
}
function getRotation(x, y, z) {
if (!y) return;

for (let i = 0; i < offsets.length; ++i) {
let [dx, dz] = offsets[i];
let [nx, nz] = [x + dx, z + dz];
let block = World.getBlockAt(nx, y, nz);
if (block.type.getID() !== 159 || block.getMetadata() !== 11) continue;
return i;
}
}

export function addListener(listener) {
if (listeners.length === 0) trigger.register();
listeners.push(listener);
}

export function removeListener(listener) {
const index = listeners.indexOf(listener);
if (index === -1) return false;
listeners.splice(index, 1);
if (listeners.length === 0) trigger.unregister();
return true;
}

export default { addListener, removeListener };
111 changes: 96 additions & 15 deletions features/bloodHelper/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 7 additions & 7 deletions features/itemHighlight/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ import Dungeon from "../../../BloomCore/dungeons/Dungeon";
const EntityItem = Java.type("net.minecraft.entity.item.EntityItem");

const items = ["Health Potion VIII Splash Potion", "Healing 8 Splash Potion", "Healing VIII Splash Potion", "Decoy", "Inflatable Jerry", "Spirit Leap", "Trap", "Training Weights", "Defuse Kit", "Dungeon Chest Key", "Treasure Talisman", "Revive Stone", "Architect's First Draft"];
let renderTriggerRegistered = false;
let inDungeon = false;

const helperTrigger = register("step", () => { // make sure to register render trigger only when needed
if (Dungeon.inDungeon) {
if (renderTriggerRegistered) return;
if (inDungeon) return;
renderTrigger.register();
renderTriggerRegistered = true;
inDungeon = true;
} else {
if (!renderTriggerRegistered) return;
if (!inDungeon) return;
renderTrigger.unregister();
renderTriggerRegistered = false;
inDungeon = false;
}
}).setFps(1).unregister();

Expand Down Expand Up @@ -50,9 +50,9 @@ export function enable() {

export function disable() {
helperTrigger.unregister();
if (renderTriggerRegistered) {
if (inDungeon) {
renderTrigger.unregister();
renderTriggerRegistered = false;
inDungeon = false;
}
}

Expand Down
2 changes: 1 addition & 1 deletion metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "soshimeeaddons",
"description": "F7 on top",
"creator": "soshimee",
"version": "2.6.1",
"version": "2.7.0",
"entry": "index.js",
"requires": ["PromiseV2", "BloomCore", "fparser", "requestV2", "Vigilance", "PogData", "RenderLib"]
}

0 comments on commit 180b998

Please sign in to comment.