3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-27 08:30:06 +01:00
Paper/src/main/java/net/minecraft/server/BlockMushroom.java

137 Zeilen
4.6 KiB
Java

package net.minecraft.server;
import java.util.Random;
2012-01-12 12:02:39 +01:00
// CraftBukkit start
import java.util.ArrayList;
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;
import org.bukkit.event.world.StructureGrowEvent;
2012-01-12 12:02:39 +01:00
// CraftBukkit end
public class BlockMushroom extends BlockFlower {
protected BlockMushroom(int i, int j) {
super(i, j);
float f = 0.2F;
this.a(0.5F - f, 0.0F, 0.5F - f, 0.5F + f, f * 2.0F, 0.5F + f);
2012-07-29 09:33:13 +02:00
this.b(true);
}
2012-07-29 09:33:13 +02:00
public void b(World world, int i, int j, int k, Random random) {
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-09-15 02:23:52 +02:00
int i1;
int j1;
int k1;
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) {
if (world.getTypeId(i1, k1, j1) == this.id) {
--l;
if (l <= 0) {
return;
}
}
}
}
}
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;
// CraftBukkit start - preserve source block coordinates
int sourceX = i;
int sourceY = j;
int sourceZ = k;
// CraftBukkit end
2011-09-15 02:23:52 +02:00
for (int l1 = 0; l1 < 4; ++l1) {
2012-07-29 09:33:13 +02:00
if (world.isEmpty(i1, j1, k1) && this.d(world, i1, j1, k1)) {
2011-09-15 02:23:52 +02:00
i = i1;
j = j1;
k = k1;
}
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-09-15 02:23:52 +02:00
2012-07-29 09:33:13 +02:00
if (world.isEmpty(i1, j1, k1) && this.d(world, i1, j1, k1)) {
// CraftBukkit start
org.bukkit.World bworld = world.getWorld();
BlockState blockState = bworld.getBlockAt(i1, j1, k1).getState();
blockState.setTypeId(this.id);
2011-09-15 02:23:52 +02:00
BlockSpreadEvent event = new BlockSpreadEvent(blockState.getBlock(), bworld.getBlockAt(sourceX, sourceY, sourceZ), blockState);
world.getServer().getPluginManager().callEvent(event);
2011-09-15 02:23:52 +02:00
if (!event.isCancelled()) {
blockState.update(true);
}
// CraftBukkit end
2011-09-15 02:23:52 +02:00
}
}
}
public boolean canPlace(World world, int i, int j, int k) {
2012-07-29 09:33:13 +02:00
return super.canPlace(world, i, j, k) && this.d(world, i, j, k);
}
2012-07-29 09:33:13 +02:00
protected boolean d_(int i) {
return Block.q[i];
}
2012-07-29 09:33:13 +02:00
public boolean d(World world, int i, int j, int k) {
2012-03-01 11:49:23 +01:00
if (j >= 0 && j < 256) {
2011-11-20 09:01:14 +01:00
int l = world.getTypeId(i, j - 1, k);
2011-09-15 02:23:52 +02:00
2012-11-06 13:05:28 +01:00
return l == Block.MYCEL.id || world.l(i, j, k) < 13 && this.d_(l);
2011-11-20 09:01:14 +01:00
} else {
return false;
}
2011-09-15 02:23:52 +02:00
}
// CraftBukkit - added bonemeal, player and itemstack
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
2011-11-20 09:01:14 +01:00
world.setRawTypeId(i, j, k, 0);
// 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
2011-11-20 09:01:14 +01:00
if (this.id == Block.BROWN_MUSHROOM.id) {
event = new StructureGrowEvent(location, TreeType.BROWN_MUSHROOM, bonemeal, player, new ArrayList<BlockState>());
2011-11-20 09:01:14 +01:00
worldgenhugemushroom = new WorldGenHugeMushroom(0);
} else if (this.id == Block.RED_MUSHROOM.id) {
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
if (worldgenhugemushroom != null && event != null) {
grown = worldgenhugemushroom.grow((org.bukkit.BlockChangeDelegate)world, random, i, j, k, event, itemstack, world.getWorld());
if (event.isFromBonemeal() && itemstack != null) {
--itemstack.count;
}
}
if (!grown || event.isCancelled()) {
2011-11-20 09:01:14 +01:00
world.setRawTypeIdAndData(i, j, k, this.id, l);
return false;
2011-09-15 02:23:52 +02:00
}
return true;
// CraftBukkit end
}
}