Skip to content

Commit

Permalink
1.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
wode490390 committed Jan 27, 2020
1 parent c66cc42 commit 0eed26f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 10 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>cn.wode490390.nukkit</groupId>
<artifactId>scatteredbuildingpopulator</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<version>1.0.1</version>
<name>ScatteredBuildingPopulator</name>
<description>Scattered building populator plugin for Nukkit</description>
<url>http://wode490390.cn/</url>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,14 @@
import cn.nukkit.event.level.LevelLoadEvent;
import cn.nukkit.event.level.LevelUnloadEvent;
import cn.nukkit.level.Level;
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.level.generator.Generator;
import cn.nukkit.level.generator.populator.type.Populator;
import cn.nukkit.math.NukkitRandom;
import cn.nukkit.plugin.PluginBase;
import cn.nukkit.utils.Logger;
import cn.wode490390.nukkit.scatteredbuilding.populator.PopulatorDesertPyramid;
import cn.wode490390.nukkit.scatteredbuilding.populator.PopulatorJungleTemple;
import cn.wode490390.nukkit.scatteredbuilding.populator.PopulatorSwampHut;
import cn.wode490390.nukkit.scatteredbuilding.scheduler.ChunkPopulateTask;
import cn.wode490390.nukkit.scatteredbuilding.util.MetricsLite;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
Expand Down Expand Up @@ -67,13 +66,7 @@ public void onChunkPopulate(ChunkPopulateEvent event) {
Level level = event.getLevel();
List<Populator> populators = this.populators.get(level);
if (populators != null) {
FullChunk chunk = event.getChunk();
int chunkX = chunk.getX();
int chunkZ = chunk.getZ();
NukkitRandom random = new NukkitRandom(0xdeadbeef ^ (chunkX << 8) ^ chunkZ ^ level.getSeed());
populators.forEach(populator -> {
populator.populate(level, chunkX, chunkZ, random, chunk);
});
this.getServer().getScheduler().scheduleAsyncTask(this, new ChunkPopulateTask(level, event.getChunk(), populators));
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package cn.wode490390.nukkit.scatteredbuilding.scheduler;

import cn.nukkit.level.ChunkManager;
import cn.nukkit.level.format.FullChunk;
import cn.nukkit.level.generator.populator.type.Populator;
import cn.nukkit.math.NukkitRandom;
import cn.nukkit.scheduler.AsyncTask;
import java.util.Collection;

public class ChunkPopulateTask extends AsyncTask {

private final ChunkManager level;
private final FullChunk chunk;
private final Collection<Populator> populators;

public ChunkPopulateTask(ChunkManager level, FullChunk chunk, Collection<Populator> populators) {
this.level = level;
this.chunk = chunk;
this.populators = populators;
}

@Override
public void onRun() {
int chunkX = this.chunk.getX();
int chunkZ = this.chunk.getZ();
NukkitRandom random = new NukkitRandom(0xdeadbeef ^ (chunkX << 8) ^ chunkZ ^ this.level.getSeed());
this.populators.forEach(populator -> {
populator.populate(this.level, chunkX, chunkZ, random, this.chunk);
});
}
}

0 comments on commit 0eed26f

Please sign in to comment.