package openperipheral.integration.buildcraft;

import net.minecraftforge.common.ForgeDirection;
import openperipheral.api.*;
import buildcraft.api.power.IPowerReceptor;
import dan200.computer.api.IComputerAccess;

public class AdapterPowerReceptor implements IPeripheralAdapter {

	@Override
	public Class<?> getTargetClass() {
		return IPowerReceptor.class;
	}

	@LuaMethod(returnType = LuaType.NUMBER, description = "Get the activation MJ for this block",
			args = {
					@Arg(name = "direction", type = LuaType.STRING, description = "The side of the block that you're interested in") })
	public float getActivationEnergy(IComputerAccess computer, IPowerReceptor powerReceptor, ForgeDirection direction) {
		return powerReceptor.getPowerReceiver(direction).getActivationEnergy();
	}

	@LuaMethod(returnType = LuaType.NUMBER, description = "Get the MJ stored for this block",
			args = {
					@Arg(name = "direction", type = LuaType.STRING, description = "The side of the block that you're interested in") })
	public float getMJStored(IComputerAccess computer, IPowerReceptor powerReceptor, ForgeDirection direction) {
		return powerReceptor.getPowerReceiver(direction).getEnergyStored();
	}

	@LuaMethod(returnType = LuaType.NUMBER, description = "Get the max MJ received",
			args = {
					@Arg(name = "direction", type = LuaType.STRING, description = "The side of the block that you're interested in") })
	public float getMaxMJReceived(IComputerAccess computer, IPowerReceptor powerReceptor, ForgeDirection direction) {
		return powerReceptor.getPowerReceiver(direction).getMaxEnergyReceived();
	}

	@LuaMethod(returnType = LuaType.NUMBER, description = "Get the max MJ stored",
			args = {
					@Arg(name = "direction", type = LuaType.STRING, description = "The side of the block that you're interested in") })
	public float getMaxMJStored(IComputerAccess computer, IPowerReceptor powerReceptor, ForgeDirection direction) {
		return powerReceptor.getPowerReceiver(direction).getMaxEnergyStored();
	}

	@LuaMethod(returnType = LuaType.NUMBER, description = "Get the min MJ received",
			args = {
					@Arg(name = "direction", type = LuaType.STRING, description = "The side of the block that you're interested in") })
	public float getMinMJReceived(IComputerAccess computer, IPowerReceptor powerReceptor, ForgeDirection direction) {
		return powerReceptor.getPowerReceiver(direction).getMinEnergyReceived();
	}

}

@@ -163,16 +163,72 @@
 ceptor;%0A
+import buildcraft.api.power.PowerHandler.PowerReceiver;%0A
 import d
@@ -641,33 +641,33 @@
 in%22) %7D)%0A%09public 
-f
+F
 loat getActivati
@@ -753,38 +753,61 @@
  direction) %7B%0A%09%09
-return
+PowerReceiver powerReceiver =
  powerReceptor.g
@@ -828,24 +828,99 @@
 r(direction)
+;%0A%09%09if (powerReceiver == null) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%09%09return powerReceiver
 .getActivati
@@ -1159,33 +1159,33 @@
 in%22) %7D)%0A%09public 
-f
+F
 loat getMJStored
@@ -1263,38 +1263,61 @@
  direction) %7B%0A%09%09
-return
+PowerReceiver powerReceiver =
  powerReceptor.g
@@ -1338,24 +1338,99 @@
 r(direction)
+;%0A%09%09if (powerReceiver == null) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%09%09return powerReceiver
 .getEnergySt
@@ -1656,33 +1656,33 @@
 in%22) %7D)%0A%09public 
-f
+F
 loat getMaxMJRec
@@ -1765,38 +1765,61 @@
  direction) %7B%0A%09%09
-return
+PowerReceiver powerReceiver =
  powerReceptor.g
@@ -1836,32 +1836,107 @@
 eiver(direction)
+;%0A%09%09if (powerReceiver == null) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%09%09return powerReceiver
 .getMaxEnergyRec
@@ -2161,33 +2161,33 @@
 in%22) %7D)%0A%09public 
-f
+F
 loat getMaxMJSto
@@ -2268,38 +2268,61 @@
  direction) %7B%0A%09%09
-return
+PowerReceiver powerReceiver =
  powerReceptor.g
@@ -2343,24 +2343,99 @@
 r(direction)
+;%0A%09%09if (powerReceiver == null) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%09%09return powerReceiver
 .getMaxEnerg
@@ -2672,17 +2672,17 @@
 %09public 
-f
+F
 loat get
@@ -2781,22 +2781,45 @@
 on) %7B%0A%09%09
-return
+PowerReceiver powerReceiver =
  powerRe
@@ -2852,16 +2852,91 @@
 rection)
+;%0A%09%09if (powerReceiver == null) %7B%0A%09%09%09return null;%0A%09%09%7D%0A%09%09return powerReceiver
 .getMinE

Check for null return from getPowerReceiver