package techreborn.tiles.generator;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.math.BlockPos;
import reborncore.api.power.EnumPowerTier;
import reborncore.api.tile.IInventoryProvider;
import reborncore.common.IWrenchable;
import reborncore.common.powerSystem.TilePowerAcceptor;
import reborncore.common.util.Inventory;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;

public class TileDragonEggSiphoner extends TilePowerAcceptor implements IWrenchable, IInventoryProvider {

	public static final int euTick = ConfigTechReborn.DragonEggSiphonerOutput;
	public Inventory inventory = new Inventory(3, "TileAlloySmelter", 64, this);

	public TileDragonEggSiphoner() {
		super(2);
	}

	@Override
	public void updateEntity() {
		super.updateEntity();

		if (!world.isRemote) {
			if (world.getBlockState(new BlockPos(getPos().getX(), getPos().getY() + 1, getPos().getZ()))
				.getBlock() == Blocks.DRAGON_EGG) {
				addEnergy(euTick);
			}
		}
	}

	@Override
	public boolean wrenchCanSetFacing(EntityPlayer entityPlayer, EnumFacing side) {
		return false;
	}

	@Override
	public EnumFacing getFacing() {
		return getFacingEnum();
	}

	@Override
	public boolean wrenchCanRemove(EntityPlayer entityPlayer) {
		return entityPlayer.isSneaking();
	}

	@Override
	public float getWrenchDropRate() {
		return 1.0F;
	}

	@Override
	public ItemStack getWrenchDrop(EntityPlayer entityPlayer) {
		return new ItemStack(ModBlocks.dragonEggEnergySiphoner, 1);
	}

	public boolean isComplete() {
		return false;
	}

	@Override
	public double getMaxPower() {
		return 1000;
	}

	@Override
	public boolean canAcceptEnergy(EnumFacing direction) {
		return false;
	}

	@Override
	public boolean canProvideEnergy(EnumFacing direction) {
		return true;
	}

	@Override
	public double getMaxOutput() {
		return euTick;
	}

	@Override
	public double getMaxInput() {
		return 0;
	}

	@Override
	public EnumPowerTier getTier() {
		return EnumPowerTier.HIGH;
	}

	@Override
	public Inventory getInventory() {
		return inventory;
	}
}

@@ -357,16 +357,66 @@
 chable;%0A
+import reborncore.common.blocks.BlockMachineBase;%0A
 import r
@@ -890,24 +890,55 @@
 per(2);%0A%09%7D%0A%0A
+%09private long lastOutput = 0;%0A%0A
 %09@Override%0A%09
@@ -1116,16 +1116,17 @@
 )))%0A%09%09%09%09
+%09
 .getBloc
@@ -1161,11 +1161,20 @@
 %09%09%09%09
-add
+if(tryAdding
 Ener
@@ -1187,18 +1187,814 @@
 ick)
-;%0A%09%09%09%7D%0A%09%09%7D
+)%0A%09%09%09%09%09this.lastOutput = this.world.getTotalWorldTime();%0A%09%09%09%7D%0A%0A%09%09%09if (this.world.getTotalWorldTime() - this.lastOutput %3C 30 && !this.isActive())%0A%09%09%09%09this.world.setBlockState(this.getPos(),%0A%09%09%09%09%09%09this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, true));%0A%09%09%09else if (this.world.getTotalWorldTime() - this.lastOutput %3E 30 && this.isActive())%0A%09%09%09%09this.world.setBlockState(this.getPos(),%0A%09%09%09%09%09%09this.world.getBlockState(this.getPos()).withProperty(BlockMachineBase.ACTIVE, false));%0A%09%09%7D%0A%09%7D%0A%09%0A%09private boolean tryAddingEnergy(int amount)%0A%09%7B%0A%09%09if(this.getMaxPower() - this.getEnergy() %3E= amount)%0A%09%09%7B%0A%09%09%09addEnergy(amount);%0A%09%09%09return true;%0A%09%09%7D%0A%09%09else if(this.getMaxPower() - this.getEnergy() %3E 0)%0A%09%09%7B%0A%09%09%09addEnergy(this.getMaxPower() - this.getEnergy());%0A%09%09%09return true;%0A%09%09%7D%0A%09%09return false;
 %0A%09%7D%0A

Add activation state change to DragonEggSiphoner + Add convenient energy add method