Location world reference
This commit is contained in:
@@ -4,15 +4,16 @@
|
|||||||
*/
|
*/
|
||||||
package mc.core;
|
package mc.core;
|
||||||
|
|
||||||
import lombok.AllArgsConstructor;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import mc.core.world.World;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
|
|
||||||
@AllArgsConstructor
|
|
||||||
@Data
|
@Data
|
||||||
public class Location implements Serializable{
|
public class Location implements Serializable{
|
||||||
private double x, y, z;
|
private double x, y, z;
|
||||||
|
private WeakReference<World> world;
|
||||||
|
|
||||||
private static int floor_double(double value) {
|
private static int floor_double(double value) {
|
||||||
int i = (int)value;
|
int i = (int)value;
|
||||||
@@ -23,16 +24,35 @@ public class Location implements Serializable{
|
|||||||
return new Location(
|
return new Location(
|
||||||
location.x,
|
location.x,
|
||||||
location.y,
|
location.y,
|
||||||
location.z
|
location.z,
|
||||||
|
location.getWorld()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Location (double x, double y, double z, World world) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
this.world = new WeakReference<>(world);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location (double x, double y, double z) {
|
||||||
|
this.x = x;
|
||||||
|
this.y = y;
|
||||||
|
this.z = z;
|
||||||
|
}
|
||||||
|
|
||||||
public static Location startPointLocation () {
|
public static Location startPointLocation () {
|
||||||
return new Location(0,10,0);
|
return new Location(0,10,0, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Location(long compactValue) {
|
public Location(long compactValue) {
|
||||||
set(compactValue);
|
set(compactValue);
|
||||||
|
this.world = new WeakReference<>(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Location(long compactValue, World world) {
|
||||||
|
set(compactValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void set(Location location) {
|
public void set(Location location) {
|
||||||
@@ -51,7 +71,8 @@ public class Location implements Serializable{
|
|||||||
return new Location(
|
return new Location(
|
||||||
this.x - location.x,
|
this.x - location.x,
|
||||||
this.y - location.y,
|
this.y - location.y,
|
||||||
this.z - location.z
|
this.z - location.z,
|
||||||
|
this.getWorld().equals(location.getWorld()) ? this.getWorld() : null
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,4 +93,12 @@ public class Location implements Serializable{
|
|||||||
| ((floor_double(y) & 0xFFF) << 26)
|
| ((floor_double(y) & 0xFFF) << 26)
|
||||||
| (floor_double(z) & 0x3FFFFFF);
|
| (floor_double(z) & 0x3FFFFFF);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public World getWorld () {
|
||||||
|
return this.world.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setWorld (World world) {
|
||||||
|
this.world = new WeakReference<>(world);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ public class ChunkImpl implements Chunk{
|
|||||||
public void setBlock(int x, int y, int z, Block block) {
|
public void setBlock(int x, int y, int z, Block block) {
|
||||||
if (block.getBlockType() == BlockType.AIR) {
|
if (block.getBlockType() == BlockType.AIR) {
|
||||||
blocks[x][y][z] = null;
|
blocks[x][y][z] = null;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
blocks[x][y][z] = block;
|
blocks[x][y][z] = block;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class SeedBasedWorldGenerator implements WorldGenerator {
|
|||||||
World world = new CubicWorld(UUID.fromString("00000000-0000-0000-C000-000000000046"), 2626949);
|
World world = new CubicWorld(UUID.fromString("00000000-0000-0000-C000-000000000046"), 2626949);
|
||||||
Region region = worldGenerator.generateRegion(0, 0, world);
|
Region region = worldGenerator.generateRegion(0, 0, world);
|
||||||
region.save(new ChunkSerializer(), new RegionReaderWriter(new File("worlds", world.getWorldId().toString())));
|
region.save(new ChunkSerializer(), new RegionReaderWriter(new File("worlds", world.getWorldId().toString())));
|
||||||
new WorldReaderWriter(new File("worlds")).writeWorldInfo(world);
|
// new WorldReaderWriter(new File("worlds")).writeWorldInfo(world);
|
||||||
/*worldGenerator.generateRegion(1, 0, world);
|
/*worldGenerator.generateRegion(1, 0, world);
|
||||||
worldGenerator.generateRegion(-1, 0, world);
|
worldGenerator.generateRegion(-1, 0, world);
|
||||||
worldGenerator.generateRegion(0, 1, world);
|
worldGenerator.generateRegion(0, 1, world);
|
||||||
|
|||||||
@@ -48,8 +48,8 @@ public class LoginHandler extends AbstractStateHandler implements LoginStateHand
|
|||||||
Player player = playerManager.getPlayer(packet.getPlayerName())
|
Player player = playerManager.getPlayer(packet.getPlayerName())
|
||||||
.orElseGet(() -> playerManager.createPlayer(
|
.orElseGet(() -> playerManager.createPlayer(
|
||||||
packet.getPlayerName(),
|
packet.getPlayerName(),
|
||||||
world.getSpawn(),
|
world.getSpawn().getLocation(),
|
||||||
new Look(0f, 0f)));
|
world.getSpawn().getLook()));
|
||||||
|
|
||||||
channel.writeAndFlush(new LoginSuccessPacket(
|
channel.writeAndFlush(new LoginSuccessPacket(
|
||||||
player.getUUID(),
|
player.getUUID(),
|
||||||
@@ -68,7 +68,7 @@ public class LoginHandler extends AbstractStateHandler implements LoginStateHand
|
|||||||
|
|
||||||
// Spawn Position
|
// Spawn Position
|
||||||
SpawnPositionPacket pkt2 = new SpawnPositionPacket();
|
SpawnPositionPacket pkt2 = new SpawnPositionPacket();
|
||||||
pkt2.setLocation(world.getSpawn());
|
pkt2.setLocation(world.getSpawn().getLocation());
|
||||||
channel.write(pkt2);
|
channel.write(pkt2);
|
||||||
|
|
||||||
// Player Abilities
|
// Player Abilities
|
||||||
|
|||||||
Reference in New Issue
Block a user