Compare commits

...

3 Commits

Author SHA1 Message Date
jay
aded1e4193 style: 🎨 fix crlf -> lf for real this time, using .gitattributes
Add a .gitattributes file to permanentyl fix crlf issues.

For explanantion:
https://adaptivepatchwork.com/2012/03/01/mind-the-end-of-your-line/#the-new-system
2021-03-24 15:07:45 +05:00
jay
60394e38eb refactor: ♻️ replace add with vec3.offset
This avoids having to import and creat a `new vec3.v()`
2021-03-24 00:40:54 +05:00
jay
22490f7ec1 fix(command): 🐛 fix bot address regex returning undefined
Waits till spawn to make sure `bot.username` is definitely initialized
2021-03-23 23:10:58 +05:00
6 changed files with 525 additions and 513 deletions

16
.gitattributes vendored Normal file
View File

@ -0,0 +1,16 @@
# See this article for reference: https://help.github.com/articles/dealing-with-line-endings/
# Refreshing repo after line ending change:
# https://help.github.com/articles/dealing-with-line-endings/#refreshing-a-repository-after-changing-line-endings
# Handle line endings automatically for files detected as text
# and leave all files detected as binary untouched.
* text=auto
#
# The above will handle all files NOT found below
#
# These files are text and should be normalized (Convert crlf => lf)
# Use lf as eol for these files
*.js text eol=lf
*.ts text eol=lf
*.json text eol=lf

View File

@ -88,7 +88,6 @@ fs.watch('./lib/plugins', reloadplugin)
cfg.bot = bot
// TODO better name, or switch to array
cfg.botAddressPrefix = '!'
cfg.botAddressRegex = new RegExp(`^${bot.username} (${cfg.botAddressPrefix}.+)`)
cfg.quiet = true
@ -110,6 +109,7 @@ bot.once("spawn", () => {
}
cfg.plugins = plugins
cfg.botAddressRegex = new RegExp(`^${bot.username} (${cfg.botAddressPrefix}.+)`)
for (const plugin of Object.values(plugins)) {
try {

View File

@ -30,11 +30,10 @@ const events = {
whisper: function command_whisper(username, message) {
if ([bot.username, "me"].includes(username)) return
if (/^gossip/.test(message)) return
// if (/^!/.test(message) && username === cfg.admin){
if (username === cfg.admin) {
message = message.replace("\\", "@")
console.info("whispered command", message)
if (/^!/.test(message)) {
if (message.startsWith(cfg.botAddressPrefix)) {
command(username, message)
} else {
bot.chat(message)
@ -297,7 +296,7 @@ function command(username, message) {
switch (message_parts[1]) {
case "me":
if (player) {
bot.lookAt((new v.Vec3(0, 1, 0)).add(player.position))
bot.lookAt(player.position.offset(0, 1, 0))
} else {
cfg.quiet || bot.chat("can't see you")
}
@ -314,7 +313,7 @@ function command(username, message) {
break
default:
const aPlayer = bot.players[message_parts[2]] ? bot.players[message_parts[2]].entity : null
if (aPlayer) bot.lookAt((new v.Vec3(0, 1, 0)).add(aPlayer.position))
if (aPlayer) bot.lookAt(aPlayer.position.offset(0, 1, 0))
break;
}
break
@ -475,7 +474,7 @@ function command(username, message) {
case "howdy":
case "heyo":
case "yo":
if (player) bot.lookAt((new v.Vec3(0, 1, 0)).add(player.position))
if (player) bot.lookAt(player.position.offset(0, 1, 0))
// TODO sneak
// function swingArm() {

View File

@ -71,9 +71,7 @@ function lookForMobs() {
bot.pvp.attack(entityEnemy)
} else if (entityEnemy) {
bot.lookAt(
// (new v.Vec3(0, 1, 0)).add(
entityEnemy.position
// )
)
cfg.quiet || bot.chat("AH! A creeper! They creep me out!")
}

View File

@ -2,7 +2,6 @@
const { createMachine, interpret, InterpreterStatus } = require('xstate');
// import { access, mkdir, writeFile, readFile } from "fs";
const { access, mkdir, writeFile, readFile } = require('fs');
const v = require('vec3'); // for look dummy action, maybe not needed in future
// ANGRAM_PREFIX='MINECRAFT'
const { MINECRAFT_DATA_FOLDER } = process.env || require("dotenv-packed").parseEnv().parsed;
const storage_dir = MINECRAFT_DATA_FOLDER || './data/' + "/sm/";
@ -82,7 +81,7 @@ function init(smName = "dummy", webserver) {
const player = context?.player || bot.nearestEntity(entity => entity.type === 'player');
if (player.position || player.entity) {
context.player = player;
bot.lookAt((new v.Vec3(0, 1, 0)).add((player.entity || player).position));
bot.lookAt((player.entity || player).position.offset(0, 1, 0));
}
}
},
@ -93,7 +92,7 @@ function init(smName = "dummy", webserver) {
if (player.position || player.entity) {
context.player = player;
function looks() {
bot.lookAt((new v.Vec3(0, 1, 0)).add((player.entity || player).position));
bot.lookAt((player.entity || player).position.offset(0, 1, 0));
}
bot.on("time", looks);
return () => bot.off("time", looks);