Advertisement
Guest User

Extended_Jamiga

a guest
Apr 12th, 2014
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. package aJamigaPack1;
  2.  
  3. import net.minecraft.entity.Entity;
  4. import net.minecraft.entity.player.EntityPlayer;
  5. import net.minecraft.nbt.NBTTagCompound;
  6. import net.minecraft.world.World;
  7. import net.minecraftforge.common.IExtendedEntityProperties;
  8.  
  9. public class ExtendedPlayer implements IExtendedEntityProperties
  10. {
  11. /*
  12. Here I create a constant EXT_PROP_NAME for this class of properties. You need a unique name for every instance of IExtendedEntityProperties you make, and doing it at the top of each class as a constant makes
  13. it very easy to organize and avoid typos. It's easiest to keep the same constant name in every class, as it will be distinguished by the class name: ExtendedPlayer.EXT_PROP_NAME vs. ExtendedEntity.EXT_PROP_NAME
  14.  
  15. Note that a single entity can have multiple extended properties, so each property should have a unique name. Try to come up with something more unique than the tutorial example.
  16. */
  17. public final static String EXT_PROP_NAME = "ExtendedPlayer";
  18. public final InventoryCustomPlayer inventory = new InventoryCustomPlayer();
  19. // I always include the entity to which the properties belong for easy access
  20. // It's final because we won't be changing which player it is
  21. private final EntityPlayer player;
  22.  
  23. // Declare other variables you want to add here
  24.  
  25. // We're adding mana to the player, so we'll need current and max mana
  26.  
  27. /*
  28. The default constructor takes no arguments, but I put in the Entity so I can initialize the above variable 'player'
  29.  
  30. Also, it's best to initialize any other variables you may have added, just like in any constructor.
  31. */
  32. public ExtendedPlayer(EntityPlayer player)
  33. {
  34. this.player = player;
  35. // Start with max mana. Every player starts with the same amount.
  36. }
  37.  
  38. /**
  39. * Used to register these extended properties for the player during EntityConstructing event
  40. * This method is for convenience only; it will make your code look nicer
  41. */
  42. public static final void register(EntityPlayer player)
  43. {
  44. player.registerExtendedProperties(ExtendedPlayer.EXT_PROP_NAME, new ExtendedPlayer(player));
  45. }
  46.  
  47. /**
  48. * Returns ExtendedPlayer properties for player
  49. * This method is for convenience only; it will make your code look nicer
  50. */
  51. public static final ExtendedPlayer get(EntityPlayer player)
  52. {
  53. return (ExtendedPlayer) player.getExtendedProperties(EXT_PROP_NAME);
  54. }
  55.  
  56.  
  57. // Save any custom data that needs saving here
  58. @Override
  59. public void saveNBTData(NBTTagCompound compound)
  60. {
  61. // We need to create a new tag compound that will save everything for our Extended Properties
  62. NBTTagCompound properties = new NBTTagCompound();
  63. this.inventory.writeToNBT(properties);
  64.  
  65. // We only have 2 variables currently; save them both to the new tag
  66.  
  67. /*
  68. Now add our custom tag to the player's tag with a unique name (our property's name). This will allow you to save multiple types of properties and distinguish between them. If you only have one type, it isn't as important, but it will still avoid conflicts between your tag names and vanilla tag names. For instance, if you add some "Items" tag, that will conflict with vanilla. Not good. So just use a unique tag name.
  69. */
  70. compound.setTag(EXT_PROP_NAME, properties);
  71. }
  72.  
  73. // Load whatever data you saved
  74. @Override
  75. public void loadNBTData(NBTTagCompound compound)
  76. {
  77. // Here we fetch the unique tag compound we set for this class of Extended Properties
  78. NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME);
  79. this.inventory.readFromNBT(properties);
  80. // Get our data from the custom tag compound
  81.  
  82. }
  83.  
  84. /*
  85. I personally have yet to find a use for this method. If you know of any,
  86. please let me know and I'll add it in!
  87. */
  88. @Override
  89. public void init(Entity entity, World world)
  90. {
  91. }
  92.  
  93.  
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement