2015-04-14 01:12:24 +02:00
|
|
|
package techreborn.tiles;
|
|
|
|
|
2016-02-20 18:06:46 +01: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;
|
2015-06-07 10:38:12 +02:00
|
|
|
import net.minecraft.inventory.IInventory;
|
2015-04-15 18:27:05 +02:00
|
|
|
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;
|
2015-11-23 21:27:06 +01:00
|
|
|
import net.minecraft.util.IChatComponent;
|
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;
|
2016-02-20 17:59:31 +01:00
|
|
|
import reborncore.common.powerSystem.TilePowerAcceptor;
|
2015-04-14 01:12:24 +02:00
|
|
|
|
2015-04-15 18:27:05 +02:00
|
|
|
//TODO add tick and power bars.
|
2015-11-16 12:17:36 +01:00
|
|
|
public class TileRollingMachine extends TilePowerAcceptor implements IWrenchable, IInventory {
|
2015-04-15 17:23:12 +02:00
|
|
|
|
2015-11-23 21:27:06 +01:00
|
|
|
public Inventory inventory = new Inventory(3, "TileRollingMachine", 64, this);
|
2015-08-09 12:05:32 +02:00
|
|
|
public final InventoryCrafting craftMatrix = new InventoryCrafting(
|
|
|
|
new RollingTileContainer(), 3, 3);
|
2015-04-24 15:20:09 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
public boolean isRunning;
|
|
|
|
public int tickTime;
|
|
|
|
public int runTime = 250;
|
|
|
|
public ItemStack currentRecipe;
|
2015-04-24 15:20:09 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
public int euTick = 5;
|
2015-04-24 15:20:09 +02:00
|
|
|
|
2015-07-23 13:52:51 +02:00
|
|
|
@Override
|
|
|
|
public double getMaxPower() {
|
|
|
|
return 100000;
|
|
|
|
}
|
2015-11-18 20:41:37 +01:00
|
|
|
|
2015-07-23 13:52:51 +02:00
|
|
|
|
|
|
|
@Override
|
2015-11-23 15:45:16 +01:00
|
|
|
public boolean canAcceptEnergy(EnumFacing direction) {
|
2015-07-23 13:52:51 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-23 15:45:16 +01:00
|
|
|
public boolean canProvideEnergy(EnumFacing direction) {
|
2015-07-23 13:52:51 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getMaxOutput() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getMaxInput() {
|
|
|
|
return 64;
|
|
|
|
}
|
|
|
|
|
|
|
|
private static class RollingTileContainer extends Container {
|
2015-04-24 15:20:09 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
@Override
|
|
|
|
public boolean canInteractWith(EntityPlayer entityplayer) {
|
|
|
|
return true;
|
|
|
|
}
|
2015-04-24 15:20:09 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
2015-04-24 15:20:09 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
public TileRollingMachine() {
|
2015-07-23 13:52:51 +02:00
|
|
|
super(1);
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void updateEntity() {
|
|
|
|
super.updateEntity();
|
2015-11-13 17:29:35 +01:00
|
|
|
charge(2);
|
2015-08-09 12:05:32 +02:00
|
|
|
if (!worldObj.isRemote) {
|
|
|
|
currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(
|
|
|
|
craftMatrix, worldObj);
|
|
|
|
if (currentRecipe != null && canMake()) {
|
|
|
|
if (tickTime >= runTime) {
|
2015-11-18 20:41:37 +01:00
|
|
|
currentRecipe = RollingMachineRecipe.instance.findMatchingRecipe(craftMatrix, worldObj);
|
2015-08-09 12:05:32 +02:00
|
|
|
if (currentRecipe != null) {
|
|
|
|
boolean hasCrafted = false;
|
|
|
|
if (inventory.getStackInSlot(0) == null) {
|
|
|
|
inventory
|
|
|
|
.setInventorySlotContents(0, currentRecipe);
|
2015-11-18 20:41:37 +01:00
|
|
|
tickTime = -1;
|
2015-08-09 12:05:32 +02:00
|
|
|
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);
|
2015-11-18 20:41:37 +01:00
|
|
|
tickTime = -1;
|
2015-08-09 12:05:32 +02:00
|
|
|
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) {
|
2015-07-23 13:52:51 +02:00
|
|
|
useEnergy(euTick);
|
2015-08-09 12:05:32 +02:00
|
|
|
tickTime++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (currentRecipe == null) {
|
2015-11-18 20:41:37 +01:00
|
|
|
tickTime = -1;
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
} 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 11:46:13 +01:00
|
|
|
public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
|
2015-08-09 12:05:32 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-01-07 11:46:13 +01:00
|
|
|
public EnumFacing getFacing() {
|
|
|
|
return getFacingEnum();
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
|
|
|
|
if (entityPlayer.isSneaking()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@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);
|
|
|
|
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-06-06 22:41:41 +02:00
|
|
|
|
|
|
|
@Override
|
2015-08-09 12:05:32 +02:00
|
|
|
public void invalidate() {
|
2015-06-06 22:41:41 +02:00
|
|
|
super.invalidate();
|
|
|
|
}
|
2015-08-09 12:05:32 +02:00
|
|
|
|
2015-06-06 22:41:41 +02:00
|
|
|
@Override
|
2015-08-09 12:05:32 +02:00
|
|
|
public void onChunkUnload() {
|
2015-06-06 22:41:41 +02:00
|
|
|
super.onChunkUnload();
|
|
|
|
}
|
2015-06-07 10:38:12 +02:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
@Override
|
|
|
|
public int getSizeInventory() {
|
|
|
|
return inventory.getSizeInventory();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack getStackInSlot(int slot) {
|
|
|
|
return inventory.getStackInSlot(slot);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ItemStack decrStackSize(int slot, int amount) {
|
|
|
|
return inventory.decrStackSize(slot, amount);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-29 10:52:45 +01:00
|
|
|
public ItemStack removeStackFromSlot(int slot) {
|
|
|
|
return inventory.removeStackFromSlot(slot);
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setInventorySlotContents(int slot, ItemStack stack) {
|
|
|
|
inventory.setInventorySlotContents(slot, stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-23 21:27:06 +01:00
|
|
|
public void openInventory(EntityPlayer player) {
|
|
|
|
inventory.openInventory(player);
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-23 21:27:06 +01:00
|
|
|
public void closeInventory(EntityPlayer player) {
|
|
|
|
inventory.closeInventory(player);
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
2015-11-23 21:27:06 +01:00
|
|
|
|
2015-08-09 12:05:32 +02:00
|
|
|
@Override
|
2015-11-23 21:27:06 +01:00
|
|
|
public int getField(int id) {
|
|
|
|
return inventory.getField(id);
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-23 21:27:06 +01:00
|
|
|
public void setField(int id, int value) {
|
|
|
|
inventory.setField(id, value);
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-23 21:27:06 +01:00
|
|
|
public int getFieldCount() {
|
|
|
|
return inventory.getFieldCount();
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-23 21:27:06 +01:00
|
|
|
public void clear() {
|
|
|
|
inventory.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2015-11-29 10:52:45 +01:00
|
|
|
public String getName() {
|
|
|
|
return inventory.getName();
|
2015-11-23 21:27:06 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean hasCustomName() {
|
|
|
|
return inventory.hasCustomName();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public IChatComponent getDisplayName() {
|
|
|
|
return inventory.getDisplayName();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getInventoryStackLimit() {
|
|
|
|
return inventory.getInventoryStackLimit();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isUseableByPlayer(EntityPlayer player) {
|
|
|
|
return inventory.isUseableByPlayer(player);
|
2015-08-09 12:05:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean isItemValidForSlot(int slot, ItemStack stack) {
|
|
|
|
return inventory.isItemValidForSlot(slot, stack);
|
|
|
|
}
|
2015-04-14 01:12:24 +02:00
|
|
|
}
|