Compare commits
44 Commits
4026b410f4
...
master
Author | SHA1 | Date | |
---|---|---|---|
bbe2d9f99c | |||
2f77c7b990 | |||
3540e5580e | |||
261684ea90 | |||
09b09b3f96 | |||
4d2d358175 | |||
324ad41bf7 | |||
343268af24 | |||
e5fd062a4a | |||
5184d4a173 | |||
396c1e2e33 | |||
217bb0dae0 | |||
f7400a1225 | |||
3c31c41acd | |||
15d4dd7922 | |||
8f0d2eb417 | |||
6315f8c309 | |||
2fc08be581 | |||
c39a8c6d93 | |||
43e8bf97a0 | |||
b59c260e90 | |||
a41d9f2793 | |||
0d2be1378f | |||
0d23dbaf9f | |||
a87cc85eab | |||
080895421d | |||
e4ea9aeaa0 | |||
ad6c412802 | |||
aec057c89c | |||
|
af9cc4b546 | ||
|
666435ddae | ||
1c0824a167 | |||
47c2fca00a | |||
76cdf90b44 | |||
33145cb3f2 | |||
963b3d9736 | |||
a49caaedf5 | |||
7caa51f011 | |||
e588c8fa1a | |||
650398255b | |||
d69f9cf09e | |||
8b85de2b2a | |||
ce9613c00c | |||
09b9002c58 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -8,7 +8,6 @@ __pycache__/
|
|||||||
|
|
||||||
# Distribution / packaging
|
# Distribution / packaging
|
||||||
.Python
|
.Python
|
||||||
build/
|
|
||||||
develop-eggs/
|
develop-eggs/
|
||||||
dist/
|
dist/
|
||||||
downloads/
|
downloads/
|
||||||
|
51
README.md
51
README.md
@@ -1,10 +1,16 @@
|
|||||||
# Mosfet Minecraft Bot
|
# Mosfet Minecraft Bot
|
||||||
|
|
||||||
A general-purpose Minecraft 1.16 bot written in Python.
|
A general-purpose Minecraft 1.16 bot written in Python that uses an actual
|
||||||
|
Minecraft account to play.
|
||||||
|
|
||||||
Mosfet is able to farm wood by cutting trees, gather sand, gather netherwart,
|
Mosfet is able to farm wood by cutting trees, farm crops, gather sand, farm
|
||||||
and trade with villagers to get emeralds. He can eat, sleep, and flee from
|
netherwart, and trade with villagers to get emeralds. He can eat, sleep, and
|
||||||
threats.
|
flee from threats.
|
||||||
|
|
||||||
|
## Requirements
|
||||||
|
|
||||||
|
- Python >= 3.6
|
||||||
|
- pip, virtualenv, git, wget, unzip
|
||||||
|
|
||||||
## Linux Setup
|
## Linux Setup
|
||||||
|
|
||||||
@@ -12,7 +18,7 @@ Assuming Debian / Ubuntu based distro:
|
|||||||
|
|
||||||
```
|
```
|
||||||
$ sudo apt update
|
$ sudo apt update
|
||||||
$ sudo apt install build-essential python3 python3-dev python3-pip python3-virtualenv git wget unzip
|
$ sudo apt install build-essential python3 python3-dev python3-pip virtualenv git wget unzip
|
||||||
|
|
||||||
$ git clone https://git.tannercollin.com/tanner/minecraft-bot.git
|
$ git clone https://git.tannercollin.com/tanner/minecraft-bot.git
|
||||||
$ cd minecraft-bot/
|
$ cd minecraft-bot/
|
||||||
@@ -20,15 +26,38 @@ $ cd minecraft-bot/
|
|||||||
|
|
||||||
## Running
|
## Running
|
||||||
|
|
||||||
|
If you want to use the built-in burner account (Minecraft name `mattstack`):
|
||||||
|
|
||||||
```
|
```
|
||||||
$ USERNAME=you@domain.com PASSWORD=supersecret SERVER=example.com ./run-linux.sh
|
$ SERVER=minecraft.example.com ./run_linux.sh
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Or, use `PORT` to specify a custom port to connect to:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ SERVER=localhost PORT=12345 ./run_linux.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
Or, if you have your own alt account for the bot:
|
||||||
|
|
||||||
|
```
|
||||||
|
$ EMAIL=you@domain.com PASSWORD=supersecret SERVER=minecraft.example.com ./run_linux.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
[How to Cache Items](docs/cache_items.md)
|
||||||
|
|
||||||
|
[How to Grab Supplies](docs/grab_supplies.md)
|
||||||
|
|
||||||
## Commands
|
## Commands
|
||||||
|
|
||||||
The command prefix character is the last character of the bot's name. For
|
The command prefix character is the last character of the bot's name. For
|
||||||
example, if the bot's name is `mosfet1`, then you would issue commands like
|
example, if the bot's name is `mattstack`, then you would issue commands like
|
||||||
`1farm wood` or `1pos`. This lets you run multiple bots on the same server.
|
`kfarm wood` or `kpos`. This lets you run multiple bots on the same server.
|
||||||
|
|
||||||
|
In the following examples, we'll assume the bot's name is `mosfet1`, so commands
|
||||||
|
would be ran like `1farm wood` or `1pos`.
|
||||||
|
|
||||||
The exception are the below public commands, they can optionally be prefixed with `!`
|
The exception are the below public commands, they can optionally be prefixed with `!`
|
||||||
and all bots will run the command.
|
and all bots will run the command.
|
||||||
@@ -59,7 +88,7 @@ These can be ran by anyone, all bots will reply.
|
|||||||
|
|
||||||
`!error` - raises an error
|
`!error` - raises an error
|
||||||
|
|
||||||
`!inv` - prints current inventory
|
`!inv` - replies and prints current inventory
|
||||||
|
|
||||||
`!time` - replies with Minecraft world time
|
`!time` - replies with Minecraft world time
|
||||||
|
|
||||||
@@ -95,7 +124,7 @@ These can be ran by anyone, all bots will reply.
|
|||||||
|
|
||||||
### Bot-specific Commands
|
### Bot-specific Commands
|
||||||
|
|
||||||
These will only run for the bot they are addressed to.
|
These will only run for the bot they are addressed to. Replace `1` with the last character of the bot's name.
|
||||||
|
|
||||||
`1respawn` - respawns the bot if it's dead
|
`1respawn` - respawns the bot if it's dead
|
||||||
|
|
||||||
@@ -160,4 +189,4 @@ put to use.
|
|||||||
|
|
||||||
## Acknowledgements
|
## Acknowledgements
|
||||||
|
|
||||||
Thanks to Isaia and the devs behind pyCraft.
|
Thanks to Isaia, sose, and the devs behind pyCraft.
|
||||||
|
28
docs/cache_items.md
Normal file
28
docs/cache_items.md
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
# Mosfet Minecraft Bot
|
||||||
|
|
||||||
|
## How to Cache Items
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Mosfet will automatically dump items into the closest [trapped
|
||||||
|
chest](https://minecraft.fandom.com/wiki/Trapped_Chest#Crafting) once his
|
||||||
|
inventory gets full enough. Normally this is when the number of used inventory
|
||||||
|
slots is >= 27.
|
||||||
|
|
||||||
|
If Mosfet can't find a trapped chest nearby, he will place down a normal chest
|
||||||
|
if he has one in his inventory. Then he will store the items in it.
|
||||||
|
|
||||||
|
Mosfet won't cache items related to his current job. For example, if he's
|
||||||
|
farming wood, he will keep axes, beds, chests, and food.
|
||||||
|
|
||||||
|
### Advanced Details
|
||||||
|
|
||||||
|
The global `g.minimum_cache_slots` in `bot.py` controls the minimum amount of
|
||||||
|
used slots needed to trigger item caching.
|
||||||
|
|
||||||
|
In `jobs.py`, each job calls `items.set_wanted()` and `items.set_needed()` to
|
||||||
|
control which items Mosfet shouldn't cache. No items in the "needed" list will
|
||||||
|
be cached and all items in the "wanted" list—except for one stack of each—will
|
||||||
|
be cached. The "needed" list is meant for essentials like tools, food, and beds,
|
||||||
|
while the "wanted" list is for stuff that's good to have a stack of like seeds
|
||||||
|
and saplings.
|
30
docs/grab_supplies.md
Normal file
30
docs/grab_supplies.md
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
# Mosfet Minecraft Bot
|
||||||
|
|
||||||
|
## How to Grab Supplies
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
Mosfet will automatically grab supplies he needs to do his job from nearby
|
||||||
|
[barrels](https://minecraft.fandom.com/wiki/Barrel#Crafting). Before starting
|
||||||
|
the job, he will check each barrel for related supplies and grab some depending
|
||||||
|
on the job. He will recheck the barrels for supplies periodically to try and get
|
||||||
|
more.
|
||||||
|
|
||||||
|
If he can't find any barrels, he will try to continue doing the job anyway. If
|
||||||
|
his inventory is too full, he will skip grabbing supplies.
|
||||||
|
|
||||||
|
### Advanced Details
|
||||||
|
|
||||||
|
The global `g.maximum_supply_slots` in `bot.py` controls the maximum amount of
|
||||||
|
used slots allowed while grabbing supplies.
|
||||||
|
|
||||||
|
In `jobs.py`, each job sets the `grab_supplies_states.supplies` dictionary to
|
||||||
|
specify what items to grab and how many. Here's an example:
|
||||||
|
|
||||||
|
```
|
||||||
|
self.grab_supplies_states.supplies = {
|
||||||
|
tuple([items.PUMPKIN_ID]): (64, 3),
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
This tells Mosfet to grab three stacks of pumpkins if he ever has less than 64.
|
BIN
docs/media/cache_items.png
Normal file
BIN
docs/media/cache_items.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 525 KiB |
BIN
docs/media/grab_supplies.png
Normal file
BIN
docs/media/grab_supplies.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 490 KiB |
35
main.py
35
main.py
@@ -4,8 +4,15 @@ import time
|
|||||||
import traceback
|
import traceback
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
import logging
|
||||||
|
log = logging.getLogger('werkzeug')
|
||||||
|
log.setLevel(logging.ERROR)
|
||||||
|
|
||||||
from flask import Flask
|
from flask import Flask
|
||||||
app = Flask(__name__)
|
from flask_cors import CORS
|
||||||
|
build_folder = 'web_interface/build'
|
||||||
|
app = Flask(__name__, template_folder=build_folder, static_folder=build_folder, static_url_path='')
|
||||||
|
CORS(app)
|
||||||
|
|
||||||
from munch import Munch
|
from munch import Munch
|
||||||
from watchdog.observers import Observer
|
from watchdog.observers import Observer
|
||||||
@@ -35,8 +42,8 @@ g.health = 20
|
|||||||
g.food = 20
|
g.food = 20
|
||||||
g.sand_origin = None
|
g.sand_origin = None
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/api/global')
|
||||||
def hello_world():
|
def api_global():
|
||||||
data = json.dumps(g, default=lambda o: str(o), indent=4)
|
data = json.dumps(g, default=lambda o: str(o), indent=4)
|
||||||
|
|
||||||
response = app.response_class(
|
response = app.response_class(
|
||||||
@@ -46,6 +53,10 @@ def hello_world():
|
|||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
@app.route('/')
|
||||||
|
def root():
|
||||||
|
return app.send_static_file('index.html')
|
||||||
|
|
||||||
reload_timeout = time.time()
|
reload_timeout = time.time()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@@ -60,7 +71,7 @@ def main():
|
|||||||
event_handler.on_any_event = reload_bot
|
event_handler.on_any_event = reload_bot
|
||||||
|
|
||||||
observer = Observer()
|
observer = Observer()
|
||||||
observer.schedule(event_handler, '.', recursive=True)
|
observer.schedule(event_handler, 'mosfet', recursive=True)
|
||||||
observer.start()
|
observer.start()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -80,8 +91,22 @@ def main():
|
|||||||
observer.stop()
|
observer.stop()
|
||||||
observer.join()
|
observer.join()
|
||||||
|
|
||||||
|
def run_api():
|
||||||
|
host = '0.0.0.0'
|
||||||
|
port = 3300
|
||||||
|
|
||||||
|
while True:
|
||||||
|
print('Trying to run web interface on port:', port)
|
||||||
|
print('If it works, go to http://localhost:' + str(port))
|
||||||
|
try:
|
||||||
|
app.run(host=host, port=port)
|
||||||
|
except OSError:
|
||||||
|
print()
|
||||||
|
print('Error: Port already taken.')
|
||||||
|
port += 1
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
threading.Thread(target=app.run).start()
|
threading.Thread(target=run_api).start()
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
main()
|
main()
|
||||||
|
@@ -3,16 +3,12 @@ if __name__ == '__main__':
|
|||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
import time
|
import time
|
||||||
import importlib
|
import importlib
|
||||||
from math import floor, ceil
|
from math import floor, ceil
|
||||||
from copy import copy
|
from copy import copy
|
||||||
|
|
||||||
USERNAME = os.environ['USERNAME']
|
|
||||||
PASSWORD = os.environ['PASSWORD']
|
|
||||||
SERVER = os.environ['SERVER']
|
|
||||||
PORT = int(os.environ.get('PORT', 25565))
|
|
||||||
|
|
||||||
from . import monkey_patch # must be before any possible pyCraft imports
|
from . import monkey_patch # must be before any possible pyCraft imports
|
||||||
|
|
||||||
from minecraft import authentication
|
from minecraft import authentication
|
||||||
@@ -69,21 +65,19 @@ def tick(global_state):
|
|||||||
target = None
|
target = None
|
||||||
|
|
||||||
# make sure current chunks are loaded for physics
|
# make sure current chunks are loaded for physics
|
||||||
if not g.chunks.check_loaded(p, 288):
|
if not g.chunks.check_loaded(g.info.render_distance):
|
||||||
if not g.chunks.loading:
|
if not g.chunks.loading:
|
||||||
print('Loading chunks', end='', flush=True)
|
print('Loading chunks', end='', flush=True)
|
||||||
g.chunks.loading = True
|
g.chunks.loading = time.time()
|
||||||
packet = serverbound.play.PositionAndLookPacket(x=p.x, feet_y=p.y, z=p.z, pitch=0, yaw=0, on_ground=True)
|
packet = serverbound.play.PositionAndLookPacket(x=p.x, feet_y=p.y, z=p.z, pitch=0, yaw=0, on_ground=True)
|
||||||
g.connection.write_packet(packet, force=True)
|
g.connection.write_packet(packet, force=True)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
if g.chunks.loading:
|
if g.chunks.loading:
|
||||||
print()
|
print()
|
||||||
print('Chunks loaded.')
|
print('Chunks loaded in', round(time.time() - g.chunks.loading, 2), 's')
|
||||||
g.chunks.loading = False
|
g.chunks.loading = False
|
||||||
|
|
||||||
g.chunks.unload_chunks(p)
|
|
||||||
|
|
||||||
########## object physics ##########
|
########## object physics ##########
|
||||||
# note: it's possible the chunk data is out of date when this runs
|
# note: it's possible the chunk data is out of date when this runs
|
||||||
|
|
||||||
@@ -206,8 +200,8 @@ def tick(global_state):
|
|||||||
packet = serverbound.play.PositionAndLookPacket(x=p.x, feet_y=p.y, z=p.z, pitch=g.pitch, yaw=g.yaw, on_ground=(not in_air))
|
packet = serverbound.play.PositionAndLookPacket(x=p.x, feet_y=p.y, z=p.z, pitch=g.pitch, yaw=g.yaw, on_ground=(not in_air))
|
||||||
g.connection.write_packet(packet)
|
g.connection.write_packet(packet)
|
||||||
|
|
||||||
g.game.tick()
|
|
||||||
g.job.tick()
|
g.job.tick()
|
||||||
|
g.game.tick() # order important for correction_count
|
||||||
|
|
||||||
|
|
||||||
def init(global_state):
|
def init(global_state):
|
||||||
@@ -244,20 +238,57 @@ def init(global_state):
|
|||||||
g.maximum_supply_slots = 33
|
g.maximum_supply_slots = 33
|
||||||
|
|
||||||
def bot(global_state):
|
def bot(global_state):
|
||||||
|
EMAIL = os.getenv('EMAIL')
|
||||||
|
PASSWORD = os.getenv('PASSWORD')
|
||||||
|
SERVER = os.getenv('SERVER')
|
||||||
|
PORT = int(os.environ.get('PORT', 25565))
|
||||||
|
|
||||||
g = global_state
|
g = global_state
|
||||||
|
|
||||||
if not g.mcdata:
|
if not g.mcdata:
|
||||||
g.mcdata = DataManager('./minecraft_data')
|
g.mcdata = DataManager('./minecraft_data')
|
||||||
|
|
||||||
if not g.connection:
|
if not SERVER:
|
||||||
auth_token = authentication.AuthenticationToken()
|
print()
|
||||||
try:
|
print('You must specify a server to connect to. For example:')
|
||||||
auth_token.authenticate(USERNAME, PASSWORD)
|
print('SERVER=minecraft.example.com ./run_linux.sh')
|
||||||
except YggdrasilError as e:
|
print('SERVER=localhost PORT=12345 ./run_linux.sh')
|
||||||
print(e)
|
print()
|
||||||
sys.exit()
|
print('If you want to use your own account:')
|
||||||
print("Logged in as %s..." % auth_token.username)
|
print('EMAIL=you@domain.com PASSWORD=supersecret SERVER=minecraft.example.com ./run_linux.sh')
|
||||||
g.connection = Connection(SERVER, PORT, auth_token=auth_token)
|
os._exit(0)
|
||||||
|
elif not g.connection:
|
||||||
|
if EMAIL and PASSWORD:
|
||||||
|
auth_token = authentication.AuthenticationToken()
|
||||||
|
try:
|
||||||
|
auth_token.authenticate(EMAIL, PASSWORD)
|
||||||
|
except YggdrasilError as e:
|
||||||
|
print(e)
|
||||||
|
os._exit(0)
|
||||||
|
print("Logged in as %s..." % auth_token.username)
|
||||||
|
g.connection = Connection(SERVER, PORT, auth_token=auth_token)
|
||||||
|
elif EMAIL:
|
||||||
|
print('No password provided, attempting to connect in offline mode...')
|
||||||
|
g.connection = Connection(SERVER, PORT, username=EMAIL)
|
||||||
|
elif PASSWORD:
|
||||||
|
print('')
|
||||||
|
print('Did you forget to specify an email?')
|
||||||
|
print('If you want to use your own account:')
|
||||||
|
print('EMAIL=you@domain.com PASSWORD=supersecret SERVER=minecraft.example.com ./run_linux.sh')
|
||||||
|
os._exit(0)
|
||||||
|
else:
|
||||||
|
print('No username or password provided, using burner minecraft account...')
|
||||||
|
EMAIL = 'moc.liamg@monortem'[::-1]
|
||||||
|
PASSWORD = '!8891anteR'[::-1]
|
||||||
|
auth_token = authentication.AuthenticationToken()
|
||||||
|
try:
|
||||||
|
auth_token.authenticate(EMAIL, PASSWORD)
|
||||||
|
except YggdrasilError as e:
|
||||||
|
print(e)
|
||||||
|
os._exit(0)
|
||||||
|
print("Logged in as %s..." % auth_token.username)
|
||||||
|
g.connection = Connection(SERVER, PORT, auth_token=auth_token)
|
||||||
|
|
||||||
|
|
||||||
g.chunks = ChunksManager(g.mcdata)
|
g.chunks = ChunksManager(g.mcdata)
|
||||||
|
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
|
from datetime import datetime, timedelta
|
||||||
import random
|
import random
|
||||||
from math import hypot
|
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from munch import Munch
|
from munch import Munch
|
||||||
|
|
||||||
@@ -22,11 +22,12 @@ class Commands:
|
|||||||
self.g.chat.set_handler(self.handle_chat)
|
self.g.chat.set_handler(self.handle_chat)
|
||||||
|
|
||||||
def handle_chat(self, message):
|
def handle_chat(self, message):
|
||||||
source, text = message
|
source, sender, text = message
|
||||||
reply = None
|
reply = ''
|
||||||
private = False
|
private = False
|
||||||
for_me = False
|
for_me = False
|
||||||
authed = False
|
authed = sender == '0c123cfa-1697-4427-9413-4b645dee7ec0'
|
||||||
|
bot_num = self.g.name[-1]
|
||||||
|
|
||||||
if source == 'SYSTEM':
|
if source == 'SYSTEM':
|
||||||
self.g.command_lock = False
|
self.g.command_lock = False
|
||||||
@@ -36,40 +37,23 @@ class Commands:
|
|||||||
elif text == 'You are no longer AFK.':
|
elif text == 'You are no longer AFK.':
|
||||||
self.g.afk = False
|
self.g.afk = False
|
||||||
|
|
||||||
match1 = re.match(r'<?(\w+)> (.*)', text)
|
text = text.replace('zzz', '!zzz')
|
||||||
match2 = re.match(r'\[(\w+) -> me] (.*)', text)
|
|
||||||
if match1:
|
match = re.match(r'(.*\W+)\s+(['+bot_num+'|!])(\w+) ?(.*)', text)
|
||||||
sender, text = match1.groups()
|
if match:
|
||||||
elif match2:
|
meta, prefix, command, data = match.groups()
|
||||||
sender, text = match2.groups()
|
else:
|
||||||
|
return
|
||||||
|
|
||||||
|
if '-> me' in meta:
|
||||||
private = True
|
private = True
|
||||||
else:
|
|
||||||
return
|
|
||||||
|
|
||||||
if sender == 'tanner6':
|
if prefix == bot_num:
|
||||||
authed = True
|
|
||||||
|
|
||||||
if text.startswith('zzz'):
|
|
||||||
text = '!zzz'
|
|
||||||
|
|
||||||
bot_num = self.g.name[-1]
|
|
||||||
|
|
||||||
if text.startswith(bot_num):
|
|
||||||
text = text[1:]
|
|
||||||
for_me = True
|
for_me = True
|
||||||
elif text.startswith('! '):
|
|
||||||
text = text[2:]
|
|
||||||
elif text.startswith('!'):
|
|
||||||
text = text[1:]
|
|
||||||
else:
|
|
||||||
return
|
|
||||||
|
|
||||||
if ' ' in text:
|
if data.startswith('[') and data.endswith(']'):
|
||||||
command = text.split(' ', 1)[0]
|
command = 'nosquarebrackets'
|
||||||
data = text.split(' ', 1)[1]
|
|
||||||
else:
|
|
||||||
command = text
|
|
||||||
data = None
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|
||||||
@@ -101,6 +85,9 @@ class Commands:
|
|||||||
if command == 'echo' and data:
|
if command == 'echo' and data:
|
||||||
reply = data
|
reply = data
|
||||||
|
|
||||||
|
if command == 'nosquarebrackets':
|
||||||
|
reply = 'don\'t literally put the [ ]'
|
||||||
|
|
||||||
## !pos - replies with position and dimension
|
## !pos - replies with position and dimension
|
||||||
if command == 'pos':
|
if command == 'pos':
|
||||||
reply = str(utils.pint(self.g.pos))[1:-1] + ', ' + self.g.dimension
|
reply = str(utils.pint(self.g.pos))[1:-1] + ', ' + self.g.dimension
|
||||||
@@ -120,19 +107,44 @@ class Commands:
|
|||||||
reply = 'ok'
|
reply = 'ok'
|
||||||
raise
|
raise
|
||||||
|
|
||||||
## !inv - prints current inventory
|
## !inv - replies and prints current inventory
|
||||||
if command == 'inv':
|
if command == 'inv' or command == 'inventory':
|
||||||
inv_list = []
|
inv_list = []
|
||||||
|
uniq_item_counts = {}
|
||||||
for i in self.g.inv.values():
|
for i in self.g.inv.values():
|
||||||
if i.present:
|
if i.present:
|
||||||
inv_list.append('{}:{} x {}'.format(items.ITEM_NAMES[i.item_id], str(i.item_id), i.item_count))
|
inv_list.append((items.ITEM_NAMES[i.item_id], str(i.item_id), i.item_count))
|
||||||
|
|
||||||
|
if i.item_id not in uniq_item_counts:
|
||||||
|
uniq_item_counts[i.item_id] = 0
|
||||||
|
uniq_item_counts[i.item_id] += i.item_count
|
||||||
|
|
||||||
inv_list.sort()
|
inv_list.sort()
|
||||||
result = '\n'.join(inv_list)
|
console_result = '\n'.join(['{}:{} x {}'.format(*x) for x in inv_list])
|
||||||
print(result or 'Empty')
|
|
||||||
|
if not console_result:
|
||||||
|
print('Empty')
|
||||||
|
reply = 'empty'
|
||||||
|
else:
|
||||||
|
print(console_result)
|
||||||
|
|
||||||
|
reply_result_1 = ', '.join(['{}:{} x {}'.format(*x) for x in inv_list])
|
||||||
|
reply_result_2 = ', '.join(['{}:{} x {}'.format(items.ITEM_NAMES[k], str(k), v) for k,v in uniq_item_counts.items()])
|
||||||
|
reply_result_3 = ', '.join(['{}:{}x{}'.format(items.ITEM_NAMES[k], str(k), v) for k,v in uniq_item_counts.items()])
|
||||||
|
reply_result_4 = ', '.join(['{}:{}x{}'.format(re.sub(r'[aeiou]', '', items.ITEM_NAMES[k]), str(k), v) for k,v in uniq_item_counts.items()])
|
||||||
|
reply_result_5 = ' '.join(['{}{}x{}'.format(re.sub(r'[aeiou]', '', items.ITEM_NAMES[k]), str(k), v) for k,v in uniq_item_counts.items()])
|
||||||
|
|
||||||
|
for r in [reply_result_1, reply_result_2, reply_result_3, reply_result_4, reply_result_5]:
|
||||||
|
reply = r
|
||||||
|
if len(reply) < 256:
|
||||||
|
break
|
||||||
|
|
||||||
## !time - replies with Minecraft world time
|
## !time - replies with Minecraft world time
|
||||||
if command == 'time':
|
if command == 'time':
|
||||||
reply = str(self.g.time)
|
seconds = self.g.time * 3.6
|
||||||
|
start = datetime(2000, 1, 1, hour=6)
|
||||||
|
mctime = start + timedelta(seconds=seconds)
|
||||||
|
reply = str(self.g.time) + ' - ' + mctime.strftime('%I:%M %p')
|
||||||
|
|
||||||
## !count [id] - counts the number of items with that id
|
## !count [id] - counts the number of items with that id
|
||||||
if command == 'count' and data:
|
if command == 'count' and data:
|
||||||
@@ -141,7 +153,9 @@ class Commands:
|
|||||||
|
|
||||||
## !loaded - replies with the current loaded area
|
## !loaded - replies with the current loaded area
|
||||||
if command == 'loaded':
|
if command == 'loaded':
|
||||||
reply = str(self.g.chunks.get_loaded_area())
|
l = self.g.chunks.get_loaded_area()
|
||||||
|
reply = '{}, {}, {} to {}, {}, {}'.format(*l[0], *l[1])
|
||||||
|
reply += ' - ' + str(len(self.g.chunks.chunks)//16) + ' chunks'
|
||||||
|
|
||||||
## !players - prints the current players
|
## !players - prints the current players
|
||||||
## !players clear - clears the current player list
|
## !players clear - clears the current player list
|
||||||
@@ -230,23 +244,67 @@ class Commands:
|
|||||||
tree = next(self.g.world.find_trees(pos, 50))
|
tree = next(self.g.world.find_trees(pos, 50))
|
||||||
reply = str(tree)[1:-1]
|
reply = str(tree)[1:-1]
|
||||||
|
|
||||||
## !block x y z - replies what block is at (x, y, z)
|
## !info [query] - replies with info on a coordinate, block, item, or player
|
||||||
if command == 'block':
|
if command == 'info':
|
||||||
try:
|
if not reply:
|
||||||
data = data.replace('(', ' ').replace(')', ' ').replace(',', ' ')
|
try:
|
||||||
x1, y1, z1 = [int(x) for x in data.split()]
|
check = data.replace('(', ' ').replace(')', ' ').replace(',', ' ')
|
||||||
except (AttributeError, ValueError):
|
x1, y1, z1 = [int(x) for x in check.split()]
|
||||||
reply = 'usage: !block x1 y1 z1'
|
coord = (x1, y1, z1)
|
||||||
|
block = self.g.world.block_at(*coord)
|
||||||
|
|
||||||
|
if not reply and block is None:
|
||||||
|
reply = 'coord out of range'
|
||||||
|
|
||||||
|
if not reply:
|
||||||
|
reply = 'Block: ' + blocks.BLOCKS[block] + ':' + str(block)
|
||||||
|
if blocks.PROPS[block]:
|
||||||
|
reply += ' - ' + ', '.join(['{}:{}'.format(k, v) for k, v in blocks.PROPS[block].items()])
|
||||||
|
except (AttributeError, ValueError):
|
||||||
|
pass
|
||||||
|
|
||||||
if not reply:
|
if not reply:
|
||||||
coord = (x1, y1, z1)
|
try:
|
||||||
block = self.g.world.block_at(*coord)
|
check = int(data)
|
||||||
|
|
||||||
if not reply and block is None:
|
if check in blocks.BLOCKS:
|
||||||
reply = 'first coord out of range'
|
block = check
|
||||||
|
reply += 'Block: ' + blocks.BLOCKS[block] + ':' + str(block)
|
||||||
|
if blocks.PROPS[block]:
|
||||||
|
reply += ' - ' + ', '.join(['{}:{}'.format(k, v) for k, v in blocks.PROPS[block].items()])
|
||||||
|
|
||||||
if not reply:
|
if check in blocks.BLOCKS and check in items.ITEM_NAMES:
|
||||||
reply = blocks.BLOCKS[block] + ':' + str(block)
|
reply += ' / '
|
||||||
|
|
||||||
|
if check in items.ITEM_NAMES:
|
||||||
|
item = check
|
||||||
|
reply += 'Item: ' + items.ITEM_NAMES[item] + ':' + str(item)
|
||||||
|
|
||||||
|
except ValueError:
|
||||||
|
pass
|
||||||
|
|
||||||
|
check = data.lower()
|
||||||
|
if not reply and check in self.g.player_names:
|
||||||
|
uuid = self.g.player_names[check]
|
||||||
|
|
||||||
|
for p in self.g.players.values():
|
||||||
|
if p.player_uuid == uuid:
|
||||||
|
player = p
|
||||||
|
break
|
||||||
|
else: # for
|
||||||
|
reply = 'player out of range'
|
||||||
|
|
||||||
|
if not reply:
|
||||||
|
reply += 'Player: '
|
||||||
|
|
||||||
|
results = []
|
||||||
|
for k, v in player.items():
|
||||||
|
try:
|
||||||
|
results.append('{}:{}'.format(k, int(v)))
|
||||||
|
except ValueError:
|
||||||
|
results.append('{}:{}'.format(k, str(v)))
|
||||||
|
|
||||||
|
reply += ', '.join(results)
|
||||||
|
|
||||||
|
|
||||||
################# Specific commands ##########################
|
################# Specific commands ##########################
|
||||||
@@ -392,14 +450,9 @@ class Commands:
|
|||||||
|
|
||||||
## 1here - bot comes to your location
|
## 1here - bot comes to your location
|
||||||
if command == 'here':
|
if command == 'here':
|
||||||
try:
|
|
||||||
sender_uuid = self.g.player_names[sender]
|
|
||||||
except KeyError:
|
|
||||||
reply = 'can\'t find your uuid'
|
|
||||||
|
|
||||||
if not reply:
|
if not reply:
|
||||||
for p in self.g.players.values():
|
for p in self.g.players.values():
|
||||||
if p.player_uuid == sender_uuid:
|
if p.player_uuid == sender:
|
||||||
player = p
|
player = p
|
||||||
break
|
break
|
||||||
else: # for
|
else: # for
|
||||||
@@ -520,9 +573,13 @@ class Commands:
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
if reply:
|
if reply:
|
||||||
print(reply)
|
print('Reply:', reply)
|
||||||
|
|
||||||
|
if len(reply) >= 256:
|
||||||
|
reply = 'reply too long, check console'
|
||||||
|
|
||||||
if private and not reply.startswith('/'):
|
if private and not reply.startswith('/'):
|
||||||
self.g.chat.send('/m ' + sender + ' ' + reply)
|
self.g.chat.send('/r ' + reply)
|
||||||
else:
|
else:
|
||||||
self.g.chat.send(reply)
|
self.g.chat.send(reply)
|
||||||
|
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
from math import hypot
|
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from munch import Munch
|
from munch import Munch
|
||||||
|
|
||||||
@@ -16,7 +15,7 @@ from mosfet.protocol.packets import (
|
|||||||
ClientWindowConfirmationPacket, EntityMetadataPacket,
|
ClientWindowConfirmationPacket, EntityMetadataPacket,
|
||||||
SpawnLivingEntityPacket, EntityPositionRotationPacket, DestroyEntitiesPacket,
|
SpawnLivingEntityPacket, EntityPositionRotationPacket, DestroyEntitiesPacket,
|
||||||
EntityActionPacket, EntityTeleport, InteractEntityPacket, TradeListPacket,
|
EntityActionPacket, EntityTeleport, InteractEntityPacket, TradeListPacket,
|
||||||
SelectTradePacket, DisconnectPacket,
|
SelectTradePacket, DisconnectPacket, UnloadChunkPacket,
|
||||||
)
|
)
|
||||||
|
|
||||||
from mosfet.protocol.types import Slot
|
from mosfet.protocol.types import Slot
|
||||||
@@ -50,6 +49,7 @@ class Game:
|
|||||||
register(self.handle_spawn_living, SpawnLivingEntityPacket)
|
register(self.handle_spawn_living, SpawnLivingEntityPacket)
|
||||||
register(self.handle_entity_position, clientbound.play.EntityPositionDeltaPacket)
|
register(self.handle_entity_position, clientbound.play.EntityPositionDeltaPacket)
|
||||||
register(self.handle_entity_position_rotation, EntityPositionRotationPacket)
|
register(self.handle_entity_position_rotation, EntityPositionRotationPacket)
|
||||||
|
register(self.handle_entity_look, clientbound.play.EntityLookPacket)
|
||||||
register(self.handle_destroy_entities, DestroyEntitiesPacket)
|
register(self.handle_destroy_entities, DestroyEntitiesPacket)
|
||||||
register(self.handle_spawn_player, clientbound.play.SpawnPlayerPacket)
|
register(self.handle_spawn_player, clientbound.play.SpawnPlayerPacket)
|
||||||
register(self.handle_respawn, clientbound.play.RespawnPacket)
|
register(self.handle_respawn, clientbound.play.RespawnPacket)
|
||||||
@@ -59,6 +59,7 @@ class Game:
|
|||||||
#register(self.handle_entity_velocity, clientbound.play.EntityVelocityPacket)
|
#register(self.handle_entity_velocity, clientbound.play.EntityVelocityPacket)
|
||||||
register(self.handle_trade_list, TradeListPacket)
|
register(self.handle_trade_list, TradeListPacket)
|
||||||
register(self.handle_disconnect, DisconnectPacket)
|
register(self.handle_disconnect, DisconnectPacket)
|
||||||
|
register(self.handle_unload_chunk, UnloadChunkPacket)
|
||||||
|
|
||||||
#register(self.handle_packet, Packet, early=True)
|
#register(self.handle_packet, Packet, early=True)
|
||||||
|
|
||||||
@@ -394,6 +395,13 @@ class Game:
|
|||||||
obj.item_id = entry.value.item_id
|
obj.item_id = entry.value.item_id
|
||||||
obj.item_count = entry.value.item_count
|
obj.item_count = entry.value.item_count
|
||||||
|
|
||||||
|
mob = self.g.mobs.get(packet.entity_id, None)
|
||||||
|
if mob:
|
||||||
|
for entry in packet.metadata:
|
||||||
|
if mob.type == mobs.VILLAGER:
|
||||||
|
if entry.index == 17:
|
||||||
|
mob.profession = entry.value[1]
|
||||||
|
|
||||||
player = self.g.players.get(packet.entity_id, None)
|
player = self.g.players.get(packet.entity_id, None)
|
||||||
if player:
|
if player:
|
||||||
return
|
return
|
||||||
@@ -435,8 +443,14 @@ class Game:
|
|||||||
player.x += packet.delta_x / 4096.0
|
player.x += packet.delta_x / 4096.0
|
||||||
player.y += packet.delta_y / 4096.0
|
player.y += packet.delta_y / 4096.0
|
||||||
player.z += packet.delta_z / 4096.0
|
player.z += packet.delta_z / 4096.0
|
||||||
|
player.yaw = packet.yaw
|
||||||
|
player.pitch = packet.pitch
|
||||||
|
|
||||||
#if player.player_uuid == '0c123cfa-1697-4427-9413-4b645dee7ec0': print(packet)
|
def handle_entity_look(self, packet):
|
||||||
|
player = self.g.players.get(packet.entity_id, None)
|
||||||
|
if player:
|
||||||
|
player.yaw = packet.yaw
|
||||||
|
player.pitch = packet.pitch
|
||||||
|
|
||||||
def handle_entity_teleport(self, packet):
|
def handle_entity_teleport(self, packet):
|
||||||
mob = self.g.mobs.get(packet.entity_id, None)
|
mob = self.g.mobs.get(packet.entity_id, None)
|
||||||
@@ -480,12 +494,14 @@ class Game:
|
|||||||
def handle_respawn(self, packet):
|
def handle_respawn(self, packet):
|
||||||
print(packet)
|
print(packet)
|
||||||
self.g.dimension = packet.world_name.replace('minecraft:', '')
|
self.g.dimension = packet.world_name.replace('minecraft:', '')
|
||||||
|
self.g.chunks.unload_all_chunks()
|
||||||
|
|
||||||
def handle_player_list(self, packet):
|
def handle_player_list(self, packet):
|
||||||
for action in packet.actions:
|
for action in packet.actions:
|
||||||
if isinstance(action, packet.AddPlayerAction):
|
if isinstance(action, packet.AddPlayerAction):
|
||||||
self.g.player_names[action.uuid] = action.name
|
self.g.player_names[action.uuid] = action.name
|
||||||
self.g.player_names[action.name] = action.uuid # porque no los dos?
|
self.g.player_names[action.name] = action.uuid
|
||||||
|
self.g.player_names[action.name.lower()] = action.uuid # porque no los dos?
|
||||||
|
|
||||||
def handle_update_health(self, packet):
|
def handle_update_health(self, packet):
|
||||||
print(packet)
|
print(packet)
|
||||||
@@ -526,6 +542,9 @@ class Game:
|
|||||||
import os
|
import os
|
||||||
os._exit(1)
|
os._exit(1)
|
||||||
|
|
||||||
|
def handle_unload_chunk(self, packet):
|
||||||
|
self.g.chunks.unload_chunk(packet.chunk_x, packet.chunk_z)
|
||||||
|
|
||||||
def tick(self):
|
def tick(self):
|
||||||
if self.g.breaking:
|
if self.g.breaking:
|
||||||
self.animate()
|
self.animate()
|
||||||
|
@@ -15,6 +15,11 @@ for name, data in JSON_BLOCKS.items():
|
|||||||
for state in data['states']:
|
for state in data['states']:
|
||||||
BLOCKS[state['id']] = name.replace('minecraft:', '')
|
BLOCKS[state['id']] = name.replace('minecraft:', '')
|
||||||
|
|
||||||
|
PROPS = {}
|
||||||
|
for name, data in JSON_BLOCKS.items():
|
||||||
|
for state in data['states']:
|
||||||
|
PROPS[state['id']] = state.get('properties', {})
|
||||||
|
|
||||||
BREAK_DISTANCE = 6
|
BREAK_DISTANCE = 6
|
||||||
|
|
||||||
AIR = 0
|
AIR = 0
|
||||||
|
@@ -89,6 +89,9 @@ for item_name, item in ITEMS.items():
|
|||||||
def get_id(name):
|
def get_id(name):
|
||||||
return ITEMS['minecraft:' + name]['protocol_id']
|
return ITEMS['minecraft:' + name]['protocol_id']
|
||||||
|
|
||||||
|
def get_name(idx):
|
||||||
|
return ITEM_NAMES[idx]
|
||||||
|
|
||||||
CHEST_ID = get_id('chest')
|
CHEST_ID = get_id('chest')
|
||||||
GAPPLE_ID = get_id('enchanted_golden_apple')
|
GAPPLE_ID = get_id('enchanted_golden_apple')
|
||||||
SAND_ID = get_id('sand')
|
SAND_ID = get_id('sand')
|
||||||
@@ -100,6 +103,7 @@ WHEAT_ID = get_id('wheat')
|
|||||||
WHEAT_SEEDS_ID = get_id('wheat_seeds')
|
WHEAT_SEEDS_ID = get_id('wheat_seeds')
|
||||||
BEETROOT_SEEDS_ID = get_id('beetroot_seeds')
|
BEETROOT_SEEDS_ID = get_id('beetroot_seeds')
|
||||||
PUMPKIN_ID = get_id('pumpkin')
|
PUMPKIN_ID = get_id('pumpkin')
|
||||||
|
BEETROOT_ID = get_id('beetroot')
|
||||||
|
|
||||||
EMERALD_ID = get_id('emerald')
|
EMERALD_ID = get_id('emerald')
|
||||||
BERRIES_ID = get_id('sweet_berries')
|
BERRIES_ID = get_id('sweet_berries')
|
||||||
@@ -115,8 +119,10 @@ INIT_WANTED_ITEMS = set()
|
|||||||
WANTED_ITEMS = INIT_WANTED_ITEMS
|
WANTED_ITEMS = INIT_WANTED_ITEMS
|
||||||
|
|
||||||
def set_needed(items):
|
def set_needed(items):
|
||||||
|
global NEEDED_ITEMS
|
||||||
NEEDED_ITEMS = INIT_NEEDED_ITEMS | items
|
NEEDED_ITEMS = INIT_NEEDED_ITEMS | items
|
||||||
|
|
||||||
def set_wanted(items):
|
def set_wanted(items):
|
||||||
|
global WANTED_ITEMS
|
||||||
WANTED_ITEMS = INIT_WANTED_ITEMS | items
|
WANTED_ITEMS = INIT_WANTED_ITEMS | items
|
||||||
|
|
||||||
|
@@ -1,8 +1,33 @@
|
|||||||
|
from mosfet.info import items
|
||||||
import json
|
import json
|
||||||
|
|
||||||
with open('minecraft_data/registries.json') as f:
|
with open('minecraft_data/registries.json') as f:
|
||||||
MOBS = json.load(f)['minecraft:entity_type']['entries']
|
MOBS = json.load(f)['minecraft:entity_type']['entries']
|
||||||
|
|
||||||
|
VILLAGER = 93
|
||||||
|
ARMORER = 1
|
||||||
|
BUTCHER = 2
|
||||||
|
CARTOGRAPHER = 3
|
||||||
|
CLERIC = 4
|
||||||
|
FARMER = 5
|
||||||
|
FISHERMAN = 6
|
||||||
|
FLETCHER = 7
|
||||||
|
LEATHERWORKER = 8
|
||||||
|
LIBRARIAN = 9
|
||||||
|
MASON = 10
|
||||||
|
NITWIT = 11
|
||||||
|
SHEPHERD = 12
|
||||||
|
TOOLSMITH = 13
|
||||||
|
WEAPONSMITH = 14
|
||||||
|
|
||||||
|
TRADES = {
|
||||||
|
ARMORER: [items.IRON_INGOT_ID],
|
||||||
|
BUTCHER: [items.BERRIES_ID],
|
||||||
|
FARMER: [items.PUMPKIN_ID, items.WHEAT_ID, items.POTATO_ID, items.CARROT_ID, items.BEETROOT_ID],
|
||||||
|
TOOLSMITH: [items.IRON_INGOT_ID],
|
||||||
|
WEAPONSMITH: [items.IRON_INGOT_ID],
|
||||||
|
}
|
||||||
|
|
||||||
EVIL = [
|
EVIL = [
|
||||||
'blaze',
|
'blaze',
|
||||||
'cave_spider',
|
'cave_spider',
|
||||||
|
@@ -3,7 +3,6 @@ import time
|
|||||||
import importlib
|
import importlib
|
||||||
import random
|
import random
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from math import hypot, floor
|
|
||||||
|
|
||||||
from minecraft.networking.types import BlockFace
|
from minecraft.networking.types import BlockFace
|
||||||
|
|
||||||
@@ -236,6 +235,8 @@ class JobStates:
|
|||||||
tuple([items.IRON_INGOT_ID]): (64, 3),
|
tuple([items.IRON_INGOT_ID]): (64, 3),
|
||||||
tuple([items.WHEAT_ID]): (64, 3),
|
tuple([items.WHEAT_ID]): (64, 3),
|
||||||
tuple([items.POTATO_ID]): (64, 3),
|
tuple([items.POTATO_ID]): (64, 3),
|
||||||
|
tuple([items.CARROT_ID]): (64, 3),
|
||||||
|
tuple([items.BEETROOT_ID]): (64, 3),
|
||||||
}
|
}
|
||||||
|
|
||||||
items.set_needed(set([
|
items.set_needed(set([
|
||||||
@@ -244,6 +245,8 @@ class JobStates:
|
|||||||
items.IRON_INGOT_ID,
|
items.IRON_INGOT_ID,
|
||||||
items.WHEAT_ID,
|
items.WHEAT_ID,
|
||||||
items.POTATO_ID,
|
items.POTATO_ID,
|
||||||
|
items.CARROT_ID,
|
||||||
|
items.BEETROOT_ID,
|
||||||
]))
|
]))
|
||||||
return machines
|
return machines
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@ import time
|
|||||||
import importlib
|
import importlib
|
||||||
import random
|
import random
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from math import hypot, floor
|
from math import floor
|
||||||
|
|
||||||
from minecraft.networking.types import BlockFace
|
from minecraft.networking.types import BlockFace
|
||||||
|
|
||||||
@@ -54,11 +54,7 @@ class CacheItemsStates:
|
|||||||
|
|
||||||
chest = self.trapped_chests[0]
|
chest = self.trapped_chests[0]
|
||||||
|
|
||||||
tmp = c.get_block_at(*chest)
|
navpath = w.path_to_place_faked(p, chest)
|
||||||
c.set_block_at(*chest, blocks.AIR)
|
|
||||||
navpath = w.path_to_place(p, chest)
|
|
||||||
c.set_block_at(*chest, tmp)
|
|
||||||
|
|
||||||
print('navpath:', navpath)
|
print('navpath:', navpath)
|
||||||
|
|
||||||
if navpath:
|
if navpath:
|
||||||
@@ -69,6 +65,7 @@ class CacheItemsStates:
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
self.trapped_chests.pop(0)
|
self.trapped_chests.pop(0)
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
def going_to_trapped_chest(self):
|
def going_to_trapped_chest(self):
|
||||||
if utils.pint(self.g.pos) == self.opening:
|
if utils.pint(self.g.pos) == self.opening:
|
||||||
|
@@ -3,7 +3,7 @@ import time
|
|||||||
import importlib
|
import importlib
|
||||||
import random
|
import random
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from math import hypot, floor
|
from math import floor
|
||||||
|
|
||||||
from minecraft.networking.types import BlockFace
|
from minecraft.networking.types import BlockFace
|
||||||
|
|
||||||
@@ -64,6 +64,7 @@ class CheckThreatsStates:
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
print('Cant get to safety', self.safety)
|
print('Cant get to safety', self.safety)
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
print('Cant get to safety, aborting')
|
print('Cant get to safety, aborting')
|
||||||
self.state = self.cleanup
|
self.state = self.cleanup
|
||||||
|
@@ -3,7 +3,7 @@ import time
|
|||||||
import importlib
|
import importlib
|
||||||
import random
|
import random
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from math import hypot, floor
|
from math import floor
|
||||||
|
|
||||||
from minecraft.networking.types import BlockFace
|
from minecraft.networking.types import BlockFace
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@ import time
|
|||||||
import importlib
|
import importlib
|
||||||
import random
|
import random
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from math import hypot, floor
|
from math import floor
|
||||||
|
|
||||||
from minecraft.networking.types import BlockFace
|
from minecraft.networking.types import BlockFace
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@ import time
|
|||||||
import importlib
|
import importlib
|
||||||
import random
|
import random
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from math import hypot, floor
|
from math import floor
|
||||||
|
|
||||||
from minecraft.networking.types import BlockFace
|
from minecraft.networking.types import BlockFace
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ class FillBlocksStates:
|
|||||||
|
|
||||||
b1, b2 = utils.pboundingbox(f.coord1, f.coord2)
|
b1, b2 = utils.pboundingbox(f.coord1, f.coord2)
|
||||||
box = utils.psub(b2, b1)
|
box = utils.psub(b2, b1)
|
||||||
xz_distance = hypot(box[0]+1, box[2]+1)
|
xz_distance = utils.hypot(box[0]+1, box[2]+1)
|
||||||
y_start = f.coord1[1]
|
y_start = f.coord1[1]
|
||||||
y_end = f.coord2[1]
|
y_end = f.coord2[1]
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ class FillBlocksStates:
|
|||||||
|
|
||||||
b1, b2 = utils.pboundingbox(f.coord1, f.coord2)
|
b1, b2 = utils.pboundingbox(f.coord1, f.coord2)
|
||||||
box = utils.psub(b2, b1)
|
box = utils.psub(b2, b1)
|
||||||
xz_distance = hypot(box[0]+1, box[2]+1)
|
xz_distance = utils.hypot(box[0]+1, box[2]+1)
|
||||||
y_start = f.coord1[1]
|
y_start = f.coord1[1]
|
||||||
y_end = f.coord2[1]
|
y_end = f.coord2[1]
|
||||||
|
|
||||||
@@ -139,8 +139,7 @@ class FillBlocksStates:
|
|||||||
else:
|
else:
|
||||||
print('Cant get to that block')
|
print('Cant get to that block')
|
||||||
self.state = self.cleanup
|
self.state = self.cleanup
|
||||||
#self.bad_sand.append(self.sand)
|
time.sleep(0.1)
|
||||||
#self.state = self.find_new_sand
|
|
||||||
|
|
||||||
def going_to_block(self):
|
def going_to_block(self):
|
||||||
if not len(self.g.path):
|
if not len(self.g.path):
|
||||||
|
@@ -3,7 +3,7 @@ import time
|
|||||||
import importlib
|
import importlib
|
||||||
import random
|
import random
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from math import hypot, floor
|
from math import floor
|
||||||
|
|
||||||
from minecraft.networking.types import BlockFace
|
from minecraft.networking.types import BlockFace
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@ import time
|
|||||||
import importlib
|
import importlib
|
||||||
import random
|
import random
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from math import hypot, floor
|
from math import floor
|
||||||
|
|
||||||
from minecraft.networking.types import BlockFace
|
from minecraft.networking.types import BlockFace
|
||||||
|
|
||||||
@@ -61,15 +61,8 @@ class GatherCropStates:
|
|||||||
self.state = self.going_to_crop
|
self.state = self.going_to_crop
|
||||||
else:
|
else:
|
||||||
print('Cant get to it, blacklisting')
|
print('Cant get to it, blacklisting')
|
||||||
|
time.sleep(0.1)
|
||||||
self.bad_crops.append(self.crop)
|
self.bad_crops.append(self.crop)
|
||||||
self.wait_time = 0.5
|
|
||||||
self.state = self.wait_to_restart
|
|
||||||
|
|
||||||
def wait_to_restart(self):
|
|
||||||
# prevent timeouts
|
|
||||||
if self.wait_time > 0:
|
|
||||||
self.wait_time -= utils.TICK
|
|
||||||
else:
|
|
||||||
self.state = self.find_new_crop
|
self.state = self.find_new_crop
|
||||||
|
|
||||||
def going_to_crop(self):
|
def going_to_crop(self):
|
||||||
@@ -79,15 +72,7 @@ class GatherCropStates:
|
|||||||
|
|
||||||
def break_crop(self):
|
def break_crop(self):
|
||||||
self.g.game.break_block(self.crop)
|
self.g.game.break_block(self.crop)
|
||||||
self.wait_time = 0.5
|
self.state = self.select_seed
|
||||||
self.state = self.wait
|
|
||||||
|
|
||||||
def wait(self):
|
|
||||||
# wait for the item
|
|
||||||
if self.wait_time > 0:
|
|
||||||
self.wait_time -= utils.TICK
|
|
||||||
else:
|
|
||||||
self.state = self.select_seed
|
|
||||||
|
|
||||||
def select_seed(self):
|
def select_seed(self):
|
||||||
p = utils.pint(self.g.pos)
|
p = utils.pint(self.g.pos)
|
||||||
@@ -98,18 +83,17 @@ class GatherCropStates:
|
|||||||
blocks.MATURE_CARROT_ID: items.CARROT_ID,
|
blocks.MATURE_CARROT_ID: items.CARROT_ID,
|
||||||
blocks.MATURE_BEETROOT_ID: items.BEETROOT_SEEDS_ID,
|
blocks.MATURE_BEETROOT_ID: items.BEETROOT_SEEDS_ID,
|
||||||
}
|
}
|
||||||
|
self.target_seed = crop_seeds[self.type_id]
|
||||||
|
|
||||||
if self.g.game.select_item([crop_seeds[self.type_id]]):
|
if self.g.game.select_item([self.target_seed]):
|
||||||
self.state = self.wait_select
|
self.state = self.wait_select
|
||||||
self.wait_time = 0.5
|
|
||||||
else:
|
else:
|
||||||
print('Aborting planting, no crop')
|
print('Havent picked up seed yet')
|
||||||
self.state = self.cleanup
|
return
|
||||||
|
|
||||||
def wait_select(self):
|
def wait_select(self):
|
||||||
# wait a bit to select
|
if self.target_seed != self.g.holding:
|
||||||
if self.wait_time > 0:
|
return
|
||||||
self.wait_time -= utils.TICK
|
|
||||||
else:
|
else:
|
||||||
self.state = self.place_crop
|
self.state = self.place_crop
|
||||||
|
|
||||||
@@ -118,12 +102,11 @@ class GatherCropStates:
|
|||||||
self.g.game.place_block(p, BlockFace.TOP)
|
self.g.game.place_block(p, BlockFace.TOP)
|
||||||
print('Placed crop')
|
print('Placed crop')
|
||||||
self.state = self.wait_place
|
self.state = self.wait_place
|
||||||
self.wait_time = 0.5
|
|
||||||
|
|
||||||
def wait_place(self):
|
def wait_place(self):
|
||||||
# wait a bit for chunk data to update
|
w = self.g.world
|
||||||
if self.wait_time > 0:
|
if w.block_at(*self.crop) == blocks.AIR:
|
||||||
self.wait_time -= utils.TICK
|
return
|
||||||
else:
|
else:
|
||||||
self.state = self.cleanup
|
self.state = self.cleanup
|
||||||
|
|
||||||
@@ -141,8 +124,8 @@ class GatherCropStates:
|
|||||||
|
|
||||||
self.crop = None
|
self.crop = None
|
||||||
self.type_id = None
|
self.type_id = None
|
||||||
|
self.target_seed = None
|
||||||
self.bad_crops = []
|
self.bad_crops = []
|
||||||
self.wait_time = 0
|
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
self.state()
|
self.state()
|
||||||
|
@@ -3,7 +3,7 @@ import time
|
|||||||
import importlib
|
import importlib
|
||||||
import random
|
import random
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from math import hypot, floor
|
from math import floor
|
||||||
|
|
||||||
from minecraft.networking.types import BlockFace
|
from minecraft.networking.types import BlockFace
|
||||||
|
|
||||||
@@ -81,16 +81,15 @@ class GatherSandStates:
|
|||||||
p = utils.pint(self.g.pos)
|
p = utils.pint(self.g.pos)
|
||||||
c = self.g.chunks
|
c = self.g.chunks
|
||||||
|
|
||||||
tmp = c.get_block_at(*self.sand)
|
navpath = w.path_to_place_faked(p, self.sand)
|
||||||
c.set_block_at(*self.sand, blocks.AIR)
|
print('navpath:', navpath)
|
||||||
navpath = w.path_to_place(p, self.sand)
|
|
||||||
c.set_block_at(*self.sand, tmp)
|
|
||||||
|
|
||||||
if navpath:
|
if navpath:
|
||||||
self.g.path = navpath[:-1]
|
self.g.path = navpath[:-1]
|
||||||
self.state = self.going_to_sand
|
self.state = self.going_to_sand
|
||||||
else:
|
else:
|
||||||
print('Cant get to that sand')
|
print('Cant get to that sand')
|
||||||
|
time.sleep(0.1)
|
||||||
self.bad_sand.append(self.sand)
|
self.bad_sand.append(self.sand)
|
||||||
self.state = self.find_new_sand
|
self.state = self.find_new_sand
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@ import time
|
|||||||
import importlib
|
import importlib
|
||||||
import random
|
import random
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from math import hypot, floor
|
from math import floor
|
||||||
|
|
||||||
from minecraft.networking.types import BlockFace
|
from minecraft.networking.types import BlockFace
|
||||||
|
|
||||||
@@ -54,15 +54,8 @@ class GatherWartStates:
|
|||||||
self.state = self.going_to_wart
|
self.state = self.going_to_wart
|
||||||
else:
|
else:
|
||||||
print('Cant get to it, blacklisting')
|
print('Cant get to it, blacklisting')
|
||||||
|
time.sleep(0.1)
|
||||||
self.bad_warts.append(wart)
|
self.bad_warts.append(wart)
|
||||||
self.wait_time = 0.5
|
|
||||||
self.state = self.wait_to_restart
|
|
||||||
|
|
||||||
def wait_to_restart(self):
|
|
||||||
# prevent timeouts
|
|
||||||
if self.wait_time > 0:
|
|
||||||
self.wait_time -= utils.TICK
|
|
||||||
else:
|
|
||||||
self.state = self.find_new_wart
|
self.state = self.find_new_wart
|
||||||
|
|
||||||
def going_to_wart(self):
|
def going_to_wart(self):
|
||||||
|
@@ -3,7 +3,7 @@ import time
|
|||||||
import importlib
|
import importlib
|
||||||
import random
|
import random
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from math import hypot, floor
|
from math import floor
|
||||||
|
|
||||||
from minecraft.networking.types import BlockFace
|
from minecraft.networking.types import BlockFace
|
||||||
|
|
||||||
@@ -80,6 +80,7 @@ class GatherWoodStates:
|
|||||||
self.state = self.going_to_tree
|
self.state = self.going_to_tree
|
||||||
else:
|
else:
|
||||||
self.openings.pop(0)
|
self.openings.pop(0)
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
def going_to_tree(self):
|
def going_to_tree(self):
|
||||||
if utils.pint(self.g.pos) == self.openings[0]:
|
if utils.pint(self.g.pos) == self.openings[0]:
|
||||||
@@ -126,6 +127,7 @@ class GatherWoodStates:
|
|||||||
else:
|
else:
|
||||||
self.openings.pop(0)
|
self.openings.pop(0)
|
||||||
self.state = self.choose_opening
|
self.state = self.choose_opening
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
def going_to_trunk_base(self):
|
def going_to_trunk_base(self):
|
||||||
if utils.pint(self.g.pos) == self.tree:
|
if utils.pint(self.g.pos) == self.tree:
|
||||||
|
@@ -3,7 +3,7 @@ import time
|
|||||||
import importlib
|
import importlib
|
||||||
import random
|
import random
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from math import hypot, floor
|
from math import floor
|
||||||
|
|
||||||
from minecraft.networking.types import BlockFace
|
from minecraft.networking.types import BlockFace
|
||||||
|
|
||||||
@@ -61,6 +61,7 @@ class GrabSandStates:
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
print('Cant get to sand', self.sand)
|
print('Cant get to sand', self.sand)
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
print('Cant get to any more sand, aborting')
|
print('Cant get to any more sand, aborting')
|
||||||
self.state = self.cleanup
|
self.state = self.cleanup
|
||||||
|
@@ -3,7 +3,7 @@ import time
|
|||||||
import importlib
|
import importlib
|
||||||
import random
|
import random
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from math import hypot, floor
|
from math import floor
|
||||||
|
|
||||||
from minecraft.networking.types import BlockFace
|
from minecraft.networking.types import BlockFace
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@ import time
|
|||||||
import importlib
|
import importlib
|
||||||
import random
|
import random
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from math import hypot, floor
|
from math import floor
|
||||||
|
|
||||||
from minecraft.networking.types import BlockFace
|
from minecraft.networking.types import BlockFace
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ class GrabSuppliesStates:
|
|||||||
w = self.g.world
|
w = self.g.world
|
||||||
p = utils.pint(self.g.pos)
|
p = utils.pint(self.g.pos)
|
||||||
|
|
||||||
self.barrels = w.find_blocks_indexed(p, blocks.BARREL_IDS)
|
self.barrels = w.find_blocks_indexed(p, blocks.BARREL_IDS, 80)
|
||||||
print('Found:', self.barrels)
|
print('Found:', self.barrels)
|
||||||
self.state = self.choose_barrel
|
self.state = self.choose_barrel
|
||||||
|
|
||||||
@@ -73,6 +73,7 @@ class GrabSuppliesStates:
|
|||||||
if barrel in self.bad_barrels:
|
if barrel in self.bad_barrels:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
print('Chose:', barrel)
|
||||||
self.barrel = barrel
|
self.barrel = barrel
|
||||||
self.state = self.path_to_barrel
|
self.state = self.path_to_barrel
|
||||||
return
|
return
|
||||||
@@ -86,27 +87,25 @@ class GrabSuppliesStates:
|
|||||||
p = utils.pint(self.g.pos)
|
p = utils.pint(self.g.pos)
|
||||||
c = self.g.chunks
|
c = self.g.chunks
|
||||||
|
|
||||||
barrel = self.barrel
|
navpath = w.path_to_place_faked(p, self.barrel)
|
||||||
|
|
||||||
tmp = c.get_block_at(*barrel)
|
|
||||||
c.set_block_at(*barrel, blocks.AIR)
|
|
||||||
navpath = w.path_to_place(p, barrel)
|
|
||||||
c.set_block_at(*barrel, tmp)
|
|
||||||
|
|
||||||
print('navpath:', navpath)
|
print('navpath:', navpath)
|
||||||
|
|
||||||
if navpath:
|
if navpath:
|
||||||
self.g.path = navpath[:-1]
|
self.g.path = navpath[:-1]
|
||||||
self.opening = self.g.path[-1]
|
self.opening = self.g.path[-1]
|
||||||
self.checked_barrels.append(barrel)
|
self.checked_barrels.append(self.barrel)
|
||||||
self.area = barrel
|
self.area = self.barrel
|
||||||
self.state = self.going_to_barrel
|
self.state = self.going_to_barrel
|
||||||
self.checked_supplies = []
|
self.checked_supplies = []
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
print('No path, blacklisting barrel')
|
print('No path, blacklisting barrel')
|
||||||
self.bad_barrels.append(barrel)
|
time.sleep(0.1)
|
||||||
self.state = self.choose_barrel
|
self.bad_barrels.append(self.barrel)
|
||||||
|
if len(self.bad_barrels) > 3:
|
||||||
|
self.state = self.cleanup
|
||||||
|
else:
|
||||||
|
self.state = self.choose_barrel
|
||||||
|
|
||||||
def going_to_barrel(self):
|
def going_to_barrel(self):
|
||||||
if utils.pint(self.g.pos) == self.opening:
|
if utils.pint(self.g.pos) == self.opening:
|
||||||
|
@@ -3,7 +3,7 @@ import time
|
|||||||
import importlib
|
import importlib
|
||||||
import random
|
import random
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from math import hypot, floor
|
from math import floor
|
||||||
|
|
||||||
from minecraft.networking.types import BlockFace
|
from minecraft.networking.types import BlockFace
|
||||||
|
|
||||||
|
@@ -3,7 +3,7 @@ import time
|
|||||||
import importlib
|
import importlib
|
||||||
import random
|
import random
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from math import hypot, floor
|
from math import floor
|
||||||
|
|
||||||
from minecraft.networking.types import BlockFace
|
from minecraft.networking.types import BlockFace
|
||||||
|
|
||||||
@@ -31,8 +31,29 @@ class SellToVillagerStates:
|
|||||||
|
|
||||||
for v in w.find_villagers(p, 100):
|
for v in w.find_villagers(p, 100):
|
||||||
print('Found villager:', v)
|
print('Found villager:', v)
|
||||||
if v not in self.bad_villagers and v not in self.spent_villagers:
|
|
||||||
break
|
if v in self.bad_villagers:
|
||||||
|
print('In bad villager list')
|
||||||
|
continue
|
||||||
|
|
||||||
|
if v in self.spent_villagers:
|
||||||
|
print('In spent villager list')
|
||||||
|
continue
|
||||||
|
|
||||||
|
if 'profession' not in v:
|
||||||
|
print('Villager has unknown profession')
|
||||||
|
continue
|
||||||
|
|
||||||
|
if v.profession not in mobs.TRADES:
|
||||||
|
print('Villager doesnt sell stuff we collect')
|
||||||
|
continue
|
||||||
|
|
||||||
|
trades = mobs.TRADES[v.profession]
|
||||||
|
if not self.g.game.count_items(trades):
|
||||||
|
print('We dont have anything to sell him')
|
||||||
|
continue
|
||||||
|
|
||||||
|
break
|
||||||
else: # for
|
else: # for
|
||||||
print('No good villagers left, aborting.')
|
print('No good villagers left, aborting.')
|
||||||
self.spent_villagers = []
|
self.spent_villagers = []
|
||||||
@@ -59,7 +80,7 @@ class SellToVillagerStates:
|
|||||||
if self.villager not in self.good_villagers:
|
if self.villager not in self.good_villagers:
|
||||||
self.bad_villagers.append(self.villager)
|
self.bad_villagers.append(self.villager)
|
||||||
print('Added to bad villager list')
|
print('Added to bad villager list')
|
||||||
self.state = self.cleanup
|
self.state = self.find_villager
|
||||||
return
|
return
|
||||||
|
|
||||||
navpath = w.path_to_place(p, self.openings[0])
|
navpath = w.path_to_place(p, self.openings[0])
|
||||||
@@ -67,8 +88,10 @@ class SellToVillagerStates:
|
|||||||
if navpath:
|
if navpath:
|
||||||
self.g.path = navpath
|
self.g.path = navpath
|
||||||
self.state = self.going_to_villager
|
self.state = self.going_to_villager
|
||||||
|
self.g.look_at = None
|
||||||
else:
|
else:
|
||||||
self.openings.pop(0)
|
self.openings.pop(0)
|
||||||
|
time.sleep(0.1)
|
||||||
|
|
||||||
def going_to_villager(self):
|
def going_to_villager(self):
|
||||||
if utils.pint(self.g.pos) == self.openings[0]:
|
if utils.pint(self.g.pos) == self.openings[0]:
|
||||||
@@ -143,8 +166,7 @@ class SellToVillagerStates:
|
|||||||
print('Villager has been spent, aborting')
|
print('Villager has been spent, aborting')
|
||||||
self.g.game.close_window()
|
self.g.game.close_window()
|
||||||
self.spent_villagers.append(self.villager)
|
self.spent_villagers.append(self.villager)
|
||||||
self.state = self.wait
|
self.state = self.find_villager
|
||||||
self.wait_time = 10
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def click_trade(self):
|
def click_trade(self):
|
||||||
|
@@ -3,7 +3,7 @@ import time
|
|||||||
import importlib
|
import importlib
|
||||||
import random
|
import random
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from math import hypot, floor
|
from math import floor
|
||||||
|
|
||||||
from minecraft.networking.types import BlockFace
|
from minecraft.networking.types import BlockFace
|
||||||
|
|
||||||
@@ -42,8 +42,13 @@ class SleepWithBedStates:
|
|||||||
|
|
||||||
self.beds = []
|
self.beds = []
|
||||||
for bed in result:
|
for bed in result:
|
||||||
if bed not in self.bad_beds:
|
if bed in self.bad_beds:
|
||||||
self.beds.append(bed)
|
continue
|
||||||
|
|
||||||
|
if w.check_bed_occupied(bed):
|
||||||
|
continue
|
||||||
|
|
||||||
|
self.beds.append(bed)
|
||||||
|
|
||||||
print('Found:', self.beds)
|
print('Found:', self.beds)
|
||||||
self.state = self.choose_bed
|
self.state = self.choose_bed
|
||||||
@@ -62,11 +67,7 @@ class SleepWithBedStates:
|
|||||||
bed = self.beds[0]
|
bed = self.beds[0]
|
||||||
print('Chose:', bed)
|
print('Chose:', bed)
|
||||||
|
|
||||||
tmp = c.get_block_at(*bed)
|
navpath = w.path_to_place_faked(p, bed)
|
||||||
c.set_block_at(*bed, blocks.AIR)
|
|
||||||
navpath = w.path_to_place(p, bed)
|
|
||||||
c.set_block_at(*bed, tmp)
|
|
||||||
|
|
||||||
print('navpath:', navpath)
|
print('navpath:', navpath)
|
||||||
|
|
||||||
if navpath:
|
if navpath:
|
||||||
@@ -80,10 +81,12 @@ class SleepWithBedStates:
|
|||||||
self.beds.pop(0)
|
self.beds.pop(0)
|
||||||
self.bad_beds.append(bed)
|
self.bad_beds.append(bed)
|
||||||
print('Cant get to bed, blacklisting')
|
print('Cant get to bed, blacklisting')
|
||||||
|
time.sleep(0.1)
|
||||||
self.state = self.select_bed
|
self.state = self.select_bed
|
||||||
|
|
||||||
def going_to_bed(self):
|
def going_to_bed(self):
|
||||||
if utils.pint(self.g.pos) == self.opening:
|
if utils.pint(self.g.pos) == self.opening:
|
||||||
|
print('At existing bed')
|
||||||
self.my_bed = False
|
self.my_bed = False
|
||||||
self.g.look_at = utils.padd(self.area, path.BLOCK_BELOW)
|
self.g.look_at = utils.padd(self.area, path.BLOCK_BELOW)
|
||||||
self.state = self.use_bed
|
self.state = self.use_bed
|
||||||
@@ -128,35 +131,57 @@ class SleepWithBedStates:
|
|||||||
|
|
||||||
def going_to_area(self):
|
def going_to_area(self):
|
||||||
if utils.pint(self.g.pos) == self.opening:
|
if utils.pint(self.g.pos) == self.opening:
|
||||||
|
print('At bed area')
|
||||||
self.g.look_at = utils.padd(self.area, path.BLOCK_BELOW)
|
self.g.look_at = utils.padd(self.area, path.BLOCK_BELOW)
|
||||||
self.state = self.place_bed
|
self.state = self.place_bed
|
||||||
|
|
||||||
def place_bed(self):
|
def place_bed(self):
|
||||||
|
print('Placing bed')
|
||||||
self.g.game.place_block(self.area, BlockFace.TOP)
|
self.g.game.place_block(self.area, BlockFace.TOP)
|
||||||
self.my_bed = True
|
self.my_bed = True
|
||||||
self.state = self.use_bed
|
self.wait_time = 0.5
|
||||||
|
self.state = self.wait_use
|
||||||
|
|
||||||
|
def wait_use(self):
|
||||||
|
# wait to use the bed
|
||||||
|
if self.wait_time > 0:
|
||||||
|
self.wait_time -= utils.TICK
|
||||||
|
else:
|
||||||
|
self.state = self.use_bed
|
||||||
|
|
||||||
def use_bed(self):
|
def use_bed(self):
|
||||||
if self.g.time > 12550:
|
w = self.g.world
|
||||||
print('Sleeping')
|
|
||||||
self.g.game.place_block(self.area, BlockFace.TOP)
|
if self.g.time < 12550:
|
||||||
if not self.silent:
|
return
|
||||||
self.g.chat.send('zzz')
|
|
||||||
self.state = self.sleep_bed
|
if w.check_bed_occupied(self.area):
|
||||||
|
print('Bed occupied, aborting.')
|
||||||
|
self.state = self.cleanup
|
||||||
|
return
|
||||||
|
|
||||||
|
print('Using bed')
|
||||||
|
self.g.game.place_block(self.area, BlockFace.TOP)
|
||||||
|
if not self.silent:
|
||||||
|
self.g.chat.send('zzz')
|
||||||
|
self.state = self.sleep_bed
|
||||||
|
|
||||||
def sleep_bed(self):
|
def sleep_bed(self):
|
||||||
w = self.g.world
|
w = self.g.world
|
||||||
p = utils.pint(self.g.pos)
|
p = utils.pint(self.g.pos)
|
||||||
|
threats = w.find_threats(p, 10)
|
||||||
|
|
||||||
threats = w.find_threats(p, 30)
|
|
||||||
if threats:
|
if threats:
|
||||||
print('Waking up due to threats:')
|
print('Waking up due to threats:')
|
||||||
print(threats)
|
print(threats)
|
||||||
self.g.game.leave_bed()
|
self.g.game.leave_bed()
|
||||||
self.state = self.break_bed
|
self.state = self.cleanup
|
||||||
elif self.g.time < 100:
|
elif self.g.time < 100:
|
||||||
print('Woke up time')
|
print('Woke up time')
|
||||||
self.state = self.break_bed
|
self.state = self.break_bed
|
||||||
|
elif self.g.correction_count:
|
||||||
|
print('Woke up by movement')
|
||||||
|
self.state = self.break_bed
|
||||||
|
|
||||||
def break_bed(self):
|
def break_bed(self):
|
||||||
if self.my_bed:
|
if self.my_bed:
|
||||||
@@ -165,7 +190,6 @@ class SleepWithBedStates:
|
|||||||
else:
|
else:
|
||||||
self.state = self.cleanup
|
self.state = self.cleanup
|
||||||
|
|
||||||
|
|
||||||
def collect_bed(self):
|
def collect_bed(self):
|
||||||
if not self.g.breaking:
|
if not self.g.breaking:
|
||||||
self.g.path = [utils.padd(self.area, utils.spiral(n)) for n in range(9)]
|
self.g.path = [utils.padd(self.area, utils.spiral(n)) for n in range(9)]
|
||||||
|
@@ -20,6 +20,7 @@ def get_packets(old_get_packets):
|
|||||||
mc_packets.add(packets.EntityTeleport)
|
mc_packets.add(packets.EntityTeleport)
|
||||||
mc_packets.add(packets.TradeListPacket)
|
mc_packets.add(packets.TradeListPacket)
|
||||||
mc_packets.add(packets.DisconnectPacket)
|
mc_packets.add(packets.DisconnectPacket)
|
||||||
|
mc_packets.add(packets.UnloadChunkPacket)
|
||||||
|
|
||||||
|
|
||||||
return mc_packets
|
return mc_packets
|
||||||
|
@@ -1,7 +1,6 @@
|
|||||||
import importlib
|
import importlib
|
||||||
import functools
|
import functools
|
||||||
import time
|
import time
|
||||||
from math import hypot, sqrt
|
|
||||||
|
|
||||||
from astar import AStar
|
from astar import AStar
|
||||||
|
|
||||||
@@ -306,7 +305,7 @@ class Pathfinder(AStar):
|
|||||||
def distance_between(self, n1, n2):
|
def distance_between(self, n1, n2):
|
||||||
(x1, y1, z1) = n1
|
(x1, y1, z1) = n1
|
||||||
(x2, y2, z2) = n2
|
(x2, y2, z2) = n2
|
||||||
return hypot(x2-x1, y2-y1, z2-z1)
|
return utils.hypot(x2-x1, y2-y1, z2-z1)
|
||||||
|
|
||||||
def heuristic_cost_estimate(self, n1, n2):
|
def heuristic_cost_estimate(self, n1, n2):
|
||||||
(x1, y1, z1) = n1
|
(x1, y1, z1) = n1
|
||||||
|
@@ -7,6 +7,7 @@ from minecraft.networking.packets import clientbound, serverbound
|
|||||||
from mosfet.protocol import packets
|
from mosfet.protocol import packets
|
||||||
|
|
||||||
from mosfet import utils
|
from mosfet import utils
|
||||||
|
from mosfet.info import blocks
|
||||||
|
|
||||||
class DataManager:
|
class DataManager:
|
||||||
def __init__(self, directory):
|
def __init__(self, directory):
|
||||||
@@ -42,7 +43,7 @@ class ChunksManager:
|
|||||||
def __init__(self, data_manager):
|
def __init__(self, data_manager):
|
||||||
self.data = data_manager
|
self.data = data_manager
|
||||||
self.chunks = {}
|
self.chunks = {}
|
||||||
self.biomes = {}
|
#self.biomes = {}
|
||||||
self.index = {}
|
self.index = {}
|
||||||
self.loading = False
|
self.loading = False
|
||||||
|
|
||||||
@@ -68,13 +69,12 @@ class ChunksManager:
|
|||||||
|
|
||||||
for item_id, locations in chunk.sub_index.items():
|
for item_id, locations in chunk.sub_index.items():
|
||||||
if item_id not in self.index:
|
if item_id not in self.index:
|
||||||
self.index[item_id] = []
|
self.index[item_id] = set()
|
||||||
|
|
||||||
for l in locations:
|
for l in locations:
|
||||||
coords = (dx + l%16, dy + l//256, dz + l%256//16)
|
coords = (dx + l%16, dy + l//256, dz + l%256//16)
|
||||||
self.index[item_id].append(coords)
|
self.index[item_id].add(coords)
|
||||||
|
|
||||||
self.biomes[(chunk_packet.x, None, chunk_packet.z)] = chunk_packet.biomes # FIXME
|
#self.biomes[(chunk_packet.x, None, chunk_packet.z)] = chunk_packet.biomes # FIXME
|
||||||
if self.loading:
|
if self.loading:
|
||||||
print('.', end='', flush=True)
|
print('.', end='', flush=True)
|
||||||
|
|
||||||
@@ -116,28 +116,26 @@ class ChunksManager:
|
|||||||
if not c: return None
|
if not c: return None
|
||||||
c.set_block_at(x%16, y%16, z%16, block)
|
c.set_block_at(x%16, y%16, z%16, block)
|
||||||
|
|
||||||
def check_loaded(self, position, steps=1):
|
if block in blocks.INDEXED_IDS:
|
||||||
x, y, z = utils.pint(position)
|
if block not in self.index:
|
||||||
player_chunk = (x//16, 1, z//16)
|
self.index[block] = set()
|
||||||
for i in range(steps): # TODO: base off render_distance?
|
self.index[block].add((x, y, z))
|
||||||
offset = utils.spiral(i)
|
|
||||||
check = utils.padd(player_chunk, offset)
|
|
||||||
|
|
||||||
if check not in self.chunks:
|
def check_loaded(self, chunk_distance):
|
||||||
return False
|
num = (chunk_distance * 2 + 1) ** 2
|
||||||
|
num_subchunks = num * 16
|
||||||
|
return len(self.chunks) >= num_subchunks
|
||||||
|
|
||||||
return True
|
def unload_chunk(self, x, z):
|
||||||
|
for y in range(16):
|
||||||
def unload_chunks(self, position):
|
try:
|
||||||
x, y, z = utils.pint(position)
|
del self.chunks[(x, y, z)]
|
||||||
player_chunk = (x//16, 0, z//16)
|
except KeyError:
|
||||||
loaded_chunks = list(self.chunks.keys())
|
pass
|
||||||
|
|
||||||
for chunk in loaded_chunks:
|
|
||||||
check = (chunk[0], 0, chunk[2])
|
|
||||||
if utils.phyp_king(player_chunk, check) > 20:
|
|
||||||
del self.chunks[chunk]
|
|
||||||
|
|
||||||
|
def unload_all_chunks(self):
|
||||||
|
self.chunks = {}
|
||||||
|
self.index = {}
|
||||||
|
|
||||||
class ChunkNotLoadedException(Exception):
|
class ChunkNotLoadedException(Exception):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@@ -155,24 +153,25 @@ class ChatManager:
|
|||||||
def translate_chat(self, data):
|
def translate_chat(self, data):
|
||||||
if isinstance(data, str):
|
if isinstance(data, str):
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
result = data.get('text', '')
|
||||||
|
result += data.get('translate', '')
|
||||||
|
|
||||||
|
if 'with' in data:
|
||||||
|
result += ' ' + ' '.join([self.translate_chat(x) for x in data['with']])
|
||||||
elif 'extra' in data:
|
elif 'extra' in data:
|
||||||
return ''.join([self.translate_chat(x) for x in data['extra']])
|
result += ''.join([self.translate_chat(x) for x in data['extra']])
|
||||||
elif 'text' in data:
|
|
||||||
return data['text']
|
return result
|
||||||
elif 'with' in data:
|
|
||||||
if len(data['with']) >= 2:
|
|
||||||
return '<{}> {}'.format(*[self.translate_chat(x) for x in data['with']])
|
|
||||||
else:
|
|
||||||
return self.translate_chat(data['with'][0])
|
|
||||||
elif 'translate' in data:
|
|
||||||
return data['translate']
|
|
||||||
else:
|
|
||||||
print(data)
|
|
||||||
return '?'
|
|
||||||
|
|
||||||
def print_chat(self, chat_packet):
|
def print_chat(self, chat_packet):
|
||||||
|
#print(chat_packet)
|
||||||
|
#print(chat_packet.json_data)
|
||||||
|
#import json
|
||||||
|
#print(json.dumps(json.loads(chat_packet.json_data), indent=4))
|
||||||
try:
|
try:
|
||||||
source = chat_packet.field_string('position')
|
source = chat_packet.field_string('position')
|
||||||
|
sender = chat_packet.sender
|
||||||
text = self.translate_chat(json.loads(chat_packet.json_data))
|
text = self.translate_chat(json.loads(chat_packet.json_data))
|
||||||
print('[%s] %s'%(source, text))
|
print('[%s] %s'%(source, text))
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
@@ -180,7 +179,7 @@ class ChatManager:
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self.handler:
|
if self.handler:
|
||||||
self.handler((source, text))
|
self.handler((source, sender, text))
|
||||||
|
|
||||||
def set_handler(self, func):
|
def set_handler(self, func):
|
||||||
self.handler = func
|
self.handler = func
|
||||||
|
@@ -31,10 +31,10 @@ class ChunkDataPacket(Packet):
|
|||||||
self.biomes.append(VarInt.read(file_object))
|
self.biomes.append(VarInt.read(file_object))
|
||||||
size = VarInt.read(file_object)
|
size = VarInt.read(file_object)
|
||||||
self.data = file_object.read(size)
|
self.data = file_object.read(size)
|
||||||
size_entities = VarInt.read(file_object)
|
#size_entities = VarInt.read(file_object)
|
||||||
self.entities = []
|
#self.entities = []
|
||||||
for i in range(size_entities):
|
#for i in range(size_entities):
|
||||||
self.entities.append(Nbt.read(file_object))
|
# self.entities.append(Nbt.read(file_object))
|
||||||
|
|
||||||
self.decode_chunk_data()
|
self.decode_chunk_data()
|
||||||
|
|
||||||
@@ -49,9 +49,9 @@ class ChunkDataPacket(Packet):
|
|||||||
Integer.send(self.biomes[i], packet_buffer)
|
Integer.send(self.biomes[i], packet_buffer)
|
||||||
VarInt.send(len(self.data), packet_buffer)
|
VarInt.send(len(self.data), packet_buffer)
|
||||||
packet_buffer.send(self.data)
|
packet_buffer.send(self.data)
|
||||||
VarInt.send(len(self.entities), packet_buffer)
|
#VarInt.send(len(self.entities), packet_buffer)
|
||||||
for e in self.entities:
|
#for e in self.entities:
|
||||||
Nbt.send(e, packet_buffer)
|
# Nbt.send(e, packet_buffer)
|
||||||
|
|
||||||
def decode_chunk_data(self):
|
def decode_chunk_data(self):
|
||||||
packet_data = PacketBuffer()
|
packet_data = PacketBuffer()
|
||||||
@@ -64,9 +64,9 @@ class ChunkDataPacket(Packet):
|
|||||||
if self.bit_mask_y & (1 << i):
|
if self.bit_mask_y & (1 << i):
|
||||||
self.chunks[i].read(packet_data)
|
self.chunks[i].read(packet_data)
|
||||||
|
|
||||||
for e in self.entities:
|
#for e in self.entities:
|
||||||
y = e['y']
|
# y = e['y']
|
||||||
self.chunks[floor(y/16)].entities.append(e)
|
# self.chunks[floor(y/16)].entities.append(e)
|
||||||
|
|
||||||
class Chunk:
|
class Chunk:
|
||||||
position = multi_attribute_alias(Vector, 'x', 'y', 'z')
|
position = multi_attribute_alias(Vector, 'x', 'y', 'z')
|
||||||
@@ -304,7 +304,7 @@ class EntityMetadataPacket(Packet):
|
|||||||
self.metadata = []
|
self.metadata = []
|
||||||
for _ in range(99):
|
for _ in range(99):
|
||||||
entry = Entry.read(file_object, self.context)
|
entry = Entry.read(file_object, self.context)
|
||||||
if not entry: break
|
if not entry: break # hit an unimplemented type, stops parsing
|
||||||
self.metadata.append(entry)
|
self.metadata.append(entry)
|
||||||
|
|
||||||
|
|
||||||
@@ -458,3 +458,15 @@ class DisconnectPacket(Packet):
|
|||||||
definition = [
|
definition = [
|
||||||
{'reason': String},
|
{'reason': String},
|
||||||
]
|
]
|
||||||
|
|
||||||
|
class UnloadChunkPacket(Packet):
|
||||||
|
# Tells the client to unload a chunk column
|
||||||
|
# https://wiki.vg/Protocol#Unload_Chunk
|
||||||
|
|
||||||
|
id = 0x1C
|
||||||
|
packet_name = 'unload chunk'
|
||||||
|
|
||||||
|
definition = [
|
||||||
|
{'chunk_x': Integer},
|
||||||
|
{'chunk_z': Integer},
|
||||||
|
]
|
||||||
|
@@ -141,7 +141,7 @@ class Slot(Type):
|
|||||||
|
|
||||||
|
|
||||||
class Entry(Type):
|
class Entry(Type):
|
||||||
types = {
|
simple_types = {
|
||||||
0: Byte,
|
0: Byte,
|
||||||
1: VarInt,
|
1: VarInt,
|
||||||
2: Float,
|
2: Float,
|
||||||
@@ -169,12 +169,19 @@ class Entry(Type):
|
|||||||
index = UnsignedByte.read(file_object)
|
index = UnsignedByte.read(file_object)
|
||||||
if index == 0xff: return None
|
if index == 0xff: return None
|
||||||
type = VarInt.read(file_object)
|
type = VarInt.read(file_object)
|
||||||
try:
|
|
||||||
value = Entry.types[type].read(file_object)
|
if type == 10: # optional position
|
||||||
except TypeError:
|
present = Boolean.read(file_object)
|
||||||
value = Entry.types[type].read_with_context(file_object, context)
|
value = Position.read_with_context(file_object, context) if present else None
|
||||||
except KeyError:
|
elif type == 16: # villager data
|
||||||
return None
|
value = (VarInt.read(file_object), VarInt.read(file_object), VarInt.read(file_object))
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
value = Entry.simple_types[type].read(file_object)
|
||||||
|
except TypeError:
|
||||||
|
value = Entry.simple_types[type].read_with_context(file_object, context)
|
||||||
|
except KeyError:
|
||||||
|
return None # unimplemented data type, stops parsing entries
|
||||||
return Entry(index, type, value)
|
return Entry(index, type, value)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -1,12 +1,16 @@
|
|||||||
import importlib
|
import importlib
|
||||||
import collections
|
import collections
|
||||||
from math import floor, ceil, sqrt, hypot
|
from math import floor, ceil, sqrt
|
||||||
|
|
||||||
from mosfet.info import blocks
|
from mosfet.info import blocks
|
||||||
from mosfet.info import mcdata
|
from mosfet.info import mcdata
|
||||||
|
|
||||||
TICK = 0.05
|
TICK = 0.05
|
||||||
|
|
||||||
|
def hypot(*coordinates):
|
||||||
|
# python's 3D hypot is too new, so we'll use our own
|
||||||
|
return sqrt(sum(x**2 for x in coordinates))
|
||||||
|
|
||||||
def padd(p1, p2):
|
def padd(p1, p2):
|
||||||
return (p1[0] + p2[0], p1[1] + p2[1], p1[2] + p2[2])
|
return (p1[0] + p2[0], p1[1] + p2[1], p1[2] + p2[2])
|
||||||
|
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import math
|
import math
|
||||||
|
from mosfet import utils
|
||||||
|
|
||||||
class Vector3D:
|
class Vector3D:
|
||||||
def __init__(self, vector):
|
def __init__(self, vector):
|
||||||
@@ -17,7 +18,7 @@ class Vector3D:
|
|||||||
return self.tuple()[key]
|
return self.tuple()[key]
|
||||||
|
|
||||||
def length(self):
|
def length(self):
|
||||||
return math.hypot(self.x, self.y, self.z)
|
return utils.hypot(self.x, self.y, self.z)
|
||||||
|
|
||||||
def normalized(self):
|
def normalized(self):
|
||||||
x = self.x / self.length()
|
x = self.x / self.length()
|
||||||
|
@@ -2,7 +2,6 @@ import collections
|
|||||||
import re
|
import re
|
||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
from math import hypot
|
|
||||||
from itertools import count
|
from itertools import count
|
||||||
from copy import copy
|
from copy import copy
|
||||||
|
|
||||||
@@ -35,7 +34,7 @@ class World:
|
|||||||
continue
|
continue
|
||||||
if y_limit and abs(cur[1]) > y_limit:
|
if y_limit and abs(cur[1]) > y_limit:
|
||||||
continue
|
continue
|
||||||
if distance and hypot(*cur) > distance:
|
if distance and utils.hypot(*cur) > distance:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
check = utils.padd(center, cur)
|
check = utils.padd(center, cur)
|
||||||
@@ -76,7 +75,7 @@ class World:
|
|||||||
offset = utils.spiral(n)
|
offset = utils.spiral(n)
|
||||||
check = utils.padd(center, offset)
|
check = utils.padd(center, offset)
|
||||||
if self.block_at(*check) in block_ids:
|
if self.block_at(*check) in block_ids:
|
||||||
if hypot(*offset) < distance:
|
if utils.hypot(*offset) < distance:
|
||||||
result.append(check)
|
result.append(check)
|
||||||
if limit and len(result) == limit:
|
if limit and len(result) == limit:
|
||||||
return result
|
return result
|
||||||
@@ -141,6 +140,26 @@ class World:
|
|||||||
except path.AStarTimeout:
|
except path.AStarTimeout:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
def path_to_place_faked(self, start, place):
|
||||||
|
# same as above, but adds a fake block below and air before pathfinding
|
||||||
|
# so that the pathfinder can actually make it to the block
|
||||||
|
c = self.g.chunks
|
||||||
|
above = utils.padd(place, path.BLOCK_ABOVE)
|
||||||
|
below = utils.padd(place, path.BLOCK_BELOW)
|
||||||
|
|
||||||
|
tmp = c.get_block_at(*place)
|
||||||
|
tmp2 = c.get_block_at(*above)
|
||||||
|
tmp3 = c.get_block_at(*below)
|
||||||
|
c.set_block_at(*place, blocks.AIR)
|
||||||
|
c.set_block_at(*above, blocks.AIR)
|
||||||
|
c.set_block_at(*below, blocks.STONE)
|
||||||
|
navpath = self.path_to_place(start, place)
|
||||||
|
c.set_block_at(*place, tmp)
|
||||||
|
c.set_block_at(*above, tmp2)
|
||||||
|
c.set_block_at(*below, tmp3)
|
||||||
|
|
||||||
|
return navpath
|
||||||
|
|
||||||
def find_bed_areas(self, center, distance):
|
def find_bed_areas(self, center, distance):
|
||||||
bed_clearance = 9 # 5x5 area
|
bed_clearance = 9 # 5x5 area
|
||||||
clear_distance = 2
|
clear_distance = 2
|
||||||
@@ -259,6 +278,16 @@ class World:
|
|||||||
result.append(utils.padd(area, direction))
|
result.append(utils.padd(area, direction))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def check_bed_occupied(self, bed):
|
||||||
|
# returns true if the bed is occupied by a player
|
||||||
|
bid = self.g.chunks.get_block_at(*bed)
|
||||||
|
if blocks.PROPS[bid]['occupied'] == 'true':
|
||||||
|
print('Checking bed occupancy:', bed, '-> occupied')
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
print('Checking bed occupancy:', bed, '-> free')
|
||||||
|
return False
|
||||||
|
|
||||||
def find_cache_openings(self, area):
|
def find_cache_openings(self, area):
|
||||||
return self.find_bed_openings(area)
|
return self.find_bed_openings(area)
|
||||||
|
|
||||||
@@ -283,6 +312,7 @@ class World:
|
|||||||
if utils.phyp(center, pos) > distance:
|
if utils.phyp(center, pos) > distance:
|
||||||
continue
|
continue
|
||||||
result.append(mob)
|
result.append(mob)
|
||||||
|
result.sort(key=lambda mob: utils.phyp(center, (mob.x, mob.y, mob.z)))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def find_threats(self, center, distance):
|
def find_threats(self, center, distance):
|
||||||
@@ -295,6 +325,7 @@ class World:
|
|||||||
if not self.check_air_column(pos, distance):
|
if not self.check_air_column(pos, distance):
|
||||||
continue
|
continue
|
||||||
result.append(mob)
|
result.append(mob)
|
||||||
|
result.sort(key=lambda mob: utils.phyp(center, (mob.x, mob.y, mob.z)))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def find_villagers(self, center, distance):
|
def find_villagers(self, center, distance):
|
||||||
@@ -307,6 +338,7 @@ class World:
|
|||||||
if utils.phyp(center, pos) > distance:
|
if utils.phyp(center, pos) > distance:
|
||||||
continue
|
continue
|
||||||
result.append(mob)
|
result.append(mob)
|
||||||
|
result.sort(key=lambda mob: utils.phyp(center, (mob.x, mob.y, mob.z)))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
def find_villager_openings(self, villager):
|
def find_villager_openings(self, villager):
|
||||||
|
@@ -1,39 +1,45 @@
|
|||||||
appdirs==1.4.3
|
appdirs==1.4.4
|
||||||
astar==0.93
|
astar==0.93
|
||||||
CacheControl==0.12.6
|
CacheControl==0.12.6
|
||||||
certifi==2019.11.28
|
certifi==2020.12.5
|
||||||
cffi==1.14.5
|
cffi==1.14.5
|
||||||
chardet==3.0.4
|
chardet==4.0.0
|
||||||
click==7.1.2
|
click==7.1.2
|
||||||
colorama==0.4.3
|
colorama==0.4.4
|
||||||
contextlib2==0.6.0
|
contextlib2==0.6.0.post1
|
||||||
cryptography==3.4.7
|
cryptography==3.4.7
|
||||||
distlib==0.3.0
|
distlib==0.3.1
|
||||||
distro==1.4.0
|
distro==1.5.0
|
||||||
Flask==1.1.2
|
Flask==1.1.2
|
||||||
html5lib==1.0.1
|
Flask-Cors==3.0.10
|
||||||
idna==2.8
|
html5lib==1.1
|
||||||
|
idna==2.10
|
||||||
|
importlib-metadata==4.0.1
|
||||||
ipaddr==2.2.0
|
ipaddr==2.2.0
|
||||||
itsdangerous==1.1.0
|
itsdangerous==1.1.0
|
||||||
Jinja2==2.11.3
|
Jinja2==2.11.3
|
||||||
lockfile==0.12.2
|
lockfile==0.12.2
|
||||||
MarkupSafe==1.1.1
|
MarkupSafe==1.1.1
|
||||||
minecraft-data==2.82.2
|
minecraft-data==2.82.2
|
||||||
msgpack==0.6.2
|
msgpack==1.0.2
|
||||||
munch==2.5.0
|
munch==2.5.0
|
||||||
mutf8==1.0.3
|
mutf8==1.0.3
|
||||||
packaging==20.3
|
packaging==20.9
|
||||||
pep517==0.8.2
|
pep517==0.10.0
|
||||||
|
pkg-resources==0.0.0
|
||||||
progress==1.5
|
progress==1.5
|
||||||
pycparser==2.20
|
pycparser==2.20
|
||||||
git+https://github.com/ammaraskar/pyCraft.git@2813d02ae7fb8182c3e5227a73de2240b09878d9
|
git+https://github.com/ammaraskar/pyCraft.git@2813d02ae7fb8182c3e5227a73de2240b09878d9
|
||||||
PyNBT==3.1.0
|
PyNBT==3.1.0
|
||||||
pyparsing==2.4.6
|
pyparsing==2.4.7
|
||||||
pytoml==0.1.21
|
pytoml==0.1.21
|
||||||
requests==2.22.0
|
requests==2.25.1
|
||||||
retrying==1.3.3
|
retrying==1.3.3
|
||||||
six==1.14.0
|
six==1.15.0
|
||||||
urllib3==1.25.8
|
toml==0.10.2
|
||||||
watchdog==2.0.2
|
typing-extensions==3.7.4.3
|
||||||
|
urllib3==1.26.4
|
||||||
|
watchdog==2.0.3
|
||||||
webencodings==0.5.1
|
webencodings==0.5.1
|
||||||
Werkzeug==1.0.1
|
Werkzeug==1.0.1
|
||||||
|
zipp==3.4.1
|
||||||
|
@@ -11,7 +11,7 @@ fi
|
|||||||
if ! command -v virtualenv &> /dev/null
|
if ! command -v virtualenv &> /dev/null
|
||||||
then
|
then
|
||||||
echo "virtualenv could not be found, please install with:"
|
echo "virtualenv could not be found, please install with:"
|
||||||
echo "sudo apt install python3-virtualenv"
|
echo "sudo apt install virtualenv"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -49,7 +49,6 @@ fi
|
|||||||
if [ ! -d "minecraft_data" ]
|
if [ ! -d "minecraft_data" ]
|
||||||
then
|
then
|
||||||
echo "Grabbing minecraft data..."
|
echo "Grabbing minecraft data..."
|
||||||
sleep 2
|
|
||||||
|
|
||||||
VERSION="1.16.4"
|
VERSION="1.16.4"
|
||||||
|
|
||||||
@@ -59,12 +58,14 @@ then
|
|||||||
rm mcdata.zip
|
rm mcdata.zip
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# https://github.com/pypa/virtualenv/issues/1029
|
||||||
|
PS1=${PS1:-}
|
||||||
|
|
||||||
# create virtual environment
|
# create virtual environment
|
||||||
|
|
||||||
if [ ! -d "env" ]
|
if [ ! -d "env" ]
|
||||||
then
|
then
|
||||||
echo "Installing Python requirements..."
|
echo "Installing Python requirements..."
|
||||||
sleep 2
|
|
||||||
|
|
||||||
virtualenv -p python3 env
|
virtualenv -p python3 env
|
||||||
source env/bin/activate
|
source env/bin/activate
|
||||||
|
@@ -11,7 +11,7 @@ fi
|
|||||||
if ! command -v virtualenv &> /dev/null
|
if ! command -v virtualenv &> /dev/null
|
||||||
then
|
then
|
||||||
echo "virtualenv could not be found, please install with:"
|
echo "virtualenv could not be found, please install with:"
|
||||||
echo "sudo apt install python3-virtualenv"
|
echo "sudo apt install virtualenv"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@@ -54,7 +54,6 @@ fi
|
|||||||
# download minecraft data
|
# download minecraft data
|
||||||
|
|
||||||
echo "Grabbing minecraft data..."
|
echo "Grabbing minecraft data..."
|
||||||
sleep 2
|
|
||||||
|
|
||||||
VERSION="1.16.4"
|
VERSION="1.16.4"
|
||||||
|
|
||||||
@@ -72,10 +71,12 @@ git pull --rebase
|
|||||||
git stash pop || true
|
git stash pop || true
|
||||||
|
|
||||||
|
|
||||||
|
# https://github.com/pypa/virtualenv/issues/1029
|
||||||
|
PS1=${PS1:-}
|
||||||
|
|
||||||
# create virtual environment
|
# create virtual environment
|
||||||
|
|
||||||
echo "Installing Python requirements..."
|
echo "Installing Python requirements..."
|
||||||
sleep 2
|
|
||||||
|
|
||||||
rm -r env || true
|
rm -r env || true
|
||||||
rm -r __pycache__ || true
|
rm -r __pycache__ || true
|
||||||
|
20
web_interface/.gitignore
vendored
Normal file
20
web_interface/.gitignore
vendored
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
/.pnp
|
||||||
|
.pnp.js
|
||||||
|
|
||||||
|
# testing
|
||||||
|
/coverage
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
.env.local
|
||||||
|
.env.development.local
|
||||||
|
.env.test.local
|
||||||
|
.env.production.local
|
||||||
|
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
17
web_interface/build/asset-manifest.json
Normal file
17
web_interface/build/asset-manifest.json
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"files": {
|
||||||
|
"main.js": "/static/js/main.27336089.chunk.js",
|
||||||
|
"main.js.map": "/static/js/main.27336089.chunk.js.map",
|
||||||
|
"runtime-main.js": "/static/js/runtime-main.97b64705.js",
|
||||||
|
"runtime-main.js.map": "/static/js/runtime-main.97b64705.js.map",
|
||||||
|
"static/js/2.2b306052.chunk.js": "/static/js/2.2b306052.chunk.js",
|
||||||
|
"static/js/2.2b306052.chunk.js.map": "/static/js/2.2b306052.chunk.js.map",
|
||||||
|
"index.html": "/index.html",
|
||||||
|
"static/js/2.2b306052.chunk.js.LICENSE.txt": "/static/js/2.2b306052.chunk.js.LICENSE.txt"
|
||||||
|
},
|
||||||
|
"entrypoints": [
|
||||||
|
"static/js/runtime-main.97b64705.js",
|
||||||
|
"static/js/2.2b306052.chunk.js",
|
||||||
|
"static/js/main.27336089.chunk.js"
|
||||||
|
]
|
||||||
|
}
|
1
web_interface/build/index.html
Normal file
1
web_interface/build/index.html
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<!doctype html><html lang="en"><head><meta charset="utf-8"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#000000"/><meta name="description" content="Web site created using create-react-app"/><title>React App</title></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div><script>!function(e){function r(r){for(var n,f,i=r[0],l=r[1],a=r[2],p=0,s=[];p<i.length;p++)f=i[p],Object.prototype.hasOwnProperty.call(o,f)&&o[f]&&s.push(o[f][0]),o[f]=0;for(n in l)Object.prototype.hasOwnProperty.call(l,n)&&(e[n]=l[n]);for(c&&c(r);s.length;)s.shift()();return u.push.apply(u,a||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,i=1;i<t.length;i++){var l=t[i];0!==o[l]&&(n=!1)}n&&(u.splice(r--,1),e=f(f.s=t[0]))}return e}var n={},o={1:0},u=[];function f(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.m=e,f.c=n,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,r){if(1&r&&(e=f(e)),8&r)return e;if(4&r&&"object"==typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)f.d(t,n,function(r){return e[r]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var i=this.webpackJsonpweb_interface=this.webpackJsonpweb_interface||[],l=i.push.bind(i);i.push=r,i=i.slice();for(var a=0;a<i.length;a++)r(i[a]);var c=l;t()}([])</script><script src="/static/js/2.2b306052.chunk.js"></script><script src="/static/js/main.27336089.chunk.js"></script></body></html>
|
3
web_interface/build/static/js/2.2b306052.chunk.js
Normal file
3
web_interface/build/static/js/2.2b306052.chunk.js
Normal file
File diff suppressed because one or more lines are too long
@@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
object-assign
|
||||||
|
(c) Sindre Sorhus
|
||||||
|
@license MIT
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @license React v0.20.2
|
||||||
|
* scheduler.production.min.js
|
||||||
|
*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @license React v17.0.2
|
||||||
|
* react-dom.production.min.js
|
||||||
|
*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @license React v17.0.2
|
||||||
|
* react-jsx-runtime.production.min.js
|
||||||
|
*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/** @license React v17.0.2
|
||||||
|
* react.production.min.js
|
||||||
|
*
|
||||||
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
||||||
|
*
|
||||||
|
* This source code is licensed under the MIT license found in the
|
||||||
|
* LICENSE file in the root directory of this source tree.
|
||||||
|
*/
|
1
web_interface/build/static/js/2.2b306052.chunk.js.map
Normal file
1
web_interface/build/static/js/2.2b306052.chunk.js.map
Normal file
File diff suppressed because one or more lines are too long
2
web_interface/build/static/js/main.27336089.chunk.js
Normal file
2
web_interface/build/static/js/main.27336089.chunk.js
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
(this.webpackJsonpweb_interface=this.webpackJsonpweb_interface||[]).push([[0],{41:function(e,t,n){"use strict";n.r(t);var c=n(2),r=n.n(c),s=n(14),a=n.n(s),i=n(4),j=n.n(i),l=n(15),d=n(16),o=n(5),p=n.n(o),b=n(0);p.a.defaults.baseURL=Object({NODE_ENV:"production",PUBLIC_URL:"",WDS_SOCKET_HOST:void 0,WDS_SOCKET_PATH:void 0,WDS_SOCKET_PORT:void 0,FAST_REFRESH:!0}).REACT_APP_SERVER;var u=function(){var e=Object(c.useState)(!1),t=Object(d.a)(e,2),n=t[0],r=t[1];return Object(c.useEffect)((function(){var e=setInterval(function(){var e=Object(l.a)(j.a.mark((function e(){var t;return j.a.wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,p.a.get("/api/global");case 3:t=e.sent,r(t.data),e.next=10;break;case 7:e.prev=7,e.t0=e.catch(0),r(!1);case 10:case"end":return e.stop()}}),e,null,[[0,7]])})));return function(){return e.apply(this,arguments)}}(),500);return function(){return clearInterval(e)}}),[]),Object(b.jsx)("div",{className:"app",children:n&&Object(b.jsxs)(b.Fragment,{children:[Object(b.jsxs)("p",{children:["Name: ",n.name]}),Object(b.jsxs)("p",{children:["Pos: ",n.pos]}),Object(b.jsxs)("p",{children:["Yaw: ",n.yaw]}),Object(b.jsxs)("p",{children:["Pitch: ",n.pitch]}),Object(b.jsxs)("p",{children:["Dimention: ",n.dimension]}),Object(b.jsxs)("p",{children:["Players:",Object.values(n.players).map((function(e){return Object(b.jsx)("div",{children:n.player_names[e.player_uuid]})}))]}),Object(b.jsxs)("p",{children:["Holding: ",n.holding]}),Object(b.jsxs)("p",{children:["AFK: ","".concat(n.afk)]}),Object(b.jsxs)("p",{children:["Health: ",n.health]}),Object(b.jsxs)("p",{children:["Food: ",n.food]}),Object(b.jsxs)("p",{children:["Time: ",n.time]})]})})};a.a.render(Object(b.jsx)(r.a.StrictMode,{children:Object(b.jsx)(u,{})}),document.getElementById("root"))}},[[41,1,2]]]);
|
||||||
|
//# sourceMappingURL=main.27336089.chunk.js.map
|
1
web_interface/build/static/js/main.27336089.chunk.js.map
Normal file
1
web_interface/build/static/js/main.27336089.chunk.js.map
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"version":3,"sources":["App.js","index.js"],"names":["axios","defaults","baseURL","process","REACT_APP_SERVER","App","useState","global","setGlobal","useEffect","interval","setInterval","a","get","res","data","clearInterval","className","name","pos","yaw","pitch","dimension","Object","values","players","map","x","player_names","player_uuid","holding","afk","health","food","time","ReactDOM","render","StrictMode","document","getElementById"],"mappings":"kNAGAA,IAAMC,SAASC,QAAUC,mIAAYC,iBAiDtBC,MA/Cf,WAAgB,IAAD,EACcC,oBAAS,GADvB,mBACPC,EADO,KACCC,EADD,KAiBd,OAdAC,qBAAU,WACT,IASMC,EAAWC,YATR,uCAAG,4BAAAC,EAAA,+EAEQZ,IAAMa,IAAI,eAFlB,OAEJC,EAFI,OAGVN,EAAUM,EAAIC,MAHJ,gDAKVP,GAAU,GALA,yDAAH,qDASyB,KAClC,OAAO,kBAAMQ,cAAcN,MACzB,IAGF,qBAAKO,UAAU,MAAf,SACEV,GACA,qCACC,uCAAUA,EAAOW,QACjB,sCAASX,EAAOY,OAChB,sCAASZ,EAAOa,OAChB,wCAAWb,EAAOc,SAElB,4CAAed,EAAOe,aAEtB,yCACEC,OAAOC,OAAOjB,EAAOkB,SAASC,KAAI,SAAAC,GAAC,OACnC,8BACEpB,EAAOqB,aAAaD,EAAEE,qBAK1B,0CAAatB,EAAOuB,WACpB,gDAAYvB,EAAOwB,QACnB,yCAAYxB,EAAOyB,UACnB,uCAAUzB,EAAO0B,QACjB,uCAAU1B,EAAO2B,cCzCtBC,IAASC,OACR,cAAC,IAAMC,WAAP,UACC,cAAC,EAAD,MAEDC,SAASC,eAAe,W","file":"static/js/main.27336089.chunk.js","sourcesContent":["import React, { useState, useEffect } from 'react';\nimport axios from 'axios';\n\naxios.defaults.baseURL = process.env.REACT_APP_SERVER;\n\nfunction App() {\n\tconst [global, setGlobal] = useState(false);\n\n\tuseEffect(() => {\n\t\tconst get = async() => {\n\t\t\ttry {\n\t\t\t\tconst res = await axios.get('/api/global');\n\t\t\t\tsetGlobal(res.data);\n\t\t\t} catch (error) {\n\t\t\t\tsetGlobal(false);\n\t\t\t}\n\t\t};\n\n\t\tconst interval = setInterval(get, 500);\n\t\treturn () => clearInterval(interval);\n\t}, []);\n\n\treturn (\n\t\t<div className=\"app\">\n\t\t\t{global &&\n\t\t\t\t<>\n\t\t\t\t\t<p>Name: {global.name}</p>\n\t\t\t\t\t<p>Pos: {global.pos}</p>\n\t\t\t\t\t<p>Yaw: {global.yaw}</p>\n\t\t\t\t\t<p>Pitch: {global.pitch}</p>\n\n\t\t\t\t\t<p>Dimention: {global.dimension}</p>\n\n\t\t\t\t\t<p>Players:\n\t\t\t\t\t\t{Object.values(global.players).map(x =>\n\t\t\t\t\t\t\t<div>\n\t\t\t\t\t\t\t\t{global.player_names[x.player_uuid]}\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t)}\n\t\t\t\t\t</p>\n\n\t\t\t\t\t<p>Holding: {global.holding}</p>\n\t\t\t\t\t<p>AFK: {`${global.afk}`}</p>\n\t\t\t\t\t<p>Health: {global.health}</p>\n\t\t\t\t\t<p>Food: {global.food}</p>\n\t\t\t\t\t<p>Time: {global.time}</p>\n\t\t\t\t</>\n\t\t\t}\n\t\t</div>\n\t);\n}\n\nexport default App;\n","import React from 'react';\nimport ReactDOM from 'react-dom';\nimport App from './App';\n\nReactDOM.render(\n\t<React.StrictMode>\n\t\t<App />\n\t</React.StrictMode>,\n\tdocument.getElementById('root')\n);\n"],"sourceRoot":""}
|
2
web_interface/build/static/js/runtime-main.97b64705.js
Normal file
2
web_interface/build/static/js/runtime-main.97b64705.js
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
!function(e){function r(r){for(var n,f,i=r[0],l=r[1],a=r[2],p=0,s=[];p<i.length;p++)f=i[p],Object.prototype.hasOwnProperty.call(o,f)&&o[f]&&s.push(o[f][0]),o[f]=0;for(n in l)Object.prototype.hasOwnProperty.call(l,n)&&(e[n]=l[n]);for(c&&c(r);s.length;)s.shift()();return u.push.apply(u,a||[]),t()}function t(){for(var e,r=0;r<u.length;r++){for(var t=u[r],n=!0,i=1;i<t.length;i++){var l=t[i];0!==o[l]&&(n=!1)}n&&(u.splice(r--,1),e=f(f.s=t[0]))}return e}var n={},o={1:0},u=[];function f(r){if(n[r])return n[r].exports;var t=n[r]={i:r,l:!1,exports:{}};return e[r].call(t.exports,t,t.exports,f),t.l=!0,t.exports}f.m=e,f.c=n,f.d=function(e,r,t){f.o(e,r)||Object.defineProperty(e,r,{enumerable:!0,get:t})},f.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},f.t=function(e,r){if(1&r&&(e=f(e)),8&r)return e;if(4&r&&"object"===typeof e&&e&&e.__esModule)return e;var t=Object.create(null);if(f.r(t),Object.defineProperty(t,"default",{enumerable:!0,value:e}),2&r&&"string"!=typeof e)for(var n in e)f.d(t,n,function(r){return e[r]}.bind(null,n));return t},f.n=function(e){var r=e&&e.__esModule?function(){return e.default}:function(){return e};return f.d(r,"a",r),r},f.o=function(e,r){return Object.prototype.hasOwnProperty.call(e,r)},f.p="/";var i=this.webpackJsonpweb_interface=this.webpackJsonpweb_interface||[],l=i.push.bind(i);i.push=r,i=i.slice();for(var a=0;a<i.length;a++)r(i[a]);var c=l;t()}([]);
|
||||||
|
//# sourceMappingURL=runtime-main.97b64705.js.map
|
File diff suppressed because one or more lines are too long
39
web_interface/package.json
Normal file
39
web_interface/package.json
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
{
|
||||||
|
"name": "web_interface",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"dependencies": {
|
||||||
|
"@testing-library/jest-dom": "^5.11.4",
|
||||||
|
"@testing-library/react": "^11.1.0",
|
||||||
|
"@testing-library/user-event": "^12.1.10",
|
||||||
|
"axios": "^0.21.1",
|
||||||
|
"react": "^17.0.2",
|
||||||
|
"react-dom": "^17.0.2",
|
||||||
|
"react-scripts": "4.0.3",
|
||||||
|
"web-vitals": "^1.0.1"
|
||||||
|
},
|
||||||
|
"scripts": {
|
||||||
|
"start": "react-scripts start",
|
||||||
|
"build": "react-scripts build",
|
||||||
|
"test": "react-scripts test",
|
||||||
|
"eject": "react-scripts eject"
|
||||||
|
},
|
||||||
|
"eslintConfig": {
|
||||||
|
"extends": [
|
||||||
|
"react-app",
|
||||||
|
"react-app/jest"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"browserslist": {
|
||||||
|
"production": [
|
||||||
|
">0.2%",
|
||||||
|
"not dead",
|
||||||
|
"not op_mini all"
|
||||||
|
],
|
||||||
|
"development": [
|
||||||
|
"last 1 chrome version",
|
||||||
|
"last 1 firefox version",
|
||||||
|
"last 1 safari version"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
36
web_interface/public/index.html
Normal file
36
web_interface/public/index.html
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
<meta name="theme-color" content="#000000" />
|
||||||
|
<meta
|
||||||
|
name="description"
|
||||||
|
content="Web site created using create-react-app"
|
||||||
|
/>
|
||||||
|
<!--
|
||||||
|
Notice the use of %PUBLIC_URL% in the tags above.
|
||||||
|
It will be replaced with the URL of the `public` folder during the build.
|
||||||
|
Only files inside the `public` folder can be referenced from the HTML.
|
||||||
|
|
||||||
|
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
|
||||||
|
work correctly both with client-side routing and a non-root public URL.
|
||||||
|
Learn how to configure a non-root public URL by running `npm run build`.
|
||||||
|
-->
|
||||||
|
<title>React App</title>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<noscript>You need to enable JavaScript to run this app.</noscript>
|
||||||
|
<div id="root"></div>
|
||||||
|
<!--
|
||||||
|
This HTML file is a template.
|
||||||
|
If you open it directly in the browser, you will see an empty page.
|
||||||
|
|
||||||
|
You can add webfonts, meta tags, or analytics to this file.
|
||||||
|
The build step will place the bundled scripts into the <body> tag.
|
||||||
|
|
||||||
|
To begin the development, run `npm start` or `yarn start`.
|
||||||
|
To create a production bundle, use `npm run build` or `yarn build`.
|
||||||
|
-->
|
||||||
|
</body>
|
||||||
|
</html>
|
53
web_interface/src/App.js
Normal file
53
web_interface/src/App.js
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
|
axios.defaults.baseURL = process.env.REACT_APP_SERVER;
|
||||||
|
|
||||||
|
function App() {
|
||||||
|
const [global, setGlobal] = useState(false);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const get = async() => {
|
||||||
|
try {
|
||||||
|
const res = await axios.get('/api/global');
|
||||||
|
setGlobal(res.data);
|
||||||
|
} catch (error) {
|
||||||
|
setGlobal(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const interval = setInterval(get, 500);
|
||||||
|
return () => clearInterval(interval);
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="app">
|
||||||
|
{global &&
|
||||||
|
<>
|
||||||
|
<p>Name: {global.name}</p>
|
||||||
|
<p>Pos: {global.pos}</p>
|
||||||
|
<p>Yaw: {global.yaw}</p>
|
||||||
|
<p>Pitch: {global.pitch}</p>
|
||||||
|
|
||||||
|
<p>Dimention: {global.dimension}</p>
|
||||||
|
|
||||||
|
<p>Players:
|
||||||
|
{Object.values(global.players).map(x =>
|
||||||
|
<div>
|
||||||
|
{global.player_names[x.player_uuid]}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<p>Holding: {global.holding}</p>
|
||||||
|
<p>AFK: {`${global.afk}`}</p>
|
||||||
|
<p>Health: {global.health}</p>
|
||||||
|
<p>Food: {global.food}</p>
|
||||||
|
<p>Time: {global.time}</p>
|
||||||
|
</>
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export default App;
|
10
web_interface/src/index.js
Normal file
10
web_interface/src/index.js
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import React from 'react';
|
||||||
|
import ReactDOM from 'react-dom';
|
||||||
|
import App from './App';
|
||||||
|
|
||||||
|
ReactDOM.render(
|
||||||
|
<React.StrictMode>
|
||||||
|
<App />
|
||||||
|
</React.StrictMode>,
|
||||||
|
document.getElementById('root')
|
||||||
|
);
|
11418
web_interface/yarn.lock
Normal file
11418
web_interface/yarn.lock
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user