Advertisement
Guest User

SanityCalculation.java

a guest
Mar 20th, 2017
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. package com.ignatio.wilsonsanity;
  2.  
  3. import java.util.Random;
  4.  
  5. import com.ignatio.wilsonsanity.block.ModBlocks;
  6.  
  7. import cpw.mods.fml.common.eventhandler.SubscribeEvent;
  8. import net.minecraft.block.Block;
  9. import net.minecraft.client.Minecraft;
  10. import net.minecraft.entity.player.EntityPlayer;
  11. import net.minecraft.util.ChatComponentText;
  12. import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
  13. import net.minecraftforge.event.entity.player.PlayerInteractEvent;
  14. import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
  15.  
  16. public class sanityCalculation {
  17.  
  18. double sanityDifficulty = 0.0001; //set sanity amount of change
  19.  
  20. //Tick event that removes sanity based on sanityDifficulty variable
  21. @SubscribeEvent
  22. public void onEvent(LivingUpdateEvent event)
  23. {
  24.  
  25. // Is Player
  26. if (event.entity instanceof EntityPlayer)
  27. {
  28. ExtendedPlayer props = ExtendedPlayer.get(Minecraft.getMinecraft().thePlayer);
  29.  
  30. //get the players position for lighting check
  31. Double playerX = Minecraft.getMinecraft().thePlayer.posX;
  32. Double playerY = Minecraft.getMinecraft().thePlayer.posY;
  33. Double playerZ = Minecraft.getMinecraft().thePlayer.posZ;
  34. //cast the players position to integer values and check the light at that spot and store in playerlightlevel var
  35. int playerlightlevel = event.entityLiving.worldObj.getBlockLightValue(playerX.intValue(), playerY.intValue(), playerZ.intValue());
  36.  
  37. //if it's dark outside
  38. if (playerlightlevel <= 10)
  39. {
  40. System.out.println("Light Level is < 10"); // debug text for light level
  41. props.consumeSanity(sanityDifficulty * 100); // then you get scared and sanity drops faster
  42. }
  43. else { //otherwise drop sanity at standard level
  44.  
  45. props.consumeSanity(sanityDifficulty);
  46. System.out.println("Sanity " + props.getCurrentSanity());
  47.  
  48. //if (props.getCurrentSanity() >= 100){ //if sanity is over 100
  49. //props.resetSanity(100.00); // cant be that sane!
  50. //}
  51.  
  52. }
  53. }
  54. }
  55.  
  56. //Interact With Wilson
  57. @SubscribeEvent
  58. public void onEvent(PlayerInteractEvent event)
  59. {
  60. // Is Player
  61. if (event.entity instanceof EntityPlayer)
  62. {
  63. ExtendedPlayer props = ExtendedPlayer.get(Minecraft.getMinecraft().thePlayer);
  64.  
  65. // Is Right Click
  66. if (event.action == Action.RIGHT_CLICK_BLOCK)
  67. {
  68. Block clickedBlock = event.world.getBlock(event.x, event.y, event.z); // make a variable containing the block jsut right clicked
  69. if (Block.getIdFromBlock(clickedBlock) == Block.getIdFromBlock(ModBlocks.wilsonBlock)) //if that block is a wilson block
  70. {
  71. System.out.println("This is a Wilson Block!"); // send debug message to console
  72.  
  73. // send chat to server only
  74. if (!event.world.isRemote)
  75. {Minecraft.getMinecraft().thePlayer.addChatMessage(new ChatComponentText("<Wilson> Well Hello Neighbor!"));}
  76.  
  77. //heal some sanity
  78. props.replenishSanity(this.sanityDifficulty * 100);
  79.  
  80.  
  81. //spawn some heart particles
  82. Random rand = new Random();
  83. double motionX = rand.nextGaussian() * 0.02D;
  84. double motionY = rand.nextGaussian() * 0.02D;
  85. double motionZ = rand.nextGaussian() * 0.02D;
  86. event.world.spawnParticle("heart", event.x + 0.5, event.y + 1, event.z + 0.5, motionX, motionY, motionZ);
  87. }
  88. }
  89. }
  90. }
  91.  
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement