Guest User

ExtendedPlayer.java

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