SPIGOT-5537: Bee nests generated by growing trees near flower have no bees

This commit is contained in:
md_5 2020-01-28 09:48:28 +11:00
parent d82b314944
commit 6515ea4957
7 changed files with 99 additions and 72 deletions

View file

@ -1,12 +1,10 @@
--- a/net/minecraft/server/BlockSapling.java --- a/net/minecraft/server/BlockSapling.java
+++ b/net/minecraft/server/BlockSapling.java +++ b/net/minecraft/server/BlockSapling.java
@@ -2,11 +2,21 @@ @@ -2,11 +2,19 @@
import java.util.Random; import java.util.Random;
+// CraftBukkit start +// CraftBukkit start
+import java.util.List;
+
+import org.bukkit.Location; +import org.bukkit.Location;
+import org.bukkit.TreeType; +import org.bukkit.TreeType;
+import org.bukkit.block.BlockState; +import org.bukkit.block.BlockState;
@ -22,7 +20,7 @@
protected BlockSapling(WorldGenTreeProvider worldgentreeprovider, Block.Info block_info) { protected BlockSapling(WorldGenTreeProvider worldgentreeprovider, Block.Info block_info) {
super(block_info); super(block_info);
@@ -23,7 +33,30 @@ @@ -23,7 +31,30 @@
public void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, Random random) { public void tick(IBlockData iblockdata, WorldServer worldserver, BlockPosition blockposition, Random random) {
super.tick(iblockdata, worldserver, blockposition, random); super.tick(iblockdata, worldserver, blockposition, random);
if (worldserver.getLightLevel(blockposition.up()) >= 9 && random.nextInt(7) == 0) { if (worldserver.getLightLevel(blockposition.up()) >= 9 && random.nextInt(7) == 0) {
@ -36,7 +34,7 @@
+ TreeType treeType = BlockSapling.treeType; + TreeType treeType = BlockSapling.treeType;
+ BlockSapling.treeType = null; + BlockSapling.treeType = null;
+ Location location = new Location(worldserver.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ()); + Location location = new Location(worldserver.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ List<BlockState> blocks = (List<BlockState>) worldserver.capturedBlockStates.clone(); + java.util.List<BlockState> blocks = new java.util.ArrayList<>(worldserver.capturedBlockStates.values());
+ worldserver.capturedBlockStates.clear(); + worldserver.capturedBlockStates.clear();
+ StructureGrowEvent event = null; + StructureGrowEvent event = null;
+ if (treeType != null) { + if (treeType != null) {

View file

@ -405,7 +405,7 @@
+ TreeType treeType = BlockSapling.treeType; + TreeType treeType = BlockSapling.treeType;
+ BlockSapling.treeType = null; + BlockSapling.treeType = null;
+ Location location = new Location(world.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ()); + Location location = new Location(world.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ List<org.bukkit.block.BlockState> blocks = (List<org.bukkit.block.BlockState>) world.capturedBlockStates.clone(); + List<org.bukkit.block.BlockState> blocks = new java.util.ArrayList<>(world.capturedBlockStates.values());
+ world.capturedBlockStates.clear(); + world.capturedBlockStates.clear();
+ StructureGrowEvent structureEvent = null; + StructureGrowEvent structureEvent = null;
+ if (treeType != null) { + if (treeType != null) {

View file

@ -108,7 +108,7 @@
+ Location location = new Location(world.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ()); + Location location = new Location(world.getWorld(), blockposition.getX(), blockposition.getY(), blockposition.getZ());
+ TreeType treeType = BlockSapling.treeType; + TreeType treeType = BlockSapling.treeType;
+ BlockSapling.treeType = null; + BlockSapling.treeType = null;
+ List<BlockState> blocks = (List<BlockState>) world.capturedBlockStates.clone(); + List<BlockState> blocks = new java.util.ArrayList<>(world.capturedBlockStates.values());
+ world.capturedBlockStates.clear(); + world.capturedBlockStates.clear();
+ StructureGrowEvent structureEvent = null; + StructureGrowEvent structureEvent = null;
+ if (treeType != null) { + if (treeType != null) {
@ -139,7 +139,7 @@
if (entityhuman != null && enuminteractionresult == EnumInteractionResult.SUCCESS) { if (entityhuman != null && enuminteractionresult == EnumInteractionResult.SUCCESS) {
- entityhuman.b(StatisticList.ITEM_USED.b(item)); - entityhuman.b(StatisticList.ITEM_USED.b(item));
+ org.bukkit.event.block.BlockPlaceEvent placeEvent = null; + org.bukkit.event.block.BlockPlaceEvent placeEvent = null;
+ List<BlockState> blocks = (List<BlockState>) world.capturedBlockStates.clone(); + List<BlockState> blocks = new java.util.ArrayList<>(world.capturedBlockStates.values());
+ world.capturedBlockStates.clear(); + world.capturedBlockStates.clear();
+ if (blocks.size() > 1) { + if (blocks.size() > 1) {
+ placeEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callBlockMultiPlaceEvent(world, entityhuman, enumhand, blocks, blockposition.getX(), blockposition.getY(), blockposition.getZ()); + placeEvent = org.bukkit.craftbukkit.event.CraftEventFactory.callBlockMultiPlaceEvent(world, entityhuman, enumhand, blocks, blockposition.getX(), blockposition.getY(), blockposition.getZ());

View file

@ -1,29 +1,24 @@
--- a/net/minecraft/server/World.java --- a/net/minecraft/server/World.java
+++ b/net/minecraft/server/World.java +++ b/net/minecraft/server/World.java
@@ -14,6 +14,22 @@ @@ -14,6 +14,17 @@
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.apache.logging.log4j.util.Supplier; import org.apache.logging.log4j.util.Supplier;
+// CraftBukkit start +// CraftBukkit start
+import com.google.common.collect.Maps; +import java.util.HashMap;
+import java.util.ArrayList;
+import java.util.Map; +import java.util.Map;
+import org.bukkit.Bukkit; +import org.bukkit.Bukkit;
+import org.bukkit.block.BlockState;
+import org.bukkit.craftbukkit.CraftServer; +import org.bukkit.craftbukkit.CraftServer;
+import org.bukkit.craftbukkit.CraftWorld; +import org.bukkit.craftbukkit.CraftWorld;
+import org.bukkit.craftbukkit.block.CraftBlockState; +import org.bukkit.craftbukkit.block.CapturedBlockState;
+import org.bukkit.craftbukkit.block.data.CraftBlockData; +import org.bukkit.craftbukkit.block.data.CraftBlockData;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.event.block.BlockPhysicsEvent; +import org.bukkit.event.block.BlockPhysicsEvent;
+import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
+import org.bukkit.event.weather.LightningStrikeEvent;
+// CraftBukkit end +// CraftBukkit end
+ +
public abstract class World implements GeneratorAccess, AutoCloseable { public abstract class World implements GeneratorAccess, AutoCloseable {
protected static final Logger LOGGER = LogManager.getLogger(); protected static final Logger LOGGER = LogManager.getLogger();
@@ -40,7 +56,51 @@ @@ -40,7 +51,39 @@
private final WorldBorder worldBorder; private final WorldBorder worldBorder;
private final BiomeManager biomeManager; private final BiomeManager biomeManager;
@ -36,20 +31,8 @@
+ +
+ public boolean captureBlockStates = false; + public boolean captureBlockStates = false;
+ public boolean captureTreeGeneration = false; + public boolean captureTreeGeneration = false;
+ public ArrayList<CraftBlockState> capturedBlockStates = new ArrayList<CraftBlockState>() { + public Map<BlockPosition, CapturedBlockState> capturedBlockStates = new HashMap<>();
+ @Override + public Map<BlockPosition, TileEntity> capturedTileEntities = new HashMap<>();
+ public boolean add(CraftBlockState blockState) {
+ Iterator<CraftBlockState> blockStateIterator = this.iterator();
+ while (blockStateIterator.hasNext()) {
+ BlockState blockState1 = blockStateIterator.next();
+ if (blockState1.getLocation().equals(blockState.getLocation())) {
+ return false;
+ }
+ }
+
+ return super.add(blockState);
+ }
+ };
+ public List<EntityItem> captureDrops; + public List<EntityItem> captureDrops;
+ public long ticksPerAnimalSpawns; + public long ticksPerAnimalSpawns;
+ public long ticksPerMonsterSpawns; + public long ticksPerMonsterSpawns;
@ -76,7 +59,7 @@
this.methodProfiler = gameprofilerfiller; this.methodProfiler = gameprofilerfiller;
this.worldData = worlddata; this.worldData = worlddata;
this.worldProvider = dimensionmanager.getWorldProvider(this); this.worldProvider = dimensionmanager.getWorldProvider(this);
@@ -49,6 +109,35 @@ @@ -49,6 +92,35 @@
this.worldBorder = this.worldProvider.getWorldBorder(); this.worldBorder = this.worldProvider.getWorldBorder();
this.serverThread = Thread.currentThread(); this.serverThread = Thread.currentThread();
this.biomeManager = new BiomeManager(this, flag ? worlddata.getSeed() : WorldData.c(worlddata.getSeed()), dimensionmanager.getGenLayerZoomer()); this.biomeManager = new BiomeManager(this, flag ? worlddata.getSeed() : WorldData.c(worlddata.getSeed()), dimensionmanager.getGenLayerZoomer());
@ -112,44 +95,34 @@
} }
@Override @Override
@@ -105,6 +194,26 @@ @@ -105,6 +177,17 @@
@Override @Override
public boolean setTypeAndData(BlockPosition blockposition, IBlockData iblockdata, int i) { public boolean setTypeAndData(BlockPosition blockposition, IBlockData iblockdata, int i) {
+ // CraftBukkit start - tree generation + // CraftBukkit start - tree generation
+ if (this.captureTreeGeneration) { + if (this.captureTreeGeneration) {
+ CraftBlockState blockstate = null; + CapturedBlockState blockstate = capturedBlockStates.get(blockposition);
+ Iterator<CraftBlockState> it = capturedBlockStates.iterator();
+ while (it.hasNext()) {
+ CraftBlockState previous = it.next();
+ if (previous.getPosition().equals(blockposition)) {
+ blockstate = previous;
+ it.remove();
+ break;
+ }
+ }
+ if (blockstate == null) { + if (blockstate == null) {
+ blockstate = org.bukkit.craftbukkit.block.CraftBlockState.getBlockState(this, blockposition, i); + blockstate = CapturedBlockState.getTreeBlockState(this, blockposition, i);
+ this.capturedBlockStates.put(blockposition.immutableCopy(), blockstate);
+ } + }
+ blockstate.setData(iblockdata); + blockstate.setData(iblockdata);
+ this.capturedBlockStates.add(blockstate);
+ return true; + return true;
+ } + }
+ // CraftBukkit end + // CraftBukkit end
if (isOutsideWorld(blockposition)) { if (isOutsideWorld(blockposition)) {
return false; return false;
} else if (!this.isClientSide && this.worldData.getType() == WorldType.DEBUG_ALL_BLOCK_STATES) { } else if (!this.isClientSide && this.worldData.getType() == WorldType.DEBUG_ALL_BLOCK_STATES) {
@@ -112,9 +221,23 @@ @@ -112,9 +195,22 @@
} else { } else {
Chunk chunk = this.getChunkAtWorldCoords(blockposition); Chunk chunk = this.getChunkAtWorldCoords(blockposition);
Block block = iblockdata.getBlock(); Block block = iblockdata.getBlock();
- IBlockData iblockdata1 = chunk.setType(blockposition, iblockdata, (i & 64) != 0); - IBlockData iblockdata1 = chunk.setType(blockposition, iblockdata, (i & 64) != 0);
+ +
+ // CraftBukkit start - capture blockstates + // CraftBukkit start - capture blockstates
+ CraftBlockState blockstate = null; + if (this.captureBlockStates && !this.capturedBlockStates.containsKey(blockposition)) {
+ if (this.captureBlockStates) { + CapturedBlockState blockstate = CapturedBlockState.getBlockState(this, blockposition, i);
+ blockstate = org.bukkit.craftbukkit.block.CraftBlockState.getBlockState(this, blockposition, i); + this.capturedBlockStates.put(blockposition.immutableCopy(), blockstate);
+ this.capturedBlockStates.add(blockstate);
+ } + }
+ // CraftBukkit end + // CraftBukkit end
+ +
@ -158,13 +131,13 @@
if (iblockdata1 == null) { if (iblockdata1 == null) {
+ // CraftBukkit start - remove blockstate if failed + // CraftBukkit start - remove blockstate if failed
+ if (this.captureBlockStates) { + if (this.captureBlockStates) {
+ this.capturedBlockStates.remove(blockstate); + this.capturedBlockStates.remove(blockposition);
+ } + }
+ // CraftBukkit end + // CraftBukkit end
return false; return false;
} else { } else {
IBlockData iblockdata2 = this.getType(blockposition); IBlockData iblockdata2 = this.getType(blockposition);
@@ -125,6 +248,7 @@ @@ -125,6 +221,7 @@
this.methodProfiler.exit(); this.methodProfiler.exit();
} }
@ -172,7 +145,7 @@
if (iblockdata2 == iblockdata) { if (iblockdata2 == iblockdata) {
if (iblockdata1 != iblockdata2) { if (iblockdata1 != iblockdata2) {
this.b(blockposition, iblockdata1, iblockdata2); this.b(blockposition, iblockdata1, iblockdata2);
@@ -151,12 +275,65 @@ @@ -151,12 +248,65 @@
this.a(blockposition, iblockdata1, iblockdata2); this.a(blockposition, iblockdata1, iblockdata2);
} }
@ -238,7 +211,7 @@
public void a(BlockPosition blockposition, IBlockData iblockdata, IBlockData iblockdata1) {} public void a(BlockPosition blockposition, IBlockData iblockdata, IBlockData iblockdata1) {}
@Override @Override
@@ -195,6 +372,11 @@ @@ -195,6 +345,11 @@
@Override @Override
public void update(BlockPosition blockposition, Block block) { public void update(BlockPosition blockposition, Block block) {
if (this.worldData.getType() != WorldType.DEBUG_ALL_BLOCK_STATES) { if (this.worldData.getType() != WorldType.DEBUG_ALL_BLOCK_STATES) {
@ -250,7 +223,7 @@
this.applyPhysics(blockposition, block); this.applyPhysics(blockposition, block);
} }
@@ -243,6 +425,17 @@ @@ -243,6 +398,17 @@
IBlockData iblockdata = this.getType(blockposition); IBlockData iblockdata = this.getType(blockposition);
try { try {
@ -268,25 +241,22 @@
iblockdata.doPhysics(this, blockposition, block, blockposition1, false); iblockdata.doPhysics(this, blockposition, block, blockposition1, false);
} catch (Throwable throwable) { } catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Exception while updating neighbours"); CrashReport crashreport = CrashReport.a(throwable, "Exception while updating neighbours");
@@ -285,6 +478,17 @@ @@ -285,6 +451,14 @@
@Override @Override
public IBlockData getType(BlockPosition blockposition) { public IBlockData getType(BlockPosition blockposition) {
+ // CraftBukkit start - tree generation + // CraftBukkit start - tree generation
+ if (captureTreeGeneration) { + if (captureTreeGeneration) {
+ Iterator<CraftBlockState> it = capturedBlockStates.iterator(); + CapturedBlockState previous = capturedBlockStates.get(blockposition);
+ while (it.hasNext()) { + if (previous != null) {
+ CraftBlockState previous = it.next(); + return previous.getHandle();
+ if (previous.getPosition().equals(blockposition)) {
+ return previous.getHandle();
+ }
+ } + }
+ } + }
+ // CraftBukkit end + // CraftBukkit end
if (isOutsideWorld(blockposition)) { if (isOutsideWorld(blockposition)) {
return Blocks.VOID_AIR.getBlockData(); return Blocks.VOID_AIR.getBlockData();
} else { } else {
@@ -306,11 +510,11 @@ @@ -306,11 +480,11 @@
} }
public boolean isDay() { public boolean isDay() {
@ -300,7 +270,7 @@
} }
@Override @Override
@@ -432,9 +636,11 @@ @@ -432,9 +606,11 @@
TileEntity tileentity1 = (TileEntity) this.tileEntityListPending.get(i); TileEntity tileentity1 = (TileEntity) this.tileEntityListPending.get(i);
if (!tileentity1.isRemoved()) { if (!tileentity1.isRemoved()) {
@ -312,7 +282,7 @@
if (this.isLoaded(tileentity1.getPosition())) { if (this.isLoaded(tileentity1.getPosition())) {
Chunk chunk = this.getChunkAtWorldCoords(tileentity1.getPosition()); Chunk chunk = this.getChunkAtWorldCoords(tileentity1.getPosition());
@@ -442,6 +648,12 @@ @@ -442,6 +618,12 @@
chunk.setTileEntity(tileentity1.getPosition(), tileentity1); chunk.setTileEntity(tileentity1.getPosition(), tileentity1);
this.notify(tileentity1.getPosition(), iblockdata, iblockdata, 3); this.notify(tileentity1.getPosition(), iblockdata, iblockdata, 3);
@ -325,7 +295,7 @@
} }
} }
} }
@@ -606,12 +818,26 @@ @@ -606,12 +788,25 @@
@Nullable @Nullable
@Override @Override
@ -333,7 +303,6 @@
public TileEntity getTileEntity(BlockPosition blockposition) { public TileEntity getTileEntity(BlockPosition blockposition) {
+ return getTileEntity(blockposition, true); + return getTileEntity(blockposition, true);
+ } + }
+ public Map<BlockPosition, TileEntity> capturedTileEntities = Maps.newHashMap();
+ +
+ @Nullable + @Nullable
+ protected TileEntity getTileEntity(BlockPosition blockposition, boolean validate) { + protected TileEntity getTileEntity(BlockPosition blockposition, boolean validate) {
@ -352,21 +321,21 @@
TileEntity tileentity = null; TileEntity tileentity = null;
if (this.tickingTileEntities) { if (this.tickingTileEntities) {
@@ -646,6 +872,13 @@ @@ -646,6 +841,13 @@
public void setTileEntity(BlockPosition blockposition, @Nullable TileEntity tileentity) { public void setTileEntity(BlockPosition blockposition, @Nullable TileEntity tileentity) {
if (!isOutsideWorld(blockposition)) { if (!isOutsideWorld(blockposition)) {
if (tileentity != null && !tileentity.isRemoved()) { if (tileentity != null && !tileentity.isRemoved()) {
+ // CraftBukkit start + // CraftBukkit start
+ if (captureBlockStates) { + if (captureBlockStates) {
+ tileentity.setLocation(this, blockposition); + tileentity.setLocation(this, blockposition);
+ capturedTileEntities.put(blockposition, tileentity); + capturedTileEntities.put(blockposition.immutableCopy(), tileentity);
+ return; + return;
+ } + }
+ // CraftBukkit end + // CraftBukkit end
if (this.tickingTileEntities) { if (this.tickingTileEntities) {
tileentity.setLocation(this, blockposition); tileentity.setLocation(this, blockposition);
Iterator iterator = this.tileEntityListPending.iterator(); Iterator iterator = this.tileEntityListPending.iterator();
@@ -670,7 +903,7 @@ @@ -670,7 +872,7 @@
} }
public void removeTileEntity(BlockPosition blockposition) { public void removeTileEntity(BlockPosition blockposition) {

View file

@ -741,7 +741,7 @@ public class CraftWorld implements World {
world.captureBlockStates = false; world.captureBlockStates = false;
world.captureTreeGeneration = false; world.captureTreeGeneration = false;
if (grownTree) { // Copy block data to delegate if (grownTree) { // Copy block data to delegate
for (BlockState blockstate : world.capturedBlockStates) { for (BlockState blockstate : world.capturedBlockStates.values()) {
BlockPosition position = ((CraftBlockState) blockstate).getPosition(); BlockPosition position = ((CraftBlockState) blockstate).getPosition();
net.minecraft.server.IBlockData oldBlock = world.getType(position); net.minecraft.server.IBlockData oldBlock = world.getType(position);
int flag = ((CraftBlockState) blockstate).getFlag(); int flag = ((CraftBlockState) blockstate).getFlag();

View file

@ -0,0 +1,60 @@
package org.bukkit.craftbukkit.block;
import java.util.Random;
import net.minecraft.server.BlockPosition;
import net.minecraft.server.EntityBee;
import net.minecraft.server.EntityTypes;
import net.minecraft.server.GeneratorAccess;
import net.minecraft.server.TileEntity;
import net.minecraft.server.TileEntityBeehive;
import net.minecraft.server.World;
import org.bukkit.Material;
import org.bukkit.block.Block;
public final class CapturedBlockState extends CraftBlockState {
private final boolean treeBlock;
public CapturedBlockState(Block block, int flag, boolean treeBlock) {
super(block, flag);
this.treeBlock = treeBlock;
}
@Override
public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
// SPIGOT-5537: Horrible hack to manually add bees given World.captureTreeGeneration does not support tiles
if (this.treeBlock && getType() == Material.BEE_NEST) {
GeneratorAccess generatoraccess = this.world.getHandle();
BlockPosition blockposition1 = this.getPosition();
Random random = generatoraccess.getRandom();
// Begin copied block from WorldGenFeatureTreeBeehive
TileEntity tileentity = generatoraccess.getTileEntity(blockposition1);
if (tileentity instanceof TileEntityBeehive) {
TileEntityBeehive tileentitybeehive = (TileEntityBeehive) tileentity;
int j = 2 + random.nextInt(2);
for (int k = 0; k < j; ++k) {
EntityBee entitybee = new EntityBee(EntityTypes.BEE, generatoraccess.getMinecraftWorld());
tileentitybeehive.a(entitybee, false, random.nextInt(599));
}
}
// End copied block
}
return result;
}
public static CapturedBlockState getBlockState(World world, BlockPosition pos, int flag) {
return new CapturedBlockState(world.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()), flag, false);
}
public static CapturedBlockState getTreeBlockState(World world, BlockPosition pos, int flag) {
return new CapturedBlockState(world.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()), flag, true);
}
}

View file

@ -22,7 +22,7 @@ import org.bukkit.metadata.MetadataValue;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
public class CraftBlockState implements BlockState { public class CraftBlockState implements BlockState {
private final CraftWorld world; protected final CraftWorld world;
private final CraftChunk chunk; private final CraftChunk chunk;
private final BlockPosition position; private final BlockPosition position;
protected IBlockData data; protected IBlockData data;