summaryrefslogtreecommitdiffstats
path: root/nms-patches/EntitySheep.patch
blob: f79667143b16686367126bf2e2f81f8a9a2bda67 (plain)
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
--- a/net/minecraft/server/EntitySheep.java
+++ b/net/minecraft/server/EntitySheep.java
@@ -10,6 +10,12 @@
 import java.util.stream.Collectors;
 import javax.annotation.Nullable;
 
+// CraftBukkit start
+import org.bukkit.event.entity.SheepRegrowWoolEvent;
+import org.bukkit.event.player.PlayerShearEntityEvent;
+import org.bukkit.inventory.InventoryView;
+// CraftBukkit end
+
 public class EntitySheep extends EntityAnimal {
 
     private static final DataWatcherObject<Byte> bC = DataWatcher.a(EntitySheep.class, DataWatcherRegistry.a);
@@ -17,8 +23,15 @@
         public boolean canUse(EntityHuman entityhuman) {
             return false;
         }
+
+        // CraftBukkit start
+        @Override
+        public InventoryView getBukkitView() {
+            return null; // TODO: O.O
+        }
+        // CraftBukkit end
     }, 2, 1);
-    private static final Map<EnumColor, IMaterial> bE = (Map) SystemUtils.a((Object) Maps.newEnumMap(EnumColor.class), (enummap) -> {
+    private static final Map<EnumColor, IMaterial> bE = (Map) SystemUtils.a(Maps.newEnumMap(EnumColor.class), (enummap) -> { // CraftBukkit - decompile error
         enummap.put(EnumColor.WHITE, Blocks.WHITE_WOOL);
         enummap.put(EnumColor.ORANGE, Blocks.ORANGE_WOOL);
         enummap.put(EnumColor.MAGENTA, Blocks.MAGENTA_WOOL);
@@ -158,11 +171,22 @@
 
         if (itemstack.getItem() == Items.SHEARS && !this.isSheared() && !this.isBaby()) {
             if (!this.world.isClientSide) {
+                // CraftBukkit start
+                PlayerShearEntityEvent event = new PlayerShearEntityEvent((org.bukkit.entity.Player) entityhuman.getBukkitEntity(), this.getBukkitEntity());
+                this.world.getServer().getPluginManager().callEvent(event);
+
+                if (event.isCancelled()) {
+                    return false;
+                }
+                // CraftBukkit end
+
                 this.setSheared(true);
                 int i = 1 + this.random.nextInt(3);
 
                 for (int j = 0; j < i; ++j) {
+                    this.forceDrops = true; // CraftBukkit
                     EntityItem entityitem = this.a((IMaterial) EntitySheep.bE.get(this.getColor()), 1);
+                    this.forceDrops = false; // CraftBukkit
 
                     if (entityitem != null) {
                         entityitem.motY += (double) (this.random.nextFloat() * 0.05F);
@@ -247,6 +271,12 @@
     }
 
     public void x() {
+        // CraftBukkit start
+        SheepRegrowWoolEvent event = new SheepRegrowWoolEvent((org.bukkit.entity.Sheep) this.getBukkitEntity());
+        this.world.getServer().getPluginManager().callEvent(event);
+
+        if (event.isCancelled()) return;
+        // CraftBukkit end
         this.setSheared(false);
         if (this.isBaby()) {
             this.setAge(60);
@@ -267,6 +297,7 @@
 
         this.container.setItem(0, new ItemStack(ItemDye.a(enumcolor)));
         this.container.setItem(1, new ItemStack(ItemDye.a(enumcolor1)));
+        this.container.resultInventory = new InventoryCraftResult(); // CraftBukkit - add result slot for event
         ItemStack itemstack = entityanimal.world.E().craft(this.container, ((EntitySheep) entityanimal).world);
         Item item = itemstack.getItem();
         EnumColor enumcolor2;