Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 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.nbt.NBTTagCompound;
  12. import net.minecraft.util.ChatComponentText;
  13. import net.minecraft.world.EnumSkyBlock;
  14. import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
  15. import net.minecraftforge.event.entity.living.LivingHurtEvent;
  16. import net.minecraftforge.event.entity.player.PlayerEvent;
  17. import net.minecraftforge.event.entity.player.PlayerInteractEvent;
  18. import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
  19.  
  20. public class sanityCalculation {
  21.  
  22. // set sanity amount of change
  23. int sanityDifficulty = 1;
  24. // counter for tick rate
  25. int i = 0;
  26. // set sanity tick rate here
  27. int sanityTickRate = 50;
  28.  
  29. @SubscribeEvent
  30. public void onClonePlayer(PlayerEvent.Clone event) {
  31. NBTTagCompound compound = new NBTTagCompound();
  32. ExtendedPlayer.get(event.original).saveNBTData(compound);
  33. ExtendedPlayer.get(event.entityPlayer).loadNBTData(compound);
  34. }
  35.  
  36. // Tick event that removes sanity based on sanityDifficulty variable
  37. @SubscribeEvent
  38. public void onEvent(LivingUpdateEvent event) {
  39. // Is Player ?
  40. if (event.entity instanceof EntityPlayer) {
  41. EntityPlayer player = (EntityPlayer) event.entity;
  42. ExtendedPlayer props = ExtendedPlayer.get(player);
  43.  
  44. //get the players position for lighting check
  45. Double playerX = Minecraft.getMinecraft().thePlayer.posX;
  46. Double playerY = Minecraft.getMinecraft().thePlayer.posY;
  47. Double playerZ = Minecraft.getMinecraft().thePlayer.posZ;
  48. //cast the players position to integer values and check the light at that spot and store in playerlightlevel var
  49. int playerlightlevel = Minecraft.getMinecraft().theWorld.getBlockLightValue(playerX.intValue(), playerY.intValue() - 1, playerZ.intValue());
  50. //playerlightlevel = 16 - playerlightlevel;
  51. // debug text for light level
  52. System.out.println("Light Level modifier is " + playerlightlevel);
  53.  
  54. if (i >= sanityTickRate) {
  55.  
  56. // then you get scared and sanity drops faster
  57. props.consumeSanity(sanityDifficulty * playerlightlevel);
  58. i = 0;
  59. // debug console text for sanity
  60. System.out.println("Player Sanity: " + props.getCurrentSanity());
  61. } else {
  62. i++;
  63. }
  64.  
  65. }
  66. }
  67.  
  68. // Interact With Wilson
  69. @SubscribeEvent
  70. public void onEvent(PlayerInteractEvent event) {
  71. // Is Player
  72. if (event.entity instanceof EntityPlayer) {
  73. EntityPlayer player = (EntityPlayer) event.entity;
  74. ExtendedPlayer props = ExtendedPlayer.get(player);
  75.  
  76. // Is Right Click
  77. if (event.action == Action.RIGHT_CLICK_BLOCK) {
  78. // make a variable containing the block just right clicked
  79. Block clickedBlock = event.world.getBlock(event.x, event.y, event.z);
  80. // if that block is a wilson block
  81. if (Block.getIdFromBlock(clickedBlock) == Block.getIdFromBlock(ModBlocks.wilsonBlock)) {
  82. // send debug message to console
  83. System.out.println("This is a Wilson Block!");
  84.  
  85. // send chat to server only
  86. if (!event.world.isRemote) {
  87. Minecraft.getMinecraft().thePlayer
  88. .addChatMessage(new ChatComponentText("<Wilson> Well Hello Neighbor!"));
  89. }
  90.  
  91. // heal some sanity
  92. props.replenishSanity(this.sanityDifficulty * 1000);
  93.  
  94. // spawn some heart particles
  95. Random rand = new Random();
  96. double motionX = rand.nextGaussian() * 0.02D;
  97. double motionY = rand.nextGaussian() * 0.02D;
  98. double motionZ = rand.nextGaussian() * 0.02D;
  99. event.world.spawnParticle("heart", event.x + 0.5, event.y + 1, event.z + 0.5, motionX, motionY,
  100. motionZ);
  101. }
  102. }
  103. }
  104. }
  105.  
  106. @SubscribeEvent
  107. public void onEvent(LivingHurtEvent event) {
  108. if (event.entity instanceof EntityPlayer) {
  109. EntityPlayer player = (EntityPlayer) event.entity;
  110. ExtendedPlayer props = ExtendedPlayer.get(player);
  111. int sanitydamage = sanityDifficulty * Math.round(event.ammount) * 100;
  112. props.consumeSanity(sanitydamage);
  113. System.out.println("Damage caused sanity reduction of " + sanitydamage);
  114.  
  115. }
  116. }
  117.  
  118. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement