mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-24 04:50:30 -04:00
Add getSlotInfo
to reactor driver, to get item heat.
This commit is contained in:
parent
dd69c680e5
commit
64505555f9
@ -1,8 +1,9 @@
|
||||
package li.cil.oc.integration.ic2;
|
||||
|
||||
import ic2.api.reactor.IReactor;
|
||||
import ic2.core.block.TileEntityBlock;
|
||||
import ic2.api.reactor.IReactorComponent;
|
||||
import ic2.core.block.reactor.tileentity.TileEntityNuclearReactorElectric;
|
||||
import java.util.HashMap;
|
||||
import li.cil.oc.api.driver.NamedBlock;
|
||||
import li.cil.oc.api.machine.Arguments;
|
||||
import li.cil.oc.api.machine.Callback;
|
||||
@ -11,6 +12,8 @@ import li.cil.oc.api.network.ManagedEnvironment;
|
||||
import li.cil.oc.api.prefab.DriverSidedTileEntity;
|
||||
import li.cil.oc.integration.ManagedTileEntityEnvironment;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
public final class DriverReactor extends DriverSidedTileEntity {
|
||||
@ -75,5 +78,34 @@ public final class DriverReactor extends DriverSidedTileEntity {
|
||||
public Object[] producesEnergy(final Context context, final Arguments args) {
|
||||
return new Object[] {tileEntity.produceEnergy()};
|
||||
}
|
||||
|
||||
@Callback(doc = "function(x:int,y:int):table -- Get information about the item stored in the given reactor slot.")
|
||||
public Object[] getSlotInfo(final Context context, final Arguments args) {
|
||||
final int x = args.optInteger(0, -1);
|
||||
final int y = args.optInteger(1, -1);
|
||||
|
||||
final ItemStack stack = tileEntity.getItemAt(x, y);
|
||||
|
||||
if (stack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Item item = stack.getItem();
|
||||
|
||||
final HashMap<String, Object> outputMap = new HashMap<String, Object> ();
|
||||
|
||||
outputMap.put("item", stack);
|
||||
|
||||
if (item instanceof IReactorComponent) {
|
||||
final IReactorComponent component = (IReactorComponent) item;
|
||||
outputMap.put("canStoreHeat", component.canStoreHeat(tileEntity, stack, x, y));
|
||||
outputMap.put("heat", component.getCurrentHeat(tileEntity, stack, x, y));
|
||||
outputMap.put("maxHeat", component.getMaxHeat(tileEntity, stack, x, y));
|
||||
}
|
||||
|
||||
return new Object[] {
|
||||
outputMap
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package li.cil.oc.integration.ic2;
|
||||
|
||||
import ic2.api.reactor.IReactor;
|
||||
import ic2.api.reactor.IReactorChamber;
|
||||
import ic2.api.reactor.IReactorComponent;
|
||||
import ic2.core.block.TileEntityBlock;
|
||||
import ic2.core.block.reactor.tileentity.TileEntityNuclearReactorElectric;
|
||||
import li.cil.oc.api.driver.NamedBlock;
|
||||
@ -11,9 +12,13 @@ import li.cil.oc.api.machine.Context;
|
||||
import li.cil.oc.api.network.ManagedEnvironment;
|
||||
import li.cil.oc.api.prefab.DriverSidedTileEntity;
|
||||
import li.cil.oc.integration.ManagedTileEntityEnvironment;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public final class DriverReactorChamber extends DriverSidedTileEntity {
|
||||
@Override
|
||||
public Class<?> getTileEntityClass() {
|
||||
@ -95,5 +100,40 @@ public final class DriverReactorChamber extends DriverSidedTileEntity {
|
||||
return new Object[] {false};
|
||||
}
|
||||
}
|
||||
|
||||
@Callback(doc = "function(x:int,y:int):table -- Get information about the item stored in the given reactor slot.")
|
||||
public Object[] getSlotInfo(final Context context, final Arguments args) {
|
||||
final IReactor reactor = tileEntity.getReactor();
|
||||
|
||||
if (reactor == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final int x = args.optInteger(0, -1);
|
||||
final int y = args.optInteger(1, -1);
|
||||
|
||||
final ItemStack stack = reactor.getItemAt(x, y);
|
||||
|
||||
if (stack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Item item = stack.getItem();
|
||||
|
||||
final HashMap<String, Object> outputMap = new HashMap<String, Object> ();
|
||||
|
||||
outputMap.put("item", stack);
|
||||
|
||||
if (item instanceof IReactorComponent) {
|
||||
final IReactorComponent component = (IReactorComponent) item;
|
||||
outputMap.put("canStoreHeat", component.canStoreHeat(reactor, stack, x, y));
|
||||
outputMap.put("heat", component.getCurrentHeat(reactor, stack, x, y));
|
||||
outputMap.put("maxHeat", component.getMaxHeat(reactor, stack, x, y));
|
||||
}
|
||||
|
||||
return new Object[] {
|
||||
outputMap
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user