use of cn.nukkit.level.format.generic.BaseFullChunk in project Nukkit by Nukkit.
the class LightPopulationTask method onRun.
@Override
public void onRun() {
BaseFullChunk chunk = this.chunk.clone();
if (chunk == null) {
return;
}
chunk.recalculateHeightMap();
chunk.populateSkyLight();
chunk.setLightPopulated();
this.chunk = chunk.clone();
}
use of cn.nukkit.level.format.generic.BaseFullChunk in project Nukkit by Nukkit.
the class PopulationTask method onCompletion.
@Override
public void onCompletion(Server server) {
Level level = server.getLevel(this.levelId);
if (level != null) {
if (!this.state) {
level.registerGenerator();
return;
}
BaseFullChunk chunk = this.chunk.clone();
if (chunk == null) {
return;
}
for (int i = 0; i < 9; i++) {
if (i == 4) {
continue;
}
BaseFullChunk c = this.chunks[i];
if (c != null) {
c = c.clone();
level.generateChunkCallback(c.getX(), c.getZ(), c);
}
}
level.generateChunkCallback(chunk.getX(), chunk.getZ(), chunk);
}
}
use of cn.nukkit.level.format.generic.BaseFullChunk in project Nukkit by Nukkit.
the class PopulatorGroundFire method populate.
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
this.level = level;
BaseFullChunk chunk = level.getChunk(chunkX, chunkZ);
int bx = chunkX << 4;
int bz = chunkZ << 4;
int tx = bx + 15;
int tz = bz + 15;
int amount = random.nextRange(0, this.randomAmount + 1) + this.baseAmount;
for (int i = 0; i < amount; ++i) {
int x = random.nextRange(0, 15);
int z = random.nextRange(0, 15);
int y = this.getHighestWorkableBlock(chunk, x, z);
if (y != -1 && this.canGroundFireStay(chunk, x, y, z)) {
chunk.setBlock(x, y, z, Block.FIRE);
chunk.setBlockLight(x, y, z, Block.light[Block.FIRE]);
}
}
}
use of cn.nukkit.level.format.generic.BaseFullChunk in project Nukkit by Nukkit.
the class PopulatorLava method populate.
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
this.random = random;
if (random.nextRange(0, 100) < 5) {
this.level = level;
int amount = random.nextRange(0, this.randomAmount + 1) + this.baseAmount;
BaseFullChunk chunk = level.getChunk(chunkX, chunkZ);
int bx = chunkX << 4;
int bz = chunkZ << 4;
int tx = bx + 15;
int tz = bz + 15;
for (int i = 0; i < amount; ++i) {
int x = random.nextRange(0, 15);
int z = random.nextRange(0, 15);
int y = this.getHighestWorkableBlock(chunk, x, z);
if (y != -1 && chunk.getBlockId(x, y, z) == Block.AIR) {
chunk.setBlock(x, y, z, Block.LAVA);
chunk.setBlockLight(x, y, z, Block.light[Block.LAVA]);
this.lavaSpread(bx + x, y, bz + z);
}
}
}
}
use of cn.nukkit.level.format.generic.BaseFullChunk in project Nukkit by Nukkit.
the class Player method processMovement.
protected void processMovement(int tickDiff) {
if (!this.isAlive() || !this.spawned || this.newPosition == null || this.teleportPosition != null || this.isSleeping()) {
return;
}
Vector3 newPos = this.newPosition;
double distanceSquared = newPos.distanceSquared(this);
boolean revert = false;
if ((distanceSquared / ((double) (tickDiff * tickDiff))) > 100 && (newPos.y - this.y) > -5) {
revert = true;
} else {
if (this.chunk == null || !this.chunk.isGenerated()) {
BaseFullChunk chunk = this.level.getChunk((int) newPos.x >> 4, (int) newPos.z >> 4, false);
if (chunk == null || !chunk.isGenerated()) {
revert = true;
this.nextChunkOrderRun = 0;
} else {
if (this.chunk != null) {
this.chunk.removeEntity(this);
}
this.chunk = chunk;
}
}
}
double tdx = newPos.x - this.x;
double tdz = newPos.z - this.z;
double distance = Math.sqrt(tdx * tdx + tdz * tdz);
if (!revert && distanceSquared != 0) {
double dx = newPos.x - this.x;
double dy = newPos.y - this.y;
double dz = newPos.z - this.z;
this.fastMove(dx, dy, dz);
if (this.newPosition == null) {
// maybe solve that in better way
return;
}
double diffX = this.x - newPos.x;
double diffY = this.y - newPos.y;
double diffZ = this.z - newPos.z;
double yS = 0.5 + this.ySize;
if (diffY >= -yS || diffY <= yS) {
diffY = 0;
}
if (diffX != 0 || diffY != 0 || diffZ != 0) {
if (this.checkMovement && !server.getAllowFlight() && this.isSurvival()) {
// blocked my movement
if (!this.isSleeping() && this.riding == null) {
double diffHorizontalSqr = (diffX * diffX + diffZ * diffZ) / ((double) (tickDiff * tickDiff));
if (diffHorizontalSqr > 0.125) {
PlayerInvalidMoveEvent ev;
this.getServer().getPluginManager().callEvent(ev = new PlayerInvalidMoveEvent(this, true));
if (!ev.isCancelled()) {
revert = ev.isRevert();
if (revert) {
this.server.getLogger().warning(this.getServer().getLanguage().translateString("nukkit.player.invalidMove", this.getName()));
}
}
}
}
}
this.x = newPos.x;
this.y = newPos.y;
this.z = newPos.z;
double radius = this.getWidth() / 2;
this.boundingBox.setBounds(this.x - radius, this.y, this.z - radius, this.x + radius, this.y + this.getHeight(), this.z + radius);
}
}
Location from = new Location(this.lastX, this.lastY, this.lastZ, this.lastYaw, this.lastPitch, this.level);
Location to = this.getLocation();
double delta = Math.pow(this.lastX - to.x, 2) + Math.pow(this.lastY - to.y, 2) + Math.pow(this.z - to.z, 2);
double deltaAngle = Math.abs(this.lastYaw - to.yaw) + Math.abs(this.lastPitch - to.pitch);
if (!revert && (delta > 0.0001d || deltaAngle > 1d)) {
boolean isFirst = this.firstMove;
this.firstMove = false;
this.lastX = to.x;
this.lastY = to.y;
this.lastZ = to.z;
this.lastYaw = to.yaw;
this.lastPitch = to.pitch;
if (!isFirst) {
List<Block> blocksAround = new ArrayList<>(this.blocksAround);
List<Block> collidingBlocks = new ArrayList<>(this.collisionBlocks);
PlayerMoveEvent ev = new PlayerMoveEvent(this, from, to);
this.blocksAround = null;
this.collisionBlocks = null;
this.server.getPluginManager().callEvent(ev);
if (!(revert = ev.isCancelled())) {
// Yes, this is intended
if (!to.equals(ev.getTo())) {
// If plugins modify the destination
this.teleport(ev.getTo(), null);
} else {
this.addMovement(this.x, this.y + this.getEyeHeight(), this.z, this.yaw, this.pitch, this.yaw);
}
} else {
this.blocksAround = blocksAround;
this.collisionBlocks = collidingBlocks;
}
}
if (!this.isSpectator()) {
this.checkNearEntities();
}
if (this.speed == null)
speed = new Vector3(from.x - to.x, from.y - to.y, from.z - to.z);
else
this.speed.setComponents(from.x - to.x, from.y - to.y, from.z - to.z);
} else {
if (this.speed == null)
speed = new Vector3(0, 0, 0);
else
this.speed.setComponents(0, 0, 0);
}
if (!revert && (this.isFoodEnabled() || this.getServer().getDifficulty() == 0)) {
if ((this.isSurvival() || this.isAdventure())) /* && !this.getRiddingOn() instanceof Entity*/
{
// UpdateFoodExpLevel
if (distance >= 0.05) {
double jump = 0;
double swimming = this.isInsideOfWater() ? 0.015 * distance : 0;
if (swimming != 0)
distance = 0;
if (this.isSprinting()) {
// Running
if (this.inAirTicks == 3 && swimming == 0) {
jump = 0.7;
}
this.getFoodData().updateFoodExpLevel(0.1 * distance + jump + swimming);
} else {
if (this.inAirTicks == 3 && swimming == 0) {
jump = 0.2;
}
this.getFoodData().updateFoodExpLevel(0.01 * distance + jump + swimming);
}
}
}
}
if (revert) {
this.lastX = from.x;
this.lastY = from.y;
this.lastZ = from.z;
this.lastYaw = from.yaw;
this.lastPitch = from.pitch;
this.sendPosition(from, from.yaw, from.pitch, MovePlayerPacket.MODE_RESET);
// this.sendSettings();
this.forceMovement = new Vector3(from.x, from.y, from.z);
} else {
this.forceMovement = null;
if (distanceSquared != 0 && this.nextChunkOrderRun > 20) {
this.nextChunkOrderRun = 20;
}
}
this.newPosition = null;
}
Aggregations