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

95 lines
2.9 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
2016-01-03 16:05:51 +01:00
* http://ellpeck.de/actaddlicense/
2015-08-29 14:33:25 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2016-01-03 16:05:51 +01:00
* © 2016 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.tile;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.items.ItemFertilizer;
import de.ellpeck.actuallyadditions.mod.items.ItemMisc;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
public class TileEntityCompost extends TileEntityInventoryBase{
public static final int AMOUNT = 10;
2015-12-01 19:48:09 +01:00
public int conversionTime;
public TileEntityCompost(){
2015-04-19 01:50:02 +02:00
super(1, "compost");
}
@Override
public void writeSyncableNBT(NBTTagCompound compound, boolean sync){
super.writeSyncableNBT(compound, sync);
compound.setInteger("ConversionTime", this.conversionTime);
}
2016-02-20 15:23:03 +01:00
public float getAmount(){
return this.getStackInSlot(0) != null ? this.getStackInSlot(0).stackSize : 0F;
}
@Override
public boolean shouldSyncSlots(){
return true;
}
@Override
public void readSyncableNBT(NBTTagCompound compound, boolean sync){
super.readSyncableNBT(compound, sync);
this.conversionTime = compound.getInteger("ConversionTime");
}
@Override
public void updateEntity(){
super.updateEntity();
2016-05-02 17:46:53 +02:00
if(!this.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 >= AMOUNT){
this.conversionTime++;
if(this.conversionTime >= 2000){
this.slots[0] = new ItemStack(InitItems.itemFertilizer, AMOUNT);
this.conversionTime = 0;
}
}
2015-03-19 21:27:56 +01:00
if(theFlag != this.conversionTime > 0){
this.markDirty();
}
}
}
2015-12-19 10:30:39 +01:00
@Override
public int getInventoryStackLimit(){
return AMOUNT;
}
@Override
2016-02-01 17:49:55 +01:00
public boolean isItemValidForSlot(int i, ItemStack stack){
return stack.getItem() instanceof ItemMisc && stack.getItemDamage() == TheMiscItems.MASHED_FOOD.ordinal();
}
2015-12-19 10:30:39 +01:00
@Override
2016-02-01 17:49:55 +01:00
public void markDirty(){
super.markDirty();
this.sendUpdate();
2015-12-19 10:30:39 +01:00
}
@Override
2016-02-01 17:49:55 +01:00
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
2016-02-01 17:49:55 +01:00
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
return stack.getItem() instanceof ItemFertilizer;
}
}