use of cn.nukkit.block.Block in project Nukkit by Nukkit.
the class Entity method fall.
public void fall(float fallDistance) {
float damage = (float) Math.floor(fallDistance - 3 - (this.hasEffect(Effect.JUMP) ? this.getEffect(Effect.JUMP).getAmplifier() + 1 : 0));
if (damage > 0) {
this.attack(new EntityDamageEvent(this, DamageCause.FALL, damage));
}
if (fallDistance > 0.75) {
Block down = this.level.getBlock(this.floor().down());
if (down.getId() == Item.FARMLAND) {
Event ev;
if (this instanceof Player) {
ev = new PlayerInteractEvent((Player) this, null, down, null, Action.PHYSICAL);
} else {
ev = new EntityInteractEvent(this, down);
}
this.server.getPluginManager().callEvent(ev);
if (ev.isCancelled()) {
return;
}
this.level.setBlock(down, new BlockDirt(), false, true);
}
}
}
use of cn.nukkit.block.Block in project Nukkit by Nukkit.
the class Entity method getBlocksAround.
public List<Block> getBlocksAround() {
if (this.blocksAround == null) {
int minX = NukkitMath.floorDouble(this.boundingBox.getMinX());
int minY = NukkitMath.floorDouble(this.boundingBox.getMinY());
int minZ = NukkitMath.floorDouble(this.boundingBox.getMinZ());
int maxX = NukkitMath.ceilDouble(this.boundingBox.getMaxX());
int maxY = NukkitMath.ceilDouble(this.boundingBox.getMaxY());
int maxZ = NukkitMath.ceilDouble(this.boundingBox.getMaxZ());
this.blocksAround = new ArrayList<>();
for (int z = minZ; z <= maxZ; ++z) {
for (int x = minX; x <= maxX; ++x) {
for (int y = minY; y <= maxY; ++y) {
Block block = this.level.getBlock(this.temporalVector.setComponents(x, y, z));
this.blocksAround.add(block);
}
}
}
}
return this.blocksAround;
}
use of cn.nukkit.block.Block in project Nukkit by Nukkit.
the class EntityLiving method getLineOfSight.
public Block[] getLineOfSight(int maxDistance, int maxLength, Integer[] transparent) {
if (maxDistance > 120) {
maxDistance = 120;
}
if (transparent != null && transparent.length == 0) {
transparent = null;
}
List<Block> blocks = new ArrayList<>();
BlockIterator itr = new BlockIterator(this.level, this.getPosition(), this.getDirectionVector(), this.getEyeHeight(), maxDistance);
while (itr.hasNext()) {
Block block = itr.next();
blocks.add(block);
if (maxLength != 0 && blocks.size() > maxLength) {
blocks.remove(0);
}
int id = block.getId();
if (transparent == null) {
if (id != 0) {
break;
}
} else {
if (Arrays.binarySearch(transparent, id) < 0) {
break;
}
}
}
return blocks.stream().toArray(Block[]::new);
}
use of cn.nukkit.block.Block in project Nukkit by Nukkit.
the class EntityLiving method getTargetBlock.
public Block getTargetBlock(int maxDistance, Integer[] transparent) {
try {
Block[] blocks = this.getLineOfSight(maxDistance, 1, transparent);
Block block = blocks[0];
if (block != null) {
if (transparent != null && transparent.length != 0) {
if (Arrays.binarySearch(transparent, block.getId()) < 0) {
return block;
}
} else {
return block;
}
}
} catch (Exception ignored) {
}
return null;
}
use of cn.nukkit.block.Block in project Nukkit by Nukkit.
the class EntityLightning method onUpdate.
@Override
public boolean onUpdate(int currentTick) {
if (this.closed) {
return false;
}
int tickDiff = currentTick - this.lastUpdate;
if (tickDiff <= 0 && !this.justCreated) {
return true;
}
this.lastUpdate = currentTick;
this.entityBaseTick(tickDiff);
if (this.state == 2) {
this.level.addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_THUNDER, 93, -1);
this.level.addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_EXPLODE, 93, -1);
}
this.state--;
if (this.state < 0) {
if (this.liveTime == 0) {
this.close();
return false;
} else if (this.state < -ThreadLocalRandom.current().nextInt(10)) {
this.liveTime--;
this.state = 1;
if (this.isEffect && this.level.gameRules.getBoolean(GameRule.DO_FIRE_TICK)) {
Block block = this.getLevelBlock();
if (block.getId() == Block.AIR || block.getId() == Block.TALL_GRASS) {
BlockIgniteEvent e = new BlockIgniteEvent(block, null, this, BlockIgniteEvent.BlockIgniteCause.LIGHTNING);
getServer().getPluginManager().callEvent(e);
if (!e.isCancelled()) {
Block fire = new BlockFire();
this.level.setBlock(block, fire);
this.getLevel().scheduleUpdate(fire, fire.tickRate());
}
}
}
}
}
if (this.state >= 0) {
if (this.isEffect) {
AxisAlignedBB bb = getBoundingBox().grow(3, 3, 3);
bb.setMaxX(bb.getMaxX() + 6);
for (Entity entity : this.level.getCollidingEntities(bb, this)) {
entity.onStruckByLightning(this);
}
}
}
return true;
}
Aggregations