Spawn named entity
This commit is contained in:
@@ -20,6 +20,7 @@ public class PacketManager {
|
||||
.put(0x0B, PlayerPositionPacket.class)
|
||||
.put(0x0C, PlayerLookPacket.class)
|
||||
.put(0x0D, PositionAndLookPacket.class)
|
||||
.put(0x14, SpawnNamedEntityPacket.class)
|
||||
.put(0x32, ChunkAllocationPacket.class)
|
||||
.put(0x33, ChunkDataPacket.class)
|
||||
.put(0xC9, PlayerInfoPacket.class)
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-04-30
|
||||
*/
|
||||
package mc.core.network.proto_125.packets;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import mc.core.Location;
|
||||
import mc.core.Look;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.network.proto_125.ByteArrayOutputNetStream;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class SpawnNamedEntityPacket implements SCPacket {
|
||||
private int id;
|
||||
private String entityName;
|
||||
private Location position;
|
||||
private Look look;
|
||||
private final int currentItem = 0;
|
||||
|
||||
@Override
|
||||
public byte[] toByteArray() {
|
||||
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
|
||||
|
||||
netStream.writeInt(id);
|
||||
netStream.writeString(entityName);
|
||||
netStream.writeInt((int) position.getX());
|
||||
netStream.writeInt((int) position.getY());
|
||||
netStream.writeInt((int) position.getZ());
|
||||
netStream.writeByte((byte)(int)((look.getYaw() * 256f) / 360f));
|
||||
netStream.writeByte((byte)(int)((look.getPitch() * 256f) / 360f));
|
||||
netStream.writeShort(currentItem);
|
||||
|
||||
return netStream.toByteArray();
|
||||
}
|
||||
}
|
||||
@@ -139,11 +139,19 @@ public class PacketHandler extends SimpleChannelInboundHandler<CSPacket> {
|
||||
posLookPkt.setLook(player.getLook());
|
||||
posLookPkt.setOnGround(false);
|
||||
channel.write(posLookPkt);
|
||||
channel.flush();
|
||||
|
||||
// send Spawn named entity
|
||||
SpawnNamedEntityPacket spawnPlayer = new SpawnNamedEntityPacket();
|
||||
spawnPlayer.setId(player.getId());
|
||||
spawnPlayer.setEntityName(player.getName());
|
||||
spawnPlayer.setPosition(player.getLocation());
|
||||
spawnPlayer.setLook(player.getLook());
|
||||
playerManager.getBroadcastChannel().writeAndFlush(spawnPlayer);
|
||||
|
||||
channel.attr(ATTR_PLAYER).set(player);
|
||||
player.setChannel(new WrapperNetChannel(channel));
|
||||
playerManager.joinServer(player);
|
||||
channel.flush();
|
||||
}
|
||||
|
||||
public void onKickPacket(Channel channel, KickPacket packet) {
|
||||
|
||||
Reference in New Issue
Block a user