spockbotmc / spockbot Goto Github PK
View Code? Open in Web Editor NEWHigh level Python framework for building Minecraft clients and bots.
License: MIT License
High level Python framework for building Minecraft clients and bots.
License: MIT License
Do /getqueuesize periodically and push to Skynet; would be useful for CivcraftPing.
Spock needs to send keep-alives for its session once every 6000 ticks (~5m) to prevent session kicks after the client as already logged in
First: thank you for SpockBot - its awesome!
Second, on our server (freebuild.mineactivity.com) sometimes SpockBot crashes like so:
Traceback (most recent call last):
File "main.py", line 16, in <module>
client.start('freebuild.mineactivity.com', 25565)
File "/usr/lib/python2.7/site-packages/spock/plugins/helpers/start.py", line 37, in start
self.event.event_loop()
File "/usr/lib/python2.7/site-packages/spock/plugins/core/event.py", line 22, in event_loop
self.emit('event_tick')
File "/usr/lib/python2.7/site-packages/spock/plugins/core/event.py", line 36, in emit
else copy.deepcopy(data)
File "/usr/lib/python2.7/site-packages/spock/plugins/core/net.py", line 185, in tick
self.event.emit(flag)
File "/usr/lib/python2.7/site-packages/spock/plugins/core/event.py", line 36, in emit
else copy.deepcopy(data)
File "/usr/lib/python2.7/site-packages/spock/plugins/core/net.py", line 203, in handleRECV
self.net.read_packet(data)
File "/usr/lib/python2.7/site-packages/spock/plugins/core/net.py", line 133, in read_packet
self.event.emit(packet.str_ident, packet)
File "/usr/lib/python2.7/site-packages/spock/plugins/core/event.py", line 36, in emit
else copy.deepcopy(data)
File "/usr/lib/python2.7/site-packages/spock/plugins/helpers/clientinfo.py", line 161, in handle_player_list
item = self.uuids[pl['uuid']]
KeyError: 237771049331261779340081663972802975458L
It might be because another player left because the only other event happening at that time was a player going offline:
[14:30:12 INFO]: ljhodge lost connection: Disconnected
[14:30:12 INFO]: ItHurtsWhenIP lost connection: Disconnected
(ItHurtsWhenIP is my 'amusing' bot name)
This would seem to be the case since the 128-bit integer 237771049331261779340081663972802975458 matches ljhodge's UUID.
I can't manage to start the client, is there something I'm missing? I've installed all the required libraries, yet still it won't start cleanly.
Probably easier to use because of the cleaner interface.
Requires mcdata.blocks
and mcdata.items
to provide the string_id -> (item_id, meta)
mapping.
I believe that there is an error with the logging of player positions. I haven't tested any other entities but it certainly looks like the case with players. I have tried to collect as much information as possible for you.
My logging code is shown below.
def onTick(self,_,__): #Only one player online (apart from the bot)
for eid in self.entities.players:
p = self.entities.players[eid]
logger.info(str(p))
The printed results is shown below. At first, the first of these is printed every tick but then it switches to the second result.
{'yaw': 12, 'current_item': 137, 'eid': 221, 'pitch': 22, 'y': 3200, 'x': -1786, 'z': -55769, 'metadata': [(18, (2, 0)), (17, (3, 0.0)), (16, (0, 0)), (10, (0, 127)), (9, (0, 0)), (8, (0, 0)), (7, (2, 0)), (6, (3, 20.0)), (4, (0, 0)), (3, (0, 0)), (2, (4, u'')), (1, (1, 300)), (0, (0, 0))]}
{'on_ground': True, 'yaw': 12, 'current_item': 137, 'eid': 221, 'pitch': 22, 'y': 3200, 'x': -1786, 'z': -55769, 'metadata': [(18, (2, 0)), (17, (3, 0.0)), (16, (0, 0)), (10, (0, 127)), (9, (0, 0)), (8, (0, 0)), (7, (2, 0)), (6, (3, 20.0)), (4, (0, 0)), (3, (0, 0)), (2, (4, u'')), (1, (1, 300)), (0, (0, 0))]}
Below is an image with the exact position etc of the player (with 'eid' 221).
I have checked that I was logging the correct player by making them hold a command block (137); the bot player was not holding one. The player that I logged was perfectly still whilst the logs were being collected.
Everywhere we currently use _parse_buffer methods we should also have _parse_string methods to work with byte strings
On startup PluginLoader should print the plugins it loads
Spock should support arbitrary protocol versions, and intelligently pick the correct protocol version when connecting to a server unless otherwise specified
thats' not really a issue, but I have seen that you made your own implementation of the timers, and I see you cant start a timer with "self.timers.reg_event_timer" but I haven't found a simple solution to stop them, did I missed it? I have made a small patch, if you interested I can submit the pull request
https://github.com/zezadas/spock/commit/a59f048a0f0360782a529dbc78b8bed6215cb476
and then you can make something like
t=self.timers.reg_event_timer(0.05, self.derp)
self.timers.timers.remove(self.timers.timers[t])
Event loop needs some sort of timer mechanisms to support position updates, should probably be tied to a position update flag
Failed packet ident is probably: PLAY<Spawn Painting
It would be nice to be Python 3 compatible, since Spock doesn't rely on any wildly incompatible behavior it should be mostly switching print statements around.
Right now it just blocks and crashes
I'm probably missing something here, but hear me out. I installed the dependencies as instructed, and got to the point where I should be able to run the demo, but I got this:
File "C:\Python34\lib\site-packages\spock\plugins\core\net.py", line 55, in
rmask = select.POLLIN|select.POLLERR|select.POLLHUP
AttributeError: 'module' object has no attribute 'POLLIN'
I did a bit of googling and came up with this post:
Which lead me back here, but before I posted I doubble checked other tickers and someone has also posted about windows support here:
#8
The last post implies that windows support has been added, but It isn't working for me on windows 7? Is there a step I'm missing to enable windows support? Or was I mistaken?
My goal is to try and run this on a raspberry pi, but use windows for most my testing and whatnaught.
I think this commit breaks offline demo
In particular I'm looking at the chat plugin here:
https://github.com/SpockBotMC/SpockBot-Extra/blob/master/plugins/Chat.py#L18
I'm trying to get a Slack <-> Minecraft relay going and it's almost done. I've gotten spockbot to send messages to my Slack channel. Now I just need to get the messages to send from Slack to spockbot.
My problem is my the chat plugin handles both listening for new messages and sending new messages. Is there any way I can keep the plugin from calling itself when the the bot sends a message?
When I run what I have, it looks like this kicks me out of minecraft. When I comment out the self.emit_chat_message from my relay function, I don't get kicked (which is why I think it has to deal with the plugin calling itself).
hlprimm@apollo:~/Code/python/SlackMCRelay$ python slackmcrelay.py
[INFO]: AUTHCORE: Attempting login with username: EMAIL
[INFO]: AUTHCORE: Logged in as: htownJD
[INFO]: AUTHCORE: Selected Profile: {u'id': u'44c37ed8d3584de2873ec179c0409ab0', u'name': u'htownJD'}
[INFO]: NETCORE: Attempting to connect to host: mc.civcraft.co port: 25565
[INFO]: NETCORE: Connected to host: mc.civcraft.co port: 25565
msg: slack msg received
hlprimm : IT WORKS
spock tries to forward the message but... gets this:
[INFO]: AUTHPLUGIN: Attempting to authenticate session with sessionserver.mojang.com
[INFO]: AUTHPLUGIN: Session authentication successful
[ERROR]: NETPLUGIN: Socket has hung up
[INFO]: EVENTCORE: Kill called, shutting down
[INFO]: NETPLUGIN: Kill event recieved, shutting down socket
Thanks :)
Failed packet ident is probably: PLAY<Entity Metadata
Client should be able to login to both authenticated and unauthenticated servers instead of just authenticated ones
Currently, only the last TaskFailed
instance and message are given to the on_error
method of task parents. This makes it hard/impossible to find the source of an error.
TaskFailed
should have access to
TaskFailed
instances that were previously raised, andTaskFailed
error, i.e. after it was raised.super().__init__()
cannot be called this way in Python 2.7. Calling the super class by name, e.g. Slot.__init__
seems to do the trick, but this may not be a correct way to handle it.
When attempting to place a block at a location with a y value that's too large, Spock crashes
e.g. l place 5 254345 29
Entering a y value โฅ 255 causes the crash, but absurdly large x and z values do not seem to break it
Traceback (most recent call last):
File "run.py", line 19, in
client.start('obfuscated.url', 12345)
File "/Library/Python/2.7/site-packages/spock/plugins/helpers/start.py", line 37, in start
self.event.event_loop()
File "/Library/Python/2.7/site-packages/spock/plugins/core/event.py", line 22, in event_loop
self.emit('event_tick')
File "/Library/Python/2.7/site-packages/spock/plugins/core/event.py", line 36, in emit
else copy.deepcopy(data)
File "/Library/Python/2.7/site-packages/spock/plugins/core/net.py", line 184, in tick
self.event.emit(flag)
File "/Library/Python/2.7/site-packages/spock/plugins/core/event.py", line 36, in emit
else copy.deepcopy(data)
File "/Library/Python/2.7/site-packages/spock/plugins/core/net.py", line 202, in handleRECV
self.net.read_packet(data)
File "/Library/Python/2.7/site-packages/spock/plugins/core/net.py", line 130, in read_packet
self.event.emit(packet.ident, packet)
File "/Library/Python/2.7/site-packages/spock/plugins/core/event.py", line 36, in emit
else copy.deepcopy(data)
File "/Library/Python/2.7/site-packages/spock/plugins/helpers/world.py", line 83, in handle23
self.world.set_block(p['x'], p['y'], p['z'], data = block_data)
File "/Library/Python/2.7/site-packages/spock/mcmap/smpmap.py", line 204, in set_block
chunk = column.chunks[y]
IndexError: list index out of range
SpockBot should, if possible, gracefully disconnect when its killed rather than just dying. Not 100% sure how this works, see this PR: #37
Datautils and Packet have individual decoders, these should be merged
Do they work?
That way we have an event to listen to to change slots and stuff
Vectors that instruct the player to move up, i.e. the jump method (and manually applied vectors) only "Activate" when the player isn't on the ground.
def onTick(self,,_):
self.physics.jump()
The code above executes every tick, for instance. When I break the block under the player, they do a little hop before falling down.
In my Ubuntu 14.04 LTS server, I accidentally encountered the error that shows depends libraries not found. It shows that the package 'openssl/aes.h', 'ffi.h', 'Python.h' not found, which leads to the following packages in Ubuntu apt-get: libssl-dev, libffi-dev, and python-dev. I am wondering that should we add them into installation script. Maybe I'll open a pull request.
When running chat plugin, I only had some output like "chat: myname"
I guess the bug comes from "if type(text) is str: "
I have fixed it on my code, but I only started to develop in python, today, so my approach may be not the best way to fix it.
BTW, great project!! ;)
Anti-AFK is currently entirely chat based, it should be timer and movement based instead. That is, a timer should trigger the bot to spin in place (thus avoiding AFK while not consuming hunger)
Add minecraft-data as a submodule.
Can be used for recipes right now, later for more stuff (e.g. generate block/biome info or item info, which is needed for Inventory).
If a plugin fails to load multiple things can happen depending on how that plugin was loaded and what actions the plugin took before it crashed.
For example, if a plugin fails to load during normal activation but registered event handlers before it failed, the bot will crash if that event fires. If that same plugin was activated by a PluginLoader.requires()
, the bot will crash upon trying to activate the plugin because of inconsistencies in exception handling by PluginLoader.
Personally I think the answer to this is just to log something useful + the error stacktrace and then shutdown whenever a plugin fails to load.
spock.utils
is made up by lots of collected code from many independent use cases:
Some stuff is not even used anymore. Definitely needs to be cleaned up, probably by splitting into several spock.utils.*
and/or moving classes/methods closer to where they are actually used.
CentOS 6.5
CPU Model: Intel(R) Xeon(R) CPU E3-1230 V2 @ 3.30GHz
[root@server SpockBot-master]# python demo.py
Traceback (most recent call last):
File "demo.py", line 5, in
from spock import Client
File "/home/SpockBot-master/spock/init.py", line 1, in
from spock.plugins.pluginloader import PluginLoader
File "/home/SpockBot-master/spock/plugins/init.py", line 1, in
from spock.plugins.core import event, net, auth, timer, ticker
File "/home/SpockBot-master/spock/plugins/core/event.py", line 7, in
from spock.mcp import mcdata
File "/home/SpockBot-master/spock/mcp/mcdata.py", line 1133
for state in packet_structs
^
SyntaxError: invalid syntax
(None of the files were modified.)
still uses old plugin format (without PluginBase)
First world state needs much better API
It seems that the script is blocking whenever there is a client open and wont let me initialize another client.
Riker should be physics aware and automatically handle gravity and velocity
Packets with extensions need to have this extra data accounted for when decoding and decoding. The packet module should use the extensions module to account for this extra information
Sleeping the main event loop is a bad idea, we should use threaded timers instead
So I'm quite new to python and programming overall. I've managed to get example.py running. I tried it out in test.civcraft.co and it worked great. However, trying it out in the main civcraft server mc.civcraft.co causes this error. Let me know if there's anything else I can provide! BTW, I tried running python 3 on example.py
with my login info in the blanks, but it kept throwing this error:
Traceback (most recent call last):
File "example.py", line 26, in <module>
from .example_plugin import ExamplePlugin
SystemError: Parent module '' not loaded, cannot perform relative import
So instead I've been running it as python3 -m basic.example
... Not sure if this is causing the problem or not!
Here is the full ouput!
hlprimm@apollo:~/Code/python/SpockBot/examples$ python3 -m basic.example
[INFO]: AUTHCORE: Attempting login with username: CENSORED
[INFO]: AUTHCORE: Logged in as: hlprimm
[INFO]: AUTHCORE: Selected Profile: {'id': '5505ae3e6d424a53ae059e19479d29e2', 'name': 'hlprimm'}
[INFO]: NETCORE: Attempting to connect to host: mc.civcraft.co port: 25565
[INFO]: NETCORE: Connected to host: mc.civcraft.co port: 25565
[INFO]: AUTHPLUGIN: Attempting to authenticate session with sessionserver.mojang.com
[INFO]: AUTHPLUGIN: Session authentication successful
Chat message received: [22:47:14] <<< (0x03, 0x02): Chat Message {'position': 1, 'json_data': {'extra': [{'color': 'white', 'text': ' '}, {'color': 'white', 'text': ' '}, {'color': 'dark_blue', 'text': ' '}, {'color': 'black', 'text': ' '}, {'color': 'dark_green', 'text': ' '}, {'color': 'white', 'text': ' '}, {'color': 'white', 'text': ' '}, {'color': 'dark_green', 'text': ' '}, {'color': 'black', 'text': ' '}, {'color': 'dark_red', 'text': ' '}, {'color': 'dark_aqua', 'text': ' '}, {'color': 'blue', 'text': ' '}, {'color': 'dark_green', 'text': ' '}, {'color': 'black', 'text': ' '}, {'color': 'black', 'text': ' '}, {'color': 'dark_aqua', 'text': ' '}, {'color': 'blue', 'text': ' '}, {'color': 'dark_green', 'text': ' '}, {'color': 'black', 'text': ' '}, {'color': 'black', 'text': ' '}, {'color': 'dark_aqua', 'text': ' '}, {'color': 'blue', 'text': ' '}, {'color': 'dark_green', 'text': ' '}, {'color': 'black', 'text': ' '}, {'color': 'black', 'text': ' '}, {'color': 'dark_aqua', 'text': ' '}, {'color': 'gold', 'text': ' '}, {'color': 'dark_aqua', 'text': ' '}, {'color': 'gold', 'text': ' '}, {'color': 'dark_aqua', 'text': ' '}, {'color': 'gold', 'text': ' '}, {'color': 'dark_aqua', 'text': ' '}, {'color': 'gold', 'text': ' '}, {'color': 'dark_aqua', 'text': ' '}, {'color': 'gold', 'text': ' '}, {'color': 'dark_aqua', 'text': ' '}, {'color': 'gold', 'text': ' '}], 'text': ''}}
Chat message received: [22:47:14] <<< (0x03, 0x02): Chat Message {'position': 1, 'json_data': {'extra': [{'color': 'gray', 'text': '[NSAccess] hlprimm: '}, {'color': 'white', 'text': 'Bot active.'}], 'text': ''}}
Chat message received: [22:47:15] <<< (0x03, 0x02): Chat Message {'position': 1, 'json_data': {'extra': [{'color': 'red', 'text': 'You have engaged in combat. Type '}, {'color': 'aqua', 'text': '/ct '}, {'color': 'red', 'text': 'to check your timer.'}], 'text': ''}}
Chat message received: [22:47:15] <<< (0x03, 0x02): Chat Message {'position': 1, 'json_data': {'extra': ['You have been Combat Tagged on Login'], 'text': ''}}
My position: (-1819.13, 67.22, -11004.61) pitch: 8.99999713897705 yaw: 96.29989624023438
Before changing the block, the type had id 0 and name air.
Chat message received: [22:47:18] <<< (0x03, 0x02): Chat Message {'position': 1, 'json_data': {'extra': [{'color': 'red', 'text': "I'm sorry, but you do not have permission to perform this command. Please contact the server administrators if you believe that this is in error."}], 'text': ''}}
Traceback (most recent call last):
File "/usr/lib/python3.4/runpy.py", line 170, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.4/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/hlprimm/Code/python/SpockBot/examples/basic/example.py", line 46, in <module>
client.start(SERVER, 25565)
File "/usr/local/lib/python3.4/dist-packages/spock-0.1.2-py3.4.egg/spock/plugins/helpers/start.py", line 37, in start
File "/usr/local/lib/python3.4/dist-packages/spock-0.1.2-py3.4.egg/spock/plugins/core/event.py", line 23, in event_loop
File "/usr/local/lib/python3.4/dist-packages/spock-0.1.2-py3.4.egg/spock/plugins/core/event.py", line 38, in emit
File "/usr/local/lib/python3.4/dist-packages/spock-0.1.2-py3.4.egg/spock/plugins/core/net.py", line 189, in tick
File "/usr/local/lib/python3.4/dist-packages/spock-0.1.2-py3.4.egg/spock/plugins/core/event.py", line 38, in emit
File "/usr/local/lib/python3.4/dist-packages/spock-0.1.2-py3.4.egg/spock/plugins/core/net.py", line 205, in handle_recv
File "/usr/local/lib/python3.4/dist-packages/spock-0.1.2-py3.4.egg/spock/plugins/core/net.py", line 129, in read_packet
File "/usr/local/lib/python3.4/dist-packages/spock-0.1.2-py3.4.egg/spock/mcp/mcpacket.py", line 70, in decode
File "/usr/local/lib/python3.4/dist-packages/spock-0.1.2-py3.4.egg/spock/mcp/datautils.py", line 220, in unpack
File "/usr/local/lib/python3.4/dist-packages/spock-0.1.2-py3.4.egg/spock/mcp/datautils.py", line 162, in unpack_metadata
File "/usr/local/lib/python3.4/dist-packages/spock-0.1.2-py3.4.egg/spock/mcp/datautils.py", line 214, in unpack
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xde in position 0: invalid continuation byte
Is there something I should change?
Thanks a bunch, spockbot is AWESOME!!
select.poll() is unsupported on windows
Exactly what it says on the tin, documentation and a setup tutorial would make Spock a much friendly platform for development.
๐
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.