use of mcjty.rftoolscontrol.logic.running.ProgException in project RFToolsControl by McJty.
the class ProcessorTileEntity method craftOk.
public void craftOk(IProgram program, @Nullable Integer slot) {
if (!program.hasCraftTicket()) {
throw new ProgException(EXCEPT_MISSINGCRAFTTICKET);
}
String ticket = program.getCraftTicket();
CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
Integer realSlot = info.getRealSlot(slot);
ItemStack craftedItem = ItemStack.EMPTY;
if (realSlot != null) {
craftedItem = getItemHandler().getStackInSlot(realSlot);
}
for (BlockPos p : craftingStations) {
TileEntity te = getWorld().getTileEntity(p);
if (te instanceof CraftingStationTileEntity) {
CraftingStationTileEntity craftingStation = (CraftingStationTileEntity) te;
craftedItem = craftingStation.craftOk(this, ticket, craftedItem);
}
}
if (realSlot != null) {
// Put back what could not be accepted
getInventoryHelper().setStackInSlot(realSlot, craftedItem);
}
}
use of mcjty.rftoolscontrol.logic.running.ProgException in project RFToolsControl by McJty.
the class ProcessorTileEntity method getParameterFromToken.
@Nullable
public Parameter getParameterFromToken(IProgram program, int slot) {
CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
int realSlot = info.getRealSlot(slot);
ItemStack stack = getItemHandler().getStackInSlot(realSlot);
if (stack.isEmpty() || !(stack.getItem() instanceof TokenItem)) {
throw new ProgException(EXCEPT_NOTATOKEN);
}
if (!stack.hasTagCompound()) {
return null;
}
NBTTagCompound tag = stack.getTagCompound().getCompoundTag("parameter");
if (tag.hasNoTags()) {
return null;
}
return ParameterTools.readFromNBT(tag);
}
use of mcjty.rftoolscontrol.logic.running.ProgException in project RFToolsControl by McJty.
the class ProcessorTileEntity method getMaxEnergyLong.
@Override
public long getMaxEnergyLong(Inventory side) {
TileEntity te = getTileEntityAt(side);
EnergyTools.EnergyLevelMulti level = EnergyTools.getEnergyLevelMulti(te);
if (level.getMaxEnergy() >= 0) {
throw new ProgException(EXCEPT_NORF);
}
return level.getMaxEnergy();
}
use of mcjty.rftoolscontrol.logic.running.ProgException in project RFToolsControl by McJty.
the class ProcessorTileEntity method getCraftableItems.
public void getCraftableItems(List<ItemStack> stacks) {
try {
for (CardInfo info : cardInfo) {
CompiledCard compiledCard = info.getCompiledCard();
if (compiledCard != null) {
for (CompiledEvent event : compiledCard.getEvents(Opcodes.EVENT_CRAFT)) {
int index = event.getIndex();
CompiledOpcode compiledOpcode = compiledCard.getOpcodes().get(index);
ItemStack stack = evaluateItemParameter(compiledOpcode, null, 0);
Inventory inv = evaluateInventoryParameter(compiledOpcode, null, 1);
if (!stack.isEmpty() && inv != null) {
throw new ProgException(EXCEPT_BADPARAMETERS);
}
if (stack.isEmpty() && inv == null) {
throw new ProgException(EXCEPT_BADPARAMETERS);
}
if (!stack.isEmpty()) {
stacks.add(stack);
} else {
// Find all crafting cards in the inventory
IItemHandler handler = getItemHandlerAt(inv);
for (int i = 0; i < handler.getSlots(); i++) {
ItemStack s = handler.getStackInSlot(i);
if (!s.isEmpty() && s.getItem() == ModItems.craftingCardItem) {
ItemStack result = CraftingCardItem.getResult(s);
if (!result.isEmpty()) {
stacks.add(result);
}
}
}
}
}
}
}
} catch (ProgException e) {
exception(e.getExceptionType(), null);
}
}
use of mcjty.rftoolscontrol.logic.running.ProgException in project RFToolsControl by McJty.
the class ProcessorTileEntity method pushItemsWorkbench.
public boolean pushItemsWorkbench(IProgram program, @Nonnull BlockSide workbench, ItemStack item, int slot1, int slot2) {
if (item.isEmpty()) {
item = getCraftResult(program);
}
if (item.isEmpty()) {
throw new ProgException(EXCEPT_MISSINGCRAFTRESULT);
}
TileEntity te = getTileEntityAt(workbench);
if (!(te instanceof WorkbenchTileEntity)) {
throw new ProgException(EXCEPT_NOTAWORKBENCH);
}
IItemHandler cardHandler = getItemHandlerAt(te, EnumFacing.EAST);
ItemStack card = findCraftingCard(cardHandler, item);
if (card.isEmpty()) {
throw new ProgException(EXCEPT_MISSINGCRAFTINGCARD);
}
if (!CraftingCardItem.fitsGrid(card)) {
throw new ProgException(EXCEPT_NOTAGRID);
}
CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
IItemHandler itemHandler = getItemHandler();
IItemHandler gridHandler = getItemHandlerAt(te, EnumFacing.UP);
List<ItemStack> ingredients = CraftingCardItem.getIngredientsGrid(card);
boolean success = true;
for (int i = 0; i < 9; i++) {
ItemStack stackInWorkbench = gridHandler.getStackInSlot(i);
ItemStack stackInIngredient = ingredients.get(i);
if (!stackInWorkbench.isEmpty() && stackInIngredient.isEmpty()) {
// Can't work. There is already something in the workbench that doesn't belong
success = false;
} else if (stackInWorkbench.isEmpty() && !stackInIngredient.isEmpty()) {
// Let's see if we can find the needed ingredient
boolean found = false;
for (int slot = slot1; slot <= slot2; slot++) {
int realSlot = info.getRealSlot(slot);
ItemStack localStack = itemHandler.getStackInSlot(realSlot);
if (stackInIngredient.isItemEqual(localStack)) {
localStack = itemHandler.extractItem(realSlot, stackInIngredient.getCount(), false);
gridHandler.insertItem(i, localStack, false);
found = true;
break;
}
}
if (!found) {
success = false;
}
} else if (!stackInWorkbench.isEmpty() && !stackInIngredient.isEmpty()) {
// See if the item matches and we have enough
if (!stackInIngredient.isItemEqual(stackInWorkbench)) {
success = false;
} else if (stackInIngredient.getCount() > stackInWorkbench.getCount()) {
success = false;
}
}
}
return success;
}
Aggregations