Disconsented

Untitled

Apr 15th, 2014
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.37 KB | None | 0 0
  1.     package tutorial.generic;
  2.     import net.minecraft.block.BlockGrass;
  3. import net.minecraft.entity.player.EntityPlayer;
  4. import net.minecraft.nbt.NBTTagCompound;
  5. import net.minecraftforge.event.entity.EntityEvent;
  6. import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;
  7. import net.minecraftforge.event.entity.EntityJoinWorldEvent;
  8. import net.minecraftforge.event.entity.living.LivingDeathEvent;
  9. import net.minecraftforge.event.entity.living.LivingSpawnEvent;
  10. import net.minecraftforge.event.world.BlockEvent.BreakEvent;
  11. import cpw.mods.fml.common.eventhandler.SubscribeEvent;
  12.      
  13.      
  14.     public class genericHooks {
  15.  
  16.         int tempXP;
  17.     @SubscribeEvent
  18.     public void onEntityConstructing(EntityConstructing event) {
  19.                     if (event.entity instanceof EntityPlayer) {
  20.                             if (PlayerInformation.get((EntityPlayer) event.entity) == null)
  21.                                     PlayerInformation.register((EntityPlayer) event.entity);
  22.                     }
  23.             }
  24.      
  25.      
  26.     @SubscribeEvent
  27.     public void onBreakEvent(BreakEvent event){
  28.      
  29.              if (event.getPlayer() instanceof EntityPlayer) {
  30.              EntityPlayer ent = (EntityPlayer) event.getPlayer();
  31.              PlayerInformation playerInfo = PlayerInformation.get((EntityPlayer) event.getPlayer());
  32.              
  33.              if ( event.block.getClass() == BlockGrass.class ){
  34.                      System.out.println("Broken block:"+event.block.getClass());            
  35.                      playerInfo.addXP(1);
  36.                      System.out.println("From NBT, Player XP:" + playerInfo.getXP());
  37.                      }
  38.              }
  39.          }
  40.     @SubscribeEvent
  41.     public void onLivingDeath(LivingDeathEvent event)
  42.     {
  43.         EntityPlayer entityPlayer;
  44.         if (event.entityLiving instanceof EntityPlayer)
  45.         {
  46.             PlayerInformation playerInfo = PlayerInformation.get((EntityPlayer) event.entity);
  47.             tempXP = playerInfo.getXP();
  48.             System.out.println(playerInfo.getXP());
  49.         }
  50.     }
  51.     @SubscribeEvent
  52.         public void onEntityJoinWorldEvent(EntityJoinWorldEvent event)
  53.         {
  54.            
  55.             if (event.entity instanceof EntityPlayer)
  56.             {
  57.                 System.out.println("Player Respawn detected");
  58.                 PlayerInformation playerInfo = PlayerInformation.get((EntityPlayer) event.entity);             
  59.                 playerInfo.setXP(tempXP);
  60.             }
  61.         }
  62.  
  63.  
  64.     }
Advertisement
Add Comment
Please, Sign In to add comment