summaryrefslogtreecommitdiffstats
path: root/nms-patches/BlockSkull.patch
blob: 85871527c77456bb8f7b2683bcb22610d854a1df (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
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
--- /home/matt/mc-dev-private//net/minecraft/server/BlockSkull.java	2015-02-27 00:00:38.507555865 +0000
+++ src/main/java/net/minecraft/server/BlockSkull.java	2015-02-27 00:00:38.507555865 +0000
@@ -4,6 +4,11 @@
 import java.util.Iterator;
 import java.util.Random;
 
+// CraftBukkit start
+import org.bukkit.craftbukkit.util.BlockStateListPopulator;
+import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
+// CraftBukkit end
+
 public class BlockSkull extends BlockContainer {
 
     public static final BlockStateDirection FACING = BlockStateDirection.of("facing");
@@ -81,8 +86,26 @@
 
         return tileentity instanceof TileEntitySkull ? ((TileEntitySkull) tileentity).getSkullType() : super.getDropData(world, blockposition);
     }
+    
+    // CraftBukkit start - Special case dropping so we can get info from the tile entity
+    @Override
+    public void dropNaturally(World world, BlockPosition blockposition, IBlockData iblockdata, float f, int i) {
+        if (world.random.nextFloat() < f) {
+            ItemStack itemstack = new ItemStack(Items.SKULL, 1, this.getDropData(world, blockposition));
+            TileEntitySkull tileentityskull = (TileEntitySkull) world.getTileEntity(blockposition);
+
+            if (tileentityskull.getSkullType() == 3 && tileentityskull.getGameProfile() != null) {
+                itemstack.setTag(new NBTTagCompound());
+                NBTTagCompound nbttagcompound = new NBTTagCompound();
+
+                GameProfileSerializer.serialize(nbttagcompound, tileentityskull.getGameProfile());
+                itemstack.getTag().set("SkullOwner", nbttagcompound);
+            }
 
-    public void dropNaturally(World world, BlockPosition blockposition, IBlockData iblockdata, float f, int i) {}
+            a(world, blockposition, itemstack);
+        }
+    }
+    // CraftBukkit end
 
     public void a(World world, BlockPosition blockposition, IBlockData iblockdata, EntityHuman entityhuman) {
         if (entityhuman.abilities.canInstantlyBuild) {
@@ -95,7 +118,10 @@
 
     public void remove(World world, BlockPosition blockposition, IBlockData iblockdata) {
         if (!world.isClientSide) {
-            if (!((Boolean) iblockdata.get(BlockSkull.NODROP)).booleanValue()) {
+            // CraftBukkit start - Drop item in code above, not here
+            // if (!((Boolean) iblockdata.get(BlockSkull.NODROP)).booleanValue()) {
+            if (false) {
+                // CraftBukkit end
                 TileEntity tileentity = world.getTileEntity(blockposition);
 
                 if (tileentity instanceof TileEntitySkull) {
@@ -127,24 +153,36 @@
     }
 
     public void a(World world, BlockPosition blockposition, TileEntitySkull tileentityskull) {
+        if (world.captureBlockStates) return; // CraftBukkit
         if (tileentityskull.getSkullType() == 1 && blockposition.getY() >= 2 && world.getDifficulty() != EnumDifficulty.PEACEFUL && !world.isClientSide) {
             ShapeDetector shapedetector = this.n();
             ShapeDetector.ShapeDetectorCollection shapedetector_shapedetectorcollection = shapedetector.a(world, blockposition);
 
             if (shapedetector_shapedetectorcollection != null) {
+                // CraftBukkit start - Use BlockStateListPopulator
+                BlockStateListPopulator blockList = new BlockStateListPopulator(world.getWorld());
                 int i;
 
                 for (i = 0; i < 3; ++i) {
                     ShapeDetectorBlock shapedetectorblock = shapedetector_shapedetectorcollection.a(i, 0, 0);
 
-                    world.setTypeAndData(shapedetectorblock.d(), shapedetectorblock.a().set(BlockSkull.NODROP, Boolean.valueOf(true)), 2);
+                    // CraftBukkit start
+                    // world.setTypeAndData(shapedetectorblock.d(), shapedetectorblock.a().set(BlockSkull.NODROP, Boolean.valueOf(true)), 2);
+                    BlockPosition pos = shapedetectorblock.d();
+                    IBlockData data = shapedetectorblock.a().set(BlockSkull.NODROP, Boolean.valueOf(true));
+                    blockList.setTypeAndData(pos.getX(), pos.getY(), pos.getZ(), data.getBlock(), data.getBlock().toLegacyData(data), 2);
+                    // CraftBukkit end
                 }
 
                 for (i = 0; i < shapedetector.c(); ++i) {
                     for (int j = 0; j < shapedetector.b(); ++j) {
                         ShapeDetectorBlock shapedetectorblock1 = shapedetector_shapedetectorcollection.a(i, j, 0);
 
-                        world.setTypeAndData(shapedetectorblock1.d(), Blocks.AIR.getBlockData(), 2);
+                        // CraftBukkit start
+                        // world.setTypeAndData(shapedetectorblock1.d(), Blocks.AIR.getBlockData(), 2);
+                        BlockPosition pos = shapedetectorblock1.d();
+                        blockList.setTypeAndData(pos.getX(), pos.getY(), pos.getZ(), Blocks.AIR, 0, 2);
+                        // CraftBukkit end
                     }
                 }
 
@@ -157,14 +195,16 @@
                 entitywither.n();
                 Iterator iterator = world.a(EntityHuman.class, entitywither.getBoundingBox().grow(50.0D, 50.0D, 50.0D)).iterator();
 
+                // CraftBukkit start
+                if (world.addEntity(entitywither, SpawnReason.BUILD_WITHER)) {
+                    blockList.updateList();
+                    
                 while (iterator.hasNext()) {
                     EntityHuman entityhuman = (EntityHuman) iterator.next();
 
                     entityhuman.b((Statistic) AchievementList.I);
                 }
 
-                world.addEntity(entitywither);
-
                 int k;
 
                 for (k = 0; k < 120; ++k) {
@@ -178,6 +218,7 @@
                         world.update(shapedetectorblock2.d(), Blocks.AIR);
                     }
                 }
+                } // CraftBukkit end
 
             }
         }