use of mcjty.rftoolscontrol.logic.running.ProgException in project RFToolsControl by McJty.
the class ProcessorTileEntity method getAdjacentPosition.
private BlockPos getAdjacentPosition(@Nonnull BlockSide side) {
BlockPos p;
if (side.getNodeName() != null && !side.getNodeName().isEmpty()) {
p = networkNodes.get(side.getNodeName());
if (p == null) {
throw new ProgException(EXCEPT_MISSINGNODE);
}
TileEntity te = getWorld().getTileEntity(p);
if (!(te instanceof NodeTileEntity)) {
throw new ProgException(EXCEPT_MISSINGNODE);
}
} else {
p = pos;
}
return p;
}
use of mcjty.rftoolscontrol.logic.running.ProgException in project RFToolsControl by McJty.
the class ProcessorTileEntity method sendMessage.
@Override
public void sendMessage(IProgram program, int idSlot, String messageName, @Nullable Integer variableSlot) {
if (!hasNetworkCard()) {
throw new ProgException(EXCEPT_MISSINGNETWORKCARD);
}
if (hasNetworkCard != NetworkCardItem.TIER_ADVANCED) {
throw new ProgException(EXCEPT_NEEDSADVANCEDNETWORK);
}
CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
int realIdSlot = info.getRealSlot(idSlot);
Integer realVariable = info.getRealVar(variableSlot);
IItemHandler handler = getItemHandler();
ItemStack idCard = handler.getStackInSlot(realIdSlot);
if (idCard.isEmpty() || !(idCard.getItem() instanceof NetworkIdentifierItem)) {
throw new ProgException(EXCEPT_NOTANIDENTIFIER);
}
NBTTagCompound tagCompound = idCard.getTagCompound();
if (tagCompound == null || !tagCompound.hasKey("monitorx")) {
throw new ProgException(EXCEPT_INVALIDDESTINATION);
}
int monitordim = tagCompound.getInteger("monitordim");
int monitorx = tagCompound.getInteger("monitorx");
int monitory = tagCompound.getInteger("monitory");
int monitorz = tagCompound.getInteger("monitorz");
WorldServer world = DimensionManager.getWorld(monitordim);
BlockPos dest = new BlockPos(monitorx, monitory, monitorz);
if (!WorldTools.chunkLoaded(world, dest)) {
throw new ProgException(EXCEPT_INVALIDDESTINATION);
}
TileEntity te = world.getTileEntity(dest);
if (!(te instanceof ProcessorTileEntity)) {
throw new ProgException(EXCEPT_INVALIDDESTINATION);
}
ProcessorTileEntity destTE = (ProcessorTileEntity) te;
destTE.receiveMessage(messageName, realVariable == null ? null : getVariableArray()[realVariable]);
}
use of mcjty.rftoolscontrol.logic.running.ProgException in project RFToolsControl by McJty.
the class ProcessorTileEntity method fetchItems.
public int fetchItems(IProgram program, Inventory inv, Integer slot, ItemStack itemMatcher, boolean routable, boolean oredict, @Nullable Integer amount, int virtualSlot) {
if (amount != null && amount == 0) {
throw new ProgException(EXCEPT_BADPARAMETERS);
}
IStorageScanner scanner = getScannerForInv(inv);
IItemHandler handler = getHandlerForInv(inv);
CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
int realSlot = info.getRealSlot(virtualSlot);
ItemStack stack = InventoryTools.tryExtractItem(handler, scanner, amount, routable, oredict, itemMatcher, slot);
if (stack.isEmpty()) {
// Nothing to do
return 0;
}
IItemHandler capability = getItemHandler();
if (!capability.insertItem(realSlot, stack, true).isEmpty()) {
// Not enough room. Do nothing
return 0;
}
// All seems ok. Do the real thing now.
stack = InventoryTools.extractItem(handler, scanner, amount, routable, oredict, false, itemMatcher, slot);
capability.insertItem(realSlot, stack, false);
return stack.getCount();
}
Aggregations