2015-04-13 19:40:13 +02:00
|
|
|
package techreborn.tiles;
|
|
|
|
|
2015-04-13 20:59:52 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
2015-04-13 19:40:13 +02:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2015-11-23 15:45:16 +01:00
|
|
|
import net.minecraft.util.EnumFacing;
|
2017-01-08 20:34:46 +01:00
|
|
|
|
2015-11-08 13:15:45 +01:00
|
|
|
import reborncore.api.IListInfoProvider;
|
2016-03-08 18:34:04 +01:00
|
|
|
import reborncore.api.power.EnumPowerTier;
|
2016-03-28 18:50:25 +02:00
|
|
|
import reborncore.api.power.IEnergyItemInfo;
|
2016-04-11 18:50:00 +02:00
|
|
|
import reborncore.api.recipe.IRecipeCrafterProvider;
|
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:29:47 +02:00
|
|
|
import reborncore.common.powerSystem.PoweredItem;
|
2016-08-10 01:45:07 +02:00
|
|
|
import reborncore.common.powerSystem.TilePowerAcceptor;
|
2016-04-11 18:23:57 +02:00
|
|
|
import reborncore.common.recipes.RecipeCrafter;
|
2016-04-11 18:50:00 +02:00
|
|
|
import reborncore.common.util.Inventory;
|
2017-01-08 20:34:46 +01:00
|
|
|
|
2016-04-11 18:50:00 +02:00
|
|
|
import techreborn.api.Reference;
|
2017-01-08 20:34:46 +01:00
|
|
|
import techreborn.client.container.IContainerProvider;
|
|
|
|
import techreborn.client.container.builder.BuiltContainer;
|
|
|
|
import techreborn.client.container.builder.ContainerBuilder;
|
2015-04-14 22:23:45 +02:00
|
|
|
import techreborn.config.ConfigTechReborn;
|
2015-04-14 20:23:16 +02:00
|
|
|
import techreborn.init.ModBlocks;
|
2016-12-13 00:57:04 +01:00
|
|
|
import techreborn.items.DynamicCell;
|
2016-11-28 22:32:13 +01:00
|
|
|
import techreborn.utils.upgrade.UpgradeHandler;
|
2016-03-28 18:50:25 +02:00
|
|
|
|
|
|
|
import java.util.List;
|
2015-04-13 19:40:13 +02:00
|
|
|
|
2016-08-10 01:45:07 +02:00
|
|
|
public class TileCentrifuge extends TilePowerAcceptor
|
2017-01-08 20:34:46 +01:00
|
|
|
implements IWrenchable, IInventoryProvider, IListInfoProvider, IRecipeCrafterProvider, IContainerProvider {
|
2016-03-25 10:47:34 +01:00
|
|
|
|
|
|
|
public int tickTime;
|
|
|
|
public Inventory inventory = new Inventory(11, "TileCentrifuge", 64, this);
|
2016-11-28 22:32:13 +01:00
|
|
|
public UpgradeHandler upgradeHandler;
|
2016-03-25 10:47:34 +01:00
|
|
|
public RecipeCrafter crafter;
|
|
|
|
|
|
|
|
public int euTick = ConfigTechReborn.CentrifugeInputTick;
|
|
|
|
|
2016-10-08 21:46:16 +02:00
|
|
|
public TileCentrifuge() {
|
2016-08-10 01:45:07 +02:00
|
|
|
super(2);
|
2016-03-25 10:47:34 +01:00
|
|
|
// Input slots
|
2017-01-08 20:34:46 +01:00
|
|
|
final int[] inputs = new int[] { 0, 1 };
|
|
|
|
final int[] outputs = new int[4];
|
2016-03-25 10:47:34 +01:00
|
|
|
outputs[0] = 2;
|
|
|
|
outputs[1] = 3;
|
|
|
|
outputs[2] = 4;
|
2016-12-13 00:57:04 +01:00
|
|
|
outputs[3] = 5;
|
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
this.crafter = new RecipeCrafter(Reference.centrifugeRecipe, this, 2, 4, this.inventory, inputs, outputs);
|
|
|
|
this.upgradeHandler = new UpgradeHandler(this.crafter, this.inventory, 7, 8, 9, 10);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2016-12-13 00:57:04 +01:00
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public void updateEntity() {
|
2016-08-10 01:45:07 +02:00
|
|
|
super.updateEntity();
|
2017-01-08 20:34:46 +01:00
|
|
|
this.crafter.updateEntity();
|
|
|
|
this.upgradeHandler.tick();
|
|
|
|
this.charge(6);
|
|
|
|
if (this.inventory.getStackInSlot(6) != ItemStack.EMPTY) {
|
|
|
|
final ItemStack stack = this.inventory.getStackInSlot(6);
|
2016-10-08 21:46:16 +02:00
|
|
|
if (stack.getItem() instanceof IEnergyItemInfo) {
|
2017-01-08 20:34:46 +01:00
|
|
|
final IEnergyItemInfo item = (IEnergyItemInfo) stack.getItem();
|
2016-10-08 21:46:16 +02:00
|
|
|
if (item.canProvideEnergy(stack)) {
|
2017-01-08 20:34:46 +01:00
|
|
|
if (this.getEnergy() != this.getMaxPower()) {
|
|
|
|
this.addEnergy(item.getMaxTransfer(stack));
|
2016-08-10 01:29:47 +02:00
|
|
|
PoweredItem.setEnergy(PoweredItem.getEnergy(stack) - item.getMaxTransfer(stack), stack);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-12-13 00:57:04 +01:00
|
|
|
}
|
2016-03-25 10:47:34 +01:00
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public boolean wrenchCanSetFacing(final EntityPlayer entityPlayer, final EnumFacing side) {
|
2016-03-25 10:47:34 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public EnumFacing getFacing() {
|
2017-01-08 20:34:46 +01:00
|
|
|
return this.getFacingEnum();
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public boolean wrenchCanRemove(final 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
|
2017-01-08 20:34:46 +01:00
|
|
|
public ItemStack getWrenchDrop(final EntityPlayer entityPlayer) {
|
2017-01-01 08:29:32 +01:00
|
|
|
return new ItemStack(ModBlocks.INDUSTRIAL_CENTRIFUGE, 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public void readFromNBT(final NBTTagCompound tagCompound) {
|
2016-03-25 10:47:34 +01:00
|
|
|
super.readFromNBT(tagCompound);
|
2017-01-08 20:34:46 +01:00
|
|
|
this.crafter.readFromNBT(tagCompound);
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public NBTTagCompound writeToNBT(final NBTTagCompound tagCompound) {
|
2016-03-25 10:47:34 +01:00
|
|
|
super.writeToNBT(tagCompound);
|
2017-01-08 20:34:46 +01:00
|
|
|
this.crafter.writeToNBT(tagCompound);
|
2016-05-18 17:53:54 +02:00
|
|
|
return tagCompound;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
2016-11-28 22:32:13 +01:00
|
|
|
// ISidedInventory
|
2016-12-13 00:57:04 +01:00
|
|
|
|
2016-11-28 22:32:13 +01:00
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public int[] getSlotsForFace(final EnumFacing side) {
|
2016-12-13 00:57:04 +01:00
|
|
|
return side == EnumFacing.DOWN ? new int[] { 0, 1, 2, 3, 4, 5 } : new int[] { 0, 1, 2, 3, 4, 5 };
|
2016-11-28 22:32:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public boolean canInsertItem(final int index, final ItemStack itemStackIn, final EnumFacing direction) {
|
2016-12-13 00:57:04 +01:00
|
|
|
return itemStackIn.isItemEqual(DynamicCell.getEmptyCell(1).copy()) ? index == 1 : index == 0;
|
2016-11-28 22:32:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public boolean canExtractItem(final int slotIndex, final ItemStack itemStack, final EnumFacing side) {
|
2016-11-28 22:32:13 +01:00
|
|
|
return slotIndex >= 2 && slotIndex <= 5;
|
2016-12-13 00:57:04 +01:00
|
|
|
}
|
|
|
|
|
2016-03-25 10:47:34 +01:00
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public void addInfo(final List<String> info, final boolean isRealTile) {
|
2016-03-25 10:47:34 +01:00
|
|
|
super.addInfo(info, isRealTile);
|
|
|
|
info.add("Round and round it goes");
|
|
|
|
}
|
2016-10-08 21:46:16 +02:00
|
|
|
|
2017-01-08 20:34:46 +01:00
|
|
|
public int getProgressScaled(final int scale) {
|
|
|
|
if (this.crafter.currentTickTime != 0) {
|
|
|
|
return this.crafter.currentTickTime * scale / this.crafter.currentNeededTicks;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-10-08 21:46:16 +02:00
|
|
|
public double getMaxPower() {
|
2016-08-10 01:45:07 +02:00
|
|
|
return 10000;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public boolean canAcceptEnergy(final EnumFacing direction) {
|
2016-08-10 01:45:07 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2017-01-08 20:34:46 +01:00
|
|
|
public boolean canProvideEnergy(final 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 32;
|
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;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2016-04-11 18:43:54 +02:00
|
|
|
public Inventory getInventory() {
|
2017-01-08 20:34:46 +01:00
|
|
|
return this.inventory;
|
2016-03-25 10:47:34 +01:00
|
|
|
}
|
2016-04-11 18:50:00 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public RecipeCrafter getRecipeCrafter() {
|
2017-01-08 20:34:46 +01:00
|
|
|
return this.crafter;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public BuiltContainer createContainer(final EntityPlayer player) {
|
|
|
|
return new ContainerBuilder("centrifuge").player(player.inventory).inventory(8, 84).hotbar(8, 142)
|
|
|
|
.addInventory().tile(this).slot(0, 80, 35).slot(1, 50, 5).outputSlot(2, 80, 5).outputSlot(3, 110, 35)
|
|
|
|
.outputSlot(4, 80, 65).outputSlot(5, 50, 35).energySlot(6, 8, 51).upgradeSlot(7, 152, 8)
|
|
|
|
.upgradeSlot(8, 152, 26).upgradeSlot(9, 152, 44).upgradeSlot(10, 152, 62).syncEnergyValue()
|
|
|
|
.syncCrafterValue().addInventory().create();
|
2016-04-11 18:50:00 +02:00
|
|
|
}
|
2016-04-12 09:33:38 +02:00
|
|
|
|
2016-11-28 22:32:13 +01:00
|
|
|
}
|