Exemple #1
0
 public static void addPlayerXP(EntityPlayer player, int amount) {
   int experience = getPlayerXP(player) + amount;
   player.experienceTotal = experience;
   player.experienceLevel = getLevelForExperience(experience);
   int expForLevel = getExperienceForLevel(player.experienceLevel);
   player.experience = (float) (experience - expForLevel) / (float) player.xpBarCap();
 }
 // I'm not 100% this is needed. You may be able to avoid this whole call by
 // using the method in the player class, might be worth testing (player.addExperience(-1)?)
 public void decreasePlayerExperience(EntityPlayer player) {
   if (player.experience - (1.0F / (float) player.xpBarCap()) <= 0
       && player.experienceLevel > Reliquary.PROXY.heroMedallionLevelThreshold) {
     decreasePlayerLevel(player);
     return;
   }
   player.experience -= 1.0F / (float) player.xpBarCap();
   player.experienceTotal -= 1;
 }
 public static boolean addPlayerXP(EntityPlayer player, int amount) {
   int experience = getPlayerXP(player) + amount;
   if (experience < 0) {
     return false;
   }
   player.experienceTotal = experience;
   player.experienceLevel = getLevelForExperience(experience);
   int expForLevel = getExperienceForLevel(player.experienceLevel);
   player.experience = (experience - expForLevel) / (float) player.xpBarCap();
   return true;
 }
  @SubscribeEvent
  public void onPlayerDeath(LivingDeathEvent event) {
    if (event.entity instanceof EntityPlayerMP) {
      GameRules gameRules = event.entity.worldObj.getGameRules();
      boolean dropInventory = gameRules.getGameRuleBooleanValue("dropInventory");
      boolean dropHotbar = gameRules.getGameRuleBooleanValue("dropHotbar");
      boolean dropArmor = gameRules.getGameRuleBooleanValue("dropArmor");
      boolean dropXP = gameRules.getGameRuleBooleanValue("dropXP");

      EntityPlayer player = (EntityPlayer) event.entity;

      TileEntityTombstone tombstone = tombstoneOnDeath ? placeTombstone(player) : null;
      if (tombstone != null) {
        tombstone.setSignString(event.source.func_151519_b((EntityPlayer) event.entity).toString());
      }

      if (!dropInventory && !dropHotbar && !dropArmor && !dropXP) {
        return;
      }

      player.captureDrops = true;
      player.capturedDrops.clear();

      /* Get items/XP to drop and clear them from Player */
      int xpDropped = 0;
      if (dropXP) {
        if (!player.worldObj.isRemote) {
          xpDropped = player.experienceTotal;
          xpDropped = xpDropped > maxDropXP ? maxDropXP : xpDropped;
          int keptXp = (player.experienceTotal - xpDropped) * percKeptXp / 100;
          redistributor.addExpereince(player, keptXp >= 0 ? keptXp : 0);
          player.experienceLevel = 0;
          player.experienceTotal = 0;
          player.experience = 0;
        }
      }

      List<ItemStack> itemsToDrop = new ArrayList<ItemStack>();
      if (dropArmor) {
        itemsToDrop.addAll(dropArmor(player));
      }

      if (dropInventory) {
        itemsToDrop.addAll(dropInventory(player));
      }

      if (dropHotbar) {
        itemsToDrop.addAll(dropHotbar(player));
      }

      dropItems(player, itemsToDrop);
      boolean isCancelled = false;
      if (doDropEvent) {
        PlayerDropsEvent dropEvent = createPlayerDropEvent(player, event.source);
        isCancelled = MinecraftForge.EVENT_BUS.post(dropEvent);
      }
      player.captureDrops = false;
      if (!isCancelled) {
        /* Handler actually Dropping Items or Placing them in Tombstone */
        if (tombstoneAbsorbDrops && tombstone != null) {
          for (EntityItem entityItem : player.capturedDrops) {
            tombstone.addDrop(entityItem.getEntityItem());
          }
          tombstone.experience = xpDropped;
        } else {
          if (tombstoneAbsorbDrops) {
            ProjectZuluLog.warning("Tombstone could not be placed so items dropping normally.");
          }
          while (xpDropped > 0) {
            int j = EntityXPOrb.getXPSplit(xpDropped);
            xpDropped -= j;
            player.worldObj.spawnEntityInWorld(
                new EntityXPOrb(player.worldObj, player.posX, player.posY, player.posZ, j));
          }
          for (EntityItem item : player.capturedDrops) {
            player.joinEntityItemWithWorld(item);
          }
        }
      } else {
        ProjectZuluLog.warning(
            "Player drop event was cancelled, so items will not be dropped per convention."
                + "Results may not desireable, consider disabling 'doDropEvent' in the config.");
      }
    }
  }
 public void decreasePlayerLevel(EntityPlayer player) {
   player.experience = 1.0F - (1.0F / (float) player.xpBarCap());
   player.experienceTotal -= 1;
   player.experienceLevel -= 1;
 }