Fixed Solidifer XP values being off.

Closes #123
This commit is contained in:
Ellpeck 2016-06-15 18:37:54 +02:00
parent 718c999f70
commit f97ba2d31c

View file

@ -83,10 +83,10 @@ public class TileEntityXPSolidifier extends TileEntityInventoryBase implements I
@Override @Override
public void onButtonPressed(int buttonID, EntityPlayer player){ public void onButtonPressed(int buttonID, EntityPlayer player){
if(buttonID < this.buttonAmounts.length){ if(buttonID < this.buttonAmounts.length){
if(this.getPlayerXP(player) > 0){ if(getPlayerXP(player) > 0){
int xp = this.buttonAmounts[buttonID] == -999 ? this.getPlayerXP(player)/ItemSolidifiedExperience.SOLID_XP_AMOUNT : this.buttonAmounts[buttonID]; int xp = this.buttonAmounts[buttonID] == -999 ? getPlayerXP(player)/ItemSolidifiedExperience.SOLID_XP_AMOUNT : this.buttonAmounts[buttonID];
if(this.amount < Short.MAX_VALUE-xp && this.getPlayerXP(player) >= ItemSolidifiedExperience.SOLID_XP_AMOUNT*xp){ if(this.amount < Short.MAX_VALUE-xp && getPlayerXP(player) >= ItemSolidifiedExperience.SOLID_XP_AMOUNT*xp){
this.addPlayerXP(player, -(ItemSolidifiedExperience.SOLID_XP_AMOUNT*xp)); addPlayerXP(player, -(ItemSolidifiedExperience.SOLID_XP_AMOUNT*xp));
if(!this.worldObj.isRemote){ if(!this.worldObj.isRemote){
this.amount += xp; this.amount += xp;
} }
@ -95,59 +95,71 @@ public class TileEntityXPSolidifier extends TileEntityInventoryBase implements I
} }
} }
//TODO Fix XP System to fit points needed in 1.8 (OpenBlocks?) /*
* The below methods were excerpted from EnderIO by SleepyTrousers with permission, thanks!
/**
* Gets the Player's XP
* (Excerpted from OpenBlocks' XP system with permission, thanks guys!)
*
* @param player The Player
* @return The XP
*/ */
private int getPlayerXP(EntityPlayer player){
return (int)(this.getExperienceForLevel(player.experienceLevel)+(player.experience*player.xpBarCap())); private static final Integer[] XP_MAP = new Integer[256];
static{
for(int i = 0; i < XP_MAP.length; i++){
XP_MAP[i] = getExperienceForLevelImpl(i);
}
} }
/** public static int getExperienceForLevel(int level){
* Adds (or removes, if negative) a certain amount of XP from a player if(level >= 0 && level < XP_MAP.length){
* (Excerpted from OpenBlocks' XP system with permission, thanks guys!) return XP_MAP[level];
* }
* @param player The Player if(level >= 21863){
* @param amount The Amount return Integer.MAX_VALUE;
*/ }
private void addPlayerXP(EntityPlayer player, int amount){ return getExperienceForLevelImpl(level);
int experience = this.getPlayerXP(player)+amount; }
private static int getExperienceForLevelImpl(int level){
int res = 0;
for(int i = 0; i < level; i++){
res += getXpBarCapacity(i);
if(res < 0){
return Integer.MAX_VALUE;
}
}
return res;
}
public static int getXpBarCapacity(int level){
if(level >= 30){
return 112+(level-30)*9;
}
else if(level >= 15){
return 37+(level-15)*5;
}
return 7+level*2;
}
public static int getLevelForExperience(int experience){
for(int i = 0; i < XP_MAP.length; i++){
if(XP_MAP[i] > experience){
return i-1;
}
}
int i = XP_MAP.length;
while(getExperienceForLevel(i) <= experience){
i++;
}
return i-1;
}
public static int getPlayerXP(EntityPlayer player){
return (int)(getExperienceForLevel(player.experienceLevel)+(player.experience*player.xpBarCap()));
}
public static void addPlayerXP(EntityPlayer player, int amount){
int experience = Math.max(0, getPlayerXP(player)+amount);
player.experienceTotal = experience; player.experienceTotal = experience;
player.experienceLevel = getLevelForExperience(experience);
int level = 0; int expForLevel = getExperienceForLevel(player.experienceLevel);
while(this.getExperienceForLevel(level) <= experience){
level++;
}
player.experienceLevel = level-1;
int expForLevel = this.getExperienceForLevel(player.experienceLevel);
player.experience = (float)(experience-expForLevel)/(float)player.xpBarCap(); player.experience = (float)(experience-expForLevel)/(float)player.xpBarCap();
} }
/**
* Gets the amount of experience a certain level contains
* (Excerpted from OpenBlocks' XP system with permission, thanks guys!)
*
* @param level The Level in question
* @return The total XP the level has
*/
private int getExperienceForLevel(int level){
if(level > 0){
if(level > 0 && level < 16){
return level*17;
}
else if(level > 15 && level < 31){
return (int)(1.5*(level*level)-29.5*level+360);
}
else{
return (int)(3.5*(level*level)-151.5*level+2220);
}
}
return 0;
}
} }