Skip to content

Commit

Permalink
Send biome updates [WIP]
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Nov 29, 2023
1 parent e7c9e64 commit 0b07d29
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.sk89q.worldedit.util.SideEffectSet;
import com.sk89q.worldedit.util.collection.BlockMap;
import com.sk89q.worldedit.world.World;
import com.sk89q.worldedit.world.biome.BiomeType;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;

Expand All @@ -50,6 +51,7 @@ public class SideEffectExtent extends AbstractDelegateExtent {
private final World world;
private final Map<BlockVector3, BlockState> positions = BlockMap.create();
private final Set<BlockVector2> dirtyChunks = new HashSet<>();
private final Set<BlockVector2> dirtyBiomes = new HashSet<>();
private SideEffectSet sideEffectSet = SideEffectSet.defaults();
private boolean postEditSimulation;

Expand Down Expand Up @@ -97,8 +99,14 @@ public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 location, B
return world.setBlock(location, block, postEditSimulation ? INTERNAL_NONE : sideEffectSet);
}

@Override
public boolean setBiome(BlockVector3 position, BiomeType biome) {
dirtyBiomes.add(BlockVector2.at(position.getBlockX() >> 4, position.getBlockZ() >> 4));
return world.setBiome(position, biome);
}

public boolean commitRequired() {
return postEditSimulation || !dirtyChunks.isEmpty();
return postEditSimulation || !dirtyChunks.isEmpty() || !dirtyBiomes.isEmpty();
}

@Override
Expand All @@ -113,6 +121,10 @@ public Operation resume(RunContext run) throws WorldEditException {
world.fixAfterFastMode(dirtyChunks);
}

if (!dirtyBiomes.isEmpty()) {
world.sendBiomeUpdates(dirtyBiomes);
}

if (postEditSimulation) {
Iterator<Map.Entry<BlockVector3, BlockState>> positionIterator = positions.entrySet().iterator();
while (run.shouldContinue() && positionIterator.hasNext()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ public void checkLoadedChunk(BlockVector3 pt) {
public void fixAfterFastMode(Iterable<BlockVector2> chunks) {
}

@Override
public void sendBiomeUpdates(Iterable<BlockVector2> chunks) {
}

@Override
public void fixLighting(Iterable<BlockVector2> chunks) {
}
Expand Down
11 changes: 11 additions & 0 deletions worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,17 @@ default boolean generateFeature(ConfiguredFeatureType type, EditSession editSess
*/
void fixAfterFastMode(Iterable<BlockVector2> chunks);

/**
* Sends biome updates for the given chunks.
*
* <p>This doesn't modify biomes at all, it just sends the current state of the biomes
* in the world to all of the nearby players, updating the visual representation of the
* biomes on their clients.</p>
*
* @param chunks a list of chunk coordinates to send biome updates for
*/
void sendBiomeUpdates(Iterable<BlockVector2> chunks);

/**
* Relight the given chunks if possible.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import com.google.common.cache.CacheLoader;
import com.google.common.cache.LoadingCache;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.collect.Streams;
import com.google.common.util.concurrent.Futures;
Expand Down Expand Up @@ -526,6 +528,15 @@ public void fixAfterFastMode(Iterable<BlockVector2> chunks) {
fixLighting(chunks);
}

@Override
public void sendBiomeUpdates(Iterable<BlockVector2> chunks) {
List<ChunkAccess> nativeChunks = Lists.newArrayListWithCapacity(Iterables.size(chunks));
for (BlockVector2 chunk : chunks) {
nativeChunks.add(getWorld().getChunk(chunk.getBlockX(), chunk.getBlockZ(), ChunkStatus.BIOMES, false));
}
((ServerLevel) getWorld()).getChunkSource().chunkMap.resendBiomesForChunks(nativeChunks);
}

@Override
public void fixLighting(Iterable<BlockVector2> chunks) {
Level world = getWorld();
Expand Down

0 comments on commit 0b07d29

Please sign in to comment.