Stage - 0 0 1

main
Theenoro 2023-02-14 12:32:48 +01:00
commit 3f10bb793a
31 changed files with 2819 additions and 0 deletions

0
README.md 100644
View File

25
bot_config.js 100644
View File

@ -0,0 +1,25 @@
import mineflayer from 'mineflayer';
import { Main } from './controller/main.js';
import { Storage } from './controller/storage.js';
let {cfg} = await import('./config/'+process.argv[2]+'.js')
let i = process.argv[3]
let bots = {}
bots[cfg.acc[i].username] = {};
bots[cfg.acc[i].username].bot = mineflayer.createBot({
host: "cbt.marin.rz.int", // optional
port: 25566, // optional
username: cfg.acc[i].username
})
bots[cfg.acc[i].username].task = cfg.acc[i].task;
bots[cfg.acc[i].username].data = cfg.acc[i].data;
bots[cfg.acc[i].username].events = cfg.acc[i].events;
bots[cfg.acc[i].username].main = new Main(bots[cfg.acc[i].username].bot);
Storage.bots = bots;
console.log(`Bot started as ${cfg.acc[i].username} with ${process.argv[2]}`)

View File

@ -0,0 +1,5 @@
export let com = {
host:"127.0.0.1",
port:30000,
path:"global"
}

View File

@ -0,0 +1,42 @@
import Vec3 from "vec3";
import digBlock from "../controller/modules/digBlock/index.js";
export let cfg = {
acc:[
{
username: "Bot_3"
},
{
username: "Bot_4",
task: digBlock,
data:{
pos: new Vec3(102,48,-2),
block_name:"obsidian"
}
},
{
username: "Bot_5",
task: digBlock,
data:{
pos: new Vec3(102,48,2),
block_name:"obsidian"
}
},
{
username: "Bot_6",
task: digBlock,
data:{
pos: new Vec3(98,48,2),
block_name:"obsidian"
}
},
{
username: "Bot_7",
task: digBlock,
data:{
pos: new Vec3(98,48,-2),
block_name:"obsidian"
}
}
]
};

View File

@ -0,0 +1,23 @@
import Vec3 from "vec3";
import killEntity, { entityKilled } from "../controller/modules/killEntity/index.js";
export let cfg = {
acc:[
{
username: "Bot_8",
data:{
webView: 31002
}
},
{
username: "Bot_9",
task: killEntity,
events:{
'entityDead':entityKilled
},
data:{
webView: 31003
}
}
]
};

View File

@ -0,0 +1,20 @@
export default function bubbleSort(arr) {
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr.length - i - 1; j++) {
if (arr[j] > arr[j + 1]) {
[arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];
}
}
}
return arr;
}
export function bubbleSortTasks(arr) {
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr.length - i - 1; j++) {
if (arr[j].priority > arr[j + 1].priority) {
[arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];
}
}
}
return arr;
}

View File

@ -0,0 +1,38 @@
import Vec3 from "vec3";
export class distances{
static distance = 0;
}
export function sortCoordinates(coordinates, referencePoint) {
coordinates.sort((a, b) => {
const distanceA = a.distanceTo(referencePoint);
const distanceB = b.distanceTo(referencePoint);
return distanceA - distanceB;
});
distances.distance += coordinates[0].distanceTo(referencePoint);
return coordinates;
}
function distanceBetweenPoints(a, b) {
const dx = a.x - b.x;
const dy = a.y - b.y;
const dz = a.z - b.z;
return Math.sqrt(dx * dx + dy * dy + dz * dz);
}
export function getNearestCoordinate(coordinates, referencePoint) {
return sortCoordinates(coordinates, referencePoint)[0];
}
export function sortTasksByDistance(arr) {
for (let i = 0; i < arr.length; i++) {
for (let j = 0; j < arr.length - i - 1; j++) {
if (arr[j].priority > arr[j + 1].priority) {
[arr[j], arr[j + 1]] = [arr[j + 1], arr[j]];
}
}
}
return arr;
}

View File

