craftbukkit/nms-patches/net/minecraft/world/level/block/BlockSapling.patch

61 lines
3 KiB
Diff
Raw Normal View History

2021-03-16 09:00:00 +11:00
--- a/net/minecraft/world/level/block/BlockSapling.java
+++ b/net/minecraft/world/level/block/BlockSapling.java
@@ -17,6 +17,15 @@
2021-03-16 09:00:00 +11:00
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
+// CraftBukkit start
+import org.bukkit.Location;
+import org.bukkit.TreeType;
+import org.bukkit.block.BlockState;
+import org.bukkit.craftbukkit.block.CapturedBlockState;
+import org.bukkit.craftbukkit.util.CraftLocation;
+import org.bukkit.event.world.StructureGrowEvent;
+// CraftBukkit end
+
2025-03-26 03:05:00 +11:00
public class BlockSapling extends VegetationBlock implements IBlockFragilePlantElement {
2023-12-06 03:40:00 +11:00
public static final MapCodec<BlockSapling> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
2025-03-26 03:05:00 +11:00
@@ -27,6 +36,7 @@
public static final BlockStateInteger STAGE = BlockProperties.STAGE;
private static final VoxelShape SHAPE = Block.column(12.0D, 0.0D, 12.0D);
2023-12-06 03:40:00 +11:00
protected final WorldGenTreeProvider treeGrower;
+ public static TreeType treeType; // CraftBukkit
2023-12-06 03:40:00 +11:00
@Override
public MapCodec<? extends BlockSapling> codec() {
2025-03-26 03:05:00 +11:00
@@ -56,7 +66,32 @@
if ((Integer) iblockdata.getValue(BlockSapling.STAGE) == 0) {
2025-03-26 03:05:00 +11:00
worldserver.setBlock(blockposition, (IBlockData) iblockdata.cycle(BlockSapling.STAGE), 260);
} else {
- this.treeGrower.growTree(worldserver, worldserver.getChunkSource().getGenerator(), blockposition, iblockdata, randomsource);
2018-07-15 10:00:00 +10:00
+ // CraftBukkit start
+ if (worldserver.captureTreeGeneration) {
+ this.treeGrower.growTree(worldserver, worldserver.getChunkSource().getGenerator(), blockposition, iblockdata, randomsource);
+ } else {
+ worldserver.captureTreeGeneration = true;
+ this.treeGrower.growTree(worldserver, worldserver.getChunkSource().getGenerator(), blockposition, iblockdata, randomsource);
+ worldserver.captureTreeGeneration = false;
+ if (worldserver.capturedBlockStates.size() > 0) {
+ TreeType treeType = BlockSapling.treeType;
+ BlockSapling.treeType = null;
+ Location location = CraftLocation.toBukkit(blockposition, worldserver.getWorld());
+ java.util.List<BlockState> blocks = new java.util.ArrayList<>(worldserver.capturedBlockStates.values());
+ worldserver.capturedBlockStates.clear();
+ StructureGrowEvent event = null;
+ if (treeType != null) {
+ event = new StructureGrowEvent(location, treeType, false, null, blocks);
+ org.bukkit.Bukkit.getPluginManager().callEvent(event);
+ }
+ if (event == null || !event.isCancelled()) {
+ for (BlockState blockstate : blocks) {
+ CapturedBlockState.setBlockState(blockstate);
+ }
+ }
+ }
2018-07-15 10:00:00 +10:00
+ }
+ // CraftBukkit end
}
2018-07-15 10:00:00 +10:00
}