2021-03-15 23:00:00 +01:00
--- a/net/minecraft/world/level/block/BlockSweetBerryBush.java
+++ b/net/minecraft/world/level/block/BlockSweetBerryBush.java
2024-04-23 17:15:00 +02:00
@@ -30,6 +30,13 @@
2021-03-15 23:00:00 +01:00
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.phys.shapes.VoxelShapeCollision;
2021-03-08 22:47:33 +01:00
2019-04-23 04:00:00 +02:00
+// CraftBukkit start
2020-07-03 07:07:15 +02:00
+import java.util.Collections;
2019-04-23 04:00:00 +02:00
+import org.bukkit.craftbukkit.event.CraftEventFactory;
2020-07-03 07:07:15 +02:00
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.player.PlayerHarvestBlockEvent;
2019-04-23 04:00:00 +02:00
+// CraftBukkit end
2021-03-08 22:47:33 +01:00
+
2019-04-23 04:00:00 +02:00
public class BlockSweetBerryBush extends BlockPlant implements IBlockFragilePlantElement {
2023-12-05 17:40:00 +01:00
public static final MapCodec<BlockSweetBerryBush> CODEC = simpleCodec(BlockSweetBerryBush::new);
2024-04-23 17:15:00 +02:00
@@ -71,7 +78,7 @@
2022-06-07 18:00:00 +02:00
if (i < 3 && randomsource.nextInt(5) == 0 && worldserver.getRawBrightness(blockposition.above(), 0) >= 9) {
IBlockData iblockdata1 = (IBlockData) iblockdata.setValue(BlockSweetBerryBush.AGE, i + 1);
2019-04-23 04:00:00 +02:00
2022-06-07 18:00:00 +02:00
- worldserver.setBlock(blockposition, iblockdata1, 2);
+ if (!CraftEventFactory.handleBlockGrowEvent(worldserver, blockposition, iblockdata1, 2)) return; // CraftBukkit
2024-04-23 17:15:00 +02:00
worldserver.gameEvent((Holder) GameEvent.BLOCK_CHANGE, blockposition, GameEvent.a.of(iblockdata1));
2019-04-23 04:00:00 +02:00
}
2024-04-23 17:15:00 +02:00
@@ -86,7 +93,7 @@
2021-11-21 23:00:00 +01:00
double d1 = Math.abs(entity.getZ() - entity.zOld);
2019-04-23 04:00:00 +02:00
if (d0 >= 0.003000000026077032D || d1 >= 0.003000000026077032D) {
2024-02-10 23:54:25 +01:00
- entity.hurt(world.damageSources().sweetBerryBush(), 1.0F);
+ entity.hurt(world.damageSources().sweetBerryBush().directBlock(world, blockposition), 1.0F); // CraftBukkit
2019-04-23 04:00:00 +02:00
}
}
2024-04-23 17:15:00 +02:00
@@ -109,7 +116,15 @@
if (i > 1) {
2020-07-03 07:07:15 +02:00
int j = 1 + world.random.nextInt(2);
2021-11-21 23:00:00 +01:00
- popResource(world, blockposition, new ItemStack(Items.SWEET_BERRIES, j + (flag ? 1 : 0)));
2024-04-23 17:15:00 +02:00
+ // CraftBukkit start - useWithoutItem is always MAIN_HAND
+ PlayerHarvestBlockEvent event = CraftEventFactory.callPlayerHarvestBlockEvent(world, blockposition, entityhuman, EnumHand.MAIN_HAND, Collections.singletonList(new ItemStack(Items.SWEET_BERRIES, j + (flag ? 1 : 0))));
2020-07-03 07:07:15 +02:00
+ if (event.isCancelled()) {
+ return EnumInteractionResult.SUCCESS; // We need to return a success either way, because making it PASS or FAIL will result in a bug where cancelling while harvesting w/ block in hand places block
+ }
+ for (org.bukkit.inventory.ItemStack itemStack : event.getItemsHarvested()) {
2021-11-21 23:00:00 +01:00
+ popResource(world, blockposition, CraftItemStack.asNMSCopy(itemStack));
2020-07-03 07:07:15 +02:00
+ }
+ // CraftBukkit end
2021-06-11 07:00:00 +02:00
world.playSound((EntityHuman) null, blockposition, SoundEffects.SWEET_BERRY_BUSH_PICK_BERRIES, SoundCategory.BLOCKS, 1.0F, 0.8F + world.random.nextFloat() * 0.4F);
2022-06-07 18:00:00 +02:00
IBlockData iblockdata1 = (IBlockData) iblockdata.setValue(BlockSweetBerryBush.AGE, 1);