Disconsented

Untitled

Apr 15th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.25 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.     @SubscribeEvent
  17.     public void onEntityConstructing(EntityConstructing event) {
  18.                     if (event.entity instanceof EntityPlayer) {
  19.                             if (PlayerInformation.get((EntityPlayer) event.entity) == null)
  20.                                     PlayerInformation.register((EntityPlayer) event.entity);
  21.                     }
  22.             }
  23.      
  24.      
  25.     @SubscribeEvent
  26.     public void onBreakEvent(BreakEvent event){
  27.      
  28.              if (event.getPlayer() instanceof EntityPlayer) {
  29.              EntityPlayer ent = (EntityPlayer) event.getPlayer();
  30.              PlayerInformation playerInfo = PlayerInformation.get((EntityPlayer) event.getPlayer());
  31.              
  32.              if ( event.block.getClass() == BlockGrass.class ){
  33.                      System.out.println("Broken block:"+event.block.getClass());            
  34.                      playerInfo.addXP(1);
  35.                      System.out.println("From NBT, Player XP:" + playerInfo.getXP());
  36.                      }
  37.              }
  38.          }
  39.     @SubscribeEvent
  40.     public void onLivingDeath(LivingDeathEvent event)
  41.     {
  42.         EntityPlayer entityPlayer;
  43.         if (event.entityLiving instanceof EntityPlayer)
  44.         {
  45.             //tempExperience = entityPlayer.getEntityData().getCompoundTag("testmod").getInteger("currentXP");         
  46.             EntityPlayer player = (EntityPlayer)event.entity;
  47.             NBTTagCompound compound = player.getEntityData();
  48.             NBTTagCompound persistent;
  49.             if (!compound.hasKey(EntityPlayer.PERSISTED_NBT_TAG)) {
  50.                 persistent = new NBTTagCompound();
  51.                 compound.setTag(EntityPlayer.PERSISTED_NBT_TAG, persistent);
  52.             } else persistent = compound.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG);
  53.             PlayerInformation playerInfo = PlayerInformation.get((EntityPlayer) event.entity);
  54.             NBTTagCompound persistentSave = new NBTTagCompound();
  55.             persistentSave.setInteger("currentXP",playerInfo.getXP() );
  56.  
  57.  
  58.         }
  59.     }
  60.     @SubscribeEvent
  61.         public void onEntityJoinWorldEvent(EntityJoinWorldEvent event)
  62.         {
  63.            
  64.             if (event.entity instanceof EntityPlayer)
  65.             {
  66.                 System.out.println("Player Respawn detected");
  67.                 EntityPlayer player = (EntityPlayer) event.entity;
  68.                 PlayerInformation playerInfo = PlayerInformation.get((EntityPlayer) event.entity);         
  69.                 NBTTagCompound compound = player.getEntityData();
  70.                 if (!compound.hasKey(EntityPlayer.PERSISTED_NBT_TAG)) return;
  71.                 NBTTagCompound persistent = compound.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG);
  72.                 playerInfo.setXP(persistent.getInteger("currentXP"));
  73.                 System.out.println("|"+persistent.getInteger("currentXP")+"|");
  74.             }
  75.         }
  76.  
  77.  
  78.     }
Advertisement
Add Comment
Please, Sign In to add comment