Files
2020-01-05 04:56:04 +08:00

134 lines
6.2 KiB
Diff

--- ../src-base/minecraft/net/minecraft/block/BlockSapling.java
+++ ../src-work/minecraft/net/minecraft/block/BlockSapling.java
@@ -1,5 +1,6 @@
package net.minecraft.block;
+import java.util.List;
import java.util.Random;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyEnum;
@@ -24,12 +25,17 @@
import net.minecraft.world.gen.feature.WorldGenTaiga2;
import net.minecraft.world.gen.feature.WorldGenTrees;
import net.minecraft.world.gen.feature.WorldGenerator;
+import org.bukkit.Location;
+import org.bukkit.TreeType;
+import org.bukkit.block.BlockState;
+import org.bukkit.event.world.StructureGrowEvent;
public class BlockSapling extends BlockBush implements IGrowable
{
public static final PropertyEnum<BlockPlanks.EnumType> TYPE = PropertyEnum.<BlockPlanks.EnumType>create("type", BlockPlanks.EnumType.class);
public static final PropertyInteger STAGE = PropertyInteger.create("stage", 0, 1);
protected static final AxisAlignedBB SAPLING_AABB = new AxisAlignedBB(0.09999999403953552D, 0.0D, 0.09999999403953552D, 0.8999999761581421D, 0.800000011920929D, 0.8999999761581421D);
+ public static TreeType treeType;
protected BlockSapling()
{
@@ -53,9 +59,32 @@
{
super.updateTick(worldIn, pos, state, rand);
- if (worldIn.getLightFromNeighbors(pos.up()) >= 9 && rand.nextInt(7) == 0)
+ if (!worldIn.isAreaLoaded(pos, 1)) return; // Forge: prevent loading unloaded chunks when checking neighbor's light
+ if (worldIn.getLightFromNeighbors(pos.up()) >= 9 && rand.nextInt(Math.max(2, (int) (((100.0F / worldIn.spigotConfig.saplingModifier) * 7) + 0.5F))) == 0)
{
+ worldIn.captureTreeGeneration = true;
this.grow(worldIn, pos, state, rand);
+ worldIn.captureTreeGeneration = false;
+ if (worldIn.capturedBlockSnapshots.size() > 0) {
+ TreeType treeType = BlockSapling.treeType;
+ BlockSapling.treeType = null;
+ Location location = new Location(worldIn.getWorld(), pos.getX(), pos.getY(), pos.getZ());
+ List<BlockState> blockstates = new java.util.ArrayList();
+ for (net.minecraftforge.common.util.BlockSnapshot snapshot : worldIn.capturedBlockSnapshots) {
+ blockstates.add(new org.bukkit.craftbukkit.block.CraftBlockState(snapshot));
+ }
+ worldIn.capturedBlockSnapshots.clear();
+ StructureGrowEvent event = null;
+ if (treeType != null) {
+ event = new StructureGrowEvent(location, treeType, false, null, blockstates);
+ org.bukkit.Bukkit.getPluginManager().callEvent(event);
+ }
+ if (event == null || !event.isCancelled()) {
+ for (BlockState blockstate : blockstates) {
+ blockstate.update(true);
+ }
+ }
+ }
}
}
}
@@ -74,7 +103,18 @@
public void generateTree(World worldIn, BlockPos pos, IBlockState state, Random rand)
{
- WorldGenerator worldgenerator = (WorldGenerator)(rand.nextInt(10) == 0 ? new WorldGenBigTree(true) : new WorldGenTrees(true));
+ if (!net.minecraftforge.event.terraingen.TerrainGen.saplingGrowTree(worldIn, rand, pos)) return;
+ // CraftBukkit start - Turn ternary operator into if statement to set treeType
+ // WorldGenerator worldgenerator = (WorldGenerator)(rand.nextInt(10) == 0 ? new WorldGenBigTree(true) : new WorldGenTrees(true));
+ WorldGenerator worldgenerator;
+ if (rand.nextInt(10) == 0) {
+ treeType = TreeType.BIG_TREE;
+ worldgenerator = new WorldGenBigTree(true);
+ } else {
+ treeType = TreeType.TREE;
+ worldgenerator = new WorldGenTrees(true);
+ }
+ // CraftBukkit end
int i = 0;
int j = 0;
boolean flag = false;
@@ -90,6 +130,7 @@
{
if (this.isTwoByTwoOfType(worldIn, pos, i, j, BlockPlanks.EnumType.SPRUCE))
{
+ treeType = TreeType.MEGA_REDWOOD;
worldgenerator = new WorldGenMegaPineTree(false, rand.nextBoolean());
flag = true;
break label68;
@@ -101,11 +142,13 @@
{
i = 0;
j = 0;
+ treeType = TreeType.REDWOOD;
worldgenerator = new WorldGenTaiga2(true);
}
break;
case BIRCH:
+ treeType = TreeType.BIRCH;
worldgenerator = new WorldGenBirchTree(true, false);
break;
case JUNGLE:
@@ -119,6 +162,7 @@
{
if (this.isTwoByTwoOfType(worldIn, pos, i, j, BlockPlanks.EnumType.JUNGLE))
{
+ treeType = TreeType.JUNGLE;
worldgenerator = new WorldGenMegaJungle(true, 10, 20, iblockstate, iblockstate1);
flag = true;
break label82;
@@ -130,11 +174,13 @@
{
i = 0;
j = 0;
+ treeType = TreeType.SMALL_JUNGLE;
worldgenerator = new WorldGenTrees(true, 4 + rand.nextInt(7), iblockstate, iblockstate1, false);
}
break;
case ACACIA:
+ treeType = TreeType.ACACIA;
worldgenerator = new WorldGenSavannaTree(true);
break;
case DARK_OAK:
@@ -146,6 +192,7 @@
{
if (this.isTwoByTwoOfType(worldIn, pos, i, j, BlockPlanks.EnumType.DARK_OAK))
{
+ treeType = TreeType.DARK_OAK;
worldgenerator = new WorldGenCanopyTree(true);
flag = true;
break label96;