@ -0,0 +1,19 @@
import { Storage } from "../storage.js";
export default function findChests(){
console.log("FINDCHESTS")
let bot = Storage.bot;
const pos = bot.entity.position;
let blocks = Storage.bot.findBlock({
point: Storage.bot.entity.position,
maxDistance: 10,
matching: (block) => {
return block && block.type === "chest"
}})
blocks.forEach(chest => {
console.log(`Chest with contents: ${JSON.stringify(chest.chestContents)}`);
});
}

View File

View File

@ -0,0 +1,50 @@
import WebSocket from 'ws';
import { Storage } from '../storage.js';
let { com } = await import('../../config/@global_communication.js');
export class IPC {
ws = null
constructor() {
const ws = new WebSocket(`ws://${com.host}:${com.port}/${com.path}`);
ws.on('error', console.error);
ws.on('open', function open() {
let k = {
type: "auth",
bot: {
name: "Bot_1"
}
}
ws.send(JSON.stringify(k));
});
ws.on('message', function message(data) {
console.log('received: %s', data);
});
ws.on('open', this.heartbeat);
ws.on('ping', this.heartbeat);
this.ws = ws;
}
async receiveData() {
}
sendData(data) {
this.ws.send(data)
}
heartbeat() {
clearTimeout(this.pingTimeout);
console.log("PING")
// Use `WebSocket#terminate()`, which immediately destroys the connection,
// instead of `WebSocket#close()`, which waits for the close timer.
// Delay should be equal to the interval at which your server
// sends out pings plus a conservative assumption of the latency.
this.pingTimeout = setTimeout(() => {
this.terminate();
}, 30000 + 1000);
}
}

131
controller/main.js 100644
View File

@ -0,0 +1,131 @@
import { Farmer } from "./modules/farmer/index.js"
import { WebView } from "./modules/viewer/index.js"
import { Storage } from "./storage.js"
import Path,{ pathfinder, Movements} from "mineflayer-pathfinder"
import Vec3 from "vec3";
import { TaskMgr } from "./taskmgr.js";
import findChests from "./helper/findChests.js";
import digBlock from "./modules/digBlock/index.js";
let me = null;
export class Main{
loopCycle = 40
loops = 0
task = null
wa = null
nextPos = []
TaskMgr = null
constructor(bot){
this.bot = bot;
this.TaskMgr = new TaskMgr();
me = this;
bot.loadPlugin(pathfinder)
bot.physicsEnabled = true;
let farm = null ;
bot.on('spawn',()=>{
const dM = new Movements(bot);
bot.pathfinder.setMovements(dM)
if(Storage.bots[bot.username].data != undefined){
console.log(Storage.bots[bot.username].data)
Storage.bots[bot.username].data.webView != undefined ? new WebView(bot,Storage.bots[bot.username].data.webView) : null;
}
for(let eventName in Storage.bots[bot.username].events){
console.log(eventName);
let e = Storage.bots[bot.username].events[eventName];
console.log(e)
bot.on(`${eventName}`,e)
}
//new WebView()
//this.task = new Farmer();
setTimeout(()=>{
//findChests();
},7000)
})
/*
ADD EVENTS
*/
bot.on('chat', (username, message) => {
if (username === bot.username) return
console.log(message)
switch(username){
default:
break;
}
//bot.chat(message)
})
bot.on('playerCollect',(collector,collected)=>{
//console.log(collected)
})
bot.on(`itemDrop`,(entity)=>{
//console.log(entity)
/**
* FARM
*/
/*if(entity.metadata[8].itemId==991){
let e = new Vec3(entity.position.x,entity.position.y,entity.position.z);
let distance = e.distanceTo(Storage.bot.entity.position)
console.log(distance)
if(distance<=7){
this.nextPos.push(new Path.goals.GoalNear(
entity.position.x,
entity.position.y,
entity.position.z,
1
));
}
}*/
})
bot.on('kicked',console.log);
bot.on('error',console.log);
bot.on('physicsTick',me.TickLoop)
}
async TickLoop(){
let bot = me;
bot.loops++;
/**if(me.loopCycle<me.loops && me.nextPos.length == 0){
console.log(`[LOOP] ${me.loops}`)
if(me.task!=null){
await me.task.loop()
}
me.loops = 0;
}
*/
if(bot.loops % 10 == 0){
bot.bot.removeListener('physicsTick',bot.TickLoop)
//console.log(Storage.bots[bot.bot.username].data)
if(Storage.bots[bot.bot.username].task != undefined){
await Storage.bots[bot.bot.username].task(bot.bot)
}
bot.bot.on('physicsTick',me.TickLoop);
//await digBlock(this.bot,new Vec3(102,48,-2))
}
switch(bot.loops){
case 10:
break;
default:
break;
}
if(bot.loops > 80){
//console.log(`[LOOP] ${bot.loops} - ${bot.nextPos}`)
bot.loops = 0;
//me.nextPos = null;
}
}
}

View File

@ -0,0 +1,23 @@
import Vec3 from "vec3";
import {Storage} from '../../storage.js';
export default async function digBlock(bot, vec) {
//console.log(`${bot.username} ${vec}`)
vec == null ? vec = Storage.bots[bot.bot.username].data.pos : null
const pos = bot.entity.position;
const block = bot.blockAt(vec);
if(block == null){ return false};
if (block.name == "obsidian") {
try {
await bot.dig(block);
console.log(`Successfully dug block at (${block.position.x}, ${block.position.y}, ${block.position.z})`);
return true;
} catch (err) {
console.log(`Error digging block: ${err}`);
return false;
}
} else {
return false
}
}

View File

@ -0,0 +1,88 @@
import { ModuleFrame } from "../module_frame.js";
import Vec3 from "vec3";
import { Storage } from "../../storage.js";
import Path from "mineflayer-pathfinder";
export class Farmer extends ModuleFrame {
bts = null
bth = null
constructor() {
super();
this.bts = Storage.bot.registry.itemsByName["potato"]
this.bth = Storage.bot.registry.blocksByName["potatoes"]
}
setItemToFarm() {
}
blockToSow() {
return Storage.bot.findBlock({
point: Storage.bot.entity.position,
matching: Storage.bot.registry.blocksByName.farmland.id,
maxDistance: 6,
useExtraInfo: (block) => {
const blockAbove = Storage.bot.blockAt(block.position.offset(0, 1, 0))
return !blockAbove || blockAbove.type === 0
}
})
}
blockToHarvest() {
return Storage.bot.findBlock({
point: Storage.bot.entity.position,
maxDistance: 5,
matching: (block) => {
return block && block.type === this.bth.id && block.metadata === 7
}
})
}
async loop() {
try {
while (1) {
const toHarvest = this.blockToHarvest()
if (toHarvest == null){
break;
}
await Storage.bot.pathfinder.goto(
new Path.goals.GoalNear(
toHarvest.position.x,
toHarvest.position.y,
toHarvest.position.z,
3
),false
)
if (toHarvest) {
await Storage.bot.dig(toHarvest)
} else {
break
}
}
while (1) {
const toSow = this.blockToSow()
if (toSow == null){
break;
}
await Storage.bot.pathfinder.goto(
new Path.goals.GoalNear(
toSow.position.x,
toSow.position.y,
toSow.position.z,
3
), false
)
if (toSow) {
await Storage.bot.equip(this.bts.id, 'hand')
await Storage.bot.placeBlock(toSow, new Vec3(0, 1, 0))
} else {
break
}
}
} catch (e) {
console.log(e)
}
return false;
}
}

View File

@ -0,0 +1,24 @@
/**
* Find & Kill Entity
* @param {*} bot
* @returns
*/
export default function killEntity(bot) {
const filter = e => e.type === 'hostile' && e.position.distanceTo(bot.entity.position) < 5 &&
e.mobType !== 'Armor Stand' // Mojang classifies armor stands as mobs for some reason?
const entity = bot.nearestEntity(filter)
if (entity) {
bot.attack(entity)
}
return true;
}
let counter = {};
export function entityKilled(entity) {
counter[entity.mobType] == undefined ? counter[entity.mobType] = 1: counter[entity.mobType]++
console.log(`The bot killed an unknown ${entity.mobType}`);
console.log(`Killed ${entity.mobType} -> ${counter[entity.mobType]}`)
}

View File

@ -0,0 +1,27 @@
export class ModuleFrame{
startVec = null;
endVec = null;
lastAction = null;
nextAction = null;
constructor(){
}
async start(){
}
async loop(){
}
async invoke(){
}
async restartLastAction(){
}
async startWithNextAction(){
}
async stop(){
}
}

View File

