SPIGOT-7572: Bee nests generated without bees

By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
CraftBukkit/Spigot
2024-01-27 14:59:22 +11:00
parent 7b15562116
commit aca2bf97bb
3 changed files with 42 additions and 15 deletions

View File

@@ -10,6 +10,8 @@ import net.minecraft.world.level.block.entity.TileEntity;
import net.minecraft.world.level.block.entity.TileEntityBeehive;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.craftbukkit.util.CraftLocation;
public final class CapturedBlockState extends CraftBlockState {
@@ -31,6 +33,22 @@ public final class CapturedBlockState extends CraftBlockState {
public boolean update(boolean force, boolean applyPhysics) {
boolean result = super.update(force, applyPhysics);
// Probably no longer needed with the extra #updatedTree method,
// but leave if here for now in case a plugin for whatever reason relies on this.
addBees();
return result;
}
private void updatedTree() {
// SPIGOT-7248 - Manual update to avoid physics where appropriate
// SPIGOT-7572 - Move SPIGOT-7248 fix from nms ItemStack to here, to allow bee generation in nests
world.getHandle().setBlock(CraftLocation.toBlockPosition(getLocation()), getHandle(), getFlag());
addBees();
}
private void addBees() {
// SPIGOT-5537: Horrible hack to manually add bees given World.captureTreeGeneration does not support tiles
if (this.treeBlock && getType() == Material.BEE_NEST) {
GeneratorAccessSeed generatoraccessseed = this.world.getHandle();
@@ -52,8 +70,6 @@ public final class CapturedBlockState extends CraftBlockState {
}
// End copied block
}
return result;
}
@Override
@@ -68,4 +84,12 @@ public final class CapturedBlockState extends CraftBlockState {
public static CapturedBlockState getTreeBlockState(World world, BlockPosition pos, int flag) {
return new CapturedBlockState(world.getWorld().getBlockAt(pos.getX(), pos.getY(), pos.getZ()), flag, true);
}
public static void setBlockState(BlockState blockState) {
if (blockState instanceof CapturedBlockState capturedBlockState) {
capturedBlockState.updatedTree();
} else {
blockState.update(true);
}
}
}