package mimickal.mc.dynamo.common;

import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ITickable;

public class TileEntityDynamo extends TileEntity implements ITickable {

    private static final float DRAG = 0.1f;
    private static final float ADDED_PER_SPIN = 1f;

    private float spinSpeed = 0f;

    /**
     * On each tick, the dynamo generates a small amount of EU
     * proportional to how fast it's spinning.
     *
     * Drag is also applied so that the dynamo slows to a stop over time.
     */
    @Override
    public void update() {
        if (spinSpeed > 0f) {
            spinSpeed -= DRAG;
            System.out.println("Spin speed " + spinSpeed); //FIXME for debug
        }

        if (spinSpeed <= 0f) {
            spinSpeed = 0f;
        }
    }

    /**
     * "Crank" the dynamo once, increasing the speed it's spinning at.
     */
    public void spin() {
        spinSpeed += ADDED_PER_SPIN;
        System.out.println("Spin speed is " + spinSpeed); // FIXME for debug. Remove when done
    }

}

@@ -40,155 +40,541 @@
 ort 
-net.minecraft.tileentity.TileEntity;%0Aimport net.minecraft.util.ITickable;%0A%0Apublic class TileEntityDynamo extends TileEntity implements ITickable %7B%0A
+ic2.api.energy.event.EnergyTileLoadEvent;%0Aimport ic2.api.energy.event.EnergyTileUnloadEvent;%0Aimport ic2.api.energy.tile.IEnergyAcceptor;%0Aimport ic2.api.energy.tile.IEnergySource;%0Aimport net.minecraft.tileentity.TileEntity;%0Aimport net.minecraft.util.EnumFacing;%0Aimport net.minecraft.util.ITickable;%0Aimport net.minecraftforge.common.MinecraftForge;%0A%0Apublic class TileEntityDynamo extends TileEntity implements ITickable, IEnergySource %7B%0A%0A    private static final int LV_TIER = 1; // Because IC2 doesn't have an enum for its power tiers
 %0A   
@@ -663,24 +663,64 @@
 SPIN = 1f;%0A%0A
+    private boolean firstUpdate = true;%0A
     private 
@@ -986,24 +986,288 @@
  update() %7B%0A
+        // IC2 requires this on the first tick to hook into the energy grid.%0A        if (firstUpdate) %7B%0A            MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));%0A            firstUpdate = false;%0A        %7D%0A%0A        // Calculate spin speed reduction%0A
         if (
@@ -1730,10 +1730,1055 @@
 %0A    %7D%0A%0A
+    @Override%0A    public double getOfferedEnergy() %7B%0A        // TODO calculate power based on spin speed%0A        return 5f; //FIXME temp value for testing%0A    %7D%0A%0A    @Override%0A    public int getSourceTier() %7B%0A        return LV_TIER;%0A    %7D%0A%0A    @Override%0A    public void drawEnergy(double amount) %7B%0A        // Noop because dynamos have no energy buffer%0A    %7D%0A%0A    @Override%0A    public boolean emitsEnergyTo(IEnergyAcceptor var1, EnumFacing var2) %7B%0A        return true;%0A    %7D%0A%0A    /*%0A     * IC2 needs an unload event to be fired when this tile entity stops existing,%0A     * either because the chunk unloaded or the dynamo was broken.%0A     * This allows IC2 to unhook the dynamo from the energy grid.%0A     */%0A    @Override%0A    public void onChunkUnload() %7B%0A        unloadEnergyTile();%0A        super.onChunkUnload();%0A    %7D%0A%0A    @Override%0A    public void invalidate() %7B%0A        unloadEnergyTile();%0A        super.invalidate();%0A    %7D%0A%0A    private void unloadEnergyTile() %7B%0A        MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));%0A    %7D%0A%0A
 %7D%0A

Set up dynamo for integrating with IC2