Skip to content

Commit 0b07d29

Browse files
committed
Send biome updates [WIP]
1 parent e7c9e64 commit 0b07d29

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

worldedit-core/src/main/java/com/sk89q/worldedit/extent/world/SideEffectExtent.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import com.sk89q.worldedit.util.SideEffectSet;
3030
import com.sk89q.worldedit.util.collection.BlockMap;
3131
import com.sk89q.worldedit.world.World;
32+
import com.sk89q.worldedit.world.biome.BiomeType;
3233
import com.sk89q.worldedit.world.block.BlockState;
3334
import com.sk89q.worldedit.world.block.BlockStateHolder;
3435

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

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

102+
@Override
103+
public boolean setBiome(BlockVector3 position, BiomeType biome) {
104+
dirtyBiomes.add(BlockVector2.at(position.getBlockX() >> 4, position.getBlockZ() >> 4));
105+
return world.setBiome(position, biome);
106+
}
107+
100108
public boolean commitRequired() {
101-
return postEditSimulation || !dirtyChunks.isEmpty();
109+
return postEditSimulation || !dirtyChunks.isEmpty() || !dirtyBiomes.isEmpty();
102110
}
103111

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

124+
if (!dirtyBiomes.isEmpty()) {
125+
world.sendBiomeUpdates(dirtyBiomes);
126+
}
127+
116128
if (postEditSimulation) {
117129
Iterator<Map.Entry<BlockVector3, BlockState>> positionIterator = positions.entrySet().iterator();
118130
while (run.shouldContinue() && positionIterator.hasNext()) {

worldedit-core/src/main/java/com/sk89q/worldedit/world/AbstractWorld.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ public void checkLoadedChunk(BlockVector3 pt) {
9494
public void fixAfterFastMode(Iterable<BlockVector2> chunks) {
9595
}
9696

97+
@Override
98+
public void sendBiomeUpdates(Iterable<BlockVector2> chunks) {
99+
}
100+
97101
@Override
98102
public void fixLighting(Iterable<BlockVector2> chunks) {
99103
}

worldedit-core/src/main/java/com/sk89q/worldedit/world/World.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,17 @@ default boolean generateFeature(ConfiguredFeatureType type, EditSession editSess
311311
*/
312312
void fixAfterFastMode(Iterable<BlockVector2> chunks);
313313

314+
/**
315+
* Sends biome updates for the given chunks.
316+
*
317+
* <p>This doesn't modify biomes at all, it just sends the current state of the biomes
318+
* in the world to all of the nearby players, updating the visual representation of the
319+
* biomes on their clients.</p>
320+
*
321+
* @param chunks a list of chunk coordinates to send biome updates for
322+
*/
323+
void sendBiomeUpdates(Iterable<BlockVector2> chunks);
324+
314325
/**
315326
* Relight the given chunks if possible.
316327
*

worldedit-fabric/src/main/java/com/sk89q/worldedit/fabric/FabricWorld.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import com.google.common.cache.CacheLoader;
2424
import com.google.common.cache.LoadingCache;
2525
import com.google.common.collect.ImmutableList;
26+
import com.google.common.collect.Iterables;
27+
import com.google.common.collect.Lists;
2628
import com.google.common.collect.Sets;
2729
import com.google.common.collect.Streams;
2830
import com.google.common.util.concurrent.Futures;
@@ -526,6 +528,15 @@ public void fixAfterFastMode(Iterable<BlockVector2> chunks) {
526528
fixLighting(chunks);
527529
}
528530

531+
@Override
532+
public void sendBiomeUpdates(Iterable<BlockVector2> chunks) {
533+
List<ChunkAccess> nativeChunks = Lists.newArrayListWithCapacity(Iterables.size(chunks));
534+
for (BlockVector2 chunk : chunks) {
535+
nativeChunks.add(getWorld().getChunk(chunk.getBlockX(), chunk.getBlockZ(), ChunkStatus.BIOMES, false));
536+
}
537+
((ServerLevel) getWorld()).getChunkSource().chunkMap.resendBiomesForChunks(nativeChunks);
538+
}
539+
529540
@Override
530541
public void fixLighting(Iterable<BlockVector2> chunks) {
531542
Level world = getWorld();

0 commit comments

Comments
 (0)