@ -0,0 +1,5 @@
import { ModuleFrame } from "../module_frame.js";
export class PickUp extends ModuleFrame{
}

View File

@ -0,0 +1,13 @@
import { mineflayer } from "prismarine-viewer";
import { Storage } from "../../storage.js";
export class WebView{
constructor(bot,port = 31001){
console.log("START")
mineflayer(bot,{
port:port,
viewDistance: 3
})
}
}

View File

@ -0,0 +1,5 @@
export class Storage{
static bot = null;
static TaskMgr = null;
static bots = null;
}

View File

@ -0,0 +1,22 @@
import { bubbleSortTasks } from "./helper/bubblesort.js";
export class TaskMgr{
tasks = []
constructor(){
}
async selectTask(){
let sorted_tasks = bubbleSortTasks(this.tasks);
}
async runTask(){
}
}
export class Task{
priority = 0
taskToRun = null
}

View File

View File

1825
package-lock.json generated 100644

File diff suppressed because it is too large Load Diff

19
package.json 100644
View File

@ -0,0 +1,19 @@
{
"name": "test-bot",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"mineflayer": "^4.7.0",
"mineflayer-pathfinder": "^2.4.2",
"prismarine-viewer": "^1.23.0",
"vec3": "^0.1.7",
"ws": "^8.12.0"
}
}

View File

@ -0,0 +1,6 @@
import { IPC } from "./controller/ipc/global_communication.js";
let ipc = new IPC();

304
tests/index.html 100644
View File

