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

97 lines
3 KiB
Java
Raw Normal View History

2015-08-29 14:33:25 +02:00
/*
2016-05-16 22:52:27 +02:00
* This file ("TileEntityCompost.java") is part of the Actually Additions mod for Minecraft.
2015-08-29 14:33:25 +02:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2015-08-29 14:33:25 +02:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2017-01-01 16:23:26 +01:00
* © 2015-2017 Ellpeck
2015-08-29 14:33:25 +02:00
*/
2016-01-05 04:47:35 +01:00
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.recipe.CompostRecipe;
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
public class TileEntityCompost extends TileEntityInventoryBase{
2015-12-01 19:48:09 +01:00
public int conversionTime;
public TileEntityCompost(){
2015-04-19 01:50:02 +02:00
super(1, "compost");
}
2016-06-01 00:39:35 +02:00
public static CompostRecipe getRecipeForInput(ItemStack input){
if(StackUtil.isValid(input)){
2016-06-01 00:39:35 +02:00
for(CompostRecipe recipe : ActuallyAdditionsAPI.COMPOST_RECIPES){
2017-03-08 20:06:55 +01:00
if(input.isItemEqual(recipe.input)){
2016-06-01 00:39:35 +02:00
return recipe;
}
}
}
return null;
}
@Override
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
super.writeSyncableNBT(compound, type);
if(type != NBTType.SAVE_BLOCK){
compound.setInteger("ConversionTime", this.conversionTime);
}
}
@Override
public boolean shouldSyncSlots(){
return true;
}
@Override
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
super.readSyncableNBT(compound, type);
if(type != NBTType.SAVE_BLOCK){
this.conversionTime = compound.getInteger("ConversionTime");
}
}
@Override
public void updateEntity(){
super.updateEntity();
2016-11-26 21:32:27 +01:00
if(!this.world.isRemote){
2015-03-19 21:27:56 +01:00
boolean theFlag = this.conversionTime > 0;
if(StackUtil.isValid(this.slots.getStackInSlot(0))){
CompostRecipe recipe = getRecipeForInput(this.slots.getStackInSlot(0));
if(recipe != null){
this.conversionTime++;
if(this.conversionTime >= 3000){
ItemStack output = recipe.output.copy();
this.slots.setStackInSlot(0, StackUtil.setStackSize(output, StackUtil.getStackSize(this.slots.getStackInSlot(0))));
this.conversionTime = 0;
this.markDirty();
}
}
else{
this.conversionTime = 0;
}
}
2015-03-19 21:27:56 +01:00
if(theFlag != this.conversionTime > 0){
this.markDirty();
}
}
}
@Override
public boolean isItemValidForSlot(int i, ItemStack stack){
return getRecipeForInput(stack) != null;
}
@Override
public boolean canExtractItem(int slot, ItemStack stack){
return getRecipeForInput(stack) == null;
}
}