mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-02 04:56:50 +01:00
[Bleeding] Added support for all TreeType entries to CraftWorld.generateTree(). Addresses BUKKIT-1161
This commit is contained in:
parent
27acb4c41e
commit
8aee4c3f56
9 changed files with 71 additions and 23 deletions
|
@ -3,6 +3,7 @@ package net.minecraft.server;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
// CraftBukkit start
|
||||
import org.bukkit.BlockChangeDelegate;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.TreeType;
|
||||
import org.bukkit.block.BlockState;
|
||||
|
@ -109,7 +110,7 @@ public class BlockMushroom extends BlockFlower {
|
|||
worldgenhugemushroom = new WorldGenHugeMushroom(1);
|
||||
}
|
||||
if (worldgenhugemushroom != null && event != null) {
|
||||
grown = worldgenhugemushroom.grow(world, random, i, j, k, event, itemstack, world.getWorld());
|
||||
grown = worldgenhugemushroom.grow((BlockChangeDelegate)world, random, i, j, k, event, itemstack, world.getWorld());
|
||||
if (event.isFromBonemeal() && itemstack != null) {
|
||||
--itemstack.count;
|
||||
}
|
||||
|
|
|
@ -78,7 +78,7 @@ public class BlockSapling extends BlockFlower {
|
|||
if (gen == null) {
|
||||
j1 = 0;
|
||||
i1 = 0;
|
||||
treeType = TreeType.TREE;
|
||||
treeType = TreeType.SMALL_JUNGLE;
|
||||
gen = new WorldGenTrees(false, 4 + random.nextInt(7), 3, 3, false);
|
||||
}
|
||||
} else {
|
||||
|
@ -132,7 +132,7 @@ public class BlockSapling extends BlockFlower {
|
|||
}
|
||||
|
||||
// CraftBukkit start
|
||||
interface TreeGenerator {
|
||||
public interface TreeGenerator {
|
||||
|
||||
public boolean a(World world, Random random, int i, int j, int k);
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import java.util.Random;
|
|||
|
||||
import org.bukkit.BlockChangeDelegate; // CraftBukkit
|
||||
|
||||
public class WorldGenGroundBush extends WorldGenerator {
|
||||
public class WorldGenGroundBush extends WorldGenerator implements BlockSapling.TreeGenerator { // CraftBukkit - add interface
|
||||
|
||||
private int a;
|
||||
private int b;
|
||||
|
@ -49,8 +49,11 @@ public class WorldGenGroundBush extends WorldGenerator {
|
|||
}
|
||||
}
|
||||
}
|
||||
// CraftBukkit start - return false if gen was unsuccessful
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// CraftBukkit end
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ package net.minecraft.server;
|
|||
|
||||
import java.util.Random;
|
||||
// CraftBukkit start
|
||||
import org.bukkit.BlockChangeDelegate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
|
@ -9,7 +10,7 @@ import org.bukkit.event.world.StructureGrowEvent;
|
|||
import org.bukkit.material.MaterialData;
|
||||
// CraftBukkit end
|
||||
|
||||
public class WorldGenHugeMushroom extends WorldGenerator {
|
||||
public class WorldGenHugeMushroom extends WorldGenerator implements BlockSapling.TreeGenerator { // CraftBukkit - add interface
|
||||
|
||||
private int a = -1;
|
||||
|
||||
|
@ -22,12 +23,16 @@ public class WorldGenHugeMushroom extends WorldGenerator {
|
|||
super(false);
|
||||
}
|
||||
|
||||
// CraftBukkit start - delegate to grow()
|
||||
// CraftBukkit start - delegate to generate() and use BlockChangeDelegate
|
||||
public boolean a(World world, Random random, int i, int j, int k) {
|
||||
return grow((BlockChangeDelegate) world, random, i, j, k, null, null, null);
|
||||
}
|
||||
|
||||
public boolean generate(BlockChangeDelegate world, Random random, int i, int j, int k) {
|
||||
return grow(world, random, i, j, k, null, null, null);
|
||||
}
|
||||
|
||||
public boolean grow(World world, Random random, int i, int j, int k, StructureGrowEvent event, ItemStack itemstack, CraftWorld bukkitWorld) {
|
||||
public boolean grow(BlockChangeDelegate world, Random random, int i, int j, int k, StructureGrowEvent event, ItemStack itemstack, CraftWorld bukkitWorld) {
|
||||
// CraftBukkit end
|
||||
int l = random.nextInt(2);
|
||||
|
||||
|
@ -71,12 +76,13 @@ public class WorldGenHugeMushroom extends WorldGenerator {
|
|||
j1 = world.getTypeId(i, j - 1, k);
|
||||
if (j1 != Block.DIRT.id && j1 != Block.GRASS.id && j1 != Block.MYCEL.id) {
|
||||
return false;
|
||||
} else if (!Block.BROWN_MUSHROOM.canPlace(world, i, j, k)) {
|
||||
// CraftBukkit - Adjust canPlace check to handle non-World BlockChangeDelegates (orig check was: !Block.BROWN_MUSHROOM.canPlace(world, i, j, k))
|
||||
} else if ((world.getTypeId(i, j, k) != 0 && !Block.byId[world.getTypeId(i, j, k)].material.isReplacable()) || (world instanceof World && !Block.BROWN_MUSHROOM.canPlace((World) world, i, j, k))) {
|
||||
return false;
|
||||
} else {
|
||||
// CraftBukkit start
|
||||
if (event == null) {
|
||||
world.setRawTypeIdAndData(i, j - 1, k, Block.DIRT.id, 0);
|
||||
this.setTypeAndData(world, i, j - 1, k, Block.DIRT.id, 0);
|
||||
} else {
|
||||
BlockState dirtState = bukkitWorld.getBlockAt(i, j - 1, k).getState();
|
||||
dirtState.setTypeId(Block.DIRT.id);
|
||||
|
@ -164,7 +170,7 @@ public class WorldGenHugeMushroom extends WorldGenerator {
|
|||
if ((l2 != 0 || j >= j + i1 - 1) && !Block.n[world.getTypeId(i2, k1, k2)]) {
|
||||
// CraftBukkit start
|
||||
if (event == null) {
|
||||
world.setRawTypeIdAndData(i2, k1, k2, Block.BIG_MUSHROOM_1.id + l, l2);
|
||||
this.setTypeAndData(world, i2, k1, k2, Block.BIG_MUSHROOM_1.id + l, l2);
|
||||
} else {
|
||||
BlockState state = bukkitWorld.getBlockAt(i2, k1, k2).getState();
|
||||
state.setTypeId(Block.BIG_MUSHROOM_1.id + l);
|
||||
|
@ -182,7 +188,7 @@ public class WorldGenHugeMushroom extends WorldGenerator {
|
|||
if (!Block.n[l1]) {
|
||||
// CraftBukkit start
|
||||
if (event == null) {
|
||||
world.setRawTypeIdAndData(i, j + k1, k, Block.BIG_MUSHROOM_1.id + l, 10);
|
||||
this.setTypeAndData(world, i, j + k1, k, Block.BIG_MUSHROOM_1.id + l, 10);
|
||||
} else {
|
||||
BlockState state = bukkitWorld.getBlockAt(i, j + k1, k).getState();
|
||||
state.setTypeId(Block.BIG_MUSHROOM_1.id + l);
|
||||
|
|
|
@ -2,14 +2,18 @@ package net.minecraft.server;
|
|||
|
||||
import java.util.Random;
|
||||
|
||||
public class WorldGenSwampTree extends WorldGenerator {
|
||||
public class WorldGenSwampTree extends WorldGenerator implements BlockSapling.TreeGenerator { // CraftBukkit - add interface
|
||||
|
||||
public WorldGenSwampTree() {}
|
||||
|
||||
public boolean a(World world, Random random, int i, int j, int k) {
|
||||
return generate((org.bukkit.BlockChangeDelegate) world, random, i, j, k);
|
||||
}
|
||||
|
||||
public boolean generate(org.bukkit.BlockChangeDelegate world, Random random, int i, int j, int k) {
|
||||
int l;
|
||||
|
||||
for (l = random.nextInt(4) + 5; world.getMaterial(i, j - 1, k) == Material.WATER; --j) {
|
||||
for (l = random.nextInt(4) + 5; world.getTypeId(i, j - 1, k) != 0 && Block.byId[world.getTypeId(i, j - 1, k)].material == Material.WATER; --j) { // CraftBukkit - bypass World.getMaterial
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -121,7 +125,7 @@ public class WorldGenSwampTree extends WorldGenerator {
|
|||
}
|
||||
}
|
||||
|
||||
private void a(World world, int i, int j, int k, int l) {
|
||||
private void a(org.bukkit.BlockChangeDelegate world, int i, int j, int k, int l) { // CraftBukkit - change signature
|
||||
world.setTypeIdAndData(i, j, k, Block.VINE.id, l);
|
||||
int i1 = 4;
|
||||
|
||||
|
|
|
@ -162,7 +162,7 @@ public class WorldGenTrees extends WorldGenerator implements BlockSapling.TreeGe
|
|||
|
||||
// CraftBukkit - Changed world to BlockChangeDelegate
|
||||
private void a(BlockChangeDelegate world, int i, int j, int k, int l) {
|
||||
((World)world).setTypeIdAndData(i, j, k, Block.VINE.id, l); // CraftBukkit - Cast
|
||||
world.setTypeIdAndData(i, j, k, Block.VINE.id, l);
|
||||
int i1 = 4;
|
||||
|
||||
while (true) {
|
||||
|
@ -171,7 +171,7 @@ public class WorldGenTrees extends WorldGenerator implements BlockSapling.TreeGe
|
|||
return;
|
||||
}
|
||||
|
||||
((World)world).setRawTypeIdAndData(i, j, k, Block.VINE.id, l); // CraftBukkit - Cast
|
||||
world.setTypeIdAndData(i, j, k, Block.VINE.id, l);
|
||||
--i1;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ public abstract class WorldGenerator {
|
|||
// CraftBukkit - change signature
|
||||
protected void setTypeAndData(BlockChangeDelegate world, int i, int j, int k, int l, int i1) {
|
||||
if (this.a) {
|
||||
((World) world).setTypeIdAndData(i, j, k, l, i1); // CraftBukkit - force-cast to world to get it working
|
||||
world.setTypeIdAndData(i, j, k, l, i1);
|
||||
} else {
|
||||
world.setRawTypeIdAndData(i, j, k, l, i1);
|
||||
}
|
||||
|
|
|
@ -369,19 +369,45 @@ public class CraftWorld implements World {
|
|||
}
|
||||
|
||||
public boolean generateTree(Location loc, TreeType type, BlockChangeDelegate delegate) {
|
||||
BlockSapling.TreeGenerator gen;
|
||||
switch (type) {
|
||||
case BIG_TREE:
|
||||
return new WorldGenBigTree(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
gen = new WorldGenBigTree(true);
|
||||
break;
|
||||
case BIRCH:
|
||||
return new WorldGenForest(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
gen = new WorldGenForest(true);
|
||||
break;
|
||||
case REDWOOD:
|
||||
return new WorldGenTaiga2(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
gen = new WorldGenTaiga2(true);
|
||||
break;
|
||||
case TALL_REDWOOD:
|
||||
return new WorldGenTaiga1().generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
gen = new WorldGenTaiga1();
|
||||
break;
|
||||
case JUNGLE:
|
||||
gen = new WorldGenMegaTree(true, 10 + rand.nextInt(20), 3, 3);
|
||||
break;
|
||||
case SMALL_JUNGLE:
|
||||
gen = new WorldGenTrees(true, 4 + rand.nextInt(7), 3, 3, false);
|
||||
break;
|
||||
case JUNGLE_BUSH:
|
||||
gen = new WorldGenGroundBush(3, 0);
|
||||
break;
|
||||
case RED_MUSHROOM:
|
||||
gen = new WorldGenHugeMushroom(1);
|
||||
break;
|
||||
case BROWN_MUSHROOM:
|
||||
gen = new WorldGenHugeMushroom(0);
|
||||
break;
|
||||
case SWAMP:
|
||||
gen = new WorldGenSwampTree();
|
||||
break;
|
||||
case TREE:
|
||||
default:
|
||||
return new WorldGenTrees(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
gen = new WorldGenTrees(true);
|
||||
break;
|
||||
}
|
||||
|
||||
return gen.generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
}
|
||||
|
||||
public TileEntity getTileEntityAt(final int x, final int y, final int z) {
|
||||
|
|
|
@ -30,6 +30,14 @@ public class StructureGrowDelegate implements BlockChangeDelegate {
|
|||
return true;
|
||||
}
|
||||
|
||||
public boolean setTypeId(int x, int y, int z, int typeId) {
|
||||
return setRawTypeId(x, y, z, typeId);
|
||||
}
|
||||
|
||||
public boolean setTypeIdAndData(int x, int y, int z, int typeId, int data) {
|
||||
return setRawTypeIdAndData(x, y, z, typeId, data);
|
||||
}
|
||||
|
||||
public int getTypeId(int x, int y, int z) {
|
||||
return world.getBlockTypeIdAt(x, y, z);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue