Skip to content

Commit

Permalink
Fixed #208
Browse files Browse the repository at this point in the history
  • Loading branch information
wdog5 committed Jan 7, 2024
1 parent 4883fcb commit a4ae1ad
Showing 1 changed file with 14 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public BlockState setBlockState(BlockPos pos, BlockState state, boolean isMoving
@Override
public void loadCallback() {
org.bukkit.Server server = Bukkit.getServer();
if (server != null) {
if (server != null && r != null) {
/*
* If it's a new world, the first few chunks are generated inside
* the World constructor. We can't reliably alter that, so we have
Expand All @@ -116,20 +116,20 @@ public void loadCallback() {
if (this.needsDecoration) {
this.needsDecoration = false;
java.util.Random random = new java.util.Random();
random.setSeed(((ServerLevel) level).getSeed());
random.setSeed(this.r.getSeed());
long xRand = random.nextLong() / 2L * 2L + 1L;
long zRand = random.nextLong() / 2L * 2L + 1L;
random.setSeed((long) this.chunkPos.x * xRand + (long) this.chunkPos.z * zRand ^ ((ServerLevel) level).getSeed());
random.setSeed((long) this.chunkPos.x * xRand + (long) this.chunkPos.z * zRand ^ this.r.getSeed());

org.bukkit.World world = this.level.getWorld();
org.bukkit.World world = this.r.getWorld();
if (world != null) {
this.level.banner$setPopulating(true);
this.r.banner$setPopulating(true);
try {
for (org.bukkit.generator.BlockPopulator populator : world.getPopulators()) {
populator.populate(world, random, bukkitChunk);
}
} finally {
this.level.banner$setPopulating(false);
this.r.banner$setPopulating(false);
}
}
server.getPluginManager().callEvent(new org.bukkit.event.world.ChunkPopulateEvent(bukkitChunk));
Expand All @@ -139,12 +139,14 @@ public void loadCallback() {

@Override
public void unloadCallback() {
org.bukkit.Server server = this.getLevel().getCraftServer();
var bukkitChunk = new CraftChunk((LevelChunk) (Object) this);
org.bukkit.event.world.ChunkUnloadEvent unloadEvent = new org.bukkit.event.world.ChunkUnloadEvent(bukkitChunk, this.isUnsaved());
server.getPluginManager().callEvent(unloadEvent);
// note: saving can be prevented, but not forced if no saving is actually required
this.mustNotSave = !unloadEvent.isSaveChunk();
if (this.r != null) {
org.bukkit.Server server = this.getLevel().getCraftServer();
var bukkitChunk = new CraftChunk((LevelChunk) (Object) this);
org.bukkit.event.world.ChunkUnloadEvent unloadEvent = new org.bukkit.event.world.ChunkUnloadEvent(bukkitChunk, this.isUnsaved());
server.getPluginManager().callEvent(unloadEvent);
// note: saving can be prevented, but not forced if no saving is actually required
this.mustNotSave = !unloadEvent.isSaveChunk();
}
}

@Redirect(method = "setBlockState", at = @At(value = "FIELD", ordinal = 1, target = "Lnet/minecraft/world/level/Level;isClientSide:Z"))
Expand Down

0 comments on commit a4ae1ad

Please sign in to comment.