Skip to content

Instantly share code, notes, and snippets.

@jwulf
Created October 6, 2019 21:58
Show Gist options
  • Save jwulf/40bcbdc0def68a7349a65aafb9de230a to your computer and use it in GitHub Desktop.
Save jwulf/40bcbdc0def68a7349a65aafb9de230a to your computer and use it in GitHub Desktop.
const magik = magikcraft.io;
const Collectors = java.util.stream.Collectors;
import * as utils from 'utils'
console.log('Loaded track')
function main(name, period = 5000) {
const world = utils.world(magik.aspecto().world)
const target = world.getLivingEntities()
.stream()
.filter(entity => entity.getName() == name)
.collect(Collectors.toList())
if (target.length > 0) {
cancelTracker()
track(target[0], period)
} else {
echo(self, `${name} not found`)
}
}
function cancelTracker() {
const tracker = magik.memento.getItem('tracker')
if (tracker) {
echo(self, `Cancelling ${tracker}`)
clearInterval(tracker);
}
}
function track(target, period) {
magik.memento.setItem('tracker',
setInterval(() => {
self.setCompassTarget(target.location)
echo(self, `Tracking ${target.getName()}`)
}, period))
echo(self, `Tracking ${target.getName()}`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment