2021-06-11 07:00:00 +02:00
--- a/net/minecraft/world/level/block/CaveVines.java
+++ b/net/minecraft/world/level/block/CaveVines.java
2023-03-14 17:30:00 +01:00
@@ -18,6 +18,14 @@
import net.minecraft.world.level.gameevent.GameEvent;
2021-06-11 07:00:00 +02:00
import net.minecraft.world.phys.shapes.VoxelShape;
+// CraftBukkit start
+import java.util.Collections;
+import net.minecraft.world.entity.Entity;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.player.PlayerHarvestBlockEvent;
+// CraftBukkit end
+
public interface CaveVines {
2021-11-21 23:00:00 +01:00
VoxelShape SHAPE = Block.box(1.0D, 0.0D, 1.0D, 15.0D, 16.0D, 15.0D);
2023-03-14 17:30:00 +01:00
@@ -25,7 +33,24 @@
2021-06-11 07:00:00 +02:00
2023-03-14 17:30:00 +01:00
static EnumInteractionResult use(@Nullable Entity entity, IBlockData iblockdata, World world, BlockPosition blockposition) {
2021-11-21 23:00:00 +01:00
if ((Boolean) iblockdata.getValue(CaveVines.BERRIES)) {
- Block.popResource(world, blockposition, new ItemStack(Items.GLOW_BERRIES, 1));
2021-06-11 07:00:00 +02:00
+ // CraftBukkit start
2021-11-21 23:00:00 +01:00
+ if (org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, blockposition, (IBlockData) iblockdata.setValue(CaveVines.BERRIES, false)).isCancelled()) {
2021-07-19 10:54:13 +02:00
+ return EnumInteractionResult.SUCCESS;
+ }
+
2021-06-11 07:00:00 +02:00
+ if (entity instanceof EntityHuman) {
2022-10-02 00:07:14 +02:00
+ PlayerHarvestBlockEvent event = CraftEventFactory.callPlayerHarvestBlockEvent(world, blockposition, (EntityHuman) entity, net.minecraft.world.EnumHand.MAIN_HAND, Collections.singletonList(new ItemStack(Items.GLOW_BERRIES, 1)));
2021-06-11 07:00:00 +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
+ Block.popResource(world, blockposition, CraftItemStack.asNMSCopy(itemStack));
2021-06-11 07:00:00 +02:00
+ }
+ } else {
2021-11-21 23:00:00 +01:00
+ Block.popResource(world, blockposition, new ItemStack(Items.GLOW_BERRIES, 1));
2021-06-11 07:00:00 +02:00
+ }
+ // CraftBukkit end
+
2021-11-21 23:00:00 +01:00
float f = MathHelper.randomBetween(world.random, 0.8F, 1.2F);
2021-06-11 07:00:00 +02:00
world.playSound((EntityHuman) null, blockposition, SoundEffects.CAVE_VINES_PICK_BERRIES, SoundCategory.BLOCKS, 1.0F, f);