Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.77 KB | None | 0 0
  1. public EntityClone(World world, EntityPlayer player) {
  2. super(world);
  3. // this.c_inventoryContainer = new ContainerPlayer(this.c_inventory, !world.isRemote, this);
  4. this.c_openContainer = this.c_inventoryContainer;
  5.  
  6. this.p_profile = player.getGameProfile();
  7. this.p_profile = func_152109_d(this.p_profile);
  8. this.c_profile = this.p_profile;
  9.  
  10. this.setHealth(player.getHealth());
  11.  
  12. setPosition(player.posX, player.posY, player.posZ);
  13.  
  14. NBTTagCompound comp = new NBTTagCompound();
  15. player.writeToNBT(comp);
  16. m_playerNBT = comp;
  17.  
  18. NBTTagList invnbt = comp.getTagList("Inventory", Constants.NBT.TAG_COMPOUND);
  19. this.p_inventoryNBT = invnbt;
  20.  
  21. ItemStack item;
  22. this.c_equipmentStack[0] = player.getCurrentEquippedItem();
  23. for (int i = 1; i < 5; i++) {
  24. item = player.getEquipmentInSlot(i);
  25. this.c_equipmentStack[i] = player.getEquipmentInSlot(i);
  26. }
  27.  
  28. for (int j = 0; j < this.equipmentDropChances.length; ++j) {
  29. this.equipmentDropChances[j] = 0.0F;
  30. }
  31.  
  32. // this.c_inventory.copyInventory(player.inventory);
  33.  
  34. NBTTagList nbttaglist1 = comp.getTagList("Inventory", 10);
  35. this.c_inventory.readFromNBT(nbttaglist1);
  36.  
  37. NBTTagList comp2 = new NBTTagList();
  38. this.writeToNBT(comp2);
  39. c_inventoryNBT = comp2;
  40. if (comp.hasKey("Inventory", 9)) {
  41. nbttaglist1 = comp.getTagList("Inventory", 10);
  42. for (int i = 0; i < nbttaglist1.tagCount(); ++i) {
  43. NBTTagCompound nbttagcompound = nbttaglist1.getCompoundTagAt(i);
  44. int j = nbttagcompound.getByte("Slot") & 255;
  45. ItemStack itemstack = ItemStack.loadItemStackFromNBT(nbttagcompound);
  46.  
  47. if (itemstack != null) {
  48. if (j >= 0 && j < this.c_inventoryStack.length) {
  49. this.c_inventoryStack[j] = itemstack;
  50. }
  51.  
  52. if (j >= 100 && j < this.c_armourStack.length + 100) {
  53. this.c_armourStack[j - 100] = itemstack;
  54. }
  55. }
  56. }
  57. }
  58. }
  59.  
  60. @Override
  61. public void readEntityFromNBT(NBTTagCompound nbt) {
  62. super.readEntityFromNBT(nbt);
  63.  
  64. NBTTagList nbttaglist = nbt.getTagList("Inventory", 10);
  65. this.c_inventory.readFromNBT(nbttaglist);
  66. if (nbt.hasKey("Inventory", 9)) {
  67. nbttaglist = nbt.getTagList("Inventory", 10);
  68. for (int i = 0; i < nbttaglist.tagCount(); ++i) {
  69. NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
  70. int j = nbttagcompound.getByte("Slot") & 255;
  71. ItemStack itemstack = ItemStack.loadItemStackFromNBT(nbttagcompound);
  72.  
  73. if (itemstack != null) {
  74. if (j >= 0 && j < this.c_inventoryStack.length) {
  75. this.c_inventoryStack[j] = itemstack;
  76. }
  77.  
  78. if (j >= 100 && j < this.c_armourStack.length + 100) {
  79. this.c_armourStack[j - 100] = itemstack;
  80. }
  81. }
  82. }
  83. }
  84.  
  85. if (nbt.hasKey("Owner", 10)) {
  86. this.c_profile = NBTUtil.func_152459_a(nbt.getCompoundTag("Owner"));
  87. }
  88. this.func_152109_d(this.c_profile);
  89.  
  90. NBTTagList nbttaglist1;
  91. int i;
  92.  
  93. if (nbt.hasKey("Equipment", 9)) {
  94. nbttaglist1 = nbt.getTagList("Equipment", 10);
  95. for (i = 0; i < this.c_equipmentStack.length; ++i) {
  96. this.c_equipmentStack[i] = ItemStack.loadItemStackFromNBT(nbttaglist1.getCompoundTagAt(i));
  97. }
  98. }
  99.  
  100. if (nbt.hasKey("DropChances", 9)) {
  101. nbttaglist = nbt.getTagList("DropChances", 5);
  102.  
  103. for (i = 0; i < nbttaglist.tagCount(); ++i) {
  104. this.equipmentDropChances[i] = nbttaglist.func_150308_e(i);
  105. }
  106. }
  107.  
  108. }
  109.  
  110. @Override
  111. public void writeEntityToNBT(NBTTagCompound nbt) {
  112.  
  113. super.writeEntityToNBT(nbt);
  114. nbt.setTag("Inventory", this.c_inventory.writeToNBT(new NBTTagList()));
  115.  
  116. NBTTagList nbttaglist = new NBTTagList();
  117. NBTTagCompound nbttagcompound1;
  118. for (int i = 0; i < this.c_equipmentStack.length; ++i) {
  119. nbttagcompound1 = new NBTTagCompound();
  120. if (this.c_equipmentStack[i] != null) {
  121. this.c_equipmentStack[i].writeToNBT(nbttagcompound1);
  122. }
  123. nbttaglist.appendTag(nbttagcompound1);
  124. }
  125. nbt.setTag("Equipment", nbttaglist);
  126.  
  127. NBTTagList nbttaglist1 = new NBTTagList();
  128. for (int j = 0; j < this.equipmentDropChances.length; ++j) {
  129. nbttaglist1.appendTag(new NBTTagFloat(this.equipmentDropChances[j]));
  130. }
  131. nbt.setTag("DropChances", nbttaglist1);
  132.  
  133. if (this.p_profile != null) {
  134. NBTTagCompound nbt2 = new NBTTagCompound();
  135. NBTUtil.func_152460_a(nbt2, this.p_profile);
  136. nbt.setTag("Owner", nbt2);
  137. } else {
  138. NBTTagCompound nbt2 = new NBTTagCompound();
  139. NBTUtil.func_152460_a(nbt2, this.c_profile);
  140. nbt.setTag("Owner", nbt2);
  141. }
  142.  
  143. }
  144.  
  145. public NBTTagList writeToNBT(NBTTagList p_70442_1_) {
  146. int i;
  147. NBTTagCompound nbttagcompound;
  148.  
  149. for (i = 0; i < this.c_inventoryStack.length; ++i) {
  150. if (this.c_inventoryStack[i] != null) {
  151. nbttagcompound = new NBTTagCompound();
  152. nbttagcompound.setByte("Slot", (byte) i);
  153. this.c_inventoryStack[i].writeToNBT(nbttagcompound);
  154. p_70442_1_.appendTag(nbttagcompound);
  155. }
  156. }
  157.  
  158. for (i = 0; i < this.c_armourStack.length; ++i) {
  159. if (this.c_armourStack[i] != null) {
  160. nbttagcompound = new NBTTagCompound();
  161. nbttagcompound.setByte("Slot", (byte) (i + 100));
  162. this.c_armourStack[i].writeToNBT(nbttagcompound);
  163. p_70442_1_.appendTag(nbttagcompound);
  164. }
  165. }
  166. return p_70442_1_;
  167. }
  168.  
  169.  
  170. @Override
  171. public void readSpawnData(ByteBuf additionalData) {
  172.  
  173. NBTTagCompound compound;
  174. compound = ByteBufUtils.readTag(additionalData);
  175. this.c_profile = NBTUtil.func_152459_a(compound.getCompoundTag("Owner"));
  176. this.func_152109_d(this.c_profile);
  177.  
  178. this.c_profile = NBTUtil.func_152459_a(compound.getCompoundTag("Inventory"));
  179. }
  180.  
  181. @Override
  182. public void writeSpawnData(ByteBuf buffer) {
  183.  
  184. NBTTagCompound compound = new NBTTagCompound();
  185. NBTTagCompound cmp = new NBTTagCompound();
  186. NBTUtil.func_152460_a(cmp, this.c_profile);
  187. compound.setTag("Owner", cmp);
  188. compound.setTag("Inventory", cmp);
  189. ByteBufUtils.writeTag(buffer, compound);
  190.  
  191. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement