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

91 lines
3.2 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
* This file ("TileEntityCompost.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-03-07 12:51:28 +01:00
package ellpeck.actuallyadditions.tile;
import ellpeck.actuallyadditions.config.values.ConfigIntValues;
2015-03-07 12:51:28 +01:00
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{
public int conversionTime;
public TileEntityCompost(){
2015-04-19 01:50:02 +02:00
super(1, "compost");
}
@Override
public void updateEntity(){
if(!worldObj.isRemote){
if(this.slots[0] != null && this.slots[0].stackSize > 0){
2015-10-02 16:48:01 +02:00
int toSet = this.slots[0].stackSize+(this.slots[0].getItem() instanceof ItemFertilizer ? 1 : 0);
if(worldObj.getBlockMetadata(xCoord, yCoord, zCoord) != toSet){
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, toSet, 2);
}
2015-05-25 17:00:54 +02:00
}
else{
2015-10-02 16:48:01 +02:00
if(worldObj.getBlockMetadata(xCoord, yCoord, zCoord) != 0){
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, 0, 2);
}
}
2015-03-19 21:27:56 +01:00
boolean theFlag = this.conversionTime > 0;
2015-08-15 20:41:45 +02:00
if(this.slots[0] != null && !(this.slots[0].getItem() instanceof ItemFertilizer) && this.slots[0].stackSize >= ConfigIntValues.COMPOST_AMOUNT.getValue()){
this.conversionTime++;
2015-08-15 20:41:45 +02:00
if(this.conversionTime >= ConfigIntValues.COMPOST_TIME.getValue()){
this.slots[0] = new ItemStack(InitItems.itemFertilizer, ConfigIntValues.COMPOST_AMOUNT.getValue());
this.conversionTime = 0;
}
}
2015-03-19 21:27:56 +01:00
if(theFlag != this.conversionTime > 0){
this.markDirty();
}
}
}
@Override
public void readFromNBT(NBTTagCompound compound){
super.readFromNBT(compound);
this.conversionTime = compound.getInteger("ConversionTime");
}
2015-10-03 22:13:57 +02:00
@Override
public void writeToNBT(NBTTagCompound compound){
super.writeToNBT(compound);
compound.setInteger("ConversionTime", this.conversionTime);
}
2015-10-03 10:19:40 +02:00
@Override
public int getInventoryStackLimit(){
return ConfigIntValues.COMPOST_AMOUNT.getValue();
}
@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;
}
}