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
|
|
|
|
*
|
2016-05-16 22:54:42 +02:00
|
|
|
* © 2015-2016 Ellpeck
|
2015-08-29 14:33:25 +02:00
|
|
|
*/
|
|
|
|
|
2016-01-05 04:47:35 +01:00
|
|
|
package de.ellpeck.actuallyadditions.mod.tile;
|
2015-02-09 17:25:05 +01:00
|
|
|
|
2016-05-20 17:55:33 +02:00
|
|
|
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
|
|
|
|
import de.ellpeck.actuallyadditions.api.recipe.CompostRecipe;
|
2015-02-09 17:25:05 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2016-01-07 23:42:42 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2015-02-09 17:25:05 +01:00
|
|
|
|
2015-02-17 16:15:16 +01:00
|
|
|
public class TileEntityCompost extends TileEntityInventoryBase{
|
2015-02-09 17:25:05 +01:00
|
|
|
|
2015-12-01 19:48:09 +01:00
|
|
|
public int conversionTime;
|
2015-11-28 19:02:01 +01:00
|
|
|
|
2015-02-09 17:25:05 +01:00
|
|
|
public TileEntityCompost(){
|
2015-04-19 01:50:02 +02:00
|
|
|
super(1, "compost");
|
2015-02-09 17:25:05 +01:00
|
|
|
}
|
|
|
|
|
2016-06-01 00:39:35 +02:00
|
|
|
public static CompostRecipe getRecipeForInput(ItemStack input){
|
|
|
|
if(input != null){
|
|
|
|
for(CompostRecipe recipe : ActuallyAdditionsAPI.COMPOST_RECIPES){
|
|
|
|
if(input.isItemEqual(recipe.input)){
|
|
|
|
return recipe;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2016-02-01 20:32:49 +01:00
|
|
|
@Override
|
2016-07-02 15:01:46 +02:00
|
|
|
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
|
|
|
|
super.writeSyncableNBT(compound, type);
|
|
|
|
if(type != NBTType.SAVE_BLOCK){
|
|
|
|
compound.setInteger("ConversionTime", this.conversionTime);
|
|
|
|
}
|
2016-02-01 20:32:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean shouldSyncSlots(){
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-07-02 15:01:46 +02:00
|
|
|
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
|
|
|
|
super.readSyncableNBT(compound, type);
|
|
|
|
if(type != NBTType.SAVE_BLOCK){
|
|
|
|
this.conversionTime = compound.getInteger("ConversionTime");
|
|
|
|
}
|
2016-02-01 20:32:49 +01:00
|
|
|
}
|
|
|
|
|
2015-02-20 22:45:33 +01:00
|
|
|
@Override
|
2015-02-17 16:15:16 +01:00
|
|
|
public void updateEntity(){
|
2015-11-18 23:11:24 +01:00
|
|
|
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;
|
2016-05-20 17:55:33 +02:00
|
|
|
|
|
|
|
if(this.slots[0] != null){
|
|
|
|
CompostRecipe recipe = getRecipeForInput(this.slots[0]);
|
|
|
|
if(recipe != null && this.slots[0].isItemEqual(recipe.input) && this.slots[0].stackSize >= recipe.input.stackSize){
|
|
|
|
this.conversionTime++;
|
|
|
|
if(this.conversionTime >= 3000){
|
|
|
|
this.slots[0] = recipe.output.copy();
|
|
|
|
this.conversionTime = 0;
|
|
|
|
this.markDirty();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else{
|
2015-02-09 17:25:05 +01:00
|
|
|
this.conversionTime = 0;
|
|
|
|
}
|
|
|
|
}
|
2016-05-20 17:55:33 +02:00
|
|
|
|
2015-03-19 21:27:56 +01:00
|
|
|
if(theFlag != this.conversionTime > 0){
|
|
|
|
this.markDirty();
|
|
|
|
}
|
2015-02-09 17:25:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-07 02:23:31 +01:00
|
|
|
@Override
|
2016-05-29 23:49:35 +02:00
|
|
|
public boolean isItemValidForSlot(int i, ItemStack stack){
|
2016-05-20 17:55:33 +02:00
|
|
|
return getRecipeForInput(stack) != null;
|
2015-03-07 02:23:31 +01:00
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-06-03 22:16:23 +02:00
|
|
|
@Override
|
|
|
|
public int getInventoryStackLimit(){
|
|
|
|
if(this.slots[0] != null){
|
|
|
|
CompostRecipe recipe = getRecipeForInput(this.slots[0]);
|
|
|
|
if(recipe != null && recipe.input != null){
|
|
|
|
return recipe.input.stackSize;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.getInventoryStackLimit();
|
|
|
|
}
|
|
|
|
|
2015-03-07 02:23:31 +01:00
|
|
|
@Override
|
2016-05-29 23:49:35 +02:00
|
|
|
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
|
2016-02-01 17:49:55 +01:00
|
|
|
return this.isItemValidForSlot(slot, stack);
|
2015-03-07 02:23:31 +01:00
|
|
|
}
|
2016-02-01 17:43:14 +01:00
|
|
|
|
|
|
|
@Override
|
2016-05-29 23:49:35 +02:00
|
|
|
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
|
2016-05-20 17:55:33 +02:00
|
|
|
return getRecipeForInput(stack) == null;
|
|
|
|
}
|
2015-02-09 17:25:05 +01:00
|
|
|
}
|