Search in sources :

Example 1 with IChunkGenerator

use of net.minecraft.world.gen.IChunkGenerator in project SpongeCommon by SpongePowered.

the class MixinWorldServer method createWorldGenerator.

@Override
public SpongeWorldGenerator createWorldGenerator(String settings) {
    final WorldServer worldServer = (WorldServer) (Object) this;
    final WorldType worldType = worldServer.getWorldType();
    final IChunkGenerator chunkGenerator;
    final BiomeProvider biomeProvider;
    if (worldType instanceof SpongeWorldType) {
        chunkGenerator = ((SpongeWorldType) worldType).getChunkGenerator(worldServer, settings);
        biomeProvider = ((SpongeWorldType) worldType).getBiomeProvider(worldServer);
    } else {
        final IChunkGenerator currentGenerator = this.getChunkProvider().chunkGenerator;
        if (currentGenerator != null) {
            chunkGenerator = currentGenerator;
        } else {
            final WorldProvider worldProvider = worldServer.provider;
            ((IMixinWorldProvider) worldProvider).setGeneratorSettings(settings);
            chunkGenerator = worldProvider.createChunkGenerator();
        }
        biomeProvider = worldServer.provider.biomeProvider;
    }
    return new SpongeWorldGenerator(worldServer, (BiomeGenerator) biomeProvider, SpongeGenerationPopulator.of(worldServer, chunkGenerator));
}
Also used : BiomeProvider(net.minecraft.world.biome.BiomeProvider) IMixinWorldProvider(org.spongepowered.common.interfaces.world.IMixinWorldProvider) SpongeWorldType(org.spongepowered.common.world.type.SpongeWorldType) WorldType(net.minecraft.world.WorldType) IChunkGenerator(net.minecraft.world.gen.IChunkGenerator) IMixinWorldProvider(org.spongepowered.common.interfaces.world.IMixinWorldProvider) WorldProvider(net.minecraft.world.WorldProvider) WorldServer(net.minecraft.world.WorldServer) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) SpongeWorldGenerator(org.spongepowered.common.world.gen.SpongeWorldGenerator) SpongeWorldType(org.spongepowered.common.world.type.SpongeWorldType)

Example 2 with IChunkGenerator

use of net.minecraft.world.gen.IChunkGenerator in project SpongeCommon by SpongePowered.

the class MixinWorldServer method updateWorldGenerator.

@Override
public void updateWorldGenerator() {
    // Get the default generator for the world type
    DataContainer generatorSettings = this.getProperties().getGeneratorSettings();
    SpongeWorldGenerator newGenerator = createWorldGenerator(generatorSettings);
    // by the base generation populator
    if (newGenerator.getBaseGenerationPopulator() instanceof IChunkGenerator) {
        // from a mod chunk provider extending a provider that we mixed into
        if (WorldGenConstants.isValid((IChunkGenerator) newGenerator.getBaseGenerationPopulator(), IPopulatorProvider.class)) {
            ((IPopulatorProvider) newGenerator.getBaseGenerationPopulator()).addPopulators(newGenerator);
        }
    } else if (newGenerator.getBaseGenerationPopulator() instanceof IPopulatorProvider) {
        // If its not a chunk provider but is a populator provider then we call it as well
        ((IPopulatorProvider) newGenerator.getBaseGenerationPopulator()).addPopulators(newGenerator);
    }
    for (WorldGeneratorModifier modifier : this.getProperties().getGeneratorModifiers()) {
        modifier.modifyWorldGenerator(this.getProperties(), generatorSettings, newGenerator);
    }
    this.spongegen = createChunkGenerator(newGenerator);
    this.spongegen.setGenerationPopulators(newGenerator.getGenerationPopulators());
    this.spongegen.setPopulators(newGenerator.getPopulators());
    this.spongegen.setBiomeOverrides(newGenerator.getBiomeSettings());
    ChunkProviderServer chunkProviderServer = this.getChunkProvider();
    chunkProviderServer.chunkGenerator = this.spongegen;
}
Also used : DataContainer(org.spongepowered.api.data.DataContainer) WorldGeneratorModifier(org.spongepowered.api.world.gen.WorldGeneratorModifier) IChunkGenerator(net.minecraft.world.gen.IChunkGenerator) IPopulatorProvider(org.spongepowered.common.interfaces.world.gen.IPopulatorProvider) IMixinChunkProviderServer(org.spongepowered.common.interfaces.world.gen.IMixinChunkProviderServer) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) SpongeWorldGenerator(org.spongepowered.common.world.gen.SpongeWorldGenerator)

