cn.nukkit.event.weather.LightningStrikeEvent Java Examples

The following examples show how to use cn.nukkit.event.weather.LightningStrikeEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Level.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private void performThunder(long index, FullChunk chunk) {
    if (areNeighboringChunksLoaded(index)) return;
    if (ThreadLocalRandom.current().nextInt(10000) == 0) {
        int LCG = this.getUpdateLCG() >> 2;

        int chunkX = chunk.getX() * 16;
        int chunkZ = chunk.getZ() * 16;
        Vector3 vector = this.adjustPosToNearbyEntity(new Vector3(chunkX + (LCG & 0xf), 0, chunkZ + (LCG >> 8 & 0xf)));

        Biome biome = Biome.getBiome(this.getBiomeId(vector.getFloorX(), vector.getFloorZ()));
        if (!biome.canRain()) {
            return;
        }

        int bId = this.getBlockIdAt(vector.getFloorX(), vector.getFloorY(), vector.getFloorZ());
        if (bId != Block.TALL_GRASS && bId != Block.WATER)
            vector.y += 1;
        CompoundTag nbt = new CompoundTag()
                .putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("", vector.x))
                        .add(new DoubleTag("", vector.y)).add(new DoubleTag("", vector.z)))
                .putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("", 0))
                        .add(new DoubleTag("", 0)).add(new DoubleTag("", 0)))
                .putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("", 0))
                        .add(new FloatTag("", 0)));

        EntityLightning bolt = (EntityLightning) Entity.createEntity("Lightning", chunk, nbt);
        if(bolt == null) return;
        LightningStrikeEvent ev = new LightningStrikeEvent(this, bolt);
        getServer().getPluginManager().callEvent(ev);
        if (!ev.isCancelled()) {
            bolt.spawnToAll();
        } else {
            bolt.setEffect(false);
        }

        this.addLevelSoundEvent(vector, LevelSoundEventPacket.SOUND_THUNDER, -1, EntityLightning.NETWORK_ID);
        this.addLevelSoundEvent(vector, LevelSoundEventPacket.SOUND_EXPLODE, -1, EntityLightning.NETWORK_ID);
    }
}
 
Example #2
Source File: Level.java    From Nukkit with GNU General Public License v3.0 5 votes vote down vote up
private void performThunder(long index, FullChunk chunk) {
    if (areNeighboringChunksLoaded(index)) return;
    if (ThreadLocalRandom.current().nextInt(10000) == 0) {
        this.updateLCG = this.updateLCG * 3 + 1013904223;
        int LCG = this.updateLCG >> 2;

        int chunkX = chunk.getX() * 16;
        int chunkZ = chunk.getZ() * 16;
        Vector3 vector = this.adjustPosToNearbyEntity(new Vector3(chunkX + (LCG & 15), 0, chunkZ + (LCG >> 8 & 15)));

        int bId = this.getBlockIdAt(vector.getFloorX(), vector.getFloorY(), vector.getFloorZ());
        if (bId != Block.TALL_GRASS && bId != Block.WATER)
            vector.y += 1;
        CompoundTag nbt = new CompoundTag()
                .putList(new ListTag<DoubleTag>("Pos").add(new DoubleTag("", vector.x))
                        .add(new DoubleTag("", vector.y)).add(new DoubleTag("", vector.z)))
                .putList(new ListTag<DoubleTag>("Motion").add(new DoubleTag("", 0))
                        .add(new DoubleTag("", 0)).add(new DoubleTag("", 0)))
                .putList(new ListTag<FloatTag>("Rotation").add(new FloatTag("", 0))
                        .add(new FloatTag("", 0)));

        EntityLightning bolt = new EntityLightning(chunk, nbt);
        LightningStrikeEvent ev = new LightningStrikeEvent(this, bolt);
        getServer().getPluginManager().callEvent(ev);
        if (!ev.isCancelled()) {
            bolt.spawnToAll();
        } else {
            bolt.setEffect(false);
        }

        this.addLevelSoundEvent(vector, LevelSoundEventPacket.SOUND_THUNDER, 93, -1, false);
        this.addLevelSoundEvent(vector, LevelSoundEventPacket.SOUND_EXPLODE, 93, -1, false);
    }
}