2015-04-28 00:51:06 +02:00
|
|
|
package techreborn.tiles;
|
|
|
|
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
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-28 00:51:06 +02:00
|
|
|
import techreborn.init.ModBlocks;
|
2015-06-22 12:32:30 +02:00
|
|
|
import techreborn.init.ModItems;
|
2016-03-27 19:56:27 +02:00
|
|
|
import techreborn.items.ItemParts;
|
2015-06-22 12:32:30 +02:00
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public class TileMatterFabricator extends TilePowerAcceptor implements IWrenchable, IInventoryProvider {
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2016-05-28 20:33:17 +02:00
|
|
|
public static int fabricationRate = 10000;
|
2016-03-25 10:47:34 +01:00
|
|
|
public int tickTime;
|
|
|
|
public Inventory inventory = new Inventory(7, "TileMatterFabricator", 64, this);
|
|
|
|
public int progresstime = 0;
|
|
|
|
private int amplifier = 0;
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public TileMatterFabricator() {
|
2016-08-10 01:45:07 +02:00
|
|
|
super(6);
|
|
|
|
// TODO configs
|
|
|
|
}
|
|
|
|
|
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) {
|
2016-12-05 10:40:55 +01:00
|
|
|
return new ItemStack(ModBlocks.matterFabricator, 1);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean isComplete() {
|
2016-03-25 10:47:34 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
// // ISidedInventory
|
|
|
|
// @Override
|
|
|
|
// public int[] getSlotsForFace(EnumFacing side)
|
|
|
|
// {
|
|
|
|
// return side == EnumFacing.DOWN ? new int[] { 0, 1, 2, 3, 4, 5, 6 } : new int[] { 0, 1, 2, 3, 4, 5, 6 };
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// @Override
|
|
|
|
// public boolean canInsertItem(int slotIndex, ItemStack itemStack, EnumFacing side)
|
|
|
|
// {
|
|
|
|
// if (slotIndex == 6)
|
|
|
|
// return false;
|
|
|
|
// return isItemValidForSlot(slotIndex, itemStack);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// @Override
|
|
|
|
// public boolean canExtractItem(int slotIndex, ItemStack itemStack, EnumFacing side)
|
|
|
|
// {
|
|
|
|
// return slotIndex == 6;
|
|
|
|
// }
|
|
|
|
|
|
|
|
public int maxProgresstime() {
|
2016-03-25 10:47:34 +01:00
|
|
|
return fabricationRate;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public void updateEntity() {
|
2016-08-10 01:45:07 +02:00
|
|
|
super.updateEntity();
|
|
|
|
|
2016-11-19 13:50:08 +01:00
|
|
|
if (!super.world.isRemote) {
|
2016-10-08 21:46:16 +02:00
|
|
|
for (int i = 0; i < 6; i++) {
|
2016-03-25 10:47:34 +01:00
|
|
|
ItemStack stack = inventory.getStackInSlot(i);
|
2016-11-19 17:36:13 +01:00
|
|
|
if (this.amplifier < 10000 && stack != ItemStack.EMPTY) {
|
2016-03-25 10:47:34 +01:00
|
|
|
int amp = (int) ((long) (getValue(stack) / 32));
|
2016-10-08 21:46:16 +02:00
|
|
|
if (ItemUtils.isItemEqual(stack, inventory.getStackInSlot(i), true, true)) {
|
|
|
|
if (canUseEnergy(1)) {
|
2016-03-25 10:47:34 +01:00
|
|
|
useEnergy(1);
|
|
|
|
this.amplifier += amp;
|
|
|
|
inventory.decrStackSize(i, 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
if (this.amplifier > 0) {
|
|
|
|
if (this.amplifier > this.getEnergy()) {
|
2016-03-25 10:47:34 +01:00
|
|
|
this.progresstime += this.getEnergy();
|
|
|
|
this.amplifier -= this.getEnergy();
|
|
|
|
this.decreaseStoredEnergy(this.getEnergy(), true);
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2016-03-25 10:47:34 +01:00
|
|
|
this.progresstime += this.amplifier;
|
|
|
|
this.decreaseStoredEnergy(this.amplifier, true);
|
|
|
|
this.amplifier = 0;
|
|
|
|
}
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
if (this.progresstime > this.maxProgresstime() && this.spaceForOutput()) {
|
2016-03-25 10:47:34 +01:00
|
|
|
this.progresstime -= this.maxProgresstime();
|
|
|
|
this.addOutputProducts();
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
private boolean spaceForOutput() {
|
2016-11-19 17:36:13 +01:00
|
|
|
return inventory.getStackInSlot(6) == ItemStack.EMPTY
|
2016-10-08 21:46:16 +02:00
|
|
|
|| ItemUtils.isItemEqual(inventory.getStackInSlot(6), new ItemStack(ModItems.uuMatter), true, true)
|
2016-11-19 13:50:08 +01:00
|
|
|
&& inventory.getStackInSlot(6).getCount() < 64;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
private void addOutputProducts() {
|
2016-03-25 10:47:34 +01:00
|
|
|
|
2016-11-19 17:36:13 +01:00
|
|
|
if (inventory.getStackInSlot(6) == ItemStack.EMPTY) {
|
2016-03-25 10:47:34 +01:00
|
|
|
inventory.setInventorySlotContents(6, new ItemStack(ModItems.uuMatter));
|
2016-10-08 21:46:16 +02:00
|
|
|
} else if (ItemUtils.isItemEqual(inventory.getStackInSlot(6), new ItemStack(ModItems.uuMatter), true, true)) {
|
2016-11-19 15:41:00 +01:00
|
|
|
inventory.getStackInSlot(6).setCount(Math.min(64, 1 + inventory.getStackInSlot(6).getCount()));
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public boolean decreaseStoredEnergy(double aEnergy, boolean aIgnoreTooLessEnergy) {
|
|
|
|
if (this.getEnergy() - aEnergy < 0 && !aIgnoreTooLessEnergy) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return false;
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2016-03-25 10:47:34 +01:00
|
|
|
setEnergy(this.getEnergy() - aEnergy);
|
2016-10-08 21:46:16 +02:00
|
|
|
if (this.getEnergy() < 0) {
|
2016-03-25 10:47:34 +01:00
|
|
|
setEnergy(0);
|
|
|
|
return false;
|
2016-10-08 21:46:16 +02:00
|
|
|
} else {
|
2016-03-25 10:47:34 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// TODO ic2
|
2016-10-08 21:46:16 +02:00
|
|
|
public int getValue(ItemStack itemStack) {
|
2016-03-25 10:47:34 +01:00
|
|
|
// int value = getValue(Recipes.matterAmplifier.getOutputFor(itemStack,
|
|
|
|
// false));
|
2016-10-08 21:46:16 +02:00
|
|
|
if (itemStack.getItem() == ModItems.parts && itemStack.getItemDamage() == ItemParts.getPartByName("scrap").getItemDamage()) {
|
2016-03-27 19:56:27 +02:00
|
|
|
return 5000;
|
2016-10-08 21:46:16 +02:00
|
|
|
} else if (itemStack.getItem() == ModItems.scrapBox) {
|
2016-03-27 19:56:27 +02:00
|
|
|
return 45000;
|
|
|
|
}
|
2016-03-25 10:47:34 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// private static Integer getValue(RecipeOutput output) {
|
|
|
|
// if (output != null && output.metadata != null) {
|
|
|
|
// return output.metadata.getInteger("amplification");
|
|
|
|
// }
|
|
|
|
// return 0;
|
|
|
|
// }
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public double getMaxPower() {
|
2016-08-10 01:45:07 +02:00
|
|
|
return 100000000;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@Override
|
|
|
|
public boolean canAcceptEnergy(EnumFacing direction) {
|
2016-08-10 01:45:07 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
@Override
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public double getMaxInput() {
|
2016-08-10 01:45:07 +02:00
|
|
|
return 4096;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public EnumPowerTier getTier() {
|
2016-03-25 10:47:34 +01:00
|
|
|
return EnumPowerTier.EXTREME;
|
|
|
|
}
|
2016-04-11 18:43:54 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public Inventory getInventory() {
|
|
|
|
return inventory;
|
|
|
|
}
|
2015-04-28 00:51:06 +02:00
|
|
|
}
|