package li.cil.oc.example.block;

import li.cil.oc.api.Network;
import li.cil.oc.api.network.*;
import li.cil.oc.api.prefab.DriverBlock;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntityFurnace;
import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary;

/**
 * This driver allows interacting with vanilla furnaces via the Adapter block.
 */
public class DriverFurnace extends DriverBlock {
    protected DriverFurnace() {
        // Specify the items that can be 'placed' into the adapter to configure
        // it for a specific block. We use the wildcard metadata here because
        // that's what's used for the furnace's rotation.
        super(new ItemStack(Block.furnaceIdle, 1, OreDictionary.WILDCARD_VALUE),
                new ItemStack(Block.furnaceBurning, 1, OreDictionary.WILDCARD_VALUE));
    }

    @Override
    public ManagedEnvironment createEnvironment(World world, int x, int y, int z) {
        return new Environment((TileEntityFurnace) world.getBlockTileEntity(x, y, z));
    }

    public class Environment extends li.cil.oc.api.prefab.ManagedEnvironment {
        protected final TileEntityFurnace furnace;

        public Environment(TileEntityFurnace furnace) {
            this.furnace = furnace;
            node = Network.newNode(this, Visibility.Network).
                    withComponent("furnace").
                    create();
        }

        // The following methods are available to programs running on computers
        // that are connected to the adapter block managing this environment.

        @Callback
        public Object[] getBurnTime(Context context, Arguments args) {
            return new Object[]{furnace.furnaceBurnTime};
        }

        @Callback
        public Object[] getCookTime(Context context, Arguments args) {
            return new Object[]{furnace.furnaceCookTime};
        }

        @Callback
        public Object[] getCurrentItemBurnTime(Context context, Arguments args) {
            return new Object[]{furnace.currentItemBurnTime};
        }

        @Callback
        public Object[] isBurning(Context context, Arguments args) {
            return new Object[]{furnace.isBurning()};
        }
    }
}

@@ -127,84 +127,18 @@
 iver
-Block;%0Aimport net.minecraft.block.Block;%0Aimport net.minecraft.item.ItemStack
+TileEntity
 ;%0Aim
@@ -223,57 +223,8 @@
 rld;
-%0Aimport net.minecraftforge.oredict.OreDictionary;
 %0A%0A/*
@@ -353,430 +353,116 @@
 iver
-Block %7B%0A    protected DriverFurnace() %7B%0A        // Specify the items that can be 'placed' into the adapter to configure%0A        // it for a specific block. We use the wildcard metadata here because%0A        // that's what's used for the furnace's rotation.%0A        super(new ItemStack(Block.furnaceIdle, 1, OreDictionary.WILDCARD_VALUE),%0A                new ItemStack(Block.furnaceBurning, 1, OreDictionary.WILDCARD_VALUE))
+TileEntity %7B%0A    @Override%0A    public Class%3C?%3E getTileEntityClass() %7B%0A        return TileEntityFurnace.class
 ;%0A  

update for api change (tile entity based detection instead of item based after recent adapter simplification)