2015-04-14 01:12:24 +02:00
|
|
|
package techreborn.tiles;
|
|
|
|
|
2016-04-11 18:50:00 +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;
|
2015-11-23 15:45:16 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2016-03-08 18:34:04 +01:00
|
|
|
import reborncore.api.power.EnumPowerTier;
|
2016-04-11 18:43:54 +02:00
|
|
|
import reborncore.api.tile.IInventoryProvider;
|
2016-02-24 09:18:21 +01:00
|
|
|
import reborncore.common.powerSystem.TilePowerAcceptor;
|
2015-11-08 13:15:45 +01:00
|
|
|
import reborncore.common.util.Inventory;
|
|
|
|
import reborncore.common.util.ItemUtils;
|
2015-04-15 18:27:05 +02:00
|
|
|
import techreborn.api.RollingMachineRecipe;
|
2015-04-14 20:23:16 +02:00
|
|
|
import techreborn.init.ModBlocks;
|
2015-04-14 01:12:24 +02:00
|
|
|
|
2015-04-15 18:27:05 +02:00
|
|
|
//TODO add tick and power bars.
|
2016-04-11 18:43:54 +02:00
|
|
|
public class TileRollingMachine extends TilePowerAcceptor implements IWrenchable,IInventoryProvider
|
2016-03-25 10:47:34 +01:00
|
|
|
{
|
|
|
|
|
|
|
|
public final InventoryCrafting craftMatrix = new InventoryCrafting(new RollingTileContainer(), 3, 3);
|
|
|
|
public Inventory inventory = new Inventory(3, "TileRollingMachine", 64, this);
|
|
|
|
public boolean isRunning;
|
|
|
|
public int tickTime;
|
|
|
|
public int runTime = 250;
|
|
|
|
public ItemStack currentRecipe;
|
|
|
|
|
|
|
|
public int euTick = 5;
|
|
|
|
|
|
|
|
public TileRollingMachine()
|
|
|
|
{
|
|
|
|
super(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getMaxPower()
|
|
|
|
{
|
|
|
|
return 100000;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canAcceptEnergy(EnumFacing direction)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canProvideEnergy(EnumFacing direction)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getMaxOutput()
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getMaxInput()
|
|
|
|
{
|
|
|
|
return 64;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumPowerTier getTier()
|
|
|
|
{
|
|
|
|
return EnumPowerTier.LOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateEntity()
|
|
|
|
{
|
|
|
|
super.updateEntity();
|
|
|
|
charge(2);
|
|
|
|
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 = -1;
|
|
|
|
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 = -1;
|
|
|
|
hasCrafted = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hasCrafted)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < craftMatrix.getSizeInventory(); i++)
|
|
|
|
{
|
|
|
|
craftMatrix.decrStackSize(i, 1);
|
|
|
|
}
|
|
|
|
currentRecipe = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentRecipe != null)
|
|
|
|
{
|
|
|
|
if (canUseEnergy(euTick) && tickTime < runTime)
|
|
|
|
{
|
|
|
|
useEnergy(euTick);
|
|
|
|
tickTime++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentRecipe == null)
|
|
|
|
{
|
|
|
|
tickTime = -1;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, worldObj);
|
|
|
|
if (currentRecipe != null)
|
|
|
|
{
|
|
|
|
inventory.setInventorySlotContents(1, currentRecipe);
|
|
|
|
} else
|
|
|
|
{
|
|
|
|
inventory.setInventorySlotContents(1, null);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean canMake()
|
|
|
|
{
|
2016-04-03 15:34:39 +02:00
|
|
|
return RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, worldObj) != null;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public EnumFacing getFacing()
|
|
|
|
{
|
|
|
|
return getFacingEnum();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean wrenchCanRemove(EntityPlayer entityPlayer)
|
|
|
|
{
|
2016-04-03 15:34:39 +02:00
|
|
|
return entityPlayer.isSneaking();
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public float getWrenchDropRate()
|
|
|
|
{
|
|
|
|
return 1.0F;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getWrenchDrop(EntityPlayer entityPlayer)
|
|
|
|
{
|
|
|
|
return new ItemStack(ModBlocks.RollingMachine, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void readFromNBT(NBTTagCompound tagCompound)
|
|
|
|
{
|
|
|
|
super.readFromNBT(tagCompound);
|
|
|
|
ItemUtils.readInvFromNBT(craftMatrix, "Crafting", tagCompound);
|
|
|
|
isRunning = tagCompound.getBoolean("isRunning");
|
|
|
|
tickTime = tagCompound.getInteger("tickTime");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void writeToNBT(NBTTagCompound tagCompound)
|
|
|
|
{
|
|
|
|
super.writeToNBT(tagCompound);
|
|
|
|
ItemUtils.writeInvToNBT(craftMatrix, "Crafting", tagCompound);
|
|
|
|
writeUpdateToNBT(tagCompound);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void writeUpdateToNBT(NBTTagCompound tagCompound)
|
|
|
|
{
|
|
|
|
tagCompound.setBoolean("isRunning", isRunning);
|
|
|
|
tagCompound.setInteger("tickTime", tickTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void invalidate()
|
|
|
|
{
|
|
|
|
super.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onChunkUnload()
|
|
|
|
{
|
|
|
|
super.onChunkUnload();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-04-11 18:43:54 +02:00
|
|
|
public Inventory getInventory() {
|
|
|
|
return inventory;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private static class RollingTileContainer extends Container
|
|
|
|
{
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean canInteractWith(EntityPlayer entityplayer)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-04-14 01:12:24 +02:00
|
|
|
}
|