about summary refs log tree commit diff
diff options
context:
space:
mode:
authorBaitinq <manuelpalenzuelamerino@gmail.com>2023-02-15 12:20:50 +0100
committerBaitinq <manuelpalenzuelamerino@gmail.com>2023-02-15 12:20:50 +0100
commit6e5648307fc6bb8f6ffb119ef53ef61fae63e18c (patch)
tree0d53d37eb9fac1d962db1c9e064909fe173f03e2
parentFormatting (diff)
download2bored2walk-6e5648307fc6bb8f6ffb119ef53ef61fae63e18c.tar.gz
2bored2walk-6e5648307fc6bb8f6ffb119ef53ef61fae63e18c.tar.bz2
2bored2walk-6e5648307fc6bb8f6ffb119ef53ef61fae63e18c.zip
Plugin: Move antihunger functionality into local plugin
-rw-r--r--src/antihunger.ts22
-rw-r--r--src/main.ts31
2 files changed, 24 insertions, 29 deletions
diff --git a/src/antihunger.ts b/src/antihunger.ts
new file mode 100644
index 0000000..d63b3ca
--- /dev/null
+++ b/src/antihunger.ts
@@ -0,0 +1,22 @@
+import { Bot } from "mineflayer";
+
+export function plugin(bot: Bot) {
+    var originalFunction = bot._client.write;
+
+    // Create a new function that wraps the original function
+    var newFunction = function (this: unknown, name: string, params: any) {
+        if (name === "entity_action") {
+            if (params.actionId === 3 || params.actionId === 4) {
+                // cancel sprint start and sprint stop packets
+                return;
+            }
+        }
+        if (name === 'position_look' || name === 'position') {
+            params.onGround = false
+        }
+        return originalFunction.apply(this, [...arguments] as [name: string, params: any])
+    }
+
+    // Replace the original function with the new function
+    bot._client.write = newFunction;
+}
\ No newline at end of file
diff --git a/src/main.ts b/src/main.ts
index 4787742..896ecee 100644
--- a/src/main.ts
+++ b/src/main.ts
@@ -4,6 +4,7 @@ import { ChannelType, Client, GatewayIntentBits } from "discord.js";
 const mineflayerViewer = require('prismarine-viewer').mineflayer
 import { pathfinder, Movements, goals } from 'mineflayer-pathfinder';
 import { plugin as autoeat } from 'mineflayer-auto-eat';
+import { plugin as antihunger } from './antihunger'
 
 const hostname: string = "localhost"
 const goal: goals.Goal = new goals.GoalNear(0, 60, -2000000, 44)
@@ -48,6 +49,7 @@ const bot = mineflayer.createBot({
 
 bot.loadPlugin(pathfinder)
 bot.loadPlugin(autoeat)
+bot.loadPlugin(antihunger)
 
 bot.once('spawn', () => {
   mineflayerViewer(bot, { firstPerson: true, port: 3000 });
@@ -79,35 +81,6 @@ bot.on('health', () => {
     quit(`low hp: ${bot.health}`)
 })
 
-
-var originalFunction = bot._client.write;
-
-// Create a new function that wraps the original function
-var newFunction = function (this: unknown, name: string, params: any) {
-  //console.log(`WRITE called with ${ name }: ${ params } `);
-  //console.log("a: " + Object.keys(name))
-  //console.log("b: " + Object.keys(params))
-  if (name === "entity_action") {
-    if (params.actionId === 3 || params.actionId === 4) {
-      //console.log("CANCELLING ACTION ID: " + params.actionId)
-      return;
-    }
-  }
-  //if (a === "chat") {
-  //console.log("CANCELLED CHAT" + b.message)
-  // return;
-  //}
-  if (name === 'position_look' || name === 'position') {
-    //console.log("PACKET: " + name + " CANCELLING ON GROUND: " + params.onGround)
-    params.onGround = false
-    //console.log("CANCELLED ON GROUND: " + params.onGround)
-  }
-  return originalFunction.apply(this, [...arguments] as [name: string, params: any])
-}
-
-// Replace the original function with the new function
-bot._client.write = newFunction;
-
 setInterval(() => {
   if (bot._client.state !== "play") return