Archived
0

Location world reference

This commit is contained in:
Forwolk
2018-08-04 11:46:28 +03:00
parent f5057d5a92
commit d84e6ca749
4 changed files with 39 additions and 9 deletions

View File

@@ -4,15 +4,16 @@
*/
package mc.core;
import lombok.AllArgsConstructor;
import lombok.Data;
import mc.core.world.World;
import java.io.Serializable;
import java.lang.ref.WeakReference;
@AllArgsConstructor
@Data
public class Location implements Serializable{
private double x, y, z;
private WeakReference<World> world;
private static int floor_double(double value) {
int i = (int)value;
@@ -23,16 +24,35 @@ public class Location implements Serializable{
return new Location(
location.x,
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 () {
return new Location(0,10,0);
return new Location(0,10,0, null);
}
public Location(long compactValue) {
set(compactValue);
this.world = new WeakReference<>(null);
}
public Location(long compactValue, World world) {
set(compactValue);
}
public void set(Location location) {
@@ -51,7 +71,8 @@ public class Location implements Serializable{
return new Location(
this.x - location.x,
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(z) & 0x3FFFFFF);
}
public World getWorld () {
return this.world.get();
}
public void setWorld (World world) {
this.world = new WeakReference<>(world);
}
}

View File

@@ -85,6 +85,7 @@ public class ChunkImpl implements Chunk{
public void setBlock(int x, int y, int z, Block block) {
if (block.getBlockType() == BlockType.AIR) {
blocks[x][y][z] = null;
return;
}
blocks[x][y][z] = block;
}

View File

@@ -28,7 +28,7 @@ public class SeedBasedWorldGenerator implements WorldGenerator {
World world = new CubicWorld(UUID.fromString("00000000-0000-0000-C000-000000000046"), 2626949);
Region region = worldGenerator.generateRegion(0, 0, world);
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(0, 1, world);

View File

@@ -48,8 +48,8 @@ public class LoginHandler extends AbstractStateHandler implements LoginStateHand
Player player = playerManager.getPlayer(packet.getPlayerName())
.orElseGet(() -> playerManager.createPlayer(
packet.getPlayerName(),
world.getSpawn(),
new Look(0f, 0f)));
world.getSpawn().getLocation(),
world.getSpawn().getLook()));
channel.writeAndFlush(new LoginSuccessPacket(
player.getUUID(),
@@ -68,7 +68,7 @@ public class LoginHandler extends AbstractStateHandler implements LoginStateHand
// Spawn Position
SpawnPositionPacket pkt2 = new SpawnPositionPacket();
pkt2.setLocation(world.getSpawn());
pkt2.setLocation(world.getSpawn().getLocation());
channel.write(pkt2);
// Player Abilities