From db38e9a8f5b89f16d846248635907295a2a619bd Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Wed, 12 Jan 2022 10:52:51 +1100 Subject: [PATCH] #987: Add generateTree method with a predicate By: DerFrZocker --- .../bukkit/craftbukkit/CraftRegionAccessor.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java index d7e027a6d5..1f3593b7b0 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/CraftRegionAccessor.java @@ -7,6 +7,7 @@ import java.util.Iterator; import java.util.List; import java.util.Optional; import java.util.Random; +import java.util.function.Predicate; import net.minecraft.core.BlockPosition; import net.minecraft.core.EnumDirection; import net.minecraft.core.IRegistry; @@ -297,16 +298,23 @@ public abstract class CraftRegionAccessor implements RegionAccessor { @Override public boolean generateTree(Location location, Random random, TreeType treeType, Consumer consumer) { + return generateTree(location, random, treeType, (consumer == null) ? null : (block) -> { + consumer.accept(block); + return true; + }); + } + + @Override + public boolean generateTree(Location location, Random random, TreeType treeType, Predicate predicate) { BlockPosition pos = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ()); BlockStateListPopulator populator = new BlockStateListPopulator(getHandle()); boolean result = generateTree(populator, getHandle().getMinecraftWorld().getChunkSource().getGenerator(), pos, random, treeType); populator.refreshTiles(); for (BlockState blockState : populator.getList()) { - if (consumer != null) { - consumer.accept(blockState); + if (predicate == null || predicate.test(blockState)) { + blockState.update(true, true); } - blockState.update(true, true); } return result;