SpawnPosition
This commit is contained in:
@@ -3,24 +3,6 @@
|
|||||||
* 2018-04-10
|
* 2018-04-10
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
http://wiki.vg/index.php?title=Protocol_FAQ&oldid=76
|
|
||||||
-- -- --
|
|
||||||
C - Client
|
|
||||||
S - Server
|
|
||||||
-- -- --
|
|
||||||
C -> S : Connects
|
|
||||||
C -> S : Sends handshake
|
|
||||||
S -> C : Sends handshake response
|
|
||||||
C -> S : After authenticating (if needed), sends the login packet
|
|
||||||
S -> C : Either kicks (invalid login) or sends a login response
|
|
||||||
S -> C : Sends pre-chunks and chunks and entities
|
|
||||||
S -> C : Sends spawn position
|
|
||||||
S -> C : Sends inventory [Need to verify this since inventory changed] (beta 1.1_02: looks like Window items with type=0, then a Set slot with window id = -1 and slot = -1)
|
|
||||||
S -> C : Tell the client they're ready to spawn by sending a position + look packet. Note: The stance and Y should be swapped when the server sends it to the client
|
|
||||||
C -> S : Sends a position + look packet to confirm the spawn position, with the stance and Y swapped back to the correct positions
|
|
||||||
*/
|
|
||||||
|
|
||||||
package mc.core.network.proto_125.netty;
|
package mc.core.network.proto_125.netty;
|
||||||
|
|
||||||
import io.netty.channel.Channel;
|
import io.netty.channel.Channel;
|
||||||
@@ -77,19 +59,26 @@ public class PacketHandler extends SimpleChannelInboundHandler<CSPacket> {
|
|||||||
|
|
||||||
public void onLoginPacket(Channel channel, LoginPacket packet) {
|
public void onLoginPacket(Channel channel, LoginPacket packet) {
|
||||||
int pId = random.nextInt(9999);
|
int pId = random.nextInt(9999);
|
||||||
|
Location spawnLoc = new Location(0, 65, 0);
|
||||||
|
|
||||||
|
NettyPlayer player = new NettyPlayer();
|
||||||
|
player.setId(pId);
|
||||||
|
player.setName(packet.getPlayerName());
|
||||||
|
player.setChannel(new WrapperNetChannel(channel));
|
||||||
|
|
||||||
|
// Response login
|
||||||
packet.setPlayerId(pId);
|
packet.setPlayerId(pId);
|
||||||
packet.setLevelType("FLAT");
|
packet.setLevelType("flat");
|
||||||
packet.setServerMode(1/*creative*/);
|
packet.setServerMode(1/*creative*/);
|
||||||
packet.setDimension(0/*Overworld*/);
|
packet.setDimension(0/*Overworld*/);
|
||||||
packet.setDifficulty(0/*Peaceful*/);
|
packet.setDifficulty(0/*Peaceful*/);
|
||||||
packet.setMaxPlayers(config.getMaxPlayers());
|
packet.setMaxPlayers(config.getMaxPlayers());
|
||||||
channel.write(packet);
|
channel.write(packet);
|
||||||
|
|
||||||
NettyPlayer player = new NettyPlayer();
|
// send Spawn position
|
||||||
player.setId(pId);
|
SpawnPositionPacket spawnPkt = new SpawnPositionPacket();
|
||||||
player.setName(packet.getPlayerName());
|
spawnPkt.setLocation(spawnLoc);
|
||||||
player.setChannel(new WrapperNetChannel(channel));
|
channel.write(spawnPkt);
|
||||||
|
|
||||||
PositionAndLookPacket pkt = new PositionAndLookPacket();
|
PositionAndLookPacket pkt = new PositionAndLookPacket();
|
||||||
pkt.setLocation(new Location(0, 0, 0));
|
pkt.setLocation(new Location(0, 0, 0));
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ public class PacketManager {
|
|||||||
private static final BiMap<Integer, Class<?>> packetMap = ImmutableBiMap.<Integer, Class<?>>builder()
|
private static final BiMap<Integer, Class<?>> packetMap = ImmutableBiMap.<Integer, Class<?>>builder()
|
||||||
.put(0x01, LoginPacket.class)
|
.put(0x01, LoginPacket.class)
|
||||||
.put(0x02, HandshakePacket.class)
|
.put(0x02, HandshakePacket.class)
|
||||||
|
.put(0x06, SpawnPositionPacket.class)
|
||||||
.put(0x0D, PositionAndLookPacket.class)
|
.put(0x0D, PositionAndLookPacket.class)
|
||||||
.put(0xFE, PingPacket.class)
|
.put(0xFE, PingPacket.class)
|
||||||
.put(0xFF, KickPacket.class)
|
.put(0xFF, KickPacket.class)
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
/*
|
||||||
|
* DmitriyMX <dimon550@gmail.com>
|
||||||
|
* 2018-04-19
|
||||||
|
*/
|
||||||
|
package mc.core.network.proto_125.packets;
|
||||||
|
|
||||||
|
import lombok.Setter;
|
||||||
|
import lombok.ToString;
|
||||||
|
import mc.core.Location;
|
||||||
|
import mc.core.network.SCPacket;
|
||||||
|
import mc.core.network.proto_125.ByteArrayOutputNetStream;
|
||||||
|
|
||||||
|
@Setter
|
||||||
|
@ToString
|
||||||
|
public class SpawnPositionPacket implements SCPacket {
|
||||||
|
private Location location;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public byte[] toByteArray() {
|
||||||
|
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
|
||||||
|
|
||||||
|
netStream.writeInt((int) location.getX());
|
||||||
|
netStream.writeInt((int) location.getY());
|
||||||
|
netStream.writeInt((int) location.getZ());
|
||||||
|
|
||||||
|
return netStream.toByteArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user