Implemented onStructureGrow event, thanks to md-5.
Dieser Commit ist enthalten in:
Ursprung
076460b419
Commit
5e43c61fad
@ -1,7 +1,15 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
// Craftbukkit start
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.TreeType;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockSpreadEvent;
|
||||
import org.bukkit.event.world.StructureGrowEvent;
|
||||
// Craftbukkit end
|
||||
|
||||
public class BlockMushroom extends BlockFlower {
|
||||
|
||||
@ -82,23 +90,32 @@ public class BlockMushroom extends BlockFlower {
|
||||
}
|
||||
}
|
||||
|
||||
public boolean b(World world, int i, int j, int k, Random random) {
|
||||
// CraftBukkit - added bonemeal, player and itemstack
|
||||
public boolean b(World world, int i, int j, int k, Random random, boolean bonemeal, Player player, ItemStack itemstack) {
|
||||
int l = world.getData(i, j, k);
|
||||
|
||||
world.setRawTypeId(i, j, k, 0);
|
||||
// CraftBukkit start
|
||||
boolean grown = false;
|
||||
StructureGrowEvent event = null;
|
||||
Location location = new Location(world.getWorld(), i, j, k);
|
||||
WorldGenHugeMushroom worldgenhugemushroom = null;
|
||||
|
||||
if (this.id == Block.BROWN_MUSHROOM.id) {
|
||||
event = new StructureGrowEvent(location, TreeType.BROWN_MUSHROOM, bonemeal, player, new ArrayList<BlockState>());
|
||||
worldgenhugemushroom = new WorldGenHugeMushroom(0);
|
||||
} else if (this.id == Block.RED_MUSHROOM.id) {
|
||||
event = new StructureGrowEvent(location, TreeType.RED_MUSHROOM, bonemeal, player, new ArrayList<BlockState>());
|
||||
worldgenhugemushroom = new WorldGenHugeMushroom(1);
|
||||
}
|
||||
|
||||
if (worldgenhugemushroom != null && worldgenhugemushroom.a(world, random, i, j, k)) {
|
||||
return true;
|
||||
} else {
|
||||
if (worldgenhugemushroom != null && event != null){
|
||||
grown = worldgenhugemushroom.grow(world, random, i, j, k, event, itemstack, world.getWorld());
|
||||
}
|
||||
if (!grown || event.isCancelled()){
|
||||
world.setRawTypeIdAndData(i, j, k, this.id, l);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
// CraftBukkit end
|
||||
}
|
||||
}
|
||||
|
@ -1,8 +1,15 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.BlockChangeDelegate; // CraftBukkit
|
||||
// CraftBukkit start
|
||||
import org.bukkit.BlockChangeDelegate;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.TreeType;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.world.StructureGrowEvent;
|
||||
// Craftbukkit end
|
||||
|
||||
public class BlockSapling extends BlockFlower {
|
||||
|
||||
@ -22,7 +29,7 @@ public class BlockSapling extends BlockFlower {
|
||||
if ((l & 8) == 0) {
|
||||
world.setData(i, j, k, l | 8);
|
||||
} else {
|
||||
this.b(world, i, j, k, random);
|
||||
this.b(world, i, j, k, random, false, null, null); // Craftbukkit - added bonemeal, player and itemstack
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -33,7 +40,8 @@ public class BlockSapling extends BlockFlower {
|
||||
return j == 1 ? 63 : (j == 2 ? 79 : super.a(i, j));
|
||||
}
|
||||
|
||||
public void b(World world, int i, int j, int k, Random random) {
|
||||
// CraftBukkit - added bonemeal, player and itemstack
|
||||
public void b(World world, int i, int j, int k, Random random, boolean bonemeal, Player player, ItemStack itemstack) {
|
||||
int l = world.getData(i, j, k) & 3;
|
||||
|
||||
world.setRawTypeId(i, j, k, 0);
|
||||
@ -41,21 +49,28 @@ public class BlockSapling extends BlockFlower {
|
||||
// CraftBukkit start - fixes client updates on recently grown trees
|
||||
boolean grownTree;
|
||||
BlockChangeWithNotify delegate = new BlockChangeWithNotify(world);
|
||||
|
||||
StructureGrowEvent event = null;
|
||||
Location location = new Location(world.getWorld(), i, j, k);
|
||||
// All of these are 'false' because we need the 'raw' calls so the block-delegate works
|
||||
if (l == 1) {
|
||||
grownTree = new WorldGenTaiga2(false).generate(delegate, random, i, j, k);
|
||||
event = new StructureGrowEvent(location, TreeType.REDWOOD, bonemeal, player, new ArrayList<BlockState>());
|
||||
grownTree = new WorldGenTaiga2(false).generate(delegate, random, i, j, k, event, itemstack, world.getWorld());
|
||||
} else if (l == 2) {
|
||||
grownTree = new WorldGenForest(false).generate(delegate, random, i, j, k);
|
||||
event = new StructureGrowEvent(location, TreeType.BIRCH, bonemeal, player, new ArrayList<BlockState>());
|
||||
grownTree = new WorldGenForest(false).generate(delegate, random, i, j, k, event, itemstack, world.getWorld());
|
||||
} else {
|
||||
if (random.nextInt(10) == 0) {
|
||||
grownTree = new WorldGenBigTree(false).generate(delegate, random, i, j, k);
|
||||
event = new StructureGrowEvent(location, TreeType.BIG_TREE, bonemeal, player, new ArrayList<BlockState>());
|
||||
grownTree = new WorldGenBigTree(false).generate(delegate, random, i, j, k, event, itemstack, world.getWorld());
|
||||
} else {
|
||||
grownTree = new WorldGenTrees(false).generate(delegate, random, i, j, k);
|
||||
event = new StructureGrowEvent(location, TreeType.TREE, bonemeal, player, new ArrayList<BlockState>());
|
||||
grownTree = new WorldGenTrees(false).generate(delegate, random, i, j, k, event, itemstack, world.getWorld());
|
||||
}
|
||||
}
|
||||
|
||||
if (!grownTree) {
|
||||
if (event == null) {
|
||||
return;
|
||||
}
|
||||
if (!grownTree || event.isCancelled()) {
|
||||
world.setRawTypeIdAndData(i, j, k, this.id, l);
|
||||
}
|
||||
// CraftBukkit end
|
||||
@ -69,7 +84,9 @@ public class BlockSapling extends BlockFlower {
|
||||
private class BlockChangeWithNotify implements BlockChangeDelegate {
|
||||
World world;
|
||||
|
||||
BlockChangeWithNotify(World world) { this.world = world; }
|
||||
BlockChangeWithNotify(World world) {
|
||||
this.world = world;
|
||||
}
|
||||
|
||||
public boolean setRawTypeId(int x, int y, int z, int type) {
|
||||
return this.world.setTypeId(x, y, z, type);
|
||||
|
@ -1,5 +1,7 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
import org.bukkit.entity.Player; // Craftbukkit
|
||||
|
||||
public class ItemDye extends Item {
|
||||
|
||||
public static final String[] a = new String[] { "black", "red", "green", "brown", "blue", "purple", "cyan", "silver", "gray", "pink", "lime", "yellow", "lightBlue", "magenta", "orange", "white"};
|
||||
@ -26,16 +28,23 @@ public class ItemDye extends Item {
|
||||
|
||||
if (i1 == Block.SAPLING.id) {
|
||||
if (!world.isStatic) {
|
||||
((BlockSapling) Block.SAPLING).b(world, i, j, k, world.random);
|
||||
--itemstack.count;
|
||||
// Craftbukkit start
|
||||
Player player = (entityhuman instanceof EntityPlayer) ? (Player)entityhuman.getBukkitEntity() : null;
|
||||
((BlockSapling) Block.SAPLING).b(world, i, j, k, world.random, true, player, itemstack);
|
||||
//--itemstack.count; - called later if the bonemeal attempt was succesful
|
||||
// Craftbukkit end
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (i1 == Block.BROWN_MUSHROOM.id || i1 == Block.RED_MUSHROOM.id) {
|
||||
if (!world.isStatic && ((BlockMushroom) Block.byId[i1]).b(world, i, j, k, world.random)) {
|
||||
--itemstack.count;
|
||||
// Craftbukkit start
|
||||
if (!world.isStatic) {
|
||||
Player player = (entityhuman instanceof EntityPlayer) ? (Player)entityhuman.getBukkitEntity() : null;
|
||||
((BlockMushroom) Block.byId[i1]).b(world, i, j, k, world.random, true, player, itemstack);
|
||||
//--itemstack.count; - called later if the bonemeal attempt was succesful
|
||||
// Craftbukkit end
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -2,13 +2,23 @@ package net.minecraft.server;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.BlockChangeDelegate; // CraftBukkit
|
||||
// CraftBukkit start
|
||||
import org.bukkit.BlockChangeDelegate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.event.world.StructureGrowEvent;
|
||||
// Craftbukkit end
|
||||
|
||||
public class WorldGenBigTree extends WorldGenerator {
|
||||
|
||||
static final byte[] a = new byte[] { (byte) 2, (byte) 0, (byte) 0, (byte) 1, (byte) 2, (byte) 1};
|
||||
Random b = new Random();
|
||||
BlockChangeDelegate c; // CraftBukkit
|
||||
// Craftbukkit start
|
||||
BlockChangeDelegate c;
|
||||
StructureGrowEvent event;
|
||||
CraftWorld bukkitWorld;
|
||||
// Craftbukkit end
|
||||
int[] d = new int[] { 0, 0, 0};
|
||||
int e = 0;
|
||||
int f;
|
||||
@ -121,7 +131,15 @@ public class WorldGenBigTree extends WorldGenerator {
|
||||
if (l1 != 0 && l1 != 18) {
|
||||
++k1;
|
||||
} else {
|
||||
// Craftbukkit start
|
||||
if (event == null) {
|
||||
this.a(this.c, aint1[0], aint1[1], aint1[2], l, 0);
|
||||
} else {
|
||||
BlockState state = bukkitWorld.getBlockAt(aint1[0], aint1[1], aint1[2]).getState();
|
||||
state.setTypeId(l);
|
||||
event.getBlocks().add(state);
|
||||
}
|
||||
// Craftbukkit end
|
||||
++k1;
|
||||
}
|
||||
}
|
||||
@ -197,7 +215,15 @@ public class WorldGenBigTree extends WorldGenerator {
|
||||
aint3[b1] = MathHelper.floor((double) (aint[b1] + j) + 0.5D);
|
||||
aint3[b2] = MathHelper.floor((double) aint[b2] + (double) j * d0 + 0.5D);
|
||||
aint3[b3] = MathHelper.floor((double) aint[b3] + (double) j * d1 + 0.5D);
|
||||
// Craftbukkit start
|
||||
if (event == null) {
|
||||
this.a(this.c, aint3[0], aint3[1], aint3[2], i, 0);
|
||||
} else {
|
||||
BlockState state = bukkitWorld.getBlockAt(aint3[0], aint3[1], aint3[2]).getState();
|
||||
state.setTypeId(i);
|
||||
event.getBlocks().add(state);
|
||||
}
|
||||
// Craftbukkit end
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -342,10 +368,12 @@ public class WorldGenBigTree extends WorldGenerator {
|
||||
// BlockChangeDelegate and then we can implicitly cast World to
|
||||
// WorldServer (a safe cast, AFAIK) and no code will be broken. This
|
||||
// then allows plugins to catch manually-invoked generation events
|
||||
return this.generate((BlockChangeDelegate) world, random, i, j, k);
|
||||
return this.generate((BlockChangeDelegate) world, random, i, j, k, null, null, world.getWorld());
|
||||
}
|
||||
|
||||
public boolean generate(BlockChangeDelegate world, Random random, int i, int j, int k) {
|
||||
public boolean generate(BlockChangeDelegate world, Random random, int i, int j, int k, StructureGrowEvent event, ItemStack itemstack, CraftWorld bukkitWorld) {
|
||||
this.event = event;
|
||||
this.bukkitWorld = bukkitWorld;
|
||||
// CraftBukkit end
|
||||
this.c = world;
|
||||
long l = random.nextLong();
|
||||
@ -365,6 +393,20 @@ public class WorldGenBigTree extends WorldGenerator {
|
||||
this.b();
|
||||
this.c();
|
||||
this.d();
|
||||
// Craftbukkit start
|
||||
if (event != null) {
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
world.setRawTypeId(i, j, k, 0);
|
||||
for (BlockState state : event.getBlocks()) {
|
||||
state.update();
|
||||
}
|
||||
if (event.isFromBonemeal() && itemstack != null) {
|
||||
--itemstack.count;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Craftbukkit end
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,14 @@ package net.minecraft.server;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.BlockChangeDelegate; // CraftBukkit
|
||||
// CraftBukkit start
|
||||
import org.bukkit.BlockChangeDelegate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.event.world.StructureGrowEvent;
|
||||
import org.bukkit.material.MaterialData;
|
||||
// CraftBukkit end
|
||||
|
||||
public class WorldGenForest extends WorldGenerator {
|
||||
|
||||
@ -16,10 +23,10 @@ public class WorldGenForest extends WorldGenerator {
|
||||
// BlockChangeDelegate and then we can implicitly cast World to
|
||||
// WorldServer (a safe cast, AFAIK) and no code will be broken. This
|
||||
// then allows plugins to catch manually-invoked generation events
|
||||
return this.generate((BlockChangeDelegate) world, random, i, j, k);
|
||||
return this.generate((BlockChangeDelegate) world, random, i, j, k, null, null, world.getWorld());
|
||||
}
|
||||
|
||||
public boolean generate(BlockChangeDelegate world, Random random, int i, int j, int k) {
|
||||
public boolean generate(BlockChangeDelegate world, Random random, int i, int j, int k, StructureGrowEvent event, ItemStack itemstack, CraftWorld bukkitWorld) {
|
||||
// CraftBukkit end
|
||||
int l = random.nextInt(3) + 5;
|
||||
boolean flag = true;
|
||||
@ -60,8 +67,15 @@ public class WorldGenForest extends WorldGenerator {
|
||||
} else {
|
||||
i1 = world.getTypeId(i, j - 1, k);
|
||||
if ((i1 == Block.GRASS.id || i1 == Block.DIRT.id) && j < world.getHeight() - l - 1) { // CraftBukkit
|
||||
// Craftbukkit start
|
||||
if (event == null) {
|
||||
world.setRawTypeId(i, j - 1, k, Block.DIRT.id);
|
||||
|
||||
} else {
|
||||
BlockState dirtState = bukkitWorld.getBlockAt(i, j - 1, k).getState();
|
||||
dirtState.setTypeId(Block.DIRT.id);
|
||||
event.getBlocks().add(dirtState);
|
||||
}
|
||||
// Craftbukkit end
|
||||
int i2;
|
||||
|
||||
for (i2 = j - 3 + l; i2 <= j + l; ++i2) {
|
||||
@ -75,7 +89,16 @@ public class WorldGenForest extends WorldGenerator {
|
||||
int l2 = k2 - k;
|
||||
|
||||
if ((Math.abs(j2) != k1 || Math.abs(l2) != k1 || random.nextInt(2) != 0 && j1 != 0) && !Block.o[world.getTypeId(l1, i2, k2)]) {
|
||||
// Craftbukkit start
|
||||
if (event == null) {
|
||||
this.a(world, l1, i2, k2, Block.LEAVES.id, 2);
|
||||
} else {
|
||||
BlockState leavesState = bukkitWorld.getBlockAt(l1, i2, k2).getState();
|
||||
leavesState.setTypeId(Block.LEAVES.id);
|
||||
leavesState.setData(new MaterialData(Block.LEAVES.id, (byte) 2));
|
||||
event.getBlocks().add(leavesState);
|
||||
}
|
||||
// Craftbukkit end
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -84,10 +107,31 @@ public class WorldGenForest extends WorldGenerator {
|
||||
for (i2 = 0; i2 < l; ++i2) {
|
||||
j1 = world.getTypeId(i, j + i2, k);
|
||||
if (j1 == 0 || j1 == Block.LEAVES.id) {
|
||||
// Craftbukkit start
|
||||
if (event == null) {
|
||||
this.a(world, i, j + i2, k, Block.LOG.id, 2);
|
||||
} else {
|
||||
BlockState logState = bukkitWorld.getBlockAt(i, j + i2, k).getState();
|
||||
logState.setTypeId(Block.LOG.id);
|
||||
logState.setData(new MaterialData(Block.LOG.id, (byte) 2));
|
||||
event.getBlocks().add(logState);
|
||||
}
|
||||
// Craftbukkit end
|
||||
}
|
||||
}
|
||||
|
||||
// Craftbukkit start
|
||||
if (event != null) {
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
for (BlockState state : event.getBlocks()) {
|
||||
state.update(true);
|
||||
}
|
||||
if (event.isFromBonemeal() && itemstack != null) {
|
||||
--itemstack.count;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Craftbukkit end
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -1,6 +1,13 @@
|
||||
package net.minecraft.server;
|
||||
|
||||
import java.util.Random;
|
||||
// Craftbukkit start
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.event.world.StructureGrowEvent;
|
||||
import org.bukkit.material.MaterialData;
|
||||
// Craftbukkit end
|
||||
|
||||
public class WorldGenHugeMushroom extends WorldGenerator {
|
||||
|
||||
@ -12,7 +19,13 @@ public class WorldGenHugeMushroom extends WorldGenerator {
|
||||
|
||||
public WorldGenHugeMushroom() {}
|
||||
|
||||
// CraftBukkit start - delegate to grow()
|
||||
public boolean a(World 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) {
|
||||
// CraftBukkit end
|
||||
int l = random.nextInt(2);
|
||||
|
||||
if (this.a >= 0) {
|
||||
@ -58,7 +71,15 @@ public class WorldGenHugeMushroom extends WorldGenerator {
|
||||
} else if (!Block.BROWN_MUSHROOM.canPlace(world, i, j, k)) {
|
||||
return false;
|
||||
} else {
|
||||
// Craftbukkit start
|
||||
if (event == null) {
|
||||
world.setRawTypeId(i, j - 1, k, Block.DIRT.id);
|
||||
} else {
|
||||
BlockState dirtState = bukkitWorld.getBlockAt(i, j - 1, k).getState();
|
||||
dirtState.setTypeId(Block.DIRT.id);
|
||||
event.getBlocks().add(dirtState);
|
||||
}
|
||||
// Craftbukkit end
|
||||
int j2 = j + i1;
|
||||
|
||||
if (l == 1) {
|
||||
@ -138,7 +159,16 @@ public class WorldGenHugeMushroom extends WorldGenerator {
|
||||
}
|
||||
|
||||
if ((l2 != 0 || j >= j + i1 - 1) && !Block.o[world.getTypeId(i2, k1, k2)]) {
|
||||
// Craftbukkit start
|
||||
if (event == null) {
|
||||
world.setRawTypeIdAndData(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);
|
||||
state.setData(new MaterialData(Block.BIG_MUSHROOM_1.id + l, (byte) l2));
|
||||
event.getBlocks().add(state);
|
||||
}
|
||||
// Craftbukkit end
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -147,10 +177,31 @@ public class WorldGenHugeMushroom extends WorldGenerator {
|
||||
for (k1 = 0; k1 < i1; ++k1) {
|
||||
l1 = world.getTypeId(i, j + k1, k);
|
||||
if (!Block.o[l1]) {
|
||||
// Craftbukkit start
|
||||
if (event == null) {
|
||||
world.setRawTypeIdAndData(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);
|
||||
state.setData(new MaterialData(Block.BIG_MUSHROOM_1.id + l, (byte) 10));
|
||||
event.getBlocks().add(state);
|
||||
}
|
||||
// Craftbukkit end
|
||||
}
|
||||
}
|
||||
|
||||
// Craftbukkit start
|
||||
if (event != null) {
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
for (BlockState state : event.getBlocks()) {
|
||||
state.update(true);
|
||||
}
|
||||
if (event.isFromBonemeal() && itemstack != null) {
|
||||
--itemstack.count;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Craftbukkit end
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -2,7 +2,14 @@ package net.minecraft.server;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.BlockChangeDelegate; // CraftBukkit
|
||||
// CraftBukkit start
|
||||
import org.bukkit.BlockChangeDelegate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.event.world.StructureGrowEvent;
|
||||
import org.bukkit.material.MaterialData;
|
||||
// CraftBukkit end
|
||||
|
||||
public class WorldGenTaiga2 extends WorldGenerator {
|
||||
|
||||
@ -16,10 +23,10 @@ public class WorldGenTaiga2 extends WorldGenerator {
|
||||
// BlockChangeDelegate and then we can implicitly cast World to
|
||||
// WorldServer (a safe cast, AFAIK) and no code will be broken. This
|
||||
// then allows plugins to catch manually-invoked generation events
|
||||
return this.generate((BlockChangeDelegate) world, random, i, j, k);
|
||||
return this.generate((BlockChangeDelegate) world, random, i, j, k, null, null, world.getWorld());
|
||||
}
|
||||
|
||||
public boolean generate(BlockChangeDelegate world, Random random, int i, int j, int k) {
|
||||
public boolean generate(BlockChangeDelegate world, Random random, int i, int j, int k, StructureGrowEvent event, ItemStack itemstack, CraftWorld bukkitWorld) {
|
||||
// CraftBukkit end
|
||||
int l = random.nextInt(4) + 6;
|
||||
int i1 = 1 + random.nextInt(2);
|
||||
@ -61,7 +68,15 @@ public class WorldGenTaiga2 extends WorldGenerator {
|
||||
} else {
|
||||
l1 = world.getTypeId(i, j - 1, k);
|
||||
if ((l1 == Block.GRASS.id || l1 == Block.DIRT.id) && j < world.getHeight() - l - 1) { // CraftBukkit
|
||||
// Craftbukkit start
|
||||
if (event == null) {
|
||||
world.setRawTypeId(i, j - 1, k, Block.DIRT.id);
|
||||
} else {
|
||||
BlockState dirtState = bukkitWorld.getBlockAt(i, j - 1, k).getState();
|
||||
dirtState.setTypeId(Block.DIRT.id);
|
||||
event.getBlocks().add(dirtState);
|
||||
}
|
||||
// Craftbukkit end
|
||||
k2 = random.nextInt(2);
|
||||
i2 = 1;
|
||||
byte b0 = 0;
|
||||
@ -79,7 +94,16 @@ public class WorldGenTaiga2 extends WorldGenerator {
|
||||
int i4 = l3 - k;
|
||||
|
||||
if ((Math.abs(k3) != k2 || Math.abs(i4) != k2 || k2 <= 0) && !Block.o[world.getTypeId(i3, j3, l3)]) {
|
||||
// Craftbukkit start
|
||||
if (event == null) {
|
||||
this.a(world, i3, j3, l3, Block.LEAVES.id, 1);
|
||||
} else {
|
||||
BlockState leavesState = bukkitWorld.getBlockAt(i3, j3, l3).getState();
|
||||
leavesState.setTypeId(Block.LEAVES.id);
|
||||
leavesState.setData(new MaterialData(Block.LEAVES.id, (byte) 1));
|
||||
event.getBlocks().add(leavesState);
|
||||
}
|
||||
// Craftbukkit end
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -101,10 +125,31 @@ public class WorldGenTaiga2 extends WorldGenerator {
|
||||
for (j3 = 0; j3 < l - j2; ++j3) {
|
||||
i3 = world.getTypeId(i, j + j3, k);
|
||||
if (i3 == 0 || i3 == Block.LEAVES.id) {
|
||||
// Craftbukkit start
|
||||
if (event == null) {
|
||||
this.a(world, i, j + j3, k, Block.LOG.id, 1);
|
||||
} else {
|
||||
BlockState logState = bukkitWorld.getBlockAt(i, j + j3, k).getState();
|
||||
logState.setTypeId(Block.LOG.id);
|
||||
logState.setData(new MaterialData(Block.LOG.id, (byte) 1));
|
||||
event.getBlocks().add(logState);
|
||||
}
|
||||
// Craftbukkit end
|
||||
}
|
||||
}
|
||||
|
||||
// Craftbukkit start
|
||||
if (event != null) {
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
for (BlockState state : event.getBlocks()) {
|
||||
state.update(true);
|
||||
}
|
||||
if (event.isFromBonemeal() && itemstack != null) {
|
||||
--itemstack.count;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Craftbukkit end
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -2,7 +2,13 @@ package net.minecraft.server;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import org.bukkit.BlockChangeDelegate; // CraftBukkit
|
||||
// Craftbukkit start
|
||||
import org.bukkit.BlockChangeDelegate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.craftbukkit.CraftWorld;
|
||||
import org.bukkit.event.world.StructureGrowEvent;
|
||||
// Craftbukkit end
|
||||
|
||||
public class WorldGenTrees extends WorldGenerator {
|
||||
|
||||
@ -16,10 +22,10 @@ public class WorldGenTrees extends WorldGenerator {
|
||||
// BlockChangeDelegate and then we can implicitly cast World to
|
||||
// WorldServer (a safe cast, AFAIK) and no code will be broken. This
|
||||
// then allows plugins to catch manually-invoked generation events
|
||||
return this.generate((BlockChangeDelegate) world, random, i, j, k);
|
||||
return this.generate((BlockChangeDelegate) world, random, i, j, k, null, null, world.getWorld());
|
||||
}
|
||||
|
||||
public boolean generate(BlockChangeDelegate world, Random random, int i, int j, int k) {
|
||||
public boolean generate(BlockChangeDelegate world, Random random, int i, int j, int k, StructureGrowEvent event, ItemStack itemstack, CraftWorld bukkitWorld) {
|
||||
// CraftBukkit end
|
||||
int l = random.nextInt(3) + 4;
|
||||
boolean flag = true;
|
||||
@ -60,7 +66,15 @@ public class WorldGenTrees extends WorldGenerator {
|
||||
} else {
|
||||
i1 = world.getTypeId(i, j - 1, k);
|
||||
if ((i1 == Block.GRASS.id || i1 == Block.DIRT.id) && j < world.getHeight() - l - 1) { // CraftBukkit
|
||||
// Craftbukkit start
|
||||
if (event == null) {
|
||||
world.setRawTypeId(i, j - 1, k, Block.DIRT.id);
|
||||
} else {
|
||||
BlockState dirtState = bukkitWorld.getBlockAt(i, j - 1, k).getState();
|
||||
dirtState.setTypeId(Block.DIRT.id);
|
||||
event.getBlocks().add(dirtState);
|
||||
}
|
||||
// Craftbukkit end
|
||||
|
||||
int i2;
|
||||
|
||||
@ -75,7 +89,15 @@ public class WorldGenTrees extends WorldGenerator {
|
||||
int l2 = k2 - k;
|
||||
|
||||
if ((Math.abs(j2) != k1 || Math.abs(l2) != k1 || random.nextInt(2) != 0 && j1 != 0) && !Block.o[world.getTypeId(l1, i2, k2)]) {
|
||||
// Craftbukkit start
|
||||
if (event == null) {
|
||||
this.a(world, l1, i2, k2, Block.LEAVES.id, 0);
|
||||
} else {
|
||||
BlockState leavesState = bukkitWorld.getBlockAt(l1, i2, k2).getState();
|
||||
leavesState.setTypeId(Block.LEAVES.id);
|
||||
event.getBlocks().add(leavesState);
|
||||
}
|
||||
// Craftbukkit end
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -84,10 +106,30 @@ public class WorldGenTrees extends WorldGenerator {
|
||||
for (i2 = 0; i2 < l; ++i2) {
|
||||
j1 = world.getTypeId(i, j + i2, k);
|
||||
if (j1 == 0 || j1 == Block.LEAVES.id) {
|
||||
// Craftbukkit start
|
||||
if (event == null) {
|
||||
this.a(world, i, j + i2, k, Block.LOG.id, 0);
|
||||
} else {
|
||||
BlockState logState = bukkitWorld.getBlockAt(i, j + i2, k).getState();
|
||||
logState.setTypeId(Block.LOG.id);
|
||||
event.getBlocks().add(logState);
|
||||
}
|
||||
// Craftbukkit end
|
||||
}
|
||||
}
|
||||
|
||||
// Craftbukkit start
|
||||
if (event != null) {
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if (!event.isCancelled()) {
|
||||
for (BlockState state : event.getBlocks()) {
|
||||
state.update(true);
|
||||
}
|
||||
if (event.isFromBonemeal() && itemstack != null) {
|
||||
--itemstack.count;
|
||||
}
|
||||
}
|
||||
}
|
||||
// Craftbukkit end
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -348,16 +348,16 @@ public class CraftWorld implements World {
|
||||
public boolean generateTree(Location loc, TreeType type, BlockChangeDelegate delegate) {
|
||||
switch (type) {
|
||||
case BIG_TREE:
|
||||
return new WorldGenBigTree(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
return new WorldGenBigTree(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), null, null, null);
|
||||
case BIRCH:
|
||||
return new WorldGenForest(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
return new WorldGenForest(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), null, null, null);
|
||||
case REDWOOD:
|
||||
return new WorldGenTaiga2(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
return new WorldGenTaiga2(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), null, null, null);
|
||||
case TALL_REDWOOD:
|
||||
return new WorldGenTaiga1().generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
case TREE:
|
||||
default:
|
||||
return new WorldGenTrees(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ());
|
||||
return new WorldGenTrees(false).generate(delegate, rand, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), null, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
|
In neuem Issue referenzieren
Einen Benutzer sperren