ActuallyAdditions/src/main/java/ellpeck/actuallyadditions/tile/TileEntityCompost.java

71 lines
2.3 KiB
Java
Raw Normal View History

2015-03-07 12:51:28 +01:00
package ellpeck.actuallyadditions.tile;
2015-03-07 12:51:28 +01:00
import ellpeck.actuallyadditions.config.ConfigValues;
import ellpeck.actuallyadditions.items.InitItems;
import ellpeck.actuallyadditions.items.ItemFertilizer;
import ellpeck.actuallyadditions.items.ItemMisc;
import ellpeck.actuallyadditions.items.metalists.TheMiscItems;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class TileEntityCompost extends TileEntityInventoryBase{
2015-04-02 12:06:42 +02:00
public final int amountNeededToConvert = ConfigValues.compostAmountNeededToConvert;
public final int conversionTimeNeeded = ConfigValues.compostConversionTimeNeeded;
public int conversionTime;
public TileEntityCompost(){
2015-04-19 01:50:02 +02:00
super(1, "compost");
}
@Override
public void updateEntity(){
if(!worldObj.isRemote){
2015-03-19 21:27:56 +01:00
boolean theFlag = this.conversionTime > 0;
if(this.slots[0] != null && !(this.slots[0].getItem() instanceof ItemFertilizer) && this.slots[0].stackSize >= this.amountNeededToConvert){
this.conversionTime++;
if(this.conversionTime >= this.conversionTimeNeeded){
this.slots[0] = new ItemStack(InitItems.itemFertilizer, this.amountNeededToConvert);
this.conversionTime = 0;
}
}
2015-03-19 21:27:56 +01:00
if(theFlag != this.conversionTime > 0){
this.markDirty();
}
}
}
@Override
public int getInventoryStackLimit(){
return this.amountNeededToConvert;
}
@Override
public void writeToNBT(NBTTagCompound compound){
super.writeToNBT(compound);
compound.setInteger("ConversionTime", this.conversionTime);
}
@Override
public void readFromNBT(NBTTagCompound compound){
super.readFromNBT(compound);
this.conversionTime = compound.getInteger("ConversionTime");
}
@Override
public boolean isItemValidForSlot(int i, ItemStack stack){
return stack.getItem() instanceof ItemMisc && stack.getItemDamage() == TheMiscItems.MASHED_FOOD.ordinal();
}
@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 stack.getItem() instanceof ItemFertilizer;
}
}