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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
--- a/net/minecraft/world/entity/animal/Bucketable.java
+++ b/net/minecraft/world/entity/animal/Bucketable.java
@@ -3,9 +3,10 @@
import java.util.Optional;
import net.minecraft.advancements.CriteriaTriggers;
import net.minecraft.nbt.CompoundTag;
+import net.minecraft.network.protocol.game.ClientboundAddEntityPacket;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.sounds.SoundEvent;
-import net.minecraft.world.InteractionHand;
+import net.minecraft.world.EnumHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
@@ -14,6 +15,10 @@
import net.minecraft.world.item.ItemUtils;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
+import org.bukkit.craftbukkit.event.CraftEventFactory;
+import org.bukkit.craftbukkit.inventory.CraftItemStack;
+import org.bukkit.event.player.PlayerBucketEntityEvent;
+// CraftBukkit end
public interface Bucketable {
@@ -31,84 +36,96 @@
/** @deprecated */
@Deprecated
- static void saveDefaultDataToBucketTag(Mob mob, ItemStack itemstack) {
- CompoundTag compoundtag = itemstack.getOrCreateTag();
+ static void saveDefaultDataToBucketTag(Mob mob, ItemStack bucket) {
+ CompoundTag nbttagcompound = bucket.getOrCreateTag();
if (mob.hasCustomName()) {
- itemstack.setHoverName(mob.getCustomName());
+ bucket.setHoverName(mob.getCustomName());
}
if (mob.isNoAi()) {
- compoundtag.putBoolean("NoAI", mob.isNoAi());
+ nbttagcompound.putBoolean("NoAI", mob.isNoAi());
}
if (mob.isSilent()) {
- compoundtag.putBoolean("Silent", mob.isSilent());
+ nbttagcompound.putBoolean("Silent", mob.isSilent());
}
if (mob.isNoGravity()) {
- compoundtag.putBoolean("NoGravity", mob.isNoGravity());
+ nbttagcompound.putBoolean("NoGravity", mob.isNoGravity());
}
if (mob.hasGlowingTag()) {
- compoundtag.putBoolean("Glowing", mob.hasGlowingTag());
+ nbttagcompound.putBoolean("Glowing", mob.hasGlowingTag());
}
if (mob.isInvulnerable()) {
- compoundtag.putBoolean("Invulnerable", mob.isInvulnerable());
+ nbttagcompound.putBoolean("Invulnerable", mob.isInvulnerable());
}
- compoundtag.putFloat("Health", mob.getHealth());
+ nbttagcompound.putFloat("Health", mob.getHealth());
}
/** @deprecated */
@Deprecated
- static void loadDefaultDataFromBucketTag(Mob mob, CompoundTag compoundtag) {
- if (compoundtag.contains("NoAI")) {
- mob.setNoAi(compoundtag.getBoolean("NoAI"));
+ static void loadDefaultDataFromBucketTag(Mob mob, CompoundTag tag) {
+ if (tag.contains("NoAI")) {
+ mob.setNoAi(tag.getBoolean("NoAI"));
}
- if (compoundtag.contains("Silent")) {
- mob.setSilent(compoundtag.getBoolean("Silent"));
+ if (tag.contains("Silent")) {
+ mob.setSilent(tag.getBoolean("Silent"));
}
- if (compoundtag.contains("NoGravity")) {
- mob.setNoGravity(compoundtag.getBoolean("NoGravity"));
+ if (tag.contains("NoGravity")) {
+ mob.setNoGravity(tag.getBoolean("NoGravity"));
}
- if (compoundtag.contains("Glowing")) {
- mob.setGlowingTag(compoundtag.getBoolean("Glowing"));
+ if (tag.contains("Glowing")) {
+ mob.setGlowingTag(tag.getBoolean("Glowing"));
}
- if (compoundtag.contains("Invulnerable")) {
- mob.setInvulnerable(compoundtag.getBoolean("Invulnerable"));
+ if (tag.contains("Invulnerable")) {
+ mob.setInvulnerable(tag.getBoolean("Invulnerable"));
}
- if (compoundtag.contains("Health", 99)) {
- mob.setHealth(compoundtag.getFloat("Health"));
+ if (tag.contains("Health", 99)) {
+ mob.setHealth(tag.getFloat("Health"));
}
}
- static <T extends LivingEntity & Bucketable> Optional<InteractionResult> bucketMobPickup(Player player, InteractionHand interactionhand, T t0) {
- ItemStack itemstack = player.getItemInHand(interactionhand);
+ static <T extends LivingEntity & Bucketable> Optional<InteractionResult> bucketMobPickup(Player player, EnumHand hand, T entity) {
+ ItemStack itemstack = player.getItemInHand(hand);
- if (itemstack.getItem() == Items.WATER_BUCKET && t0.isAlive()) {
- t0.playSound(((Bucketable) t0).getPickupSound(), 1.0F, 1.0F);
- ItemStack itemstack1 = ((Bucketable) t0).getBucketItemStack();
+ if (itemstack.getItem() == Items.WATER_BUCKET && entity.isAlive()) {
+ // CraftBukkit start
+ // t0.playSound(((Bucketable) t0).getPickupSound(), 1.0F, 1.0F); // CraftBukkit - moved down
+ ItemStack itemstack1 = ((Bucketable) entity).getBucketItemStack();
- ((Bucketable) t0).saveToBucketTag(itemstack1);
+ ((Bucketable) entity).saveToBucketTag(itemstack1);
+
+ PlayerBucketEntityEvent playerBucketFishEvent = CraftEventFactory.callPlayerFishBucketEvent(entity, player, itemstack, itemstack1, hand);
+ itemstack1 = CraftItemStack.asNMSCopy(playerBucketFishEvent.getEntityBucket());
+ if (playerBucketFishEvent.isCancelled()) {
+ ((ServerPlayer) player).containerMenu.sendAllDataToRemote(); // We need to update inventory to resync client's bucket
+ ((ServerPlayer) player).connection.send(new ClientboundAddEntityPacket(entity)); // We need to play out these packets as the client assumes the fish is gone
+ entity.getEntityData().refresh((ServerPlayer) player); // Need to send data such as the display name to client
+ return Optional.of(InteractionResult.FAIL);
+ }
+ entity.playSound(((Bucketable) entity).getPickupSound(), 1.0F, 1.0F);
+ // CraftBukkit end
ItemStack itemstack2 = ItemUtils.createFilledResult(itemstack, player, itemstack1, false);
- player.setItemInHand(interactionhand, itemstack2);
- Level level = t0.level();
+ player.setItemInHand(hand, itemstack2);
+ Level world = entity.level();
- if (!level.isClientSide) {
+ if (!world.isClientSide) {
CriteriaTriggers.FILLED_BUCKET.trigger((ServerPlayer) player, itemstack1);
}
- t0.discard();
- return Optional.of(InteractionResult.sidedSuccess(level.isClientSide));
+ entity.discard();
+ return Optional.of(InteractionResult.sidedSuccess(world.isClientSide));
} else {
return Optional.empty();
}
|