Comments (18)
-
I noticed just now that the packet ID for PlayerPositionAndLookPacket (the clientbound packet) was incorrect in pyCraft, which would have made this a bit difficult to do properly. That has been fixed by 2cf1d3c.
-
I would note that pyCraft automatically sends Teleport Confirm packets when requested, so it is not necessary to do that manually.
-
@BloodySenpai In case the previous example was unclear, here is a full working example of movement using pyCraft. The player moves around continuously in a circle, unless stopped by an obstacle. It assumes a server running in offline mode, and works best if the player is on a flat surface, or in the air in creative mode.
import threading
import time
import math
from minecraft.networking.connection import Connection
from minecraft.networking.packets import PlayerPositionAndLookPacket
from minecraft.networking.packets import PositionAndLookPacket
# Protect objects accessed by multiple threads with a lock.
lock = threading.Lock()
# The player's current position and look direction.
pos_look = PlayerPositionAndLookPacket.PositionAndLook()
# This conditions occurs when the server sets (or resets) pos_look.
pos_look_set = threading.Condition(lock)
conn = Connection('localhost', username='User')
def h_position_and_look(packet):
with lock:
packet.apply(pos_look)
pos_look_set.notify_all()
conn.register_packet_listener(h_position_and_look, PlayerPositionAndLookPacket)
conn.connect()
# Wait until our initial position is set by the server.
with lock:
pos_look_set.wait()
while True:
# Every 1 tick (50ms):
time.sleep(0.05)
with lock:
# Rotate 1 degree to the right.
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)
conn.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.
from minecraft.networking.connection import Connection
from minecraft.networking.packets import PositionAndLookPacket
conn = Connection(...)
conn.connect()
...
packet = PositionAndLookPacket(x=..., feet_y=..., z=..., yaw=..., pitch=..., on_ground=...)
conn.write_packet(packet)
Is this what you mean?
See also: http://wiki.vg/Protocol#Player_Position_And_Look_.28serverbound.29
from pycraft.
yes that's what I mean thannks m8
from pycraft.
I tried to write packets passes but my character does not move
from pycraft.
do you send the teleport response? http://wiki.vg/Protocol#Teleport_Confirm
also this might still help even though a lot of it is outdated
from pycraft.
@BloodySenpai It would be better to keep discussions on this repository to issues with pyCraft itself, rather than Minecraft's protocol in general. For the latter, #mcdevs on irc.freenode.net is a better forum.
However, insofar as your problem relates to pyCraft's API, post your code or a minimal test case, and I'll have a look at it.
from pycraft.
I'm sorry I'm new to this so I wouldn't know. I just did what you sent as code
from pycraft.
I just don't know how to use both chat and position at the same time.
I get this error TypeError: unsupported operand type(s) for +: 'NoneType' and 'float'
from pycraft.
@BloodySenpai You will have to be more specific than that. It is possible to use chat and position packets at the same time, of course, but there are many ways that could be done.
Did you get that type error from the code I posted? If so, please post a full stack trace. If not, you should post the code that is causing it.
from pycraft.
Is there any other way I can contact you? Like email or stuff like that?
from pycraft.
I'm use the example that they gave with library
from pycraft.
connection.register_packet_listener(print_chat, ChatMessagePacket,PlayerPositionAndLookPacket)
elif "Position" in text:
print True
packet = PlayerPositionAndLookPacket()
print "true1"
pos_look = PlayerPositionAndLookPacket.PositionAndLook()
print pos_look
print "true2"
packet = ChatPacket()
packet.message = "Status:1 Passed Movement Packet"
connection.write_packet(packet)
pos_look.yaw = (pos_look.yaw + 1.0) % 360.0
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))
print "Passed that shit"
packet.apply(pos_look)
print True
from pycraft.
@BloodySenpai The code you have posted there appears to be incomplete (and not properly indented or formatted), so I can't say much about it. You should post the full code you are using so that I can run it myself if I need to.
However, the error you are getting is probably from the fact that you're using the uninitialised value of pos_look.yaw
in an arithmethic expression. PositionAndLook
instances need to receive an initial value, such as from the first PlayerPositionAndLookPacket
the server sends. That is why my example waits for this to happen before continuing.
We can continue this conversation by email. Email me at ''.join(reversed('[email protected]'))
.
from pycraft.
hi , i'd check this code and added to my bot. it looks like work
but unfortunately it will caused my bot kicked for flying status. i'd already change the 1 stick to 1.5s which i think it cant be send too fast. so is it because i should wait the server confirm before i send the next packet?
from pycraft.
@yunfan If you're referring to the code from this comment, the reason you are being kicked for "flying" is most likely because this example assumes the player is initially standing on a flat surface large enough for the player to walk around in a circle, but in your world it ends up walking off the edge of a block and into the air. This example (and pyCraft in general) does not implement the physics required to remain on the ground while walking around.
from pycraft.
@joodicator thanks for the replying, after some trying, i got the same conclution, i'll check that later.
also i havnt saw any event emiting examples, would you recommand some sample code for it? i intent to make a bot which could move and dig
from pycraft.
@yunfan start.py contains some basic examples of sending packets, which is what I interpret you to mean by "event emitting", but as far as I know nobody has used pyCraft to implement anything as advanced as a bot that walks around and digs. If you do choose to do this yourself, your experience might be valuable for others, though.
from pycraft.
@joodicator thanks, i already read the code again and again, and learnt a lot, but i do remember there was a python library which is event based and could emit your own event just like the js implementation by rom1514. but that library has stopped since 1.7.2
from pycraft.
Related Issues (20)
- How to reconnect to the server? HOT 1
- attempting to write None field (workaround included)
- 1.19 support? HOT 24
- Unable to dig block HOT 3
- 1.18.2 support HOT 1
- disconnect.timeout HOT 1
- Logging in, getting 403 invalid credentials. HOT 2
- We need pyCraft3 HOT 5
- a1.2.6 supported?
- Rooted Roku HOT 4
- Baritone Bot integration? HOT 1
- 1.18.2 support?
- Microsoft authentication failure HOT 2
- Can't import Minecraft from PyCraft?
- 1.19 and 1.20 support ? HOT 2
- 支持1.20.2?
- 1.20. support? HOT 1
- "ModuleNotFoundError: No module named 'mutf8'" HOT 2
- PlayerPositionAndLookPacket
- 1.20.6 porting
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pycraft.