Advertisement
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.util.ChatComponentText;
- import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
- import net.minecraftforge.event.entity.player.PlayerInteractEvent;
- import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
- public class sanityCalculation {
- double sanityDifficulty = 0.0001; //set sanity amount of change
- //Tick event that removes sanity based on sanityDifficulty variable
- @SubscribeEvent
- public void onEvent(LivingUpdateEvent event)
- {
- // Is Player
- if (event.entity instanceof EntityPlayer)
- {
- ExtendedPlayer props = ExtendedPlayer.get(Minecraft.getMinecraft().thePlayer);
- //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 = event.entityLiving.worldObj.getBlockLightValue(playerX.intValue(), playerY.intValue(), playerZ.intValue());
- //if it's dark outside
- if (playerlightlevel <= 10)
- {
- System.out.println("Light Level is < 10"); // debug text for light level
- props.consumeSanity(sanityDifficulty * 100); // then you get scared and sanity drops faster
- }
- else { //otherwise drop sanity at standard level
- props.consumeSanity(sanityDifficulty);
- System.out.println("Sanity " + props.getCurrentSanity());
- //if (props.getCurrentSanity() >= 100){ //if sanity is over 100
- //props.resetSanity(100.00); // cant be that sane!
- //}
- }
- }
- }
- //Interact With Wilson
- @SubscribeEvent
- public void onEvent(PlayerInteractEvent event)
- {
- // Is Player
- if (event.entity instanceof EntityPlayer)
- {
- ExtendedPlayer props = ExtendedPlayer.get(Minecraft.getMinecraft().thePlayer);
- // Is Right Click
- if (event.action == Action.RIGHT_CLICK_BLOCK)
- {
- Block clickedBlock = event.world.getBlock(event.x, event.y, event.z); // make a variable containing the block jsut right clicked
- if (Block.getIdFromBlock(clickedBlock) == Block.getIdFromBlock(ModBlocks.wilsonBlock)) //if that block is a wilson block
- {
- System.out.println("This is a Wilson Block!"); // send debug message to console
- // 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 * 100);
- //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);
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement