Not a member of Pastebin yet?
                        Sign Up,
                        it unlocks many cool features!                    
                - package com.ignatio.wilsonsanity;
 - import java.util.Random;
 - import com.ignatio.wilsonsanity.block.ModBlocks;
 - import cpw.mods.fml.common.eventhandler.SubscribeEvent;
 - import net.minecraft.block.Block;
 - import net.minecraft.client.Minecraft;
 - import net.minecraft.entity.player.EntityPlayer;
 - import net.minecraft.nbt.NBTTagCompound;
 - import net.minecraft.util.ChatComponentText;
 - import net.minecraft.world.EnumSkyBlock;
 - import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
 - import net.minecraftforge.event.entity.living.LivingHurtEvent;
 - import net.minecraftforge.event.entity.player.PlayerEvent;
 - import net.minecraftforge.event.entity.player.PlayerInteractEvent;
 - import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
 - public class sanityCalculation {
 - // set sanity amount of change
 - int sanityDifficulty = 1;
 - // counter for tick rate
 - int i = 0;
 - // set sanity tick rate here
 - int sanityTickRate = 50;
 - @SubscribeEvent
 - public void onClonePlayer(PlayerEvent.Clone event) {
 - NBTTagCompound compound = new NBTTagCompound();
 - ExtendedPlayer.get(event.original).saveNBTData(compound);
 - ExtendedPlayer.get(event.entityPlayer).loadNBTData(compound);
 - }
 - // Tick event that removes sanity based on sanityDifficulty variable
 - @SubscribeEvent
 - public void onEvent(LivingUpdateEvent event) {
 - // Is Player ?
 - if (event.entity instanceof EntityPlayer) {
 - EntityPlayer player = (EntityPlayer) event.entity;
 - ExtendedPlayer props = ExtendedPlayer.get(player);
 - //get the players position for lighting check
 - Double playerX = Minecraft.getMinecraft().thePlayer.posX;
 - Double playerY = Minecraft.getMinecraft().thePlayer.posY;
 - Double playerZ = Minecraft.getMinecraft().thePlayer.posZ;
 - //cast the players position to integer values and check the light at that spot and store in playerlightlevel var
 - int playerlightlevel = Minecraft.getMinecraft().theWorld.getBlockLightValue(playerX.intValue(), playerY.intValue() - 1, playerZ.intValue());
 - //playerlightlevel = 16 - playerlightlevel;
 - // debug text for light level
 - System.out.println("Light Level modifier is " + playerlightlevel);
 - if (i >= sanityTickRate) {
 - // then you get scared and sanity drops faster
 - props.consumeSanity(sanityDifficulty * playerlightlevel);
 - i = 0;
 - // debug console text for sanity
 - System.out.println("Player Sanity: " + props.getCurrentSanity());
 - } else {
 - i++;
 - }
 - }
 - }
 - // Interact With Wilson
 - @SubscribeEvent
 - public void onEvent(PlayerInteractEvent event) {
 - // Is Player
 - if (event.entity instanceof EntityPlayer) {
 - EntityPlayer player = (EntityPlayer) event.entity;
 - ExtendedPlayer props = ExtendedPlayer.get(player);
 - // Is Right Click
 - if (event.action == Action.RIGHT_CLICK_BLOCK) {
 - // make a variable containing the block just right clicked
 - Block clickedBlock = event.world.getBlock(event.x, event.y, event.z);
 - // if that block is a wilson block
 - if (Block.getIdFromBlock(clickedBlock) == Block.getIdFromBlock(ModBlocks.wilsonBlock)) {
 - // send debug message to console
 - System.out.println("This is a Wilson Block!");
 - // send chat to server only
 - if (!event.world.isRemote) {
 - Minecraft.getMinecraft().thePlayer
 - .addChatMessage(new ChatComponentText("<Wilson> Well Hello Neighbor!"));
 - }
 - // heal some sanity
 - props.replenishSanity(this.sanityDifficulty * 1000);
 - // spawn some heart particles
 - Random rand = new Random();
 - double motionX = rand.nextGaussian() * 0.02D;
 - double motionY = rand.nextGaussian() * 0.02D;
 - double motionZ = rand.nextGaussian() * 0.02D;
 - event.world.spawnParticle("heart", event.x + 0.5, event.y + 1, event.z + 0.5, motionX, motionY,
 - motionZ);
 - }
 - }
 - }
 - }
 - @SubscribeEvent
 - public void onEvent(LivingHurtEvent event) {
 - if (event.entity instanceof EntityPlayer) {
 - EntityPlayer player = (EntityPlayer) event.entity;
 - ExtendedPlayer props = ExtendedPlayer.get(player);
 - int sanitydamage = sanityDifficulty * Math.round(event.ammount) * 100;
 - props.consumeSanity(sanitydamage);
 - System.out.println("Damage caused sanity reduction of " + sanitydamage);
 - }
 - }
 - }
 
Advertisement
 
                    Add Comment                
                
                        Please, Sign In to add comment