Skip to content

Commit

Permalink
Merge pull request #131 from Engineer12798/feat/more-reactor-utils
Browse files Browse the repository at this point in the history
Updated redstone port to allow for getting slot info.
  • Loading branch information
Dream-Master authored Aug 31, 2024
2 parents ec38f4e + 8df01ec commit 806ceb4
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

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 ic2.core.block.reactor.tileentity.TileEntityReactorChamberElectric;
Expand All @@ -13,10 +14,14 @@
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.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;

import java.util.HashMap;

public final class DriverReactorRedstonePort extends DriverSidedTileEntity {
@Override
public Class<?> getTileEntityClass() {
Expand Down Expand Up @@ -122,5 +127,40 @@ public Object[] getEmitHeat(final Context context, final Arguments args) {
return new Object[] {0};
}
}

@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 = 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
};
}
}
}

0 comments on commit 806ceb4

Please sign in to comment.