Skip to content

Commit

Permalink
SPIGOT-7572: Bee nests generated without bees
Browse files Browse the repository at this point in the history
  • Loading branch information
DerFrZocker authored and md-5 committed Jan 27, 2024
1 parent f48f417 commit 3337018
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 15 deletions.
20 changes: 11 additions & 9 deletions nms-patches/net/minecraft/world/item/ItemStack.patch
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
--- a/net/minecraft/world/item/ItemStack.java
+++ b/net/minecraft/world/item/ItemStack.java
@@ -81,6 +81,43 @@
@@ -81,6 +81,44 @@
import net.minecraft.world.level.block.state.pattern.ShapeDetectorBlock;
import org.slf4j.Logger;

Expand Down Expand Up @@ -30,6 +30,7 @@
+import org.bukkit.Location;
+import org.bukkit.TreeType;
+import org.bukkit.block.BlockState;
+import org.bukkit.craftbukkit.block.CapturedBlockState;
+import org.bukkit.craftbukkit.block.CraftBlock;
+import org.bukkit.craftbukkit.block.CraftBlockState;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
Expand All @@ -44,7 +45,7 @@
public final class ItemStack {

public static final Codec<ItemStack> CODEC = RecordCodecBuilder.create((instance) -> {
@@ -175,7 +212,18 @@
@@ -175,7 +213,18 @@
this.item = null;
}

Expand All @@ -64,7 +65,7 @@
this.item = (Item) BuiltInRegistries.ITEM.get(new MinecraftKey(nbttagcompound.getString("id")));
this.count = nbttagcompound.getByte("Count");
if (nbttagcompound.contains("tag", 10)) {
@@ -189,6 +237,11 @@
@@ -189,6 +238,11 @@

}

Expand All @@ -76,7 +77,7 @@
public static ItemStack of(NBTTagCompound nbttagcompound) {
try {
return new ItemStack(nbttagcompound);
@@ -266,11 +319,190 @@
@@ -266,11 +320,191 @@
return EnumInteractionResult.PASS;
} else {
Item item = this.getItem();
Expand Down Expand Up @@ -128,7 +129,8 @@
+ this.setCount(newCount);
+ }
+ for (CraftBlockState blockstate : blocks) {
+ world.setBlock(blockstate.getPosition(),blockstate.getHandle(), blockstate.getFlag()); // SPIGOT-7248 - manual update to avoid physics where appropriate
+ // SPIGOT-7572 - Move fix for SPIGOT-7248 to CapturedBlockState, to allow bees in bee nest
+ CapturedBlockState.setBlockState(blockstate);
+ }
+ entityhuman.awardStat(StatisticList.ITEM_USED.get(item)); // SPIGOT-7236 - award stat
+ }
Expand Down Expand Up @@ -269,7 +271,7 @@

return enuminteractionresult;
}
@@ -351,6 +583,21 @@
@@ -351,6 +585,21 @@
}

i -= k;
Expand All @@ -291,7 +293,7 @@
if (i <= 0) {
return false;
}
@@ -372,6 +619,11 @@
@@ -372,6 +621,11 @@
if (this.hurt(i, t0.getRandom(), t0 instanceof EntityPlayer ? (EntityPlayer) t0 : null)) {
consumer.accept(t0);
Item item = this.getItem();
Expand All @@ -303,7 +305,7 @@

this.shrink(1);
if (t0 instanceof EntityHuman) {
@@ -524,6 +776,17 @@
@@ -524,6 +778,17 @@
return this.tag;
}

Expand All @@ -321,7 +323,7 @@
public NBTTagCompound getOrCreateTag() {
if (this.tag == null) {
this.setTag(new NBTTagCompound());
@@ -948,6 +1211,13 @@
@@ -948,6 +1213,13 @@
nbttaglist.add(nbttagcompound);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
--- a/net/minecraft/world/level/block/BlockSapling.java
+++ b/net/minecraft/world/level/block/BlockSapling.java
@@ -17,6 +17,14 @@
@@ -17,6 +17,15 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;

+// CraftBukkit start
+import org.bukkit.Location;
+import org.bukkit.TreeType;
+import org.bukkit.block.BlockState;
+import org.bukkit.craftbukkit.block.CapturedBlockState;
+import org.bukkit.craftbukkit.util.CraftLocation;
+import org.bukkit.event.world.StructureGrowEvent;
+// CraftBukkit end
+
public class BlockSapling extends BlockPlant implements IBlockFragilePlantElement {

public static final MapCodec<BlockSapling> CODEC = RecordCodecBuilder.mapCodec((instance) -> {
@@ -28,6 +36,7 @@
@@ -28,6 +37,7 @@
protected static final float AABB_OFFSET = 6.0F;
protected static final VoxelShape SHAPE = Block.box(2.0D, 0.0D, 2.0D, 14.0D, 12.0D, 14.0D);
protected final WorldGenTreeProvider treeGrower;
+ public static TreeType treeType; // CraftBukkit

@Override
public MapCodec<? extends BlockSapling> codec() {
@@ -57,7 +66,32 @@
@@ -57,7 +67,32 @@
if ((Integer) iblockdata.getValue(BlockSapling.STAGE) == 0) {
worldserver.setBlock(blockposition, (IBlockData) iblockdata.cycle(BlockSapling.STAGE), 4);
} else {
Expand All @@ -48,7 +49,7 @@
+ }
+ if (event == null || !event.isCancelled()) {
+ for (BlockState blockstate : blocks) {
+ blockstate.update(true);
+ CapturedBlockState.setBlockState(blockstate);
+ }
+ }
+ }
Expand Down
28 changes: 26 additions & 2 deletions src/main/java/org/bukkit/craftbukkit/block/CapturedBlockState.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
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 {

Expand All @@ -31,6 +33,22 @@ protected CapturedBlockState(CapturedBlockState state) {
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();
Expand All @@ -52,8 +70,6 @@ public boolean update(boolean force, boolean applyPhysics) {
}
// End copied block
}

return result;
}

@Override
Expand All @@ -68,4 +84,12 @@ public static CapturedBlockState getBlockState(World world, BlockPosition pos, i
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);
}
}
}

0 comments on commit 3337018

Please sign in to comment.