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
|
--- a/net/minecraft/world/entity/animal/Cow.java
+++ b/net/minecraft/world/entity/animal/Cow.java
@@ -33,6 +33,12 @@
import net.minecraft.world.level.block.state.BlockState;
import org.joml.Vector3f;
+// CraftBukkit start
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.player.PlayerBucketFillEvent;
+// CraftBukkit end
+
public class Cow extends Animal {
public Cow(EntityType<? extends Cow> entityType, Level level) {
super(entityType, level);
@@ -80,12 +87,22 @@
}
@Override
- public InteractionResult mobInteract(Player player, InteractionHand hand) {
- ItemStack itemInHand = player.getItemInHand(hand);
- if (itemInHand.is(Items.BUCKET) && !this.isBaby()) {
+ public InteractionResult mobInteract(Player player, EnumHand hand) {
+ ItemStack itemstack = player.getItemInHand(hand);
+
+ if (itemstack.is(Items.BUCKET) && !this.isBaby()) {
+ // CraftBukkit start - Got milk?
+ PlayerBucketFillEvent event = CraftEventFactory.callPlayerBucketFillEvent((ServerLevel) player.level(), player, this.blockPosition(), this.blockPosition(), null, itemstack, Items.MILK_BUCKET, hand);
+
+ if (event.isCancelled()) {
+ return InteractionResult.PASS;
+ }
+ // CraftBukkit end
+
player.playSound(SoundEvents.COW_MILK, 1.0F, 1.0F);
- ItemStack itemStack = ItemUtils.createFilledResult(itemInHand, player, Items.MILK_BUCKET.getDefaultInstance());
- player.setItemInHand(hand, itemStack);
+ ItemStack itemstack1 = ItemUtils.createFilledResult(itemstack, player, CraftItemStack.asNMSCopy(event.getItemStack())); // CraftBukkit
+
+ player.setItemInHand(hand, itemstack1);
return InteractionResult.sidedSuccess(this.level().isClientSide);
} else {
return super.mobInteract(player, hand);
|