Git Product home page Git Product logo

Comments (20)

joodicator avatar joodicator commented on July 27, 2024 1

PlayerPositionAndLookPacket was broken for 1.11.2, with the wrong packet ID configured. I think this was my fault - my apologies. This is fixed in 9765e93.

(We should consider adding some kind of test to make sure the packet IDs are correct in each supported version.)

from pycraft.

joodicator avatar joodicator commented on July 27, 2024

@MobAction PlayerPositionAndLookPacket is a clientbound packet. When you send it, the server terminates your connection without the courtesy of a disconnect message, hence the unexpected end of the stream. PositionAndLookPacket is the serverbound packet that you probably intended to use.

It also seems worth mentionioning that this line:

packet.PositionAndLook(x=-7400, y=1, z=5319, yaw=160, pitch=160, teleport_id=1, flags=0b11111)

does not do anything useful. It just constructs a PositionAndLook object and then discards it. Moreover, the arguments teleport_id and flags are not used by PositionAndLook objects, which just record an absolute position and and look direction.

The names of these packets do not make this very clear, I realise. It might be difficult to change the names while preserving backward compatibility, but perhaps a warning could be printed when trying to send a clientbound packet to the server.

from pycraft.

MobAction avatar MobAction commented on July 27, 2024

Awesome. Thanks! I'll give it a try tonight.

from pycraft.

ammaraskar avatar ammaraskar commented on July 27, 2024

Hey @MobAction, did you end up getting this to work?

from pycraft.

MobAction avatar MobAction commented on July 27, 2024

Sorry guys -- slacking hard (and wound up going out of town), should have a moment to follow around on this shortly. Appreciate the expeditious support!

from pycraft.

MobAction avatar MobAction commented on July 27, 2024

Hi guys,

Still having some sort of issue, here's my code in the ChatMessagePacket listener:

          if "!special_chat_words" in concatted_chat: 
            
                packet = PositionAndLookPacket()
                packet.x = 1.0
                packet.z = 0.0
                packet.y = 1.0

                packet.yaw = 150
                packet.pitch = 150

                connection.write_packet(packet)
                
                print('position change trigger')

Produces:

Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
    self.run()
  File "C:\Users\mobaction\Desktop\pyCraft-master\minecraft\networking\connection.p
 line 341, in run
    self.connection._handle_exception(e, sys.exc_info())
  File "C:\Users\mobaction\Desktop\pyCraft-master\minecraft\networking\connection.p
 line 319, in _handle_exception
    raise_(*exc_info)
  File "C:\Users\mobaction\Desktop\pyCraft-master\minecraft\networking\connection.p
 line 339, in run
    self._run()
  File "C:\Users\mobaction\Desktop\pyCraft-master\minecraft\networking\connection.p
 line 394, in _run
    raise_(*exc_info)
  File "C:\Users\mobaction\Desktop\pyCraft-master\minecraft\networking\connection.p
 line 358, in _run
    while self.connection._pop_packet():
  File "C:\Users\mobaction\Desktop\pyCraft-master\minecraft\networking\connection.p
 line 194, in _pop_packet
    packet.write(self.socket, self.options.compression_threshold)
  File "C:\Users\mobaction\Desktop\pyCraft-master\minecraft\networking\packets.py",
ne 143, in write
    data = getattr(self, var_name)
AttributeError: 'PositionAndLookPacket' object has no attribute 'feet_y'

from pycraft.

ammaraskar avatar ammaraskar commented on July 27, 2024

As the error says you're missing the feet_y attribute in your packet. Take a look at the fields in the packet here: https://github.com/ammaraskar/pyCraft/blob/master/minecraft/networking/packets/serverbound/play/__init__.py#L58-L74

This is what the mcdevs wiki says about the packet http://wiki.vg/Protocol#Player_Position_And_Look_.28serverbound.29

So you should add a

packet.feet_y = packet.y - 1.62
packet.on_ground = True

from pycraft.

MobAction avatar MobAction commented on July 27, 2024

That one was a gimmie, should have tore into it a bit more..

Added the requisite missing values; and now the code doesn't fail; but the player doesn't move :)

I'm going to give it a more in-depth review shortly, but is there a way to see if the packet is being received but rejected as invalid? On some servers I am kicked, on the local LAN game there is no movement. Curious if I'm specifying something out-of-bounds.

from pycraft.

ammaraskar avatar ammaraskar commented on July 27, 2024

Well if you're hardcoding the values in, the server won't allow you to move to just any arbitrary coordinates in one motion. See this example by joodicator which waits for the server to send you your initial position and then moves in a circle relative to that: #62 (comment)

from pycraft.

MobAction avatar MobAction commented on July 27, 2024

I copied a bit of his code, but it didn't work -- so I started changing it up and adding some print staements to isolate the issue.

It looks like I'm not receiving a position and look packet from the server, as I never see it on the console..

    def h_position_and_look(packet):
        packet.apply(pos_look)
        print 'GOT POSITION PACKET'

    connection.connect()
    connection.register_packet_listener(h_position_and_look, PlayerPositionAndLookPacket)  

from pycraft.

joodicator avatar joodicator commented on July 27, 2024

@MobAction Might it be that you have a race condition where the packet is received before you register the listener? Try connecting after setting the listener.

from pycraft.

em202020 avatar em202020 commented on July 27, 2024

Im also having an issue with not receiving the PlayerPositionAndLookPacket after connecting. I have copied the example code from #62 verbatim, and it is not getting the packet, the user connects, but no movement, and h_position_and_look() is never called. I have setup the packet listener before the client has connected, as well.

EDIT:
I noticed in the example code, it uses the lock at line 27, then stalls until pos_look_set has been called. Then when PlayerPositionAndLookPacket should be called, it also requires lock. Wouldnt the calling of lock on like 27 block the attempt to acquire the lock on line 20? I have tried removing the line 21 lock, but it still did not work, which makes me think that it is still a problem with the packet not being received.

from pycraft.

joodicator avatar joodicator commented on July 27, 2024

@em202020 It works for me with a vanilla 1.12.1 server, using Pythons 2.7.13 and 3.6.1, and the latest commit of pyCraft, namely 46e058d. If your configuration is different and this code doesn't work for you, please let us know the details in case there is a bug in pyCraft or the example code.

Regarding the call to wait() on line 27: this is the standard pattern for waiting on condition variables: the lock is released during the call to wait() and then reacquired when it ends. See: https://docs.python.org/3/library/threading.html#threading.Condition.wait.

I don't think these are related, but also make sure the server is in offline mode, the player's path is unobstructed, and preferably the player is in creative mode so they can walk through the air without problems.

from pycraft.

em202020 avatar em202020 commented on July 27, 2024

I have tested it on windows and on Linux, both with the same result.
I attempted to use a virtual environment to prevent outside conflicts, leaving only these packages in use.
image

The server I am testing it on is 1.11.2. I attempted to change the initial_version to 1.11.1, but it did not work. When I created a 1.12.2 server though, it did work.

What reason would it have to work on 1.12.1, but not 1.11.2? I am using Spigot for my server as well.

from pycraft.

em202020 avatar em202020 commented on July 27, 2024

Huh, I noticed some of the packet IDs were weird before I went to bed last night, and had changed them in the same way that you did, though it still didnt work for me. Though after recloning the repo, it did. Thanks for getting this fixed 👍

from pycraft.

MobAction avatar MobAction commented on July 27, 2024

Hi guys,

Just wanted to follow up. After DLing the latest including the fix, I AM receiving the location packet, but I am still not able to move the player. It appears to have no effect:

    if CTEP.parseChatEvent(chat_packet) == "test":
        print 'bout to move'
        print pos_look.x
        print pos_look.y
        print pos_look.z
        print pos_look.yaw
        print pos_look.pitch
        pos_look.yaw = (pos_look.yaw + 1.0) % 360.0

        # Move forward 0.1m.
        pos_look.x -= 0.1 * math.sin(pos_look.yaw * math.pi / 180.0)
        pos_look.z += 0.1 * math.cos(pos_look.yaw * math.pi / 180.0)
    
        connection.write_packet(PositionAndLookPacket(
            x         = pos_look.x,
            feet_y    = pos_look.y,
            z         = pos_look.z,
            yaw       = pos_look.yaw,
            pitch     = pos_look.pitch,
            on_ground = True))

from pycraft.

em202020 avatar em202020 commented on July 27, 2024

Is that block of code only called when you receive the PlayerPositionAndLookPacket? From my experience, you only get that packet when you join, and when your character makes an invalid movement (and the server tries to move you to a valid one, eg. if you try to move feet_y into the ground). Your problem might be that the movement might be too small to notice if it is only called once.

from pycraft.

MobAction avatar MobAction commented on July 27, 2024

It's being called upon parsing chat for a keyword. Good point on it potentially being too little to notice. I increased it by 1, but still doesn't work. What's the maximum I can move in one packet?
connection.write_packet(PositionAndLookPacket(
x = pos_look.x + 1,
feet_y = pos_look.y,
z = pos_look.z + 1,
yaw = pos_look.yaw,
pitch = pos_look.pitch,
on_ground = True))

from pycraft.

joodicator avatar joodicator commented on July 27, 2024

@MobAction You do not appear to be updating pos_look with your target coordinates, which might be causing your problems. It means that each time that command is issued, you will be moving to (approximately) the same location. If you want to increase the distance moved, you should rather do it here:

        pos_look.x -= 1 * math.sin(pos_look.yaw * math.pi / 180.0)
        pos_look.z += 1 * math.cos(pos_look.yaw * math.pi / 180.0)

from pycraft.

joodicator avatar joodicator commented on July 27, 2024

I'm closing this issue for now as there have been no comments for 8 months, but if you have further questions feel free to post them here.

from pycraft.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.