видно новых игроков и их передвижения
This commit is contained in:
@@ -16,6 +16,7 @@ import mc.core.chat.ChatProcessor;
|
||||
import mc.core.chat.ChatStyle;
|
||||
import mc.core.events.*;
|
||||
import mc.core.network.CSPacket;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.network.proto_125.netty.wrappers.WrapperNetChannel;
|
||||
import mc.core.network.proto_125.packets.*;
|
||||
import mc.core.player.Look;
|
||||
@@ -29,6 +30,7 @@ import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@Slf4j
|
||||
public class PacketHandler extends SimpleChannelInboundHandler<CSPacket> {
|
||||
@@ -192,11 +194,22 @@ public class PacketHandler extends SimpleChannelInboundHandler<CSPacket> {
|
||||
EventBusGetter.INSTANCE.post(event);
|
||||
|
||||
if (!event.isCanceled()) {
|
||||
player.getLocation().setX(event.getNewPosition().getX());
|
||||
player.getLocation().setY(event.getNewPosition().getY());
|
||||
player.getLocation().setZ(event.getNewPosition().getZ());
|
||||
Location diffLoc = event.getNewPosition().diff(player.getLocation());
|
||||
player.getLocation().set(event.getNewPosition());
|
||||
|
||||
//TODO если позиция была изменена, нужно оповестить клиент
|
||||
|
||||
final SCPacket pkt;
|
||||
if ((diffLoc.getBlockX() >= 4 || diffLoc.getBlockX() <= -4)
|
||||
|| (diffLoc.getBlockY() >= 4 || diffLoc.getBlockY() <= -4)
|
||||
|| (diffLoc.getBlockZ() >= 4 || diffLoc.getBlockZ() <= -4)) {
|
||||
pkt = new EntityTeleportPacket(player.getId(), player.getLocation(), player.getLook());
|
||||
} else {
|
||||
pkt = new EntityRelativeMovePacket(player.getId(), diffLoc);
|
||||
}
|
||||
playerManager.getPlayers().stream()
|
||||
.filter(pl -> pl.getId() != player.getId())
|
||||
.forEach(pl -> pl.getChannel().writeAndFlush(pkt));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -207,10 +220,45 @@ public class PacketHandler extends SimpleChannelInboundHandler<CSPacket> {
|
||||
EventBusGetter.INSTANCE.post(event);
|
||||
|
||||
if (!event.isCanceled()) {
|
||||
player.getLook().setYaw(event.getNewLook().getYaw());
|
||||
player.getLook().setPitch(event.getNewLook().getPitch());
|
||||
player.getLook().set(event.getNewLook());
|
||||
|
||||
//TODO если обзор был изменен, нужно оповестить клиент
|
||||
|
||||
final SCPacket pkt1 = new EntityLookPacket(player.getId(), player.getLook());
|
||||
final SCPacket pkt2 = new EntityLookHeadPacket(player.getId(), player.getLook().getYaw());
|
||||
playerManager.getPlayers().stream()
|
||||
.filter(pl -> pl.getId() != player.getId())
|
||||
.forEach(pl -> {
|
||||
pl.getChannel().write(pkt1);
|
||||
pl.getChannel().write(pkt2);
|
||||
pl.getChannel().flush();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void onPositionAndLookPacket(Channel channel, PositionAndLookPacket packet) {
|
||||
Player player = channel.attr(ATTR_PLAYER).get();
|
||||
|
||||
Location diffLoc = packet.getLocation().diff(player.getLocation());
|
||||
player.getLocation().set(packet.getLocation());
|
||||
player.getLook().set(packet.getLook());
|
||||
|
||||
Stream<Player> stream = playerManager.getPlayers().stream()
|
||||
.filter(pl -> pl.getId() != player.getId());
|
||||
|
||||
if ((diffLoc.getBlockX() >= 4 || diffLoc.getBlockX() <= -4)
|
||||
|| (diffLoc.getBlockY() >= 4 || diffLoc.getBlockY() <= -4)
|
||||
|| (diffLoc.getBlockZ() >= 4 || diffLoc.getBlockZ() <= -4)) {
|
||||
final SCPacket pkt = new EntityTeleportPacket(player.getId(), player.getLocation(), player.getLook());
|
||||
stream.forEach(pl -> pl.getChannel().writeAndFlush(pkt));
|
||||
} else {
|
||||
final SCPacket pkt1 = new EntityLookRelativeMovePacket(player.getId(), diffLoc, player.getLook());
|
||||
final SCPacket pkt2 = new EntityLookHeadPacket(player.getId(), player.getLook().getYaw());
|
||||
stream.forEach(pl -> {
|
||||
pl.getChannel().write(pkt1);
|
||||
pl.getChannel().write(pkt2);
|
||||
pl.getChannel().flush();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -35,4 +35,14 @@ public class WrapperNetChannel implements NetChannel {
|
||||
public void writeAndFlush(SCPacket pkt) {
|
||||
channel.writeAndFlush(pkt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(SCPacket pkt) {
|
||||
channel.write(pkt);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
channel.flush();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user