-
-
Save Larsg310/0bafea64ccac7280f32158dc52ead2a2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package wexalian.mods.minetech.tileentity; | |
import net.minecraft.item.ItemStack; | |
import net.minecraft.nbt.NBTTagCompound; | |
import net.minecraft.tileentity.TileEntity; | |
import net.minecraft.util.ITickable; | |
import net.minecraftforge.items.ItemStackHandler; | |
import wexalian.mods.minetech.recipe.GrindstoneRecipes; | |
import javax.annotation.Nonnull; | |
import javax.annotation.Nullable; | |
public class TileEntityGrindstone extends TileEntity implements ITickable | |
{ | |
public static final int MAX_PROGRESS = 160; | |
public ItemStackHandler inventory = new ItemStackHandler(8) | |
{ | |
@Override | |
public int getSlotLimit(int slot) | |
{ | |
return 1; | |
} | |
}; | |
private int progress = 0; | |
@Override | |
public void update() | |
{ | |
processTick(); | |
if (canFinish()) | |
{ | |
processFinish(); | |
} | |
} | |
private void processTick() | |
{ | |
progress++; | |
} | |
private boolean canFinish() | |
{ | |
return progress >= MAX_PROGRESS; | |
} | |
private void processFinish() | |
{ | |
progress -= MAX_PROGRESS; | |
for (int slot = 0; slot < inventory.getSlots(); slot++) | |
{ | |
ItemStack stack = GrindstoneRecipes.instance().getGrindingResult(inventory.getStackInSlot(slot)).copy(); | |
if (!stack.isEmpty()) inventory.setStackInSlot(slot, stack); | |
} | |
} | |
@Nonnull | |
@Override | |
public NBTTagCompound writeToNBT(NBTTagCompound nbt) | |
{ | |
super.writeToNBT(nbt); | |
nbt.setTag("inventory", inventory.serializeNBT()); | |
nbt.setInteger("progress", progress); | |
return nbt; | |
} | |
@Override | |
public void readFromNBT(NBTTagCompound nbt) | |
{ | |
super.readFromNBT(nbt); | |
inventory.deserializeNBT(nbt.getCompoundTag("inventory")); | |
progress = nbt.getInteger("progress"); | |
} | |
public int getProgress() | |
{ | |
return progress; | |
} | |
public void setProgress(int progress) | |
{ | |
this.progress = progress; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment