Advertisement
Guest User

Untitled

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