apply upgraded Location & EntityLocation
This commit is contained in:
@@ -1,14 +0,0 @@
|
||||
package mc.core;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import mc.core.player.Look;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
public class WarpPosition implements Serializable {
|
||||
private Location location;
|
||||
private Look look;
|
||||
}
|
||||
@@ -4,11 +4,10 @@
|
||||
*/
|
||||
package mc.core.embedded;
|
||||
|
||||
import mc.core.Location;
|
||||
import mc.core.EntityLocation;
|
||||
import mc.core.chat.MessageType;
|
||||
import mc.core.network.NetChannel;
|
||||
import mc.core.network.SCPacket;
|
||||
import mc.core.player.Look;
|
||||
import mc.core.player.Player;
|
||||
import mc.core.player.PlayerManager;
|
||||
import mc.core.text.Text;
|
||||
@@ -52,7 +51,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, EntityLocation defaultLocation) {
|
||||
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.EntityLocation;
|
||||
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 EntityLocation newLook;
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ package mc.core.player;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.Config;
|
||||
import mc.core.EntityLocation;
|
||||
import mc.core.Location;
|
||||
import mc.core.network.BroadcastNetChannel;
|
||||
import mc.core.network.NetChannel;
|
||||
@@ -31,13 +32,13 @@ public class InMemoryPlayerManager implements PlayerManager, Runnable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Player createPlayer(String name, Location defaultLocation, Look defaultLook) {
|
||||
public Player createPlayer(String name, EntityLocation defaultLocation) {
|
||||
SimplePlayer player = new SimplePlayer();
|
||||
player.setId(rand.nextInt(10000));
|
||||
player.setUUID(UUID.nameUUIDFromBytes(name.getBytes()));
|
||||
player.setName(name);
|
||||
player.getLocation().set(defaultLocation);
|
||||
player.getLook().set(defaultLook);
|
||||
player.getLocation().setXYZ(defaultLocation);
|
||||
player.getLocation().setYawPitch(defaultLocation);
|
||||
player.setSettings(new PlayerSettings());
|
||||
|
||||
synchronized (lock) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
package mc.core.player;
|
||||
|
||||
import mc.core.EntityLocation;
|
||||
import mc.core.Location;
|
||||
import mc.core.network.NetChannel;
|
||||
|
||||
@@ -18,9 +19,7 @@ public interface Player {
|
||||
NetChannel getChannel();
|
||||
void setChannel(NetChannel channel);
|
||||
|
||||
Location getLocation();
|
||||
|
||||
Look getLook();
|
||||
EntityLocation getLocation();
|
||||
|
||||
boolean isFlying();
|
||||
void setFlying(boolean value);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
package mc.core.player;
|
||||
|
||||
import mc.core.EntityLocation;
|
||||
import mc.core.Location;
|
||||
import mc.core.network.NetChannel;
|
||||
|
||||
@@ -11,7 +12,7 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
public interface PlayerManager {
|
||||
Player createPlayer(String name, Location defaultLocation, Look defaultLook);
|
||||
Player createPlayer(String name, EntityLocation defaultLocation);
|
||||
void joinServer(Player player);
|
||||
void leftServer(Player player);
|
||||
Optional<Player> getPlayer(String name);
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
package mc.core.player;
|
||||
|
||||
import lombok.Data;
|
||||
import mc.core.EntityLocation;
|
||||
import mc.core.Location;
|
||||
import mc.core.network.NetChannel;
|
||||
|
||||
@@ -17,17 +18,13 @@ public class SimplePlayer implements Player {
|
||||
private String name;
|
||||
private boolean online = false;
|
||||
private NetChannel channel;
|
||||
private Location location = new Location(0, 0, 0);
|
||||
private Look look = new Look(0, 0);
|
||||
private EntityLocation location = new EntityLocation(0d, 0d, 0d, 0f, 0f, null);
|
||||
private boolean flying = false;
|
||||
private PlayerSettings settings;
|
||||
|
||||
public void setLocation(Location location) {
|
||||
this.location.set(location);
|
||||
}
|
||||
|
||||
public void setLook(Look look) {
|
||||
this.look.set(look);
|
||||
public void setLocation(EntityLocation location) {
|
||||
this.location.setXYZ(location);
|
||||
this.location.setYawPitch(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
package mc.core.world;
|
||||
|
||||
import mc.core.WarpPosition;
|
||||
import mc.core.EntityLocation;
|
||||
import mc.core.nbt.Taggable;
|
||||
import mc.core.world.chunk.Chunk;
|
||||
|
||||
@@ -46,8 +46,8 @@ public interface World extends Taggable, Serializable{
|
||||
UUID getWorldId();
|
||||
IWorldType getWorldType();
|
||||
|
||||
WarpPosition getSpawn();
|
||||
void setSpawn(WarpPosition location);
|
||||
EntityLocation getSpawn();
|
||||
void setSpawn(EntityLocation location);
|
||||
|
||||
Chunk getChunk(int x, int y, int z);
|
||||
void setChunk(int x, int y, int z, Chunk chunk);
|
||||
|
||||
@@ -22,7 +22,7 @@ public class BlockFactory {
|
||||
private class EmbeddedBlock extends AbstractBlock {
|
||||
EmbeddedBlock(BlockType type, int meta, int x, int y, int z) {
|
||||
super(type, meta);
|
||||
super.setLocation(new Location(x,y,z));
|
||||
super.setLocation(new Location(x,y,z, null));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,9 +7,7 @@ package mc.world.flat;
|
||||
import com.flowpowered.nbt.Tag;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import mc.core.Location;
|
||||
import mc.core.WarpPosition;
|
||||
import mc.core.player.Look;
|
||||
import mc.core.EntityLocation;
|
||||
import mc.core.world.*;
|
||||
import mc.core.world.chunk.Chunk;
|
||||
|
||||
@@ -27,7 +25,7 @@ public class FlatWorld implements World {
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
private WarpPosition spawn = new WarpPosition(new Location(0, 6, 0), new Look(0, 0));
|
||||
private EntityLocation spawn = new EntityLocation(0d, 6d, 0d, 0f, 0f, this);
|
||||
private Chunk chunk = new SimpleChunk(0, 0, 0); //FIXME temporary dummy
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,7 +2,7 @@ package mc.world.generated_world.serialization;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.WarpPosition;
|
||||
import mc.core.EntityLocation;
|
||||
import mc.core.world.World;
|
||||
import mc.world.generated_world.world.CubicWorld;
|
||||
|
||||
@@ -55,7 +55,7 @@ public class WorldReaderWriter {
|
||||
|
||||
@Data
|
||||
public static class WorldInfo implements Serializable {
|
||||
private WarpPosition spawn;
|
||||
private EntityLocation spawn;
|
||||
private String name;
|
||||
private int seed;
|
||||
}
|
||||
|
||||
@@ -4,10 +4,9 @@ import com.flowpowered.nbt.Tag;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import mc.core.EntityLocation;
|
||||
import mc.core.Location;
|
||||
import mc.core.WarpPosition;
|
||||
import mc.core.world.block.BlockType;
|
||||
import mc.core.player.Look;
|
||||
import mc.core.world.chunk.Chunk;
|
||||
import mc.core.world.IWorldType;
|
||||
import mc.core.world.Region;
|
||||
@@ -27,7 +26,7 @@ public class CubicWorld implements World {
|
||||
@Getter
|
||||
private final UUID worldId;
|
||||
private final int seed;
|
||||
private volatile WarpPosition warpPosition;
|
||||
private volatile EntityLocation warpPosition;
|
||||
private final transient Object spawnLocationLock = new Object();
|
||||
private final Map<String, Tag<?>> nbtTagMap = new HashMap<>();
|
||||
@Autowired
|
||||
@@ -61,20 +60,20 @@ public class CubicWorld implements World {
|
||||
}
|
||||
|
||||
@Override
|
||||
public WarpPosition getSpawn() {
|
||||
public EntityLocation getSpawn() {
|
||||
if (warpPosition == null) {
|
||||
synchronized (spawnLocationLock) {
|
||||
if (warpPosition == null) {
|
||||
log.warn("Spawn location is not defined. Trying to select best location");
|
||||
warpPosition = new WarpPosition(Location.startPointLocation(), new Look(0, 0));
|
||||
warpPosition = new EntityLocation(0d, 10d, 0d, 0f, 0f, this);
|
||||
for (int y = WORLD_MAX_HEIGHT; y > 0; y --) {
|
||||
Chunk chunk = getChunk(0,y / WORLD_CHUNK_SIZE, 0);
|
||||
if (chunk.getBlock(0, y, 0).getBlockType() != BlockType.AIR) {
|
||||
warpPosition = new WarpPosition(new Location(0, y + 1, 0), new Look(0, 0));
|
||||
warpPosition = new EntityLocation(0d, y + 1d, 0d, 0f, 0f, this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
warpPosition = new WarpPosition(Location.startPointLocation(), new Look(0,0));
|
||||
warpPosition = new EntityLocation(0d, 10d, 0d, 0f, 0f, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,7 +81,7 @@ public class CubicWorld implements World {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSpawn(WarpPosition warpPosition) {
|
||||
public void setSpawn(EntityLocation warpPosition) {
|
||||
synchronized (spawnLocationLock) {
|
||||
this.warpPosition = warpPosition;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
package mc.core.network.proto_1_12_2;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import mc.core.EntityLocation;
|
||||
import mc.core.Location;
|
||||
import mc.core.player.Player;
|
||||
|
||||
@@ -22,7 +23,7 @@ public class TeleportManager {
|
||||
@AllArgsConstructor
|
||||
private class TpData {
|
||||
public Player player;
|
||||
public Location newLocation;
|
||||
public EntityLocation newLocation;
|
||||
// TODO необходимо добавить TimeStamp, что бы понимать, когда клиент отвергнул телепортацию
|
||||
// т.е. идея такова: долгое молчание клиента знак отвержения телепортации.
|
||||
}
|
||||
@@ -32,7 +33,7 @@ public class TeleportManager {
|
||||
|
||||
private TeleportManager() {}
|
||||
|
||||
public int append(Player player, Location location) {
|
||||
public int append(Player player, EntityLocation location) {
|
||||
int teleportId;
|
||||
do {
|
||||
teleportId = RAND.nextInt(9999);
|
||||
@@ -45,7 +46,8 @@ public class TeleportManager {
|
||||
public void apply(int teleportId) {
|
||||
if (teleportMap.containsKey(teleportId)) {
|
||||
TpData data = teleportMap.remove(teleportId);
|
||||
data.player.getLocation().set(data.newLocation);
|
||||
data.player.getLocation().setXYZ(data.newLocation);
|
||||
data.player.getLocation().setYawPitch(data.newLocation);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,17 +8,15 @@ import lombok.Getter;
|
||||
import lombok.NoArgsConstructor;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
import mc.core.Location;
|
||||
import mc.core.EntityLocation;
|
||||
import mc.core.network.*;
|
||||
import mc.core.player.Look;
|
||||
|
||||
@NoArgsConstructor
|
||||
@Getter
|
||||
@Setter
|
||||
@ToString
|
||||
public class PlayerPositionAndLookPacket implements SCPacket, CSPacket {
|
||||
private Location location;
|
||||
private Look look;
|
||||
private EntityLocation location;
|
||||
private int teleportId;
|
||||
private boolean onGround = false;
|
||||
|
||||
@@ -27,9 +25,9 @@ public class PlayerPositionAndLookPacket implements SCPacket, CSPacket {
|
||||
netStream.writeDouble(location.getX());
|
||||
netStream.writeDouble(location.getY());
|
||||
netStream.writeDouble(location.getZ());
|
||||
netStream.writeFloat(look.getYaw());
|
||||
netStream.writeFloat(look.getPitch());
|
||||
netStream.writeByte(0); // It's a bitfield, X/Y/Z/Y_ROT/X_ROT. If X is set, the x value is relative and not absolute.
|
||||
netStream.writeFloat(location.getYaw());
|
||||
netStream.writeFloat(location.getPitch());
|
||||
netStream.writeByte(0); // It's a bitfield, X/Y/Z/Y_ROT/X_ROT. If X is setXYZ, the x value is relative and not absolute.
|
||||
/* X - 0x01
|
||||
* Y - 0x02
|
||||
* Z - 0x04
|
||||
@@ -41,15 +39,13 @@ public class PlayerPositionAndLookPacket implements SCPacket, CSPacket {
|
||||
|
||||
@Override
|
||||
public void readSelf(NetInputStream netStream) {
|
||||
this.location = new Location(
|
||||
this.location = new EntityLocation(
|
||||
netStream.readDouble(),
|
||||
netStream.readDouble(),
|
||||
netStream.readDouble(),
|
||||
netStream.readDouble()
|
||||
);
|
||||
|
||||
this.look = new Look(
|
||||
netStream.readFloat(),
|
||||
netStream.readFloat()
|
||||
netStream.readFloat(),
|
||||
null
|
||||
);
|
||||
|
||||
this.onGround = netStream.readBoolean();
|
||||
|
||||
@@ -19,8 +19,19 @@ import mc.core.network.SCPacket;
|
||||
public class SpawnPositionPacket implements SCPacket {
|
||||
private Location location;
|
||||
|
||||
private int floor_double(double value) {
|
||||
int i = (int)value;
|
||||
return value < (double)i ? i - 1 : i;
|
||||
}
|
||||
|
||||
private long location2long(Location location) {
|
||||
return ((floor_double(location.getX()) & 0x3FFFFFF) << 38)
|
||||
| ((floor_double(location.getY()) & 0xFFF) << 26)
|
||||
| (floor_double(location.getZ()) & 0x3FFFFFF);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeSelf(NetOutputStream netStream) {
|
||||
netStream.writeLong(location.toLong());
|
||||
netStream.writeLong(location2long(location));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,13 @@ public class TabCompletePacket implements CSPacket {
|
||||
this.hasPosition = netStream.readBoolean();
|
||||
|
||||
if (this.hasPosition) {
|
||||
this.location = new Location(netStream.readLong());
|
||||
long compactValue = netStream.readLong();
|
||||
|
||||
double x = compactValue >> 38;
|
||||
double y = (compactValue >> 26) & 0xFFF;
|
||||
double z = compactValue << 38 >> 38; // is normal?
|
||||
|
||||
this.location = new Location(x, y, z, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,7 @@ public class LoginHandler extends AbstractStateHandler implements LoginStateHand
|
||||
Player player = playerManager.getPlayer(packet.getPlayerName())
|
||||
.orElseGet(() -> playerManager.createPlayer(
|
||||
packet.getPlayerName(),
|
||||
world.getSpawn().getLocation(),
|
||||
new Look(0f, 0f)));
|
||||
world.getSpawn()));
|
||||
|
||||
channel.writeAndFlush(new LoginSuccessPacket(
|
||||
player.getUUID(),
|
||||
@@ -68,7 +66,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
|
||||
@@ -91,7 +89,6 @@ public class LoginHandler extends AbstractStateHandler implements LoginStateHand
|
||||
// Player Position And Look
|
||||
PlayerPositionAndLookPacket pkt4 = new PlayerPositionAndLookPacket();
|
||||
pkt4.setLocation(player.getLocation());
|
||||
pkt4.setLook(player.getLook());
|
||||
pkt4.setTeleportId(TeleportManager.getInstance().append(player, player.getLocation()));
|
||||
channel.writeAndFlush(pkt4);
|
||||
|
||||
|
||||
@@ -52,8 +52,8 @@ public class PlayHandler extends AbstractStateHandler implements PlayStateHandle
|
||||
@Handler
|
||||
public void onPositionAndLook(Channel channel, PlayerPositionAndLookPacket packet) {
|
||||
Player player = channel.attr(ATTR_PLAYER).get();
|
||||
player.getLocation().set(packet.getLocation());
|
||||
player.getLook().set(packet.getLook());
|
||||
player.getLocation().setXYZ(packet.getLocation());
|
||||
player.getLocation().setYawPitch(packet.getLocation());
|
||||
}
|
||||
|
||||
@Handler
|
||||
|
||||
Reference in New Issue
Block a user