Advertisement
Disconsented

Untitled

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