gilesknap / mciwb

Minecraft Interactive world builder
Apache License 2.0
299 stars 6 forks source link

Connecting without a player logged in fails #108

Open gilesknap opened 1 year ago

gilesknap commented 1 year ago

@jhutar reports that this fails with ERROR: AttributeError: 'NoneType' object has no attribute 'pos').

gilesknap commented 1 year ago

@jhutar this seems to still be working for me.

Please can you post the output when you try this. Thanks.

(venv) (dev) [giles@ws1 mciwb]$ mciwb shell --debug --server nuc2.lan --port 30555 --player TransformerScorn --passwd spider
DEBUG: /home/giles/work/mciwb/src/mciwb/logging.py:26 init_logging 
        Debugging logging initialized
INFO: /home/giles/work/mciwb/src/mciwb/iwb.py:108 connect 
        Connected to nuc2.lan on 30555
ERROR: /home/giles/work/mciwb/src/mciwb/iwb.py:161 add_player 
        failed to give signs to player, 
INFO: /home/giles/work/mciwb/src/mciwb/iwb.py:163 add_player 
        Monitoring player TransformerScorn enabled for sign commands
INFO: /home/giles/work/mciwb/src/mciwb/__main__.py:84 shell 
        ######### Starting Interactive Session ##########

Python 3.10.6 (main, Mar 10 2023, 10:55:28) [GCC 11.3.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.10.0 -- An enhanced Interactive Python. Type '?' for help.

In [1]: world.add_player('TransformerScorn')
DEBUG: /home/giles/work/mciwb/src/mciwb/monitor.py:74 start_poller 
        starting polling thread TransformerScorn
INFO: /home/giles/work/mciwb/src/mciwb/iwb.py:163 add_player 
        Monitoring player TransformerScorn enabled for sign commands

In [2]: pos = world.player.pos

In [3]: pos
Out[3]: Vec3(x=633, y=73, z=-1651)

In [4]: 
gilesknap commented 1 year ago

I just re-read your post on this and it looks like you are trying to call world.player.pos without doing an add_player first.

In that case the error would be expected but I probably should trap that and give a better error.

You either need to start with the player logged in or use add_player once you log in. Note also that you can add_player for multiple users so they can all use signs etc. (I use multi-player to have exploding snowball fights with my son).

There is no automatic monitoring of players joining - I guess we could implement that though.

gilesknap commented 1 year ago

Also:

I detect when a player leaves but fail to clean up the player list in world.

TODO add a monitor which runs list once every 5 secs and parses the output to determine the current list of players and update world.players accordingly (including killing exiting players monitors).

Question: how do we determine which is the 'primary' player i.e. world.player ?? Maybe we should not have primary player - but it is mighty convenient for the most common case of accessing a single player.

In [1]: world
Out[1]: 
Minecraft Interactive World Builder status:
  copy buffer start: None
  copy buffer stop: None
  copy buffer size: Vec3(x=0, y=0, z=0)
  paste point: None
  player: TransformerScorn
    position: Vec3(x=633, y=73, z=-1651)
    facing: Vec3(x=0, y=0, z=1)

In [2]: WARNING:        player TransformerScorn left
INFO:   Monitor TransformerScorn stopped
In [2]: 

In [2]: world
Out[2]: Traceback (most recent call last):
  File "/home/giles/work/mciwb/venv/lib/python3.10/site-packages/IPython/core/formatters.py", line 221, in catch_format_error
    r = method(self, *args, **kwargs)
  File "/home/giles/work/mciwb/venv/lib/python3.10/site-packages/IPython/core/formatters.py", line 706, in __call__
    printer.pretty(obj)
  File "/home/giles/work/mciwb/venv/lib/python3.10/site-packages/IPython/lib/pretty.py", line 410, in pretty
    return _repr_pprint(obj, self, cycle)
  File "/home/giles/work/mciwb/venv/lib/python3.10/site-packages/IPython/lib/pretty.py", line 778, in _repr_pprint
    output = repr(obj)
  File "/home/giles/work/mciwb/src/mciwb/iwb.py", line 239, in __repr__
    f"    position: {player.pos}\n"
  File "/home/giles/work/mciwb/src/mciwb/player.py", line 80, in pos
    return self.pos_f.with_ints()
  File "/home/giles/work/mciwb/src/mciwb/player.py", line 72, in pos_f
    match = self._get_entity_data("Pos", regex_coord)
  File "/home/giles/work/mciwb/src/mciwb/player.py", line 56, in _get_entity_data
    raise PlayerNotInWorld(f"player {self.name} left")
mciwb.player.PlayerNotInWorld: player TransformerScorn left