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));
}
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;
}
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;
}
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);
}
}
}
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();
}
Aggregations