use of net.glowstone.chunk.GlowChunk.Key in project Glowstone by GlowstoneMC.
the class GlowWorld method refreshChunk.
@Override
public boolean refreshChunk(int x, int z) {
if (!isChunkLoaded(x, z)) {
return false;
}
Key key = new Key(x, z);
boolean result = false;
for (GlowPlayer player : getRawPlayers()) {
if (player.canSeeChunk(key)) {
player.getSession().send(getChunkAt(x, z).toMessage());
result = true;
}
}
return result;
}
use of net.glowstone.chunk.GlowChunk.Key in project Glowstone by GlowstoneMC.
the class GlowWorld method updateActiveChunkCollection.
private void updateActiveChunkCollection(GlowEntity entity) {
// build a set of chunks around each player in this world, the
// server view distance is taken here
int radius = server.getViewDistance();
Location playerLocation = entity.getLocation();
if (playerLocation.getWorld() == this) {
int cx = playerLocation.getBlockX() >> 4;
int cz = playerLocation.getBlockZ() >> 4;
for (int x = cx - radius; x <= cx + radius; x++) {
for (int z = cz - radius; z <= cz + radius; z++) {
if (isChunkLoaded(cx, cz)) {
activeChunksSet.add(new Key(x, z));
}
}
}
}
}
use of net.glowstone.chunk.GlowChunk.Key in project Glowstone by GlowstoneMC.
the class GlowPlayer method broadcastBlockBreakAnimation.
private void broadcastBlockBreakAnimation(GlowBlock block, int destroyStage) {
GlowChunk.Key key = new GlowChunk.Key(block.getChunk().getX(), block.getChunk().getZ());
block.getWorld().getRawPlayers().stream().filter(player -> player.canSeeChunk(key) && player != this).forEach(player -> player.sendBlockBreakAnimation(block.getLocation(), destroyStage));
}
use of net.glowstone.chunk.GlowChunk.Key in project Glowstone by GlowstoneMC.
the class GlowItemFrame method generateTeleportMessage.
void generateTeleportMessage(BlockFace face) {
int xoffset = 0;
int zoffset = 0;
int yaw = 0;
switch(getFacingNumber(face)) {
case 1:
xoffset = -32;
yaw = 64;
break;
case 2:
zoffset = -32;
yaw = -128;
break;
case 3:
xoffset = 32;
yaw = -64;
break;
case 0:
zoffset = 32;
yaw = 0;
break;
}
Location itemframelocation = location;
Key key = new Key(itemframelocation.getBlockX() >> 4, itemframelocation.getBlockZ() >> 4);
for (GlowPlayer player : getWorld().getRawPlayers()) {
if (player.canSeeChunk(key)) {
double x = location.getX();
double y = location.getY();
double z = location.getZ();
player.getSession().send(new EntityTeleportMessage(id, x + xoffset, y, z + zoffset, yaw, 0));
}
}
}
use of net.glowstone.chunk.GlowChunk.Key in project Glowstone by GlowstoneMC.
the class StructurePopulator method populate.
@Override
public void populate(World world, Random random, Chunk source) {
if (world.canGenerateStructures()) {
int cx = source.getX();
int cz = source.getZ();
random.setSeed(world.getSeed());
long xRand = random.nextLong();
long zRand = random.nextLong();
boolean placed = false;
for (int x = cx - 8; x <= cx + 8 && !placed; x++) {
for (int z = cz - 8; z <= cz + 8 && !placed; z++) {
if (world.getChunkAt(x, z).isLoaded() || world.getChunkAt(x, z).load(true)) {
random.setSeed(x * xRand + z * zRand ^ world.getSeed());
Map<Integer, GlowStructure> structures = ((GlowWorld) world).getStructures();
int key = new Key(x, z).hashCode();
if (!structures.containsKey(key)) {
for (StructureStore<?> store : StructureStorage.getStructureStores()) {
GlowStructure structure = store.createNewStructure((GlowWorld) world, random, x, z);
if (structure.shouldGenerate(random)) {
structure.setDirty(true);
structures.put(key, structure);
GlowServer.logger.finer("structure in chunk " + x + "," + z);
placed = true;
break;
}
}
}
}
}
}
int x = cx << 4;
int z = cz << 4;
Iterator<Entry<Integer, GlowStructure>> it = ((GlowWorld) world).getStructures().entrySet().iterator();
while (it.hasNext()) {
GlowStructure structure = it.next().getValue();
if (structure.getBoundingBox().intersectsWith(x, z, x + 15, z + 15)) {
BlockStateDelegate delegate = new BlockStateDelegate();
if (structure.generate(random, x, z, delegate)) {
// maybe later trigger a StructureGeneratedEvent event and cancel
delegate.updateBlockStates();
} else {
delegate.rollbackBlockStates();
it.remove();
}
}
}
}
}
Aggregations