2015-04-14 01:12:24 +02:00
|
|
|
package techreborn.tiles;
|
|
|
|
|
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-10-08 21:46:16 +02:00
|
|
|
import reborncore.common.IWrenchable;
|
2016-08-10 01:45:07 +02: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-10-08 21:46:16 +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;
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public TileRollingMachine() {
|
2016-08-10 01:45:07 +02:00
|
|
|
super(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public double getMaxPower() {
|
2016-08-10 01:45:07 +02:00
|
|
|
return 100000;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean canAcceptEnergy(EnumFacing direction) {
|
2016-08-10 01:45:07 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-03-25 10:47:34 +01:00
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean canProvideEnergy(EnumFacing direction) {
|
2016-08-10 01:45:07 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public double getMaxOutput() {
|
2016-08-10 01:45:07 +02:00
|
|
|
return 0;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public double getMaxInput() {
|
2016-08-10 01:45:07 +02:00
|
|
|
return 64;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public EnumPowerTier getTier() {
|
2016-08-10 01:45:07 +02:00
|
|
|
return EnumPowerTier.LOW;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public void updateEntity() {
|
2016-08-10 01:45:07 +02:00
|
|
|
super.updateEntity();
|
|
|
|
charge(2);
|
2016-11-19 13:50:08 +01:00
|
|
|
if (!world.isRemote) {
|
|
|
|
currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, world);
|
2016-10-08 21:46:16 +02:00
|
|
|
if (currentRecipe != null && canMake()) {
|
|
|
|
if (tickTime >= runTime) {
|
2016-11-19 13:50:08 +01:00
|
|
|
currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, world);
|
2016-10-08 21:46:16 +02:00
|
|
|
if (currentRecipe != null) {
|
2016-03-25 10:47:34 +01:00
|
|
|
boolean hasCrafted = false;
|
2016-11-19 17:36:13 +01:00
|
|
|
if (inventory.getStackInSlot(0) == ItemStack.EMPTY) {
|
2016-03-25 10:47:34 +01:00
|
|
|
inventory.setInventorySlotContents(0, currentRecipe);
|
|
|
|
tickTime = -1;
|
|
|
|
hasCrafted = true;
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2016-11-19 13:50:08 +01:00
|
|
|
if (inventory.getStackInSlot(0).getCount() + currentRecipe.getCount() <= currentRecipe
|
2016-10-08 21:46:16 +02:00
|
|
|
.getMaxStackSize()) {
|
2016-03-25 10:47:34 +01:00
|
|
|
ItemStack stack = inventory.getStackInSlot(0);
|
2016-11-19 15:41:00 +01:00
|
|
|
stack.setCount(stack.getCount() + currentRecipe.getCount());
|
2016-03-25 10:47:34 +01:00
|
|
|
inventory.setInventorySlotContents(0, stack);
|
|
|
|
tickTime = -1;
|
|
|
|
hasCrafted = true;
|
|
|
|
}
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
if (hasCrafted) {
|
|
|
|
for (int i = 0; i < craftMatrix.getSizeInventory(); i++) {
|
2016-03-25 10:47:34 +01:00
|
|
|
craftMatrix.decrStackSize(i, 1);
|
|
|
|
}
|
|
|
|
currentRecipe = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
if (currentRecipe != null) {
|
|
|
|
if (canUseEnergy(euTick) && tickTime < runTime) {
|
2016-03-25 10:47:34 +01:00
|
|
|
useEnergy(euTick);
|
|
|
|
tickTime++;
|
|
|
|
}
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
if (currentRecipe == null) {
|
2016-03-25 10:47:34 +01:00
|
|
|
tickTime = -1;
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2016-11-19 13:50:08 +01:00
|
|
|
currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, world);
|
2016-10-08 21:46:16 +02:00
|
|
|
if (currentRecipe != null) {
|
2016-03-25 10:47:34 +01:00
|
|
|
inventory.setInventorySlotContents(1, currentRecipe);
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2016-11-19 17:36:13 +01:00
|
|
|
inventory.setInventorySlotContents(1, ItemStack.EMPTY);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean canMake() {
|
2016-11-19 13:50:08 +01:00
|
|
|
return RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, world) != null;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public EnumFacing getFacing() {
|
2016-03-25 10:47:34 +01:00
|
|
|
return getFacingEnum();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
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
|
2016-10-08 21:46:16 +02:00
|
|
|
public float getWrenchDropRate() {
|
2016-03-25 10:47:34 +01:00
|
|
|
return 1.0F;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
|
2017-01-01 08:29:32 +01:00
|
|
|
return new ItemStack(ModBlocks.ROLLING_MACHINE, 1);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public void readFromNBT(NBTTagCompound tagCompound) {
|
2016-03-25 10:47:34 +01:00
|
|
|
super.readFromNBT(tagCompound);
|
|
|
|
ItemUtils.readInvFromNBT(craftMatrix, "Crafting", tagCompound);
|
|
|
|
isRunning = tagCompound.getBoolean("isRunning");
|
|
|
|
tickTime = tagCompound.getInteger("tickTime");
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public NBTTagCompound writeToNBT(NBTTagCompound tagCompound) {
|
2016-03-25 10:47:34 +01:00
|
|
|
super.writeToNBT(tagCompound);
|
|
|
|
ItemUtils.writeInvToNBT(craftMatrix, "Crafting", tagCompound);
|
|
|
|
writeUpdateToNBT(tagCompound);
|
2016-05-18 17:53:54 +02:00
|
|
|
return tagCompound;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public void writeUpdateToNBT(NBTTagCompound tagCompound) {
|
2016-03-25 10:47:34 +01:00
|
|
|
tagCompound.setBoolean("isRunning", isRunning);
|
|
|
|
tagCompound.setInteger("tickTime", tickTime);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public void invalidate() {
|
2016-03-25 10:47:34 +01:00
|
|
|
super.invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public void onChunkUnload() {
|
2016-03-25 10:47:34 +01:00
|
|
|
super.onChunkUnload();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-04-11 18:43:54 +02:00
|
|
|
public Inventory getInventory() {
|
|
|
|
return inventory;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
private static class RollingTileContainer extends Container {
|
2016-03-25 10:47:34 +01:00
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean canInteractWith(EntityPlayer entityplayer) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2015-04-14 01:12:24 +02:00
|
|
|
}
|