2015-08-29 14:33:25 +02:00
|
|
|
|
/*
|
|
|
|
|
* This file ("TileEntityXPSolidifier.java") is part of the Actually Additions Mod for Minecraft.
|
|
|
|
|
* It is created and owned by Ellpeck and distributed
|
|
|
|
|
* under the Actually Additions License to be found at
|
|
|
|
|
* http://github.com/Ellpeck/ActuallyAdditions/blob/master/README.md
|
|
|
|
|
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
|
|
|
|
|
*
|
|
|
|
|
* <EFBFBD> 2015 Ellpeck
|
|
|
|
|
*/
|
|
|
|
|
|
2015-07-13 23:44:33 +02:00
|
|
|
|
package ellpeck.actuallyadditions.tile;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import ellpeck.actuallyadditions.items.InitItems;
|
|
|
|
|
import ellpeck.actuallyadditions.items.ItemSpecialDrop;
|
|
|
|
|
import ellpeck.actuallyadditions.items.metalists.TheSpecialDrops;
|
|
|
|
|
import ellpeck.actuallyadditions.network.gui.IButtonReactor;
|
2015-07-15 00:17:21 +02:00
|
|
|
|
import ellpeck.actuallyadditions.network.sync.IPacketSyncerToClient;
|
|
|
|
|
import ellpeck.actuallyadditions.network.sync.PacketSyncerToClient;
|
2015-07-13 23:44:33 +02:00
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
|
import net.minecraft.item.ItemStack;
|
2015-07-15 00:17:21 +02:00
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2015-07-13 23:44:33 +02:00
|
|
|
|
|
2015-07-15 00:17:21 +02:00
|
|
|
|
public class TileEntityXPSolidifier extends TileEntityInventoryBase implements IButtonReactor, IPacketSyncerToClient{
|
|
|
|
|
|
|
|
|
|
public short amount;
|
|
|
|
|
private short lastAmount;
|
2015-10-03 10:16:18 +02:00
|
|
|
|
private int[] buttonAmounts = new int[]{1, 5, 10, 20, 30, 40, 50, 64, -999};
|
2015-07-13 23:44:33 +02:00
|
|
|
|
|
|
|
|
|
public TileEntityXPSolidifier(){
|
2015-07-15 00:17:21 +02:00
|
|
|
|
super(1, "xpSolidifier");
|
2015-07-13 23:44:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2015-07-15 00:17:21 +02:00
|
|
|
|
public void updateEntity(){
|
|
|
|
|
if(!worldObj.isRemote){
|
|
|
|
|
if(this.amount > 0){
|
|
|
|
|
if(this.slots[0] == null){
|
|
|
|
|
int toSet = this.amount > 64 ? 64 : this.amount;
|
|
|
|
|
this.slots[0] = new ItemStack(InitItems.itemSpecialDrop, toSet, TheSpecialDrops.SOLIDIFIED_EXPERIENCE.ordinal());
|
|
|
|
|
this.amount -= toSet;
|
|
|
|
|
}
|
|
|
|
|
else if(this.slots[0].stackSize < 64){
|
|
|
|
|
int needed = 64-this.slots[0].stackSize;
|
|
|
|
|
int toAdd = this.amount > needed ? needed : this.amount;
|
|
|
|
|
this.slots[0].stackSize += toAdd;
|
|
|
|
|
this.amount -= toAdd;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(this.lastAmount != this.amount){
|
|
|
|
|
this.lastAmount = this.amount;
|
|
|
|
|
this.sendUpdate();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void readFromNBT(NBTTagCompound compound){
|
|
|
|
|
super.readFromNBT(compound);
|
|
|
|
|
this.amount = compound.getShort("Amount");
|
2015-07-13 23:44:33 +02:00
|
|
|
|
}
|
|
|
|
|
|
2015-10-03 22:13:57 +02:00
|
|
|
|
@Override
|
|
|
|
|
public void writeToNBT(NBTTagCompound compound){
|
|
|
|
|
super.writeToNBT(compound);
|
|
|
|
|
compound.setShort("Amount", this.amount);
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-13 23:44:33 +02:00
|
|
|
|
@Override
|
|
|
|
|
public boolean isItemValidForSlot(int i, ItemStack stack){
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canInsertItem(int slot, ItemStack stack, int side){
|
|
|
|
|
return this.isItemValidForSlot(slot, stack);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public boolean canExtractItem(int slot, ItemStack stack, int side){
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onButtonPressed(int buttonID, EntityPlayer player){
|
2015-07-15 00:17:21 +02:00
|
|
|
|
if(buttonID < this.buttonAmounts.length){
|
2015-07-15 07:50:33 +02:00
|
|
|
|
if(this.getPlayerXP(player) > 0){
|
2015-07-15 09:28:01 +02:00
|
|
|
|
int xp = this.buttonAmounts[buttonID] == -999 ? this.getPlayerXP(player)/ItemSpecialDrop.SOLID_XP_AMOUNT : this.buttonAmounts[buttonID];
|
|
|
|
|
if(this.amount < Short.MAX_VALUE-xp && this.getPlayerXP(player) >= ItemSpecialDrop.SOLID_XP_AMOUNT*xp){
|
|
|
|
|
this.addPlayerXP(player, -(ItemSpecialDrop.SOLID_XP_AMOUNT*xp));
|
2015-10-03 10:16:18 +02:00
|
|
|
|
if(!worldObj.isRemote){
|
|
|
|
|
this.amount += xp;
|
|
|
|
|
}
|
2015-07-15 01:53:04 +02:00
|
|
|
|
}
|
2015-07-15 00:17:21 +02:00
|
|
|
|
}
|
2015-07-13 23:44:33 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-09 23:06:43 +02:00
|
|
|
|
/**
|
|
|
|
|
* Gets the Player's XP
|
|
|
|
|
* (Excerpted from OpenBlocks' XP system with permission, thanks guys!)
|
2015-10-02 16:48:01 +02:00
|
|
|
|
*
|
2015-08-09 23:06:43 +02:00
|
|
|
|
* @param player The Player
|
|
|
|
|
* @return The XP
|
|
|
|
|
*/
|
2015-07-13 23:44:33 +02:00
|
|
|
|
private int getPlayerXP(EntityPlayer player){
|
|
|
|
|
return (int)(this.getExperienceForLevel(player.experienceLevel)+(player.experience*player.xpBarCap()));
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-09 23:06:43 +02:00
|
|
|
|
/**
|
|
|
|
|
* Adds (or removes, if negative) a certain amount of XP from a player
|
|
|
|
|
* (Excerpted from OpenBlocks' XP system with permission, thanks guys!)
|
2015-10-02 16:48:01 +02:00
|
|
|
|
*
|
2015-08-09 23:06:43 +02:00
|
|
|
|
* @param player The Player
|
|
|
|
|
* @param amount The Amount
|
|
|
|
|
*/
|
2015-07-13 23:44:33 +02:00
|
|
|
|
private void addPlayerXP(EntityPlayer player, int amount){
|
|
|
|
|
int experience = getPlayerXP(player)+amount;
|
|
|
|
|
player.experienceTotal = experience;
|
|
|
|
|
|
|
|
|
|
int level = 0;
|
|
|
|
|
while(getExperienceForLevel(level) <= experience){
|
|
|
|
|
level++;
|
|
|
|
|
}
|
|
|
|
|
player.experienceLevel = level-1;
|
|
|
|
|
|
|
|
|
|
int expForLevel = this.getExperienceForLevel(player.experienceLevel);
|
|
|
|
|
player.experience = (float)(experience-expForLevel)/(float)player.xpBarCap();
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-09 23:06:43 +02:00
|
|
|
|
/**
|
|
|
|
|
* Gets the amount of experience a certain level contains
|
|
|
|
|
* (Excerpted from OpenBlocks' XP system with permission, thanks guys!)
|
2015-10-02 16:48:01 +02:00
|
|
|
|
*
|
2015-08-09 23:06:43 +02:00
|
|
|
|
* @param level The Level in question
|
|
|
|
|
* @return The total XP the level has
|
|
|
|
|
*/
|
2015-07-13 23:44:33 +02:00
|
|
|
|
private int getExperienceForLevel(int level){
|
2015-07-15 07:50:33 +02:00
|
|
|
|
if(level > 0){
|
2015-10-02 16:48:01 +02:00
|
|
|
|
if(level > 0 && level < 16){
|
|
|
|
|
return level*17;
|
|
|
|
|
}
|
|
|
|
|
else if(level > 15 && level < 31){
|
|
|
|
|
return (int)(1.5*Math.pow(level, 2)-29.5*level+360);
|
|
|
|
|
}
|
|
|
|
|
else{
|
|
|
|
|
return (int)(3.5*Math.pow(level, 2)-151.5*level+2220);
|
|
|
|
|
}
|
2015-07-13 23:44:33 +02:00
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
2015-07-15 00:17:21 +02:00
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int[] getValues(){
|
|
|
|
|
return new int[]{this.amount};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void setValues(int[] values){
|
|
|
|
|
this.amount = (short)values[0];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void sendUpdate(){
|
|
|
|
|
PacketSyncerToClient.sendPacket(this);
|
|
|
|
|
}
|
2015-07-13 23:44:33 +02:00
|
|
|
|
}
|