Search in sources :

Example 1 with WorldProviderDiona

use of stevekung.mods.moreplanets.module.planets.diona.dimension.WorldProviderDiona in project MorePlanets by SteveKunG.

the class WorldTickEventHandler method onServerTick.

@SubscribeEvent
public void onServerTick(ServerTickEvent event) {
    MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
    if (server == null) {
        return;
    }
    if (event.phase == Phase.START) {
        if (WorldTickEventHandler.startedDimensionData == null) {
            World world = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(0);
            WorldTickEventHandler.startedDimensionData = (WorldDataStartedDimension) world.getMapStorage().getOrLoadData(WorldDataStartedDimension.class, WorldDataStartedDimension.saveDataID);
            if (WorldTickEventHandler.startedDimensionData == null) {
                WorldTickEventHandler.startedDimensionData = new WorldDataStartedDimension(WorldDataStartedDimension.saveDataID);
                world.getMapStorage().setData(WorldDataStartedDimension.saveDataID, WorldTickEventHandler.startedDimensionData);
            }
        }
    }
    if (event.phase == Phase.END) {
        World world = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(ConfigManagerMP.idDimensionDiona);
        if (world.provider instanceof WorldProviderDiona) {
            if (world instanceof WorldServer) {
                WorldServer worldServer = (WorldServer) world;
                for (Iterator<Chunk> iterator = world.getPersistentChunkIterable(worldServer.getPlayerChunkMap().getChunkIterator()); iterator.hasNext(); world.profiler.endSection()) {
                    Chunk chunk = iterator.next();
                    int j = chunk.x * 16;
                    int k = chunk.z * 16;
                    if (world.rand.nextInt(75000) == 0) {
                        this.updateLCG = this.updateLCG * 3 + 1013904223;
                        int l = this.updateLCG >> 2;
                        BlockPos blockpos = this.adjustPosToNearbyEntity(world, new BlockPos(j + (l & 15), 0, k + (l >> 8 & 15)));
                        if (this.canBeamStrike(world, blockpos)) {
                            EntityAlienBeam beam = new EntityAlienBeam(world);
                            beam.setLocationAndAngles(blockpos.getX(), blockpos.getY(), blockpos.getZ(), 0.0F, 0.0F);
                            world.spawnEntity(beam);
                        }
                    }
                }
            }
        }
        world = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(ConfigManagerMP.idDimensionNibiru);
        if (world.provider instanceof WorldProviderNibiru) {
            if (world instanceof WorldServer) {
                WorldServer worldServer = (WorldServer) world;
                for (Iterator<Chunk> iterator = world.getPersistentChunkIterable(worldServer.getPlayerChunkMap().getChunkIterator()); iterator.hasNext(); world.profiler.endSection()) {
                    Chunk chunk = iterator.next();
                    int j = chunk.x * 16;
                    int k = chunk.z * 16;
                    boolean flag = world.isRaining();
                    boolean flag1 = world.isThundering();
                    if (world.provider.canDoLightning(chunk) && flag && flag1 && world.rand.nextInt(1000) == 0) {
                        this.updateLCG = this.updateLCG * 3 + 1013904223;
                        int l = this.updateLCG >> 2;
                        BlockPos blockpos = this.adjustPosToNearbyEntity(world, new BlockPos(j + (l & 15), 0, k + (l >> 8 & 15)));
                        if (world.isRainingAt(blockpos)) {
                            world.spawnEntity(new EntityNibiruLightningBolt(world, blockpos.getX(), blockpos.getY(), blockpos.getZ(), true));
                        }
                    }
                    if (world.rand.nextInt(16) == 0) {
                        this.updateLCG = this.updateLCG * 3 + 1013904223;
                        int j2 = this.updateLCG >> 2;
                        BlockPos blockpos1 = world.getPrecipitationHeight(new BlockPos(j + (j2 & 15), 0, k + (j2 >> 8 & 15)));
                        BlockPos blockpos2 = blockpos1.down();
                        if (world.canBlockFreezeNoWater(blockpos2)) {
                            world.setBlockState(blockpos2, NibiruBlocks.INFECTED_ICE.getDefaultState());
                        }
                        if (flag && world.canSnowAt(blockpos1, true)) {
                            world.setBlockState(blockpos1, NibiruBlocks.INFECTED_SNOW_LAYER.getDefaultState());
                        }
                        if (flag && world.getBiome(blockpos2).canRain()) {
                            world.getBlockState(blockpos2).getBlock().fillWithRain(world, blockpos2);
                        }
                    }
                    if (world.getBiome(new BlockPos(j, 0, k)) == MPBiomes.INFECTED_DESERT || world.getBiome(new BlockPos(j, 0, k)) == MPBiomes.INFECTED_EXTREME_HILLS) {
                        if (world.rand.nextInt(250000) == 0) {
                            this.updateLCG = this.updateLCG * 3 + 1013904223;
                            int l = this.updateLCG >> 2;
                            BlockPos blockpos = this.adjustPosToNearbyEntity(world, new BlockPos(j + (l & 15), 0, k + (l >> 8 & 15)));
                            world.spawnEntity(new EntityNibiruLightningBolt(world, blockpos.getX(), blockpos.getY(), blockpos.getZ(), false));
                        }
                    }
                }
            }
        }
    }
}
Also used : WorldProviderNibiru(stevekung.mods.moreplanets.module.planets.nibiru.dimension.WorldProviderNibiru) WorldServer(net.minecraft.world.WorldServer) EntityAlienBeam(stevekung.mods.moreplanets.module.planets.diona.entity.EntityAlienBeam) World(net.minecraft.world.World) Chunk(net.minecraft.world.chunk.Chunk) WorldDataStartedDimension(stevekung.mods.moreplanets.core.data.WorldDataStartedDimension) MinecraftServer(net.minecraft.server.MinecraftServer) WorldProviderDiona(stevekung.mods.moreplanets.module.planets.diona.dimension.WorldProviderDiona) BlockPos(net.minecraft.util.math.BlockPos) EntityNibiruLightningBolt(stevekung.mods.moreplanets.module.planets.nibiru.entity.weather.EntityNibiruLightningBolt) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with WorldProviderDiona

use of stevekung.mods.moreplanets.module.planets.diona.dimension.WorldProviderDiona in project MorePlanets by SteveKunG.

the class ClientEventHandler method runAlienBeamTick.

private void runAlienBeamTick(EntityPlayer player) {
    Iterator<Map.Entry<BlockPos, Integer>> it = this.beam.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry<BlockPos, Integer> entry = it.next();
        int val = entry.getValue();
        if (val - 1 <= 0) {
            it.remove();
        } else {
            entry.setValue(val - 1);
        }
    }
    if (player.getRNG().nextInt(512) == 0 && player.world.provider instanceof WorldProviderDiona) {
        if (player.world.getSunBrightness(1.0F) < 0.25F) {
            double freq = player.getRNG().nextDouble() * Math.PI * 2.0F;
            double dist = 64.0F;
            double dX = dist * Math.cos(freq);
            double dZ = dist * Math.sin(freq);
            double posX = player.posX + dX;
            double posY = 48;
            double posZ = player.posZ + dZ;
            this.mc.world.playSound(player, posX, player.posY, posZ, MPSounds.ALIEN_BEAM, SoundCategory.WEATHER, 100.0F, 1.0F + player.getRNG().nextFloat() * 0.8F);
            this.beam.put(new BlockPos(posX, posY, posZ), 40);
        }
    }
}
Also used : WorldProviderDiona(stevekung.mods.moreplanets.module.planets.diona.dimension.WorldProviderDiona) MutableBlockPos(net.minecraft.util.math.BlockPos.MutableBlockPos) BlockPos(net.minecraft.util.math.BlockPos) TextureMap(net.minecraft.client.renderer.texture.TextureMap)

Aggregations

BlockPos (net.minecraft.util.math.BlockPos)2 WorldProviderDiona (stevekung.mods.moreplanets.module.planets.diona.dimension.WorldProviderDiona)2 TextureMap (net.minecraft.client.renderer.texture.TextureMap)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 MutableBlockPos (net.minecraft.util.math.BlockPos.MutableBlockPos)1 World (net.minecraft.world.World)1 WorldServer (net.minecraft.world.WorldServer)1 Chunk (net.minecraft.world.chunk.Chunk)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 WorldDataStartedDimension (stevekung.mods.moreplanets.core.data.WorldDataStartedDimension)1 EntityAlienBeam (stevekung.mods.moreplanets.module.planets.diona.entity.EntityAlienBeam)1 WorldProviderNibiru (stevekung.mods.moreplanets.module.planets.nibiru.dimension.WorldProviderNibiru)1 EntityNibiruLightningBolt (stevekung.mods.moreplanets.module.planets.nibiru.entity.weather.EntityNibiruLightningBolt)1