Location
This commit is contained in:
14
src/main/java/mc/core/Location.java
Normal file
14
src/main/java/mc/core/Location.java
Normal file
@@ -0,0 +1,14 @@
|
||||
/*
|
||||
* DmitriyMX <dimon550@gmail.com>
|
||||
* 2018-04-15
|
||||
*/
|
||||
package mc.core;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Location {
|
||||
private double x, y, z;
|
||||
}
|
||||
@@ -10,4 +10,6 @@ public interface Player {
|
||||
int getId();
|
||||
String getName();
|
||||
NetChannel getChannel();
|
||||
Location getLocation();
|
||||
void setLocation(Location location);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ package mc.core.network.proto_125.netty;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import mc.core.Location;
|
||||
import mc.core.Player;
|
||||
import mc.core.network.NetChannel;
|
||||
|
||||
@@ -15,4 +16,5 @@ public class NettyPlayer implements Player {
|
||||
private int id;
|
||||
private String name;
|
||||
private NetChannel channel;
|
||||
private Location location;
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import io.netty.channel.Channel;
|
||||
import io.netty.channel.ChannelHandlerContext;
|
||||
import io.netty.channel.SimpleChannelInboundHandler;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.Location;
|
||||
import mc.core.PlayerManager;
|
||||
import mc.core.network.CSPacket;
|
||||
import mc.core.Config;
|
||||
@@ -91,9 +92,7 @@ public class PacketHandler extends SimpleChannelInboundHandler<CSPacket> {
|
||||
player.setChannel(new WrapperNetChannel(channel));
|
||||
|
||||
PositionAndLookPacket pkt = new PositionAndLookPacket();
|
||||
pkt.setX(0);
|
||||
pkt.setY(0);
|
||||
pkt.setZ(0);
|
||||
pkt.setLocation(new Location(0, 0, 0));
|
||||
pkt.setStance(0);
|
||||
pkt.setYaw(0f);
|
||||
pkt.setPitch(0f);
|
||||
|
||||
@@ -7,6 +7,7 @@ package mc.core.network.proto_125.packets;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import mc.core.Location;
|
||||
import mc.core.network.CSPacket;
|
||||
import mc.core.network.NetStream;
|
||||
import mc.core.network.SCPacket;
|
||||
@@ -16,29 +17,32 @@ import mc.core.network.proto_125.ByteArrayOutputNetStream;
|
||||
@Setter
|
||||
@ToString
|
||||
public class PositionAndLookPacket implements SCPacket, CSPacket {
|
||||
private double x, y, z, stance;
|
||||
private Location location;
|
||||
private double stance;
|
||||
private float yaw, pitch;
|
||||
private boolean onGround;
|
||||
|
||||
@Override
|
||||
public void readSelf(NetStream netStream) {
|
||||
x = netStream.readDouble();
|
||||
y = netStream.readDouble();
|
||||
double x = netStream.readDouble();
|
||||
double y = netStream.readDouble();
|
||||
stance = netStream.readDouble();
|
||||
z = netStream.readDouble();
|
||||
double z = netStream.readDouble();
|
||||
yaw = netStream.readFloat();
|
||||
pitch = netStream.readFloat();
|
||||
onGround = netStream.readBoolean();
|
||||
|
||||
location = new Location(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] toByteArray() {
|
||||
ByteArrayOutputNetStream netStream = new ByteArrayOutputNetStream();
|
||||
|
||||
netStream.writeDouble(x);
|
||||
netStream.writeDouble(y);
|
||||
netStream.writeDouble(location.getX());
|
||||
netStream.writeDouble(location.getY());
|
||||
netStream.writeDouble(stance);
|
||||
netStream.writeDouble(z);
|
||||
netStream.writeDouble(location.getZ());
|
||||
netStream.writeFloat(yaw);
|
||||
netStream.writeFloat(pitch);
|
||||
netStream.writeBoolean(onGround);
|
||||
|
||||
Reference in New Issue
Block a user