Mirror von
https://github.com/PaperMC/Paper.git
synchronisiert 2024-12-18 20:40:08 +01:00
[Bleeding] Completely fix the tree generation algorithm to make it near identical to vanilla as well as fix potential bugs associated with disappearing saplings.
Dieser Commit ist enthalten in:
Ursprung
ea60181a87
Commit
7966531113
@ -2,6 +2,7 @@ package net.minecraft.server;
|
|||||||
|
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
|
import org.bukkit.BlockChangeDelegate;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.TreeType;
|
import org.bukkit.TreeType;
|
||||||
@ -43,56 +44,61 @@ public class BlockSapling extends BlockFlower {
|
|||||||
// CraftBukkit - added bonemeal, player and itemstack
|
// CraftBukkit - added bonemeal, player and itemstack
|
||||||
public void grow(World world, int i, int j, int k, Random random, boolean bonemeal, Player player, ItemStack itemstack) {
|
public void grow(World world, int i, int j, int k, Random random, boolean bonemeal, Player player, ItemStack itemstack) {
|
||||||
int l = world.getData(i, j, k) & 3;
|
int l = world.getData(i, j, k) & 3;
|
||||||
|
|
||||||
// CraftBukkit start - records tree generation and calls StructureGrowEvent
|
|
||||||
StructureGrowDelegate delegate = new StructureGrowDelegate(world);
|
|
||||||
TreeType treeType;
|
|
||||||
int i1 = 0;
|
int i1 = 0;
|
||||||
int j1 = 0;
|
int j1 = 0;
|
||||||
|
// CraftBukkit start - records tree generation and calls StructureGrowEvent
|
||||||
|
StructureGrowDelegate delegate = new StructureGrowDelegate(world);
|
||||||
|
TreeType treeType = null;
|
||||||
|
TreeGenerator gen = null;
|
||||||
boolean grownTree = false;
|
boolean grownTree = false;
|
||||||
boolean megaTree = false;
|
boolean flag = false;
|
||||||
// All of these are 'false' because we need the 'raw' calls so the block-delegate works
|
|
||||||
if (l == 1) {
|
if (l == 1) {
|
||||||
treeType = TreeType.REDWOOD;
|
treeType = TreeType.REDWOOD;
|
||||||
world.setRawTypeId(i, j, k, 0);
|
gen = new WorldGenTaiga2(false);
|
||||||
grownTree = new WorldGenTaiga2(false).generate(delegate, random, i, j, k);
|
|
||||||
} else if (l == 2) {
|
} else if (l == 2) {
|
||||||
treeType = TreeType.BIRCH;
|
treeType = TreeType.BIRCH;
|
||||||
world.setRawTypeId(i, j, k, 0);
|
gen = new WorldGenForest(false);
|
||||||
grownTree = new WorldGenForest(false).generate(delegate, random, i, j, k);
|
|
||||||
} else if (l == 3) {
|
} else if (l == 3) {
|
||||||
treeType = TreeType.JUNGLE;
|
|
||||||
for (i1 = 0; i1 >= -1; --i1) {
|
for (i1 = 0; i1 >= -1; --i1) {
|
||||||
for (j1 = 0; j1 >= -1; --j1) {
|
for (j1 = 0; j1 >= -1; --j1) {
|
||||||
if (world.getTypeId(i + i1, j, k + j1) == this.id && world.getTypeId(i + i1 + 1, j, k + j1) == this.id && world.getTypeId(i + i1, j, k + j1 + 1) == this.id && world.getTypeId(i + i1 + 1, j, k + j1 + 1) == this.id) {
|
if (world.getTypeId(i + i1, j, k + j1) == this.id && world.getTypeId(i + i1 + 1, j, k + j1) == this.id && world.getTypeId(i + i1, j, k + j1 + 1) == this.id && world.getTypeId(i + i1 + 1, j, k + j1 + 1) == this.id) {
|
||||||
world.setRawTypeId(i + i1, j, k + j1, 0);
|
treeType = TreeType.JUNGLE;
|
||||||
world.setRawTypeId(i + i1 + 1, j, k + j1, 0);
|
gen = new WorldGenMegaTree(false, 10 + random.nextInt(20), 3, 3);
|
||||||
world.setRawTypeId(i + i1, j, k + j1 + 1, 0);
|
flag = true;
|
||||||
world.setRawTypeId(i + i1 + 1, j, k + j1 + 1, 0);
|
|
||||||
grownTree = new WorldGenMegaTree(false, 10 + random.nextInt(20), 3, 3).generate(delegate, random, i + i1, j, k + j1);
|
|
||||||
megaTree = true;
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (gen != null) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!grownTree) {
|
|
||||||
|
if (gen == null) {
|
||||||
j1 = 0;
|
j1 = 0;
|
||||||
i1 = 0;
|
i1 = 0;
|
||||||
world.setRawTypeId(i, j, k, 0);
|
treeType = TreeType.TREE;
|
||||||
grownTree = new WorldGenTrees(false, 4 + random.nextInt(7), 3, 3, false).generate(delegate, random, i, j, k);
|
gen = new WorldGenTrees(false, 4 + random.nextInt(7), 3, 3, false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
treeType = TreeType.TREE;
|
||||||
|
gen = new WorldGenTrees(false);
|
||||||
if (random.nextInt(10) == 0) {
|
if (random.nextInt(10) == 0) {
|
||||||
treeType = TreeType.BIG_TREE;
|
treeType = TreeType.BIG_TREE;
|
||||||
world.setRawTypeId(i, j, k, 0);
|
gen = new WorldGenBigTree(false);
|
||||||
grownTree = new WorldGenBigTree(false).generate(delegate, random, i, j, k);
|
|
||||||
} else {
|
|
||||||
treeType = TreeType.TREE;
|
|
||||||
world.setRawTypeId(i, j, k, 0);
|
|
||||||
grownTree = new WorldGenTrees(false).generate(delegate, random, i, j, k);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flag) {
|
||||||
|
world.setRawTypeId(i + i1, j, k + j1, 0);
|
||||||
|
world.setRawTypeId(i + i1 + 1, j, k + j1, 0);
|
||||||
|
world.setRawTypeId(i + i1, j, k + j1 + 1, 0);
|
||||||
|
world.setRawTypeId(i + i1 + 1, j, k + j1 + 1, 0);
|
||||||
|
} else {
|
||||||
|
world.setRawTypeId(i, j, k, 0);
|
||||||
|
}
|
||||||
|
grownTree = gen.generate(delegate, random, i + i1, j, k + j1);
|
||||||
if (grownTree) {
|
if (grownTree) {
|
||||||
Location location = new Location(world.getWorld(), i, j, k);
|
Location location = new Location(world.getWorld(), i, j, k);
|
||||||
StructureGrowEvent event = new StructureGrowEvent(location, treeType, bonemeal, player, delegate.getBlocks());
|
StructureGrowEvent event = new StructureGrowEvent(location, treeType, bonemeal, player, delegate.getBlocks());
|
||||||
@ -108,10 +114,8 @@ public class BlockSapling extends BlockFlower {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!grownTree) {
|
if (!grownTree) {
|
||||||
if (megaTree) {
|
if (flag) {
|
||||||
// CraftBukkit end
|
|
||||||
world.setRawTypeIdAndData(i + i1, j, k + j1, this.id, l);
|
world.setRawTypeIdAndData(i + i1, j, k + j1, this.id, l);
|
||||||
world.setRawTypeIdAndData(i + i1 + 1, j, k + j1, this.id, l);
|
world.setRawTypeIdAndData(i + i1 + 1, j, k + j1, this.id, l);
|
||||||
world.setRawTypeIdAndData(i + i1, j, k + j1 + 1, this.id, l);
|
world.setRawTypeIdAndData(i + i1, j, k + j1 + 1, this.id, l);
|
||||||
@ -120,9 +124,19 @@ public class BlockSapling extends BlockFlower {
|
|||||||
world.setRawTypeIdAndData(i, j, k, this.id, l);
|
world.setRawTypeIdAndData(i, j, k, this.id, l);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// CraftBukkit end
|
||||||
}
|
}
|
||||||
|
|
||||||
protected int getDropData(int i) {
|
protected int getDropData(int i) {
|
||||||
return i & 3;
|
return i & 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// CraftBukkit start
|
||||||
|
interface TreeGenerator {
|
||||||
|
|
||||||
|
public boolean a(World world, Random random, int i, int j, int k);
|
||||||
|
|
||||||
|
public boolean generate(BlockChangeDelegate world, Random random, int i, int j, int k);
|
||||||
|
}
|
||||||
|
// CraftBukkit end
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,7 @@ import java.util.Random;
|
|||||||
|
|
||||||
import org.bukkit.BlockChangeDelegate; // CraftBukkit
|
import org.bukkit.BlockChangeDelegate; // CraftBukkit
|
||||||
|
|
||||||
public class WorldGenBigTree extends WorldGenerator {
|
public class WorldGenBigTree extends WorldGenerator implements BlockSapling.TreeGenerator { // CraftBukkit add interface
|
||||||
|
|
||||||
static final byte[] a = new byte[] { (byte) 2, (byte) 0, (byte) 0, (byte) 1, (byte) 2, (byte) 1};
|
static final byte[] a = new byte[] { (byte) 2, (byte) 0, (byte) 0, (byte) 1, (byte) 2, (byte) 1};
|
||||||
Random b = new Random();
|
Random b = new Random();
|
||||||
|
@ -4,7 +4,7 @@ import java.util.Random;
|
|||||||
|
|
||||||
import org.bukkit.BlockChangeDelegate; // CraftBukkit
|
import org.bukkit.BlockChangeDelegate; // CraftBukkit
|
||||||
|
|
||||||
public class WorldGenForest extends WorldGenerator {
|
public class WorldGenForest extends WorldGenerator implements BlockSapling.TreeGenerator { // CraftBukkit add interface
|
||||||
|
|
||||||
public WorldGenForest(boolean flag) {
|
public WorldGenForest(boolean flag) {
|
||||||
super(flag);
|
super(flag);
|
||||||
|
@ -4,7 +4,7 @@ import java.util.Random;
|
|||||||
|
|
||||||
import org.bukkit.BlockChangeDelegate; // CraftBukkit
|
import org.bukkit.BlockChangeDelegate; // CraftBukkit
|
||||||
|
|
||||||
public class WorldGenMegaTree extends WorldGenerator {
|
public class WorldGenMegaTree extends WorldGenerator implements BlockSapling.TreeGenerator { // CraftBukkit add interface
|
||||||
|
|
||||||
private final int a;
|
private final int a;
|
||||||
private final int b;
|
private final int b;
|
||||||
|
@ -4,7 +4,7 @@ import java.util.Random;
|
|||||||
|
|
||||||
import org.bukkit.BlockChangeDelegate; // CraftBukkit
|
import org.bukkit.BlockChangeDelegate; // CraftBukkit
|
||||||
|
|
||||||
public class WorldGenTaiga1 extends WorldGenerator {
|
public class WorldGenTaiga1 extends WorldGenerator implements BlockSapling.TreeGenerator { // CraftBukkit add interface
|
||||||
|
|
||||||
public WorldGenTaiga1() {}
|
public WorldGenTaiga1() {}
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ import java.util.Random;
|
|||||||
|
|
||||||
import org.bukkit.BlockChangeDelegate; // CraftBukkit
|
import org.bukkit.BlockChangeDelegate; // CraftBukkit
|
||||||
|
|
||||||
public class WorldGenTaiga2 extends WorldGenerator {
|
public class WorldGenTaiga2 extends WorldGenerator implements BlockSapling.TreeGenerator { // CraftBukkit add interface
|
||||||
|
|
||||||
public WorldGenTaiga2(boolean flag) {
|
public WorldGenTaiga2(boolean flag) {
|
||||||
super(flag);
|
super(flag);
|
||||||
|
@ -4,7 +4,7 @@ import java.util.Random;
|
|||||||
|
|
||||||
import org.bukkit.BlockChangeDelegate; // CraftBukkit
|
import org.bukkit.BlockChangeDelegate; // CraftBukkit
|
||||||
|
|
||||||
public class WorldGenTrees extends WorldGenerator {
|
public class WorldGenTrees extends WorldGenerator implements BlockSapling.TreeGenerator { // CraftBukkit add interface
|
||||||
|
|
||||||
private final int a;
|
private final int a;
|
||||||
private final boolean b;
|
private final boolean b;
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren