Advertisement
Guest User

extendedplayernew.java

a guest
Mar 20th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.49 KB | None | 0 0
  1. package com.ignatio.wilsonsanity;
  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. public final static String EXT_PROP_NAME = "PlayerSanity";
  12. private final EntityPlayer player;
  13. private double playerSanity;
  14.  
  15. public ExtendedPlayer(EntityPlayer player)
  16. {
  17. System.out.println("ExtendedPlayer instantiated. Current sanity is " + this.playerSanity + ". About to be set to 50.");
  18.  
  19. this.player = player;
  20.  
  21. this.playerSanity = 50.00;
  22. }
  23.  
  24.  
  25. public static final void register(EntityPlayer player)
  26. {
  27. player.registerExtendedProperties(ExtendedPlayer.EXT_PROP_NAME, new ExtendedPlayer(player));
  28.  
  29. }
  30. public static final ExtendedPlayer get(EntityPlayer player)
  31. {
  32. return (ExtendedPlayer) player.getExtendedProperties(EXT_PROP_NAME);
  33. }
  34.  
  35. //save NBT
  36. @Override
  37. public void saveNBTData(NBTTagCompound compound)
  38. {
  39.  
  40.  
  41. System.out.println("Wilson > (pre) saveNBTData Sanity from NBT: " + this.playerSanity);
  42. compound.setDouble("PlayerSanity", 25);
  43. System.out.println("Saved sanity: " + compound.getDouble("PlayerSanity"));
  44.  
  45.  
  46. }
  47.  
  48.  
  49.  
  50. // Load NBT
  51. @Override
  52. public void loadNBTData(NBTTagCompound compound)
  53. {
  54. System.out.println("Sanity in compound at load: " + compound.getDouble("PlayerSanity"));
  55.  
  56. this.playerSanity = compound.getDouble("PlayerSanity");
  57.  
  58. System.out.println("Wilson > loadNBTData Sanity from NBT: " + this.playerSanity);
  59. }
  60.  
  61.  
  62.  
  63.  
  64. //from the tutorial, not sure what it does
  65. @Override
  66. public void init(Entity entity, World world)
  67. {
  68.  
  69. }
  70.  
  71.  
  72. // consume some sanity
  73. public boolean consumeSanity(Double amount)
  74. {
  75.  
  76. boolean sufficient = amount <= this.playerSanity;
  77.  
  78. this.playerSanity -= (amount < this.playerSanity ? amount : this.playerSanity);
  79.  
  80. return sufficient;
  81. }
  82.  
  83. //add some sanity
  84. public void replenishSanity(Double amount)
  85. {
  86. this.playerSanity += amount;
  87. }
  88.  
  89. //set the sanity directly
  90. public void resetSanity(Double amount)
  91. {
  92. this.playerSanity = amount;
  93. }
  94.  
  95. //get the current sanity
  96. public double getCurrentSanity()
  97. {
  98. return this.playerSanity;
  99.  
  100. }
  101.  
  102. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement