Advertisement
Guest User

Untitled

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