2011-06-17 20:48:20 +02:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.Random;
|
2012-07-22 08:18:00 +02:00
|
|
|
|
2012-01-12 12:02:39 +01:00
|
|
|
// CraftBukkit start
|
2012-07-22 08:18:00 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2011-12-09 17:11:56 +01:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.TreeType;
|
|
|
|
import org.bukkit.block.BlockState;
|
2011-09-15 02:23:52 +02:00
|
|
|
import org.bukkit.event.block.BlockSpreadEvent;
|
2011-12-09 17:11:56 +01:00
|
|
|
import org.bukkit.event.world.StructureGrowEvent;
|
2012-01-12 12:02:39 +01:00
|
|
|
// CraftBukkit end
|
2011-06-17 20:48:20 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public class BlockMushroom extends BlockPlant implements IBlockFragilePlantElement {
|
2011-06-17 20:48:20 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
protected BlockMushroom() {
|
2011-06-17 20:48:20 +02:00
|
|
|
float f = 0.2F;
|
|
|
|
|
|
|
|
this.a(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f * 2.0F, 0.5F + f);
|
2013-11-04 14:07:38 +01:00
|
|
|
this.a(true);
|
2011-06-17 20:48:20 +02:00
|
|
|
}
|
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
public void a(World world, int i, int j, int k, Random random) {
|
2013-01-27 17:44:32 +01:00
|
|
|
final int sourceX = i, sourceY = j, sourceZ = k; // CraftBukkit
|
2011-11-20 09:01:14 +01:00
|
|
|
if (random.nextInt(25) == 0) {
|
2011-09-15 02:23:52 +02:00
|
|
|
byte b0 = 4;
|
|
|
|
int l = 5;
|
2011-06-17 20:48:20 +02:00
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
int i1;
|
|
|
|
int j1;
|
|
|
|
int k1;
|
2011-06-17 20:48:20 +02:00
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
for (i1 = i - b0; i1 <= i + b0; ++i1) {
|
|
|
|
for (j1 = k - b0; j1 <= k + b0; ++j1) {
|
|
|
|
for (k1 = j - 1; k1 <= j + 1; ++k1) {
|
2013-11-04 14:07:38 +01:00
|
|
|
if (world.getType(i1, k1, j1) == this) {
|
2011-09-15 02:23:52 +02:00
|
|
|
--l;
|
|
|
|
if (l <= 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-17 20:48:20 +02:00
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
i1 = i + random.nextInt(3) - 1;
|
|
|
|
j1 = j + random.nextInt(2) - random.nextInt(2);
|
|
|
|
k1 = k + random.nextInt(3) - 1;
|
2011-06-17 20:48:20 +02:00
|
|
|
|
2011-09-15 02:23:52 +02:00
|
|
|
for (int l1 = 0; l1 < 4; ++l1) {
|
2013-11-04 14:07:38 +01:00
|
|
|
if (world.isEmpty(i1, j1, k1) && this.j(world, i1, j1, k1)) {
|
2011-09-15 02:23:52 +02:00
|
|
|
i = i1;
|
|
|
|
j = j1;
|
|
|
|
k = k1;
|
2011-06-17 20:48:20 +02:00
|
|
|
}
|
2011-09-15 02:23:52 +02:00
|
|
|
|
|
|
|
i1 = i + random.nextInt(3) - 1;
|
|
|
|
j1 = j + random.nextInt(2) - random.nextInt(2);
|
|
|
|
k1 = k + random.nextInt(3) - 1;
|
2011-06-17 20:48:20 +02:00
|
|
|
}
|
2011-09-15 02:23:52 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (world.isEmpty(i1, j1, k1) && this.j(world, i1, j1, k1)) {
|
2011-09-16 21:10:11 +02:00
|
|
|
// CraftBukkit start
|
|
|
|
org.bukkit.World bworld = world.getWorld();
|
2012-07-22 08:18:00 +02:00
|
|
|
BlockState blockState = bworld.getBlockAt(i1, j1, k1).getState();
|
2013-11-04 14:07:38 +01:00
|
|
|
blockState.setTypeId(Block.b(this)); // nms: this.id, 0, 2
|
2011-09-15 02:23:52 +02:00
|
|
|
|
2013-01-02 18:36:23 +01:00
|
|
|
BlockSpreadEvent event = new BlockSpreadEvent(blockState.getBlock(), bworld.getBlockAt(sourceX, sourceY, sourceZ), blockState);
|
2011-09-16 21:10:11 +02:00
|
|
|
world.getServer().getPluginManager().callEvent(event);
|
2011-09-15 02:23:52 +02:00
|
|
|
|
2011-09-16 21:10:11 +02:00
|
|
|
if (!event.isCancelled()) {
|
|
|
|
blockState.update(true);
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
2011-09-15 02:23:52 +02:00
|
|
|
}
|
2011-06-17 20:48:20 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-22 21:39:39 +01:00
|
|
|
public boolean canPlace(World world, int i, int j, int k) {
|
2013-11-04 14:07:38 +01:00
|
|
|
return super.canPlace(world, i, j, k) && this.j(world, i, j, k);
|
2012-03-22 21:39:39 +01:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
protected boolean a(Block block) {
|
|
|
|
return block.j();
|
2011-06-17 20:48:20 +02:00
|
|
|
}
|
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
public boolean j(World world, int i, int j, int k) {
|
2012-03-01 11:49:23 +01:00
|
|
|
if (j >= 0 && j < 256) {
|
2013-11-04 14:07:38 +01:00
|
|
|
Block block = world.getType(i, j - 1, k);
|
2011-09-15 02:23:52 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
return block == Blocks.MYCEL || block == Blocks.DIRT && world.getData(i, j - 1, k) == 2 || world.j(i, j, k) < 13 && this.a(block);
|
2011-11-20 09:01:14 +01:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2011-09-15 02:23:52 +02:00
|
|
|
}
|
|
|
|
|
2011-12-09 17:11:56 +01:00
|
|
|
// CraftBukkit - added bonemeal, player and itemstack
|
2012-07-22 08:18:00 +02:00
|
|
|
public boolean grow(World world, int i, int j, int k, Random random, boolean bonemeal, org.bukkit.entity.Player player, ItemStack itemstack) {
|
2011-11-20 09:01:14 +01:00
|
|
|
int l = world.getData(i, j, k);
|
2011-09-15 02:23:52 +02:00
|
|
|
|
2013-03-13 23:33:27 +01:00
|
|
|
world.setAir(i, j, k);
|
2011-12-09 17:11:56 +01:00
|
|
|
// CraftBukkit start
|
|
|
|
boolean grown = false;
|
|
|
|
StructureGrowEvent event = null;
|
|
|
|
Location location = new Location(world.getWorld(), i, j, k);
|
2011-11-20 09:01:14 +01:00
|
|
|
WorldGenHugeMushroom worldgenhugemushroom = null;
|
2011-09-15 02:23:52 +02:00
|
|
|
|
2013-11-04 14:07:38 +01:00
|
|
|
if (this == Blocks.BROWN_MUSHROOM) {
|
2011-12-09 17:11:56 +01:00
|
|
|
event = new StructureGrowEvent(location, TreeType.BROWN_MUSHROOM, bonemeal, player, new ArrayList<BlockState>());
|
2011-11-20 09:01:14 +01:00
|
|
|
worldgenhugemushroom = new WorldGenHugeMushroom(0);
|
2013-11-04 14:07:38 +01:00
|
|
|
} else if (this == Blocks.RED_MUSHROOM) {
|
2011-12-09 17:11:56 +01:00
|
|
|
event = new StructureGrowEvent(location, TreeType.RED_MUSHROOM, bonemeal, player, new ArrayList<BlockState>());
|
2011-11-20 09:01:14 +01:00
|
|
|
worldgenhugemushroom = new WorldGenHugeMushroom(1);
|
|
|
|
}
|
2012-07-29 09:33:13 +02:00
|
|
|
|
2011-12-19 17:41:55 +01:00
|
|
|
if (worldgenhugemushroom != null && event != null) {
|
2013-11-04 14:07:38 +01:00
|
|
|
grown = worldgenhugemushroom.grow(new org.bukkit.craftbukkit.CraftBlockChangeDelegate((org.bukkit.BlockChangeDelegate) world), random, i, j, k, event, itemstack, world.getWorld());
|
2011-12-19 17:41:55 +01:00
|
|
|
if (event.isFromBonemeal() && itemstack != null) {
|
|
|
|
--itemstack.count;
|
|
|
|
}
|
2011-12-09 17:11:56 +01:00
|
|
|
}
|
2011-12-19 17:41:55 +01:00
|
|
|
if (!grown || event.isCancelled()) {
|
2013-11-04 14:07:38 +01:00
|
|
|
world.setTypeAndData(i, j, k, this, l, 3);
|
2011-11-20 09:01:14 +01:00
|
|
|
return false;
|
2011-09-15 02:23:52 +02:00
|
|
|
}
|
2011-12-09 17:11:56 +01:00
|
|
|
return true;
|
|
|
|
// CraftBukkit end
|
2011-06-17 20:48:20 +02:00
|
|
|
}
|
2013-11-04 14:07:38 +01:00
|
|
|
|
|
|
|
public boolean a(World world, int i, int j, int k, boolean flag) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean a(World world, Random random, int i, int j, int k) {
|
|
|
|
return (double) random.nextFloat() < 0.4D;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void b(World world, Random random, int i, int j, int k) {
|
|
|
|
this.grow(world, i, j, k, random, false, null, null); // CraftBukkit - Add bonemeal, player, and itemstack
|
|
|
|
}
|
2011-06-17 20:48:20 +02:00
|
|
|
}
|