2015-04-14 01:12:24 +02:00
|
|
|
package techreborn.tiles;
|
|
|
|
|
|
|
|
import ic2.api.energy.prefab.BasicSink;
|
2015-04-14 13:57:43 +02:00
|
|
|
import ic2.api.tile.IWrenchable;
|
2015-04-15 17:23:12 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2015-04-15 18:27:05 +02:00
|
|
|
import net.minecraft.inventory.Container;
|
|
|
|
import net.minecraft.inventory.InventoryCrafting;
|
2015-04-15 17:23:12 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2015-04-15 18:27:05 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
|
|
|
import techreborn.api.RollingMachineRecipe;
|
2015-04-14 20:23:16 +02:00
|
|
|
import techreborn.init.ModBlocks;
|
2015-04-14 01:12:24 +02:00
|
|
|
import techreborn.util.Inventory;
|
2015-04-15 18:27:05 +02:00
|
|
|
import techreborn.util.ItemUtils;
|
2015-04-14 01:12:24 +02:00
|
|
|
|
2015-04-15 18:27:05 +02:00
|
|
|
//TODO add tick and power bars.
|
2015-04-15 17:23:12 +02:00
|
|
|
public class TileRollingMachine extends TileMachineBase implements IWrenchable {
|
|
|
|
|
|
|
|
public BasicSink energy;
|
2015-04-15 18:27:05 +02:00
|
|
|
public Inventory inventory = new Inventory(2, "TileRollingMachine", 64);
|
|
|
|
public final InventoryCrafting craftMatrix = new InventoryCrafting(new RollingTileContainer(), 3, 3);
|
2015-04-14 01:12:24 +02:00
|
|
|
|
|
|
|
public boolean isRunning;
|
|
|
|
public int tickTime;
|
2015-04-15 18:27:05 +02:00
|
|
|
public int runTime = 250;
|
|
|
|
public ItemStack currentRecipe;
|
2015-04-15 17:23:12 +02:00
|
|
|
|
2015-04-14 01:12:24 +02:00
|
|
|
public int euTick = 5;
|
2015-04-15 17:23:12 +02:00
|
|
|
|
2015-04-15 18:27:05 +02:00
|
|
|
private static class RollingTileContainer extends Container {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canInteractWith(EntityPlayer entityplayer) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-04-15 17:23:12 +02:00
|
|
|
public TileRollingMachine() {
|
2015-04-14 01:12:24 +02:00
|
|
|
energy = new BasicSink(this, 100000, 1);
|
|
|
|
}
|
2015-04-15 17:23:12 +02:00
|
|
|
|
2015-04-14 01:12:24 +02:00
|
|
|
@Override
|
2015-04-15 17:23:12 +02:00
|
|
|
public void updateEntity() {
|
|
|
|
super.updateEntity();
|
|
|
|
energy.updateEntity();
|
2015-04-15 18:27:05 +02:00
|
|
|
if(!worldObj.isRemote){
|
|
|
|
currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, worldObj);
|
|
|
|
if(currentRecipe != null && canMake()){
|
|
|
|
if(tickTime >= runTime){
|
|
|
|
currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, worldObj);
|
|
|
|
if (currentRecipe != null) {
|
|
|
|
boolean hasCrafted = false;
|
|
|
|
if(inventory.getStackInSlot(0) == null){
|
|
|
|
inventory.setInventorySlotContents(0, currentRecipe);
|
|
|
|
tickTime = 0;
|
|
|
|
hasCrafted = true;
|
|
|
|
} else {
|
|
|
|
if(inventory.getStackInSlot(0).stackSize + currentRecipe.stackSize <= currentRecipe.getMaxStackSize()){
|
|
|
|
ItemStack stack = inventory.getStackInSlot(0);
|
|
|
|
stack.stackSize = stack.stackSize + currentRecipe.stackSize;
|
|
|
|
inventory.setInventorySlotContents(0, stack);
|
|
|
|
tickTime = 0;
|
|
|
|
hasCrafted = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(hasCrafted){
|
|
|
|
for (int i = 0; i < craftMatrix.getSizeInventory(); i++) {
|
|
|
|
craftMatrix.decrStackSize(i, 1);
|
|
|
|
}
|
|
|
|
currentRecipe = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(currentRecipe != null) {
|
|
|
|
if(energy.canUseEnergy(euTick) && tickTime < runTime){
|
|
|
|
tickTime ++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if(currentRecipe == null){
|
|
|
|
tickTime = 0;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, worldObj);
|
|
|
|
if(currentRecipe != null){
|
|
|
|
inventory.setInventorySlotContents(1, currentRecipe);
|
|
|
|
} else {
|
|
|
|
inventory.setInventorySlotContents(1, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canMake() {
|
|
|
|
if (RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, worldObj) == null){
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2015-04-14 01:12:24 +02:00
|
|
|
}
|
|
|
|
|
2015-04-15 17:23:12 +02:00
|
|
|
@Override
|
|
|
|
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, int side) {
|
|
|
|
return false;
|
|
|
|
}
|
2015-04-14 13:57:43 +02:00
|
|
|
|
2015-04-15 17:23:12 +02:00
|
|
|
@Override
|
|
|
|
public short getFacing() {
|
|
|
|
return 0;
|
|
|
|
}
|
2015-04-14 13:57:43 +02:00
|
|
|
|
2015-04-15 17:23:12 +02:00
|
|
|
@Override
|
|
|
|
public void setFacing(short facing) {
|
|
|
|
}
|
2015-04-14 13:57:43 +02:00
|
|
|
|
2015-04-15 17:23:12 +02:00
|
|
|
@Override
|
|
|
|
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-04-14 13:57:43 +02:00
|
|
|
|
2015-04-15 17:23:12 +02:00
|
|
|
@Override
|
|
|
|
public float getWrenchDropRate() {
|
|
|
|
return 1.0F;
|
|
|
|
}
|
2015-04-14 13:57:43 +02:00
|
|
|
|
2015-04-15 17:23:12 +02:00
|
|
|
@Override
|
|
|
|
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
|
|
|
|
return new ItemStack(ModBlocks.RollingMachine, 1);
|
|
|
|
}
|
2015-04-14 13:57:43 +02:00
|
|
|
|
2015-04-15 18:27:05 +02:00
|
|
|
@Override
|
|
|
|
public void readFromNBT(NBTTagCompound tagCompound) {
|
|
|
|
super.readFromNBT(tagCompound);
|
|
|
|
inventory.readFromNBT(tagCompound);
|
|
|
|
ItemUtils.readInvFromNBT(craftMatrix, "Crafting", tagCompound);
|
|
|
|
isRunning = tagCompound.getBoolean("isRunning");
|
|
|
|
tickTime = tagCompound.getInteger("tickTime");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToNBT(NBTTagCompound tagCompound) {
|
|
|
|
super.writeToNBT(tagCompound);
|
|
|
|
inventory.writeToNBT(tagCompound);
|
|
|
|
ItemUtils.writeInvToNBT(craftMatrix, "Crafting", tagCompound);
|
|
|
|
writeUpdateToNBT(tagCompound);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void writeUpdateToNBT(NBTTagCompound tagCompound) {
|
|
|
|
tagCompound.setBoolean("isRunning", isRunning);
|
|
|
|
tagCompound.setInteger("tickTime", tickTime);
|
|
|
|
}
|
2015-04-14 01:12:24 +02:00
|
|
|
}
|