Guest User

ExtendedPlayer

a guest
Oct 21st, 2015
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 KB | None | 0 0
  1. package com.fluffy2.amnesialights.handler;
  2.  
  3. import net.minecraft.entity.Entity;
  4. import net.minecraft.entity.player.EntityPlayer;
  5. import net.minecraft.nbt.NBTTagCompound;
  6. import net.minecraft.util.MovingObjectPosition;
  7. import net.minecraft.util.MovingObjectPosition.MovingObjectType;
  8. import net.minecraft.util.Vec3;
  9. import net.minecraft.world.World;
  10. import net.minecraft.world.WorldServer;
  11. import net.minecraftforge.common.IExtendedEntityProperties;
  12.  
  13. import com.fluffy2.amnesialights.AmnesiaLights;
  14. import com.fluffy2.amnesialights.pakets.HotbarLanternMessageHandler;
  15.  
  16. public class ExtendedPlayerPropertiesHandler implements IExtendedEntityProperties{
  17.  
  18. public final static String PropName = AmnesiaLights.ModID+"_Player_Properties";
  19.  
  20. private int lastPlayerX;
  21. private int lastPlayerY;
  22. private int lastPlayerZ;
  23.  
  24. private int rayTraceX;
  25. private int rayTraceY;
  26. private int rayTraceZ;
  27. private int lastPlayerX2;
  28. private int lastPlayerY2;
  29. private int lastPlayerZ2;
  30.  
  31. private boolean lanternEquipped;
  32. private boolean candleEquipped;
  33. private boolean flashlightEquipped;
  34. private boolean bullseyeEquipped;
  35. private boolean quickEquipped;
  36. private boolean quick2Equipped;
  37.  
  38. public int hotbarLantern;
  39.  
  40. private final EntityPlayer player;
  41.  
  42. public ExtendedPlayerPropertiesHandler(EntityPlayer player){
  43. this.player = player;
  44.  
  45. this.lastPlayerX = 0;
  46. this.lastPlayerY = 0;
  47. this.lastPlayerZ = 0;
  48.  
  49. this.rayTraceX = 0;
  50. this.rayTraceY = 0;
  51. this.rayTraceZ = 0;
  52. this.lastPlayerX2 = 0;
  53. this.lastPlayerY2 = 0;
  54. this.lastPlayerZ2 = 0;
  55.  
  56.  
  57. this.lanternEquipped = false;
  58. this.bullseyeEquipped = false;
  59. this.candleEquipped = false;
  60. this.flashlightEquipped = false;
  61. this.quickEquipped = false;
  62. this.quick2Equipped = false;
  63.  
  64. this.hotbarLantern = 0;
  65. }
  66.  
  67. public static final void register(EntityPlayer player){
  68. player.registerExtendedProperties(ExtendedPlayerPropertiesHandler.PropName, new ExtendedPlayerPropertiesHandler(player));
  69. }
  70.  
  71. public static final ExtendedPlayerPropertiesHandler get(EntityPlayer player){
  72. return (ExtendedPlayerPropertiesHandler)player.getExtendedProperties(PropName);
  73. }
  74.  
  75. @Override
  76. public void saveNBTData(NBTTagCompound compound){
  77. }
  78.  
  79. @Override
  80. public void loadNBTData(NBTTagCompound compound){
  81. }
  82.  
  83. @Override
  84. public void init(Entity entity, World world){
  85. }
  86.  
  87. //getCurrentPos
  88. public int getPlayerPosX(){
  89. return (int)Math.floor(this.player.posX);
  90. }
  91. public int getPlayerPosY(){
  92. return (int)Math.floor(this.player.posY);
  93. }
  94. public int getPlayerPosZ(){
  95. return (int)Math.floor(this.player.posZ);
  96. }
  97.  
  98. //getLastPos
  99. public int getLastPosX(){
  100. return this.lastPlayerX;
  101. }
  102. public int getLastPosY(){
  103. return this.lastPlayerY;
  104. }
  105. public int getLastPosZ(){
  106. return this.lastPlayerZ;
  107. }
  108.  
  109. //getRayTrace
  110. public int getRayTraceX(){
  111. return this.rayTraceX;
  112. }
  113. public int getRayTraceY(){
  114. return this.rayTraceY;
  115. }
  116. public int getRayTraceZ(){
  117. return this.rayTraceZ;
  118. }
  119.  
  120. //getLashPos2
  121. public int getLastPosX2(){
  122. return this.lastPlayerX2;
  123. }
  124. public int getLastPosY2(){
  125. return this.lastPlayerY2;
  126. }
  127. public int getLastPosZ2(){
  128. return this.lastPlayerZ2;
  129. }
  130.  
  131. //getBoolean
  132. public boolean isLanternEquipped(){
  133. return this.lanternEquipped;
  134. }
  135. public boolean isBullseyeEquipped(){
  136. return this.bullseyeEquipped;
  137. }
  138. public boolean isCandleEquipped(){
  139. return this.candleEquipped;
  140. }
  141. public boolean isFlashlightEquipped(){
  142. return this.flashlightEquipped;
  143. }
  144. public boolean isQuickEquipped(){
  145. return this.quickEquipped;
  146. }
  147. public boolean isQuick2Equipped(){
  148. return this.quick2Equipped;
  149. }
  150.  
  151. //setLastPos
  152. public void setLastPos(int x, int y, int z){
  153. this.lastPlayerX = x;
  154. this.lastPlayerY = y;
  155. this.lastPlayerZ = z;
  156. }
  157.  
  158. //setRayTrace
  159. public void setRayTrace(double distance){
  160. Vec3 look = player.getLookVec();
  161. Vec3 pos = new Vec3(player.posX, player.posY+player.getEyeHeight(), player.posZ);
  162. Vec3 addedlook = pos.addVector(look.xCoord * distance, look.yCoord * distance, look.zCoord * distance);
  163. MovingObjectPosition mop = player.worldObj.rayTraceBlocks(pos, addedlook);
  164. if(mop != null && mop.typeOfHit == MovingObjectType.BLOCK){
  165. this.rayTraceX = mop.getBlockPos().getX();
  166. this.rayTraceY = mop.getBlockPos().getY();
  167. this.rayTraceZ = mop.getBlockPos().getZ();
  168. }else{
  169. this.rayTraceX = (int)Math.floor(addedlook.xCoord);
  170. this.rayTraceY = (int)Math.floor(addedlook.yCoord);
  171. this.rayTraceZ = (int)Math.floor(addedlook.zCoord);
  172. }
  173. }
  174.  
  175. //setLastPos2
  176. public void setLastPos2(int x, int y, int z){
  177. this.lastPlayerX2 = x;
  178. this.lastPlayerY2 = y;
  179. this.lastPlayerZ2 = z;
  180. }
  181.  
  182. //setBoolean
  183. public void setLanternEquipped(boolean state){
  184. this.lanternEquipped = state;
  185. }
  186. public void setBullseyeEquipped(boolean state){
  187. this.bullseyeEquipped = state;
  188. }
  189. public void setCandleEquipped(boolean state){
  190. this.candleEquipped = state;
  191. }
  192. public void setFlashlightEquipped(boolean state){
  193. this.flashlightEquipped = state;
  194. }
  195. public void setQuickEquipped(boolean state){
  196. this.quickEquipped = state;
  197. }
  198. public void setQuick2Equipped(boolean state){
  199. this.quick2Equipped = state;
  200. }
  201.  
  202. //hotbarLantern
  203. public int hotbarLantern(){
  204. return this.hotbarLantern;
  205. }
  206. public void setHotbarLantern(int state){
  207. this.hotbarLantern = state;
  208. ((WorldServer)player.worldObj).getEntityTracker().func_151248_b(player, AmnesiaLights.snw.getPacketFrom(new HotbarLanternMessageHandler(player, state)));
  209. }
  210. }
Advertisement
Add Comment
Please, Sign In to add comment