blob: 90aff3877bc1c8e17710a40b2db06a11b2615a9d [file] [log] [blame] [raw]
package li.cil.oc.integration.appeng;
import appeng.api.networking.IGrid;
import appeng.api.networking.IGridNode;
import appeng.api.networking.energy.IEnergyGrid;
import li.cil.oc.api.machine.Arguments;
import li.cil.oc.api.machine.Callback;
import li.cil.oc.api.machine.Context;
import li.cil.oc.api.network.ManagedEnvironment;
import li.cil.oc.api.prefab.DriverTileEntity;
import li.cil.oc.integration.ManagedTileEntityEnvironment;
import net.minecraft.world.World;
public final class DriverGridNode extends DriverTileEntity {
@Override
public Class<?> getTileEntityClass() {
return IGridNode.class;
}
@Override
public ManagedEnvironment createEnvironment(final World world, final int x, final int y, final int z) {
return new Environment((IGridNode) world.getTileEntity(x, y, z));
}
public static final class Environment extends ManagedTileEntityEnvironment<IGridNode> {
public Environment(final IGridNode tileEntity) {
super(tileEntity, "me_node");
}
@Callback(doc = "function():number -- Returns the average of energy usage over the last 10 ticks.")
public Object[] getAvgPowerUsage(final Context context, final Arguments args) {
final IGrid grid = tileEntity.getGrid();
return grid != null
? new Object[]{((IEnergyGrid) grid.getCache(IEnergyGrid.class)).getAvgPowerUsage()}
: new Object[]{null, "no grid"};
}
@Callback(doc = "function():number -- Returns the total amount of power available.")
public Object[] getStoredPower(final Context context, final Arguments args) {
final IGrid grid = tileEntity.getGrid();
return grid != null
? new Object[]{((IEnergyGrid) grid.getCache(IEnergyGrid.class)).getStoredPower()}
: new Object[]{null, "no grid"};
}
@Callback(doc = "function():boolean -- Returns whether the network is powered.")
public Object[] isNetworkPowered(final Context context, final Arguments args) {
final IGrid grid = tileEntity.getGrid();
return grid != null
? new Object[]{((IEnergyGrid) grid.getCache(IEnergyGrid.class)).isNetworkPowered()}
: new Object[]{null, "no grid"};
}
}
}