1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
--- a/net/minecraft/world/level/block/CaveVines.java
+++ b/net/minecraft/world/level/block/CaveVines.java
@@ -12,40 +12,64 @@
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
-import net.minecraft.world.level.block.state.BlockState;
+import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.phys.shapes.VoxelShape;
+// CraftBukkit start
+import java.util.Collections;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.player.PlayerHarvestBlockEvent;
+// CraftBukkit end
+
public interface CaveVines {
VoxelShape SHAPE = Block.box(1.0D, 0.0D, 1.0D, 15.0D, 16.0D, 15.0D);
BooleanProperty BERRIES = BlockStateProperties.BERRIES;
- static InteractionResult use(@Nullable Entity entity, BlockState blockstate, Level level, BlockPos blockpos) {
- if ((Boolean) blockstate.getValue(CaveVines.BERRIES)) {
- Block.popResource(level, blockpos, new ItemStack(Items.GLOW_BERRIES, 1));
+ static InteractionResult use(@Nullable Entity entity, IBlockData state, Level level, BlockPos pos) {
+ if ((Boolean) state.getValue(CaveVines.BERRIES)) {
+ // CraftBukkit start
+ if (!org.bukkit.craftbukkit.event.CraftEventFactory.callEntityChangeBlockEvent(entity, pos, (IBlockData) state.setValue(CaveVines.BERRIES, false))) {
+ return InteractionResult.SUCCESS;
+ }
+
+ if (entity instanceof Player) {
+ PlayerHarvestBlockEvent event = CraftEventFactory.callPlayerHarvestBlockEvent(level, pos, (Player) entity, net.minecraft.world.EnumHand.MAIN_HAND, Collections.singletonList(new ItemStack(Items.GLOW_BERRIES, 1)));
+ if (event.isCancelled()) {
+ return InteractionResult.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()) {
+ Block.popResource(level, pos, CraftItemStack.asNMSCopy(itemStack));
+ }
+ } else {
+ Block.popResource(level, pos, new ItemStack(Items.GLOW_BERRIES, 1));
+ }
+ // CraftBukkit end
+
float f = Mth.randomBetween(level.random, 0.8F, 1.2F);
- level.playSound((Player) null, blockpos, SoundEvents.CAVE_VINES_PICK_BERRIES, SoundSource.BLOCKS, 1.0F, f);
- BlockState blockstate1 = (BlockState) blockstate.setValue(CaveVines.BERRIES, false);
+ level.playSound((Player) null, pos, SoundEvents.CAVE_VINES_PICK_BERRIES, SoundSource.BLOCKS, 1.0F, f);
+ IBlockData iblockdata1 = (IBlockData) state.setValue(CaveVines.BERRIES, false);
- level.setBlock(blockpos, blockstate1, 2);
- level.gameEvent(GameEvent.BLOCK_CHANGE, blockpos, GameEvent.Context.of(entity, blockstate1));
+ level.setBlock(pos, iblockdata1, 2);
+ level.gameEvent(GameEvent.BLOCK_CHANGE, pos, GameEvent.Context.of(entity, iblockdata1));
return InteractionResult.sidedSuccess(level.isClientSide);
} else {
return InteractionResult.PASS;
}
}
- static boolean hasGlowBerries(BlockState blockstate) {
- return blockstate.hasProperty(CaveVines.BERRIES) && (Boolean) blockstate.getValue(CaveVines.BERRIES);
+ static boolean hasGlowBerries(IBlockData state) {
+ return state.hasProperty(CaveVines.BERRIES) && (Boolean) state.getValue(CaveVines.BERRIES);
}
- static ToIntFunction<BlockState> emission(int i) {
- return (blockstate) -> {
- return (Boolean) blockstate.getValue(BlockStateProperties.BERRIES) ? i : 0;
+ static ToIntFunction<IBlockData> emission(int berries) {
+ return (iblockdata) -> {
+ return (Boolean) iblockdata.getValue(BlockStateProperties.BERRIES) ? berries : 0;
};
}
}
|