Merge branch 'forwolk/dev/location-world' into anarok/loop-3
This commit is contained in:
@@ -1,14 +1,90 @@
|
||||
package mc.core;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import mc.core.player.ILook;
|
||||
import mc.core.player.Look;
|
||||
import mc.core.world.World;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Objects;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class WarpPosition implements Serializable {
|
||||
private Location location;
|
||||
private Look look;
|
||||
public class WarpPosition extends Location implements Serializable, ILook {
|
||||
private ILook look;
|
||||
|
||||
public WarpPosition(double x, double y, double z, World world) {
|
||||
super(x, y, z, world);
|
||||
}
|
||||
|
||||
public WarpPosition(double x, double y, double z, float yaw, float pitch, World world) {
|
||||
super(x, y, z, world);
|
||||
this.look = new Look(yaw, pitch);
|
||||
}
|
||||
|
||||
public WarpPosition(double x, double y, double z) {
|
||||
super(x, y, z);
|
||||
}
|
||||
|
||||
public WarpPosition(double x, double y, double z, float yaw, float pitch) {
|
||||
super(x, y, z);
|
||||
this.look = new Look(yaw, pitch);
|
||||
}
|
||||
|
||||
public WarpPosition(long compactValue) {
|
||||
super(compactValue);
|
||||
}
|
||||
|
||||
public WarpPosition(Location location) {
|
||||
super(location.getX(), location.getY(), location.getZ());
|
||||
}
|
||||
|
||||
public WarpPosition(Location location, ILook look) {
|
||||
super(location.getX(), location.getY(), location.getZ());
|
||||
this.look = look;
|
||||
}
|
||||
|
||||
public WarpPosition(long compactValue, World world) {
|
||||
super(compactValue, world);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void set(ILook look) {
|
||||
this.look = look;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getYaw() {
|
||||
return this.look.getYaw();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setYaw(float yaw) {
|
||||
this.look.setYaw(yaw);
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getPitch() {
|
||||
return this.look.getPitch();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPitch(float pitch) {
|
||||
this.look.setPitch(pitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!super.equals(o)) return false;
|
||||
WarpPosition that = (WarpPosition) o;
|
||||
return Objects.equals(look, that.look);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(super.hashCode(), look);
|
||||
}
|
||||
|
||||
public boolean hasLook() {
|
||||
return look != null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import mc.core.Location;
|
||||
import mc.core.chat.MessageType;
|
||||
import mc.core.network.NetChannel;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.player.Look;
|
||||
import mc.core.player.ILook;
|
||||
import mc.core.player.Player;
|
||||
import mc.core.player.PlayerManager;
|
||||
import mc.core.text.Text;
|
||||
@@ -52,7 +52,7 @@ public class FakePlayerManager implements PlayerManager {
|
||||
private static final NetChannel FAKE_NET_CHANNEL = new FakeNetChannet();
|
||||
|
||||
@Override
|
||||
public Player createPlayer(String name, Location defaultLocation, Look defaultLook) {
|
||||
public Player createPlayer(String name, Location defaultLocation, ILook defaultLook) {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ package mc.core.events;
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import mc.core.player.Look;
|
||||
import mc.core.player.ILook;
|
||||
import mc.core.player.Player;
|
||||
|
||||
@RequiredArgsConstructor
|
||||
@@ -15,5 +15,5 @@ import mc.core.player.Player;
|
||||
@Setter
|
||||
public class PlayerLookEvent extends EventBase {
|
||||
private final Player player;
|
||||
private Look newLook;
|
||||
private ILook newLook;
|
||||
}
|
||||
|
||||
13
core/src/main/java/mc/core/player/ILook.java
Normal file
13
core/src/main/java/mc/core/player/ILook.java
Normal file
@@ -0,0 +1,13 @@
|
||||
package mc.core.player;
|
||||
|
||||
public interface ILook {
|
||||
void set(ILook look);
|
||||
|
||||
float getYaw();
|
||||
|
||||
float getPitch();
|
||||
|
||||
void setYaw(float yaw);
|
||||
|
||||
void setPitch(float pitch);
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public class InMemoryPlayerManager implements PlayerManager, Runnable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player createPlayer(String name, Location defaultLocation, Look defaultLook) {
|
||||
public Player createPlayer(String name, Location defaultLocation, ILook defaultLook) {
|
||||
SimplePlayer player = new SimplePlayer();
|
||||
player.setId(rand.nextInt(10000));
|
||||
player.setUUID(UUID.nameUUIDFromBytes(name.getBytes()));
|
||||
|
||||
@@ -7,15 +7,14 @@ package mc.core.player;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class Look implements Serializable{
|
||||
public class Look implements ILook {
|
||||
private float yaw, pitch;
|
||||
|
||||
public void set(Look look) {
|
||||
this.yaw = look.yaw;
|
||||
this.pitch = look.pitch;
|
||||
@Override
|
||||
public void set(ILook look) {
|
||||
this.yaw = look.getYaw();
|
||||
this.pitch = look.getPitch();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ public interface Player {
|
||||
|
||||
Location getLocation();
|
||||
|
||||
Look getLook();
|
||||
ILook getLook();
|
||||
|
||||
boolean isFlying();
|
||||
void setFlying(boolean value);
|
||||
|
||||
@@ -11,7 +11,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface PlayerManager {
|
||||
Player createPlayer(String name, Location defaultLocation, Look defaultLook);
|
||||
Player createPlayer(String name, Location defaultLocation, ILook defaultLook);
|
||||
void joinServer(Player player);
|
||||
void leftServer(Player player);
|
||||
Optional<Player> getPlayer(String name);
|
||||
|
||||
@@ -18,7 +18,7 @@ public class SimplePlayer implements Player {
|
||||
private boolean online = false;
|
||||
private NetChannel channel;
|
||||
private Location location = new Location(0, 0, 0);
|
||||
private Look look = new Look(0, 0);
|
||||
private ILook look = new Look(0, 0);
|
||||
private boolean flying = false;
|
||||
private PlayerSettings settings;
|
||||
|
||||
@@ -26,7 +26,7 @@ public class SimplePlayer implements Player {
|
||||
this.location.set(location);
|
||||
}
|
||||
|
||||
public void setLook(Look look) {
|
||||
public void setLook(ILook look) {
|
||||
this.look.set(look);
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import mc.core.Location;
|
||||
import mc.core.network.*;
|
||||
import mc.core.player.ILook;
|
||||
import mc.core.player.Look;
|
||||
|
||||
@NoArgsConstructor
|
||||
@@ -18,7 +19,7 @@ import mc.core.player.Look;
|
||||
@ToString
|
||||
public class PlayerPositionAndLookPacket implements SCPacket, CSPacket {
|
||||
private Location location;
|
||||
private Look look;
|
||||
private ILook look;
|
||||
private int teleportId;
|
||||
private boolean onGround = false;
|
||||
|
||||
|
||||
@@ -10,7 +10,6 @@ import mc.core.network.proto_1_12_2.State;
|
||||
import mc.core.network.proto_1_12_2.TeleportManager;
|
||||
import mc.core.network.proto_1_12_2.netty.wrappers.WrapperNetChannel;
|
||||
import mc.core.network.proto_1_12_2.packets.*;
|
||||
import mc.core.player.Look;
|
||||
import mc.core.player.Player;
|
||||
import mc.core.player.PlayerManager;
|
||||
import mc.core.player.PlayerMode;
|
||||
@@ -48,8 +47,8 @@ public class LoginHandler extends AbstractStateHandler implements LoginStateHand
|
||||
Player player = playerManager.getPlayer(packet.getPlayerName())
|
||||
.orElseGet(() -> playerManager.createPlayer(
|
||||
packet.getPlayerName(),
|
||||
world.getSpawn().getLocation(),
|
||||
world.getSpawn().getLook()));
|
||||
world.getSpawn(),
|
||||
world.getSpawn()));
|
||||
|
||||
channel.writeAndFlush(new LoginSuccessPacket(
|
||||
player.getUUID(),
|
||||
@@ -68,7 +67,7 @@ public class LoginHandler extends AbstractStateHandler implements LoginStateHand
|
||||
|
||||
// Spawn Position
|
||||
SpawnPositionPacket pkt2 = new SpawnPositionPacket();
|
||||
pkt2.setLocation(world.getSpawn().getLocation());
|
||||
pkt2.setLocation(world.getSpawn());
|
||||
channel.write(pkt2);
|
||||
|
||||
// Player Abilities
|
||||
|
||||
Reference in New Issue
Block a user