Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. package com.mightydanp.eot.core.entities.player;
  2.  
  3. import java.lang.ref.WeakReference;
  4.  
  5. import com.mightydanp.eot.inventory.InventoryEotInventory;
  6. import com.mightydanp.eot.lib.References;
  7.  
  8. import net.minecraft.entity.Entity;
  9. import net.minecraft.entity.player.EntityPlayer;
  10. import net.minecraft.inventory.IInventory;
  11. import net.minecraft.nbt.NBTTagCompound;
  12. import net.minecraft.world.World;
  13. import net.minecraftforge.common.IExtendedEntityProperties;
  14.  
  15. public class EotExtendedPlayer implements IExtendedEntityProperties
  16. {
  17. public final static String EXT_PROP_NAME = "EotExtendedPlayer";
  18.  
  19. public WeakReference<EntityPlayer> player;
  20.  
  21. public InventoryEotInventory inventoryEot;
  22.  
  23. @Override
  24. public void init (Entity entity, World world){
  25. this.player = new WeakReference<EntityPlayer>((EntityPlayer)entity);
  26. this.inventoryEot.init((EntityPlayer)entity);
  27. }
  28.  
  29. public EotExtendedPlayer(){}
  30.  
  31. public EotExtendedPlayer(EntityPlayer player) {
  32. this.player = new WeakReference<EntityPlayer>(player);
  33.  
  34. this.inventoryEot = new InventoryEotInventory();
  35. this.inventoryEot.init(player);
  36. }
  37.  
  38. /**
  39. * Used to register these extended properties for the player during EntityConstructing event
  40. */
  41. public static final void register(EntityPlayer player) {
  42. player.registerExtendedProperties(EotExtendedPlayer.EXT_PROP_NAME, new EotExtendedPlayer(player));
  43. }
  44.  
  45. /**
  46. * Returns ExtendedPlayer properties for player
  47. */
  48. public static final EotExtendedPlayer get(EntityPlayer player) {
  49. return (EotExtendedPlayer) player.getExtendedProperties(EXT_PROP_NAME);
  50. }
  51.  
  52. /**
  53. * Copies additional player data from the given ExtendedPlayer instance
  54. * Avoids NBT disk I/O overhead when cloning a player after respawn
  55. */
  56. public void copy(EotExtendedPlayer props) {
  57. inventoryEot.copy(props.inventoryEot);
  58. }
  59.  
  60. public void copyFrom (EotExtendedPlayer props, boolean copyCalc){
  61. inventoryEot.copy(props.inventoryEot);
  62. }
  63.  
  64. @Override
  65. public final void saveNBTData(NBTTagCompound compound) {
  66. NBTTagCompound properties = new NBTTagCompound();
  67. compound.setTag(EXT_PROP_NAME, properties);
  68. this.inventoryEot.writeToNBT(properties);
  69. }
  70.  
  71. @Override
  72. public final void loadNBTData(NBTTagCompound compound) {
  73. NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME);
  74. this.inventoryEot.readFromNBT(properties);
  75. }
  76.  
  77. public IInventory getEotInventory (EntityPlayer player){
  78. return this.inventoryEot;
  79. }
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement