use of cn.nukkit.block.Block in project Nukkit by Nukkit.
the class Entity method isInsideOfWater.
public boolean isInsideOfWater() {
double y = this.y + this.getEyeHeight();
Block block = this.level.getBlock(this.temporalVector.setComponents(NukkitMath.floorDouble(this.x), NukkitMath.floorDouble(y), NukkitMath.floorDouble(this.z)));
if (block instanceof BlockWater) {
double f = (block.y + 1) - (((BlockWater) block).getFluidHeightPercent() - 0.1111111);
return y < f;
}
return false;
}
use of cn.nukkit.block.Block in project Nukkit by Nukkit.
the class PopulatorGroundCover method populate.
@Override
public void populate(ChunkManager level, int chunkX, int chunkZ, NukkitRandom random) {
FullChunk chunk = level.getChunk(chunkX, chunkZ);
for (int x = 0; x < 16; ++x) {
for (int z = 0; z < 16; ++z) {
Biome biome = Biome.getBiome(chunk.getBiomeId(x, z));
Block[] cover = biome.getGroundCover();
if (cover != null && cover.length > 0) {
int diffY = 0;
if (!cover[0].isSolid()) {
diffY = 1;
}
int height = chunk.getHeightMap(x, z);
if (height == 0 || height == 255)
height = 126;
int y;
for (y = height + 1; y > 0; --y) {
int fullId = chunk.getFullBlock(x, y, z);
if (fullId != 0 && !Block.get(fullId >> 4).isTransparent()) {
break;
}
}
int startY = Math.min(127, y + diffY);
int endY = startY - cover.length;
for (y = startY; y > endY && y >= 0; --y) {
Block b = cover[startY - y];
int blockId = chunk.getBlockId(x, y, z);
if (blockId == 0 && b.isSolid()) {
break;
}
if (b.getDamage() == 0) {
chunk.setBlockId(x, y, z, b.getId());
} else {
chunk.setBlock(x, y, z, b.getId(), b.getDamage());
}
}
}
}
}
}
use of cn.nukkit.block.Block in project Nukkit by Nukkit.
the class Explosion method explodeA.
/**
* @return bool
*/
public boolean explodeA() {
if (this.size < 0.1) {
return false;
}
Vector3 vector = new Vector3(0, 0, 0);
Vector3 vBlock = new Vector3(0, 0, 0);
int mRays = this.rays - 1;
for (int i = 0; i < this.rays; ++i) {
for (int j = 0; j < this.rays; ++j) {
for (int k = 0; k < this.rays; ++k) {
if (i == 0 || i == mRays || j == 0 || j == mRays || k == 0 || k == mRays) {
vector.setComponents((double) i / (double) mRays * 2d - 1, (double) j / (double) mRays * 2d - 1, (double) k / (double) mRays * 2d - 1);
double len = vector.length();
vector.setComponents((vector.x / len) * this.stepLen, (vector.y / len) * this.stepLen, (vector.z / len) * this.stepLen);
double pointerX = this.source.x;
double pointerY = this.source.y;
double pointerZ = this.source.z;
for (double blastForce = this.size * (ThreadLocalRandom.current().nextInt(700, 1301)) / 1000d; blastForce > 0; blastForce -= this.stepLen * 0.75d) {
int x = (int) pointerX;
int y = (int) pointerY;
int z = (int) pointerZ;
vBlock.x = pointerX >= x ? x : x - 1;
vBlock.y = pointerY >= y ? y : y - 1;
vBlock.z = pointerZ >= z ? z : z - 1;
if (vBlock.y < 0 || vBlock.y > 255) {
break;
}
Block block = this.level.getBlock(vBlock);
if (block.getId() != 0) {
blastForce -= (block.getResistance() / 5 + 0.3d) * this.stepLen;
if (blastForce > 0) {
if (!this.affectedBlocks.contains(block)) {
this.affectedBlocks.add(block);
}
}
}
pointerX += vector.x;
pointerY += vector.y;
pointerZ += vector.z;
}
}
}
}
}
return true;
}
use of cn.nukkit.block.Block in project Nukkit by Nukkit.
the class Explosion method explodeB.
public boolean explodeB() {
HashMap<BlockVector3, Boolean> updateBlocks = new HashMap<>();
List<Vector3> send = new ArrayList<>();
Vector3 source = (new Vector3(this.source.x, this.source.y, this.source.z)).floor();
double yield = (1d / this.size) * 100d;
if (this.what instanceof Entity) {
EntityExplodeEvent ev = new EntityExplodeEvent((Entity) this.what, this.source, this.affectedBlocks, yield);
this.level.getServer().getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
return false;
} else {
yield = ev.getYield();
this.affectedBlocks = ev.getBlockList();
}
}
double explosionSize = this.size * 2d;
double minX = NukkitMath.floorDouble(this.source.x - explosionSize - 1);
double maxX = NukkitMath.ceilDouble(this.source.x + explosionSize + 1);
double minY = NukkitMath.floorDouble(this.source.y - explosionSize - 1);
double maxY = NukkitMath.ceilDouble(this.source.y + explosionSize + 1);
double minZ = NukkitMath.floorDouble(this.source.z - explosionSize - 1);
double maxZ = NukkitMath.ceilDouble(this.source.z + explosionSize + 1);
AxisAlignedBB explosionBB = new SimpleAxisAlignedBB(minX, minY, minZ, maxX, maxY, maxZ);
Entity[] list = this.level.getNearbyEntities(explosionBB, this.what instanceof Entity ? (Entity) this.what : null);
for (Entity entity : list) {
double distance = entity.distance(this.source) / explosionSize;
if (distance <= 1) {
Vector3 motion = entity.subtract(this.source).normalize();
int exposure = 1;
double impact = (1 - distance) * exposure;
int damage = (int) (((impact * impact + impact) / 2) * 8 * explosionSize + 1);
if (this.what instanceof Entity) {
entity.attack(new EntityDamageByEntityEvent((Entity) this.what, entity, DamageCause.ENTITY_EXPLOSION, damage));
} else if (this.what instanceof Block) {
entity.attack(new EntityDamageByBlockEvent((Block) this.what, entity, DamageCause.BLOCK_EXPLOSION, damage));
} else {
entity.attack(new EntityDamageEvent(entity, DamageCause.BLOCK_EXPLOSION, damage));
}
entity.setMotion(motion.multiply(impact));
}
}
ItemBlock air = new ItemBlock(new BlockAir());
// Iterator iter = this.affectedBlocks.entrySet().iterator();
for (Block block : this.affectedBlocks) {
// Block block = (Block) ((HashMap.Entry) iter.next()).getValue();
if (block.getId() == Block.TNT) {
((BlockTNT) block).prime(new NukkitRandom().nextRange(10, 30));
} else if (Math.random() * 100 < yield) {
for (Item drop : block.getDrops(air)) {
this.level.dropItem(block.add(0.5, 0.5, 0.5), drop);
}
}
this.level.setBlockIdAt((int) block.x, (int) block.y, (int) block.z, 0);
Vector3 pos = new Vector3(block.x, block.y, block.z);
for (BlockFace side : BlockFace.values()) {
Vector3 sideBlock = pos.getSide(side);
BlockVector3 index = Level.blockHash((int) sideBlock.x, (int) sideBlock.y, (int) sideBlock.z);
if (!this.affectedBlocks.contains(sideBlock) && !updateBlocks.containsKey(index)) {
BlockUpdateEvent ev = new BlockUpdateEvent(this.level.getBlock(sideBlock));
this.level.getServer().getPluginManager().callEvent(ev);
if (!ev.isCancelled()) {
ev.getBlock().onUpdate(Level.BLOCK_UPDATE_NORMAL);
}
updateBlocks.put(index, true);
}
}
send.add(new Vector3(block.x - source.x, block.y - source.y, block.z - source.z));
}
ExplodePacket pk = new ExplodePacket();
pk.x = (float) this.source.x;
pk.y = (float) this.source.y;
pk.z = (float) this.source.z;
pk.radius = (float) this.size;
pk.records = send.stream().toArray(Vector3[]::new);
this.level.addChunkPacket((int) source.x >> 4, (int) source.z >> 4, pk);
this.level.addParticle(new HugeExplodeSeedParticle(this.source));
this.level.addSound(new Vector3(this.source.x, this.source.y, this.source.z), Sound.RANDOM_EXPLODE);
return true;
}
use of cn.nukkit.block.Block in project Nukkit by Nukkit.
the class Level method getMapColorAt.
public BlockColor getMapColorAt(int x, int z) {
int y = getHighestBlockAt(x, z);
while (y > 1) {
Block block = getBlock(new Vector3(x, y, z));
BlockColor blockColor = block.getColor();
if (blockColor.getAlpha() == 0x00) {
y--;
} else {
return blockColor;
}
}
return BlockColor.VOID_BLOCK_COLOR;
}
Aggregations