@ -0,0 +1,304 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Three.js - Basic Example</title>
<script src="https://cdn.jsdelivr.net/npm/three@0.117.0/build/three.js"></script>
<style>
body {
margin: 0;
}
canvas {
display: block;
}
</style>
</head>
<body>
<script>
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
var renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
const materia = new THREE.LineBasicMaterial({ color: 0xFFFFff });
const points = [];
points.push(new THREE.Vector3(0, 0, 0));
points.push(new THREE.Vector3(0.95, 2.81, 3.19));
points.push(new THREE.Vector3(2.82, 0.58, 1.85));
points.push(new THREE.Vector3(4.06, 3.82, 1.86));
points.push(new THREE.Vector3(5.72, 5.52, 2));
points.push(new THREE.Vector3(8.84, 8.04, 0.47));
points.push(new THREE.Vector3(10.18, 10.03, 0.45));
points.push(new THREE.Vector3(11.53, 11.17, 2.13));
points.push(new THREE.Vector3(11.26, 11.12, 3.08));
points.push(new THREE.Vector3(15.19, 12.88, 2.28));
points.push(new THREE.Vector3(16.68, 12.21, 1.71));
points.push(new THREE.Vector3(19.09, 11.24, 2.17));
points.push(new THREE.Vector3(20.02, 14.73, 0.53));
points.push(new THREE.Vector3(19.02, 15.23, 1.82));
points.push(new THREE.Vector3(20.7, 16.93, 0.44));
points.push(new THREE.Vector3(18.66, 17.92, 0.57));
points.push(new THREE.Vector3(17.49, 17.6, 0.56));
points.push(new THREE.Vector3(14.42, 20.41, 1.97));
points.push(new THREE.Vector3(12.36, 16.38, 0.71));
points.push(new THREE.Vector3(13.59, 15.58, 2.94));
points.push(new THREE.Vector3(5.33, 16.38, 2.79));
points.push(new THREE.Vector3(3.57, 16.74, 2.25));
points.push(new THREE.Vector3(3.31, 18.68, 2.86));
points.push(new THREE.Vector3(2.5, 16.23, 0.54));
points.push(new THREE.Vector3(3.94, 14.81, 0.98));
points.push(new THREE.Vector3(5.3, 12.79, 0.37));
points.push(new THREE.Vector3(2.85, 11.46, 1.19));
points.push(new THREE.Vector3(0.64, 20.99, 3));
points.push(new THREE.Vector3(3.21, 29.2, 2.46));
points.push(new THREE.Vector3(5.54, 29.75, 2.51));
points.push(new THREE.Vector3(7.52, 27.36, 0.69));
points.push(new THREE.Vector3(8.99, 29.38, 1.32));
points.push(new THREE.Vector3(10.72, 29.73, 0.67));
points.push(new THREE.Vector3(13.7, 28.8, 1.47));
points.push(new THREE.Vector3(15.33, 31.06, 2.82));
points.push(new THREE.Vector3(19.42, 29.97, 2.94));
points.push(new THREE.Vector3(21.72, 28.69, 2.1));
points.push(new THREE.Vector3(22.1, 27.31, 1.72));
points.push(new THREE.Vector3(20.96, 27.64, 0.66));
points.push(new THREE.Vector3(18.43, 28.65, 0.45));
points.push(new THREE.Vector3(17.19, 25.69, 0.02));
points.push(new THREE.Vector3(16.25, 25.17, 2.34));
points.push(new THREE.Vector3(21.56, 25, 2.37));
points.push(new THREE.Vector3(22.11, 23.51, 1.39));
points.push(new THREE.Vector3(21.54, 18.28, 2.48));
points.push(new THREE.Vector3(24.66, 18.44, 1.46));
points.push(new THREE.Vector3(26.46, 16.07, 1.9));
points.push(new THREE.Vector3(27.24, 17.39, 0.07));
points.push(new THREE.Vector3(28.63, 17.36, 0.36));
points.push(new THREE.Vector3(33.57, 17.08, 1.54));
points.push(new THREE.Vector3(35.29, 18.35, 0.5));
points.push(new THREE.Vector3(35.29, 14.3, 0.33));
points.push(new THREE.Vector3(36.51, 13.94, 1.37));
points.push(new THREE.Vector3(37.14, 13.37, 1.35));
points.push(new THREE.Vector3(39.25, 12.44, 1.31));
points.push(new THREE.Vector3(38.82, 11.32, 1.89));
points.push(new THREE.Vector3(38.73, 13, 3.01));
points.push(new THREE.Vector3(37.21, 10.56, 2.94));
points.push(new THREE.Vector3(36.4, 10.72, 2.67));
points.push(new THREE.Vector3(34.05, 13.07, 1.97));
points.push(new THREE.Vector3(29.41, 11.14, 1.5));
points.push(new THREE.Vector3(27.17, 11.96, 0.06));
points.push(new THREE.Vector3(26.95, 9.35, 1.73));
points.push(new THREE.Vector3(30.2, 8.24, 2.33));
points.push(new THREE.Vector3(31.04, 8.23, 0.41));
points.push(new THREE.Vector3(32.06, 6.48, 0.89));
points.push(new THREE.Vector3(33.88, 6.38, 0.17));
points.push(new THREE.Vector3(33.03, 7.02, 2.62));
points.push(new THREE.Vector3(29.29, 3.45, 2.53));
points.push(new THREE.Vector3(27.76, 3.78, 1.49));
points.push(new THREE.Vector3(27.73, 0.14, 2.72));
points.push(new THREE.Vector3(24.86, 0.59, 3.03));
points.push(new THREE.Vector3(18.88, 1.36, 2.06));
points.push(new THREE.Vector3(16.72, 4.56, 1.34));
points.push(new THREE.Vector3(16.67, 5.22, 0.62));
points.push(new THREE.Vector3(14.06, 6, 1.54));
points.push(new THREE.Vector3(14.56, 2.41, 3.13));
points.push(new THREE.Vector3(22.77, 6.95, 3.04));
points.push(new THREE.Vector3(24.07, 6.78, 0.06));
points.push(new THREE.Vector3(38.29, 2.87, 0.91));
points.push(new THREE.Vector3(38.24, 2.94, 1.95));
points.push(new THREE.Vector3(39.49, 2.07, 0.51));
points.push(new THREE.Vector3(43.13, 5.36, 1.8));
points.push(new THREE.Vector3(42.37, 6.22, 1));
points.push(new THREE.Vector3(44.27, 6.07, 0.51));
points.push(new THREE.Vector3(46.1, 7.65, 0.14));
points.push(new THREE.Vector3(48.73, 7.73, 2.49));
points.push(new THREE.Vector3(49.15, 6.97, 2.37));
points.push(new THREE.Vector3(48.28, 2.16, 1.92));
points.push(new THREE.Vector3(44.48, 0.15, 3.18));
points.push(new THREE.Vector3(39.71, 7.18, 1.35));
points.push(new THREE.Vector3(40.69, 7.91, 1.91));
points.push(new THREE.Vector3(43.47, 10.69, 0.76));
points.push(new THREE.Vector3(44.41, 12.72, 2.46));
points.push(new THREE.Vector3(44.93, 14.42, 1.44));
points.push(new THREE.Vector3(44.55, 16.82, 1.99));
points.push(new THREE.Vector3(43.03, 16.65, 2.77));
points.push(new THREE.Vector3(43.51, 18.52, 2.25));
points.push(new THREE.Vector3(44.18, 20.26, 1.7));
points.push(new THREE.Vector3(43.84, 21.28, 2.91));
points.push(new THREE.Vector3(44.94, 22.65, 1.39));
points.push(new THREE.Vector3(42.48, 23.66, 1.47));
points.push(new THREE.Vector3(41.35, 23.65, 0.2));
points.push(new THREE.Vector3(40.52, 24.2, 1.04));
points.push(new THREE.Vector3(40.56, 26.51, 0.94));
points.push(new THREE.Vector3(36.7, 28.41, 0.8));
points.push(new THREE.Vector3(36.54, 27.3, 2.76));
points.push(new THREE.Vector3(33.87, 26.95, 2.21));
points.push(new THREE.Vector3(33.22, 27.68, 1.89));
points.push(new THREE.Vector3(31.53, 27.92, 1.89));
points.push(new THREE.Vector3(33.48, 29.26, 1.05));
points.push(new THREE.Vector3(34.21, 29.71, 0.04));
points.push(new THREE.Vector3(35.23, 31.66, 0.02));
points.push(new THREE.Vector3(32.48, 32.78, 0.37));
points.push(new THREE.Vector3(33.99, 33.72, 2.04));
points.push(new THREE.Vector3(31.66, 34.93, 2.11));
points.push(new THREE.Vector3(28.88, 33.62, 2.62));
points.push(new THREE.Vector3(28.49, 36.58, 2.15));
points.push(new THREE.Vector3(28.46, 38.41, 2.02));
points.push(new THREE.Vector3(29.32, 40.35, 0.93));
points.push(new THREE.Vector3(26.65, 40.24, 1.84));
points.push(new THREE.Vector3(27.91, 42.7, 1.76));
points.push(new THREE.Vector3(29.41, 45.35, 0.83));
points.push(new THREE.Vector3(32.23, 45.54, 0.3));
points.push(new THREE.Vector3(34.16, 44.51, 0.97));
points.push(new THREE.Vector3(33.73, 43.06, 1.34));
points.push(new THREE.Vector3(31.3, 43.25, 1.68));
points.push(new THREE.Vector3(31.45, 44.46, 2.72));
points.push(new THREE.Vector3(32.16, 40.5, 0.54));
points.push(new THREE.Vector3(36.32, 41.78, 0.5));
points.push(new THREE.Vector3(36.25, 42.27, 0.72));
points.push(new THREE.Vector3(38.42, 42.05, 2.03));
points.push(new THREE.Vector3(37.99, 43.93, 1.86));
points.push(new THREE.Vector3(42.28, 42.82, 0.64));
points.push(new THREE.Vector3(43.24, 45.45, 1.64));
points.push(new THREE.Vector3(41.98, 46.42, 1.4));
points.push(new THREE.Vector3(44.83, 47.32, 1.49));
points.push(new THREE.Vector3(45.28, 44.83, 2.95));
points.push(new THREE.Vector3(47.22, 44.08, 1.71));
points.push(new THREE.Vector3(47.79, 46.34, 0.48));
points.push(new THREE.Vector3(47.89, 48.23, 1.04));
points.push(new THREE.Vector3(49.94, 44.26, 3.16));
points.push(new THREE.Vector3(49.31, 42.37, 2.71));
points.push(new THREE.Vector3(49.96, 41.57, 2.69));
points.push(new THREE.Vector3(43.95, 38.26, 0.1));
points.push(new THREE.Vector3(43.87, 37.3, 1.91));
points.push(new THREE.Vector3(44.32, 33.69, 0.98));
points.push(new THREE.Vector3(47.34, 33.55, 0.6));
points.push(new THREE.Vector3(49.89, 32.73, 3.17));
points.push(new THREE.Vector3(47.38, 26.12, 0.99));
points.push(new THREE.Vector3(48.16, 21.67, 1.05));
points.push(new THREE.Vector3(49.24, 20.99, 2.05));
points.push(new THREE.Vector3(47.72, 19.43, 0.79));
points.push(new THREE.Vector3(49.22, 17.74, 2.2));
points.push(new THREE.Vector3(41.21, 13.81, 1.11));
points.push(new THREE.Vector3(39.25, 15.42, 1.34));
points.push(new THREE.Vector3(39.37, 16.28, 2.53));
points.push(new THREE.Vector3(38.58, 22.41, 0.32));
points.push(new THREE.Vector3(37.91, 22.74, 2.4));
points.push(new THREE.Vector3(35.52, 24.95, 0.8));
points.push(new THREE.Vector3(33.88, 22.07, 1.54));
points.push(new THREE.Vector3(32.38, 22.27, 1.12));
points.push(new THREE.Vector3(30.04, 22.61, 0.88));
points.push(new THREE.Vector3(28.89, 23.95, 1.72));
points.push(new THREE.Vector3(25.09, 28.41, 1.05));
points.push(new THREE.Vector3(23.8, 30.71, 2.3));
points.push(new THREE.Vector3(21.17, 32.44, 0.01));
points.push(new THREE.Vector3(24.7, 36.73, 1.52));
points.push(new THREE.Vector3(20.14, 38.29, 1.55));
points.push(new THREE.Vector3(18.5, 41.92, 1.84));
points.push(new THREE.Vector3(16.6, 40.21, 2.98));
points.push(new THREE.Vector3(14.68, 40.19, 0.37));
points.push(new THREE.Vector3(10.99, 40.35, 0.37));
points.push(new THREE.Vector3(11.74, 35.08, 0.38));
points.push(new THREE.Vector3(13.89, 36.17, 3.11));
points.push(new THREE.Vector3(4.85, 39.52, 1.07));
points.push(new THREE.Vector3(2.14, 41.61, 0.95));
points.push(new THREE.Vector3(4.85, 42.95, 0.91));
points.push(new THREE.Vector3(8.46, 45.53, 2.16));
points.push(new THREE.Vector3(7.28, 49.74, 0.54));
points.push(new THREE.Vector3(20.54, 43.58, 0.48));
points.push(new THREE.Vector3(22.63, 41.65, 0.38));
points.push(new THREE.Vector3(22.27, 42.16, 3.13));
points.push(new THREE.Vector3(25.17, 45.83, 0.33));
points.push(new THREE.Vector3(23.5, 47.89, 0.11));
points.push(new THREE.Vector3(24.34, 49.57, 0.23));
points.push(new THREE.Vector3(23.25, 48.55, 2.53));
points.push(new THREE.Vector3(25.38, 47.59, 2.41));
points.push(new THREE.Vector3(26, 48.3, 3.1));
points.push(new THREE.Vector3(27.32, 48.08, 1.64));
points.push(new THREE.Vector3(35, 48.65, 3.14));
points.push(new THREE.Vector3(37.66, 49.13, 1.28));
points.push(new THREE.Vector3(36.76, 49.99, 0.46));
points.push(new THREE.Vector3(39.83, 36.92, 2.93));
points.push(new THREE.Vector3(40.24, 34.53, 2.66));
points.push(new THREE.Vector3(40.91, 32.99, 2.34));
points.push(new THREE.Vector3(40.79, 32.73, 1.28));
points.push(new THREE.Vector3(37.8, 34.05, 2.33));
points.push(new THREE.Vector3(28.66, 30.73, 0.39));
points.push(new THREE.Vector3(2.72, 35.05, 2.93));
points.push(new THREE.Vector3(2.33, 35.87, 1.15));
points.push(new THREE.Vector3(0.37, 30.41, 3.13));
const geometry_ = new THREE.BufferGeometry().setFromPoints(points);
const line = new THREE.Line(geometry_, materia);
scene.add(line);
renderer.render(scene, camera);
camera.position.z = 5;
var zoomSpeed = 10;
var zoomDirection = 0;
// Listen for mouse wheel events
window.addEventListener('mousewheel', onMouseWheel, false);
window.addEventListener('DOMMouseScroll', onMouseWheel, false);
window.addEventListener('keydown', function (event) {
switch (event.keyCode) {
case 87:
case 38:
camera.position.y += 0.5
break;
case 83:
case 40:
camera.position.y -= 0.5
break;
case 65:
case 37:
camera.position.x -= 0.5
break;
case 39:
case 68:
camera.position.x += 0.5
break;
case 81:
camera.rotation.x += 0.5
break;
case 69:
camera.rotation.x -= 0.5
break;
default:
break;
}
console.log(event.keyCode)
});
function onMouseWheel(event) {
event.preventDefault();
if (event.wheelDelta > 0 || event.detail < 0) {
zoomDirection = 1;
} else {
zoomDirection = -1;
}
}
function animate() {
requestAnimationFrame(animate);
// Zoom in or out
camera.position.z -= zoomSpeed * zoomDirection;
camera.updateProjectionMatrix();
// Reset zoom direction
zoomDirection = 0;
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>

18
tests/iron_farm.js 100644
View File

@ -0,0 +1,18 @@
import mineflayer from 'mineflayer';
import { Main } from './controller/main.js';
import { cfg } from './config/config.js'
const bot = mineflayer.createBot({
host: "cbt.marin.rz.int", // optional
port: 25566, // optional
username: "Bot_1"
})
const bot2 = mineflayer.createBot({
host: "cbt.marin.rz.int", // optional
port: 25566, // optional
username: "Bot_2"
})
let x = new Main(bot);
let z = new Main(bot2)

View File

@ -0,0 +1,36 @@
import mineflayer from 'mineflayer';
import { Main } from './controller/main.js';
import { cfg } from './config/obsi_config.js'
import { Storage } from './controller/storage.js';
/*const bot = mineflayer.createBot({
host: "cbt.marin.rz.int", // optional
port: 25566, // optional
username: "Bot_3"
})
const bot2 = mineflayer.createBot({
host: "cbt.marin.rz.int", // optional
port: 25566, // optional
username: "Bot_4"
})*/
let i = process.argv[2]
let bots = {}
bots[cfg.acc[i].username] = {};
bots[cfg.acc[i].username].bot = mineflayer.createBot({
host: "cbt.marin.rz.int", // optional
port: 25566, // optional
username: cfg.acc[i].username
})
bots[cfg.acc[i].username].task = cfg.acc[i].task;
bots[cfg.acc[i].username].data = cfg.acc[i].data;
bots[cfg.acc[i].username].main = new Main(bots[cfg.acc[i].username].bot);
/**
process.setMaxListeners(500);
let bots = {}
for(var i = 0;i<cfg.acc.length;i++){
}
*/
Storage.bots = bots;

15
tests/test.js 100644
View File

@ -0,0 +1,15 @@
import mineflayer from 'mineflayer';
import { Main } from './controller/main.js';
import { cfg } from './config/config.js'
import findChests from './controller/helper/findChests.js';
const options = {
host: "cbt.marin.thee.moe", // optional
port: 25565, // optional
...cfg.acc,
version:"1.19.2"
}
const bot = mineflayer.createBot(options)
let x = new Main(bot);

0
tests/test2.js 100644
View File

36
tests/vecSort.js 100644
View File

@ -0,0 +1,36 @@
import Vec3 from "vec3";
import { distances, getNearestCoordinate,sortCoordinates } from "../controller/helper/distancesort.js";
let ve = [
]
let c = 200
let random = 5000
for(let i = 0;i<c;i++){
let x = Math.ceil(Math.random()*random)
let y = Math.ceil(Math.random()*320)
let z = Math.ceil(Math.random()*random)
ve.push(new Vec3(x,y,z))
}
let temp = [...ve];
let sorted_ve = [];
console.log(temp)
for(let i = 0;i < c ;i++){
let t = null;
if(i!=0){
t = sortCoordinates(temp,sorted_ve[i-1])[0]
}else{
t = sortCoordinates(temp,new Vec3(0,0,0))[0]
}
console.log(t)
temp.splice(0,1)
sorted_ve.push(t);
}
console.log(sorted_ve)
console.log(distances.distance)
for(let co of sorted_ve){
console.log(`points.push(new THREE.Vector3(${co.x/100}, ${co.z/100}, ${co.y/100}));`)
}