Example 3 with IChunkGenerator

use of net.minecraft.world.gen.IChunkGenerator in project Minestuck by mraof.

the class SessionHandler method createDataTag.

/**
 * Creates data to be used for the data checker
 */
public static NBTTagCompound createDataTag(MinecraftServer server) {
    NBTTagCompound nbt = new NBTTagCompound();
    NBTTagList sessionList = new NBTTagList();
    nbt.setTag("sessions", sessionList);
    int nameIndex = 1;
    for (int i = 0; i < sessions.size(); i++) {
        Session session = sessions.get(i);
        NBTTagList connectionList = new NBTTagList();
        Set<PlayerIdentifier> playerSet = new HashSet<PlayerIdentifier>();
        for (SburbConnection c : session.connections) {
            if (c.isMain)
                playerSet.add(c.getClientIdentifier());
            NBTTagCompound connectionTag = new NBTTagCompound();
            connectionTag.setString("client", c.getClientIdentifier().getUsername());
            connectionTag.setString("clientId", c.getClientIdentifier().getString());
            if (!c.getServerIdentifier().equals(IdentifierHandler.nullIdentifier))
                connectionTag.setString("server", c.getServerIdentifier().getUsername());
            connectionTag.setBoolean("isMain", c.isMain);
            connectionTag.setBoolean("isActive", c.isActive);
            if (c.isMain) {
                connectionTag.setInteger("clientDim", c.enteredGame ? c.clientHomeLand : 0);
                if (c.enteredGame && DimensionManager.isDimensionRegistered(c.clientHomeLand)) {
                    LandAspectRegistry.AspectCombination aspects = MinestuckDimensionHandler.getAspects(c.clientHomeLand);
                    IChunkGenerator chunkGen = server.getWorld(c.clientHomeLand).provider.createChunkGenerator();
                    if (chunkGen instanceof ChunkProviderLands) {
                        ChunkProviderLands landChunkGen = (ChunkProviderLands) chunkGen;
                        if (landChunkGen.nameOrder) {
                            connectionTag.setString("aspect1", aspects.aspectTerrain.getNames()[landChunkGen.nameIndex1]);
                            connectionTag.setString("aspect2", aspects.aspectTitle.getNames()[landChunkGen.nameIndex2]);
                        } else {
                            connectionTag.setString("aspect1", aspects.aspectTitle.getNames()[landChunkGen.nameIndex2]);
                            connectionTag.setString("aspect2", aspects.aspectTerrain.getNames()[landChunkGen.nameIndex1]);
                        }
                    }
                    Title title = MinestuckPlayerData.getTitle(c.getClientIdentifier());
                    connectionTag.setByte("class", title == null ? -1 : (byte) title.getHeroClass().ordinal());
                    connectionTag.setByte("aspect", title == null ? -1 : (byte) title.getHeroAspect().ordinal());
                } else if (session.predefinedPlayers.containsKey(c.getClientIdentifier())) {
                    PredefineData data = session.predefinedPlayers.get(c.getClientIdentifier());
                    if (data.title != null) {
                        connectionTag.setByte("class", (byte) data.title.getHeroClass().ordinal());
                        connectionTag.setByte("aspect", (byte) data.title.getHeroAspect().ordinal());
                    }
                    if (data.landTerrain != null)
                        connectionTag.setString("aspectTerrain", data.landTerrain.getPrimaryName());
                    if (data.landTitle != null)
                        connectionTag.setString("aspectTitle", data.landTitle.getPrimaryName());
                }
            }
            connectionList.appendTag(connectionTag);
        }
        for (Map.Entry<PlayerIdentifier, PredefineData> entry : session.predefinedPlayers.entrySet()) {
            if (playerSet.contains(entry.getKey()))
                continue;
            NBTTagCompound connectionTag = new NBTTagCompound();
            connectionTag.setString("client", entry.getKey().getUsername());
            connectionTag.setString("clientId", entry.getKey().getString());
            connectionTag.setBoolean("isMain", true);
            connectionTag.setBoolean("isActive", false);
            connectionTag.setInteger("clientDim", 0);
            PredefineData data = entry.getValue();
            if (data.title != null) {
                connectionTag.setByte("class", (byte) data.title.getHeroClass().ordinal());
                connectionTag.setByte("aspect", (byte) data.title.getHeroAspect().ordinal());
            }
            if (data.landTerrain != null)
                connectionTag.setString("aspectTerrain", data.landTerrain.getPrimaryName());
            if (data.landTitle != null)
                connectionTag.setString("aspectTitle", data.landTitle.getPrimaryName());
            connectionList.appendTag(connectionTag);
        }
        NBTTagCompound sessionTag = new NBTTagCompound();
        if (session.name != null)
            sessionTag.setString("name", session.name);
        sessionTag.setTag("connections", connectionList);
        sessionList.appendTag(sessionTag);
    }
    return nbt;
}
Also used : ChunkProviderLands(com.mraof.minestuck.world.lands.gen.ChunkProviderLands) IChunkGenerator(net.minecraft.world.gen.IChunkGenerator) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Title(com.mraof.minestuck.util.Title) PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier) LandAspectRegistry(com.mraof.minestuck.world.lands.LandAspectRegistry) NBTTagList(net.minecraft.nbt.NBTTagList)

Example 4 with IChunkGenerator

use of net.minecraft.world.gen.IChunkGenerator in project OreSpawn by MinecraftModDevelopmentMods.

the class EventHandlers method worldTick.

@SubscribeEvent
public void worldTick(WorldTickEvent ev) {
    if (ev.side != Side.SERVER) {
        return;
    }
    World world = ev.world;
    if (ev.phase == Phase.END) {
        Deque<ChunkPos> keys = Queues.newArrayDeque(chunks.keySet());
        for (int c = 0; c < 5 && !chunks.isEmpty(); c++) {
            ChunkPos p = keys.pop();
            List<String> spawns = chunks.remove(p);
            Random random = new Random(world.getSeed());
            // re-seed with something totally new :P
            random.setSeed((((random.nextLong() >> 4 + 1) + p.x) + ((random.nextLong() >> 2 + 1) + p.z)) ^ world.getSeed());
            ChunkProviderServer chunkProvider = (ChunkProviderServer) world.getChunkProvider();
            IChunkGenerator chunkGenerator = ObfuscationReflectionHelper.getPrivateValue(ChunkProviderServer.class, chunkProvider, "field_186029_c", "chunkGenerator");
            for (String s : spawns) {
                OreSpawn.API.getSpawn(s).generate(random, world, chunkGenerator, chunkProvider, p);
            }
        }
        for (int c = 0; c < 5 && !retroChunks.isEmpty(); c++) {
            ChunkPos p = retroChunks.pop();
            OreSpawn.flatBedrock.retrogen(world, p.x, p.z);
        }
    }
}
Also used : IChunkGenerator(net.minecraft.world.gen.IChunkGenerator) Random(java.util.Random) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) ChunkPos(net.minecraft.util.math.ChunkPos) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 5 with IChunkGenerator

use of net.minecraft.world.gen.IChunkGenerator in project SpongeForge by SpongePowered.

the class SpongeChunkGeneratorForge method populate.

@Override
public void populate(int chunkX, int chunkZ) {
    final PhaseTracker phaseTracker = PhaseTracker.getInstance();
    this.chunkGeneratorTiming.startTimingIfSync();
    this.rand.setSeed(this.world.getSeed());
    long i1 = this.rand.nextLong() / 2L * 2L + 1L;
    long j1 = this.rand.nextLong() / 2L * 2L + 1L;
    this.rand.setSeed(chunkX * i1 + chunkZ * j1 ^ this.world.getSeed());
    BlockFalling.fallInstantly = true;
    // Have to regeneate the biomes so that any virtual biomes can be passed to the populator.
    this.cachedBiomes.reuse(new Vector3i(chunkX * 16, 0, chunkZ * 16));
    this.biomeGenerator.generateBiomes(this.cachedBiomes);
    ImmutableBiomeVolume biomeBuffer = this.cachedBiomes.getImmutableBiomeCopy();
    BlockPos blockpos = new BlockPos(chunkX * 16, 0, chunkZ * 16);
    BiomeType biome = (BiomeType) this.world.getBiome(blockpos.add(16, 0, 16));
    Chunk chunk = (Chunk) this.world.getChunkFromChunkCoords(chunkX, chunkZ);
    BiomeGenerationSettings settings = getBiomeSettings(biome);
    List<Populator> populators = new ArrayList<>(this.pop);
    Populator snowPopulator = null;
    Iterator<Populator> itr = populators.iterator();
    while (itr.hasNext()) {
        Populator populator = itr.next();
        if (populator instanceof SnowPopulator) {
            itr.remove();
            snowPopulator = populator;
            break;
        }
    }
    populators.addAll(settings.getPopulators());
    if (snowPopulator != null) {
        populators.add(snowPopulator);
    }
    Sponge.getGame().getEventManager().post(SpongeEventFactory.createPopulateChunkEventPre(Sponge.getCauseStackManager().getCurrentCause(), populators, chunk));
    MinecraftForge.EVENT_BUS.post(new PopulateChunkEvent.Pre(this, this.world, this.rand, chunkX, chunkZ, false));
    MinecraftForge.EVENT_BUS.post(new DecorateBiomeEvent.Pre(this.world, this.rand, blockpos));
    MinecraftForge.ORE_GEN_BUS.post(new OreGenEvent.Pre(this.world, this.rand, blockpos));
    List<String> flags = Lists.newArrayList();
    Vector3i min = new Vector3i(chunkX * 16 + 8, 0, chunkZ * 16 + 8);
    org.spongepowered.api.world.World spongeWorld = (org.spongepowered.api.world.World) this.world;
    Extent volume = new SoftBufferExtentViewDownsize(chunk.getWorld(), min, min.add(15, 255, 15), min.sub(8, 0, 8), min.add(23, 255, 23));
    for (Populator populator : populators) {
        if (!(populator instanceof PlainsGrassPopulator)) {
            if (!this.checkForgeEvent(populator, this, chunkX, chunkZ, flags, chunk)) {
                continue;
            }
        } else {
            final PlainsGrassPopulator grassPop = (PlainsGrassPopulator) populator;
            if (!this.checkForgeEvent(grassPop.getFlowers(), this, chunkX, chunkZ, flags, chunk)) {
                grassPop.setPopulateFlowers(false);
            }
            if (!this.checkForgeEvent(grassPop.getGrass(), this, chunkX, chunkZ, flags, chunk)) {
                grassPop.setPopulateGrass(false);
            }
            if (!this.checkForgeEvent(grassPop.getPlant(), this, chunkX, chunkZ, flags, chunk)) {
                grassPop.setPopulateGrass(false);
            }
            if (!grassPop.isPopulateFlowers() && !grassPop.isPopulateGrass()) {
                continue;
            }
        }
        final PopulatorType type = populator.getType();
        if (Sponge.getGame().getEventManager().post(SpongeEventFactory.createPopulateChunkEventPopulate(Sponge.getCauseStackManager().getCurrentCause(), populator, chunk))) {
            continue;
        }
        try (PopulatorPhaseContext context = GenerationPhase.State.POPULATOR_RUNNING.createPhaseContext().world(this.world).populator(type).buildAndSwitch()) {
            Timing timing = null;
            if (Timings.isTimingsEnabled()) {
                timing = this.populatorTimings.get(populator.getType().getId());
                if (timing == null) {
                    timing = SpongeTimingsFactory.ofSafe(populator.getType().getId());
                    this.populatorTimings.put(populator.getType().getId(), timing);
                }
                timing.startTimingIfSync();
            }
            if (populator instanceof IFlaggedPopulator) {
                ((IFlaggedPopulator) populator).populate(spongeWorld, volume, this.rand, biomeBuffer, flags);
            } else {
                populator.populate(spongeWorld, volume, this.rand, biomeBuffer);
            }
            if (Timings.isTimingsEnabled()) {
                timing.stopTimingIfSync();
            }
        }
    }
    MinecraftForge.ORE_GEN_BUS.post(new OreGenEvent.Post(this.world, this.rand, blockpos));
    MinecraftForge.EVENT_BUS.post(new DecorateBiomeEvent.Post(this.world, this.rand, blockpos));
    MinecraftForge.EVENT_BUS.post(new PopulateChunkEvent.Post(this, this.world, this.rand, chunkX, chunkZ, false));
    // populate method so that its particular changes are used.
    if (this.baseGenerator instanceof SpongeGenerationPopulator) {
        Timing timing = null;
        IChunkGenerator chunkGenerator = ((SpongeGenerationPopulator) this.baseGenerator).getHandle(this.world);
        if (Timings.isTimingsEnabled()) {
            IGenerationPopulator spongePopulator = (IGenerationPopulator) this.baseGenerator;
            timing = spongePopulator.getTimingsHandler();
            timing.startTimingIfSync();
        }
        chunkGenerator.populate(chunkX, chunkZ);
        if (Timings.isTimingsEnabled()) {
            timing.stopTimingIfSync();
        }
    }
    org.spongepowered.api.event.world.chunk.PopulateChunkEvent.Post event = SpongeEventFactory.createPopulateChunkEventPost(Sponge.getCauseStackManager().getCurrentCause(), ImmutableList.copyOf(populators), chunk);
    SpongeImpl.postEvent(event);
    BlockFalling.fallInstantly = false;
    this.chunkGeneratorTiming.stopTimingIfSync();
    ((IMixinWorldServer) spongeWorld).getTimingsHandler().chunkPopulate.stopTimingIfSync();
}
Also used : PlainsGrassPopulator(org.spongepowered.common.world.gen.populators.PlainsGrassPopulator) IChunkGenerator(net.minecraft.world.gen.IChunkGenerator) OreGenEvent(net.minecraftforge.event.terraingen.OreGenEvent) Extent(org.spongepowered.api.world.extent.Extent) ArrayList(java.util.ArrayList) IGenerationPopulator(org.spongepowered.common.interfaces.world.gen.IGenerationPopulator) PopulatorType(org.spongepowered.api.world.gen.PopulatorType) World(net.minecraft.world.World) BiomeType(org.spongepowered.api.world.biome.BiomeType) SoftBufferExtentViewDownsize(org.spongepowered.common.world.extent.SoftBufferExtentViewDownsize) BlockPos(net.minecraft.util.math.BlockPos) BiomeGenerationSettings(org.spongepowered.api.world.biome.BiomeGenerationSettings) GenerationPopulator(org.spongepowered.api.world.gen.GenerationPopulator) PlainsGrassPopulator(org.spongepowered.common.world.gen.populators.PlainsGrassPopulator) SpongeGenerationPopulator(org.spongepowered.common.world.gen.SpongeGenerationPopulator) Populator(org.spongepowered.api.world.gen.Populator) AnimalPopulator(org.spongepowered.common.world.gen.populators.AnimalPopulator) IFlaggedPopulator(org.spongepowered.common.interfaces.world.gen.IFlaggedPopulator) SnowPopulator(org.spongepowered.common.world.gen.populators.SnowPopulator) IGenerationPopulator(org.spongepowered.common.interfaces.world.gen.IGenerationPopulator) DecorateBiomeEvent(net.minecraftforge.event.terraingen.DecorateBiomeEvent) ImmutableBiomeVolume(org.spongepowered.api.world.extent.ImmutableBiomeVolume) PopulatorPhaseContext(org.spongepowered.common.event.tracking.phase.generation.PopulatorPhaseContext) IFlaggedPopulator(org.spongepowered.common.interfaces.world.gen.IFlaggedPopulator) SpongeGenerationPopulator(org.spongepowered.common.world.gen.SpongeGenerationPopulator) PopulateChunkEvent(net.minecraftforge.event.terraingen.PopulateChunkEvent) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) Chunk(org.spongepowered.api.world.Chunk) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) Vector3i(com.flowpowered.math.vector.Vector3i) SnowPopulator(org.spongepowered.common.world.gen.populators.SnowPopulator) Timing(co.aikar.timings.Timing)

Aggregations

IChunkGenerator (net.minecraft.world.gen.IChunkGenerator)6 World (net.minecraft.world.World)3 Random (java.util.Random)2 ChunkPos (net.minecraft.util.math.ChunkPos)2 ChunkProviderServer (net.minecraft.world.gen.ChunkProviderServer)2 IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)2 SpongeWorldGenerator (org.spongepowered.common.world.gen.SpongeWorldGenerator)2 Timing (co.aikar.timings.Timing)1 Vector3i (com.flowpowered.math.vector.Vector3i)1 PlayerIdentifier (com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)1 Title (com.mraof.minestuck.util.Title)1 LandAspectRegistry (com.mraof.minestuck.world.lands.LandAspectRegistry)1 ChunkProviderLands (com.mraof.minestuck.world.lands.gen.ChunkProviderLands)1 ArrayList (java.util.ArrayList)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1 BlockPos (net.minecraft.util.math.BlockPos)1 WorldProvider (net.minecraft.world.WorldProvider)1 WorldServer (net.minecraft.world.WorldServer)1 WorldType (net.minecraft.world.WorldType)1