mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-26 08:48:34 +01:00
parent
718c999f70
commit
f97ba2d31c
1 changed files with 64 additions and 52 deletions
|
@ -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
|
|
||||||
* @param amount The Amount
|
|
||||||
*/
|
|
||||||
private void addPlayerXP(EntityPlayer player, int amount){
|
|
||||||
int experience = this.getPlayerXP(player)+amount;
|
|
||||||
player.experienceTotal = experience;
|
|
||||||
|
|
||||||
int level = 0;
|
|
||||||
while(this.getExperienceForLevel(level) <= experience){
|
|
||||||
level++;
|
|
||||||
}
|
}
|
||||||
player.experienceLevel = level-1;
|
if(level >= 21863){
|
||||||
|
return Integer.MAX_VALUE;
|
||||||
|
}
|
||||||
|
return getExperienceForLevelImpl(level);
|
||||||
|
}
|
||||||
|
|
||||||
int expForLevel = this.getExperienceForLevel(player.experienceLevel);
|
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.experienceLevel = getLevelForExperience(experience);
|
||||||
|
int expForLevel = 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;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue