Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tutorial.generic;
- import net.minecraft.block.BlockGrass;
- import net.minecraft.entity.player.EntityPlayer;
- import net.minecraft.nbt.NBTTagCompound;
- import net.minecraftforge.event.entity.EntityEvent;
- import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;
- import net.minecraftforge.event.entity.EntityJoinWorldEvent;
- import net.minecraftforge.event.entity.living.LivingDeathEvent;
- import net.minecraftforge.event.entity.living.LivingSpawnEvent;
- import net.minecraftforge.event.world.BlockEvent.BreakEvent;
- import cpw.mods.fml.common.eventhandler.SubscribeEvent;
- public class genericHooks {
- @SubscribeEvent
- public void onEntityConstructing(EntityConstructing event) {
- if (event.entity instanceof EntityPlayer) {
- if (PlayerInformation.get((EntityPlayer) event.entity) == null)
- PlayerInformation.register((EntityPlayer) event.entity);
- }
- }
- @SubscribeEvent
- public void onBreakEvent(BreakEvent event){
- if (event.getPlayer() instanceof EntityPlayer) {
- EntityPlayer ent = (EntityPlayer) event.getPlayer();
- PlayerInformation playerInfo = PlayerInformation.get((EntityPlayer) event.getPlayer());
- if ( event.block.getClass() == BlockGrass.class ){
- System.out.println("Broken block:"+event.block.getClass());
- playerInfo.addXP(1);
- System.out.println("From NBT, Player XP:" + playerInfo.getXP());
- }
- }
- }
- @SubscribeEvent
- public void onLivingDeath(LivingDeathEvent event)
- {
- EntityPlayer entityPlayer;
- if (event.entityLiving instanceof EntityPlayer)
- {
- //tempExperience = entityPlayer.getEntityData().getCompoundTag("testmod").getInteger("currentXP");
- EntityPlayer player = (EntityPlayer)event.entity;
- NBTTagCompound compound = player.getEntityData();
- NBTTagCompound persistent;
- if (!compound.hasKey(EntityPlayer.PERSISTED_NBT_TAG)) {
- persistent = new NBTTagCompound();
- compound.setTag(EntityPlayer.PERSISTED_NBT_TAG, persistent);
- } else persistent = compound.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG);
- PlayerInformation playerInfo = PlayerInformation.get((EntityPlayer) event.entity);
- NBTTagCompound persistentSave = new NBTTagCompound();
- persistentSave.setInteger("currentXP",playerInfo.getXP() );
- }
- }
- @SubscribeEvent
- public void onEntityJoinWorldEvent(EntityJoinWorldEvent event)
- {
- if (event.entity instanceof EntityPlayer)
- {
- System.out.println("Player Respawn detected");
- EntityPlayer player = (EntityPlayer) event.entity;
- PlayerInformation playerInfo = PlayerInformation.get((EntityPlayer) event.entity);
- NBTTagCompound compound = player.getEntityData();
- if (!compound.hasKey(EntityPlayer.PERSISTED_NBT_TAG)) return;
- NBTTagCompound persistent = compound.getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG);
- playerInfo.setXP(persistent.getInteger("currentXP"));
- System.out.println("|"+persistent.getInteger("currentXP")+"|");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment