use of mcjty.rftoolscontrol.logic.running.ProgException in project RFToolsControl by McJty.
the class ProcessorTileEntity method getIngredients.
public int getIngredients(IProgram program, Inventory inv, Inventory cardInv, ItemStack item, int slot1, int slot2) {
IStorageScanner scanner = getScannerForInv(inv);
IItemHandler handler = getHandlerForInv(inv);
if (item.isEmpty()) {
item = getCraftResult(program);
}
if (item.isEmpty()) {
throw new ProgException(EXCEPT_MISSINGCRAFTRESULT);
}
IItemHandler cardHandler = getItemHandlerAt(cardInv);
ItemStack card = findCraftingCard(cardHandler, item);
if (card.isEmpty()) {
throw new ProgException(EXCEPT_MISSINGCRAFTINGCARD);
}
CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
IItemHandler itemHandler = getItemHandler();
int slot = slot1;
List<ItemStack> ingredients;
if (CraftingCardItem.fitsGrid(card) && (slot2 - slot1 >= 8)) {
// We have something that fits a crafting grid and we have enough room for a 3x3 grid
ingredients = CraftingCardItem.getIngredientsGrid(card);
} else {
ingredients = CraftingCardItem.getIngredients(card);
}
boolean strictnbt = CraftingCardItem.isStrictNBT(card);
int failed = 0;
for (ItemStack ingredient : ingredients) {
int realSlot = info.getRealSlot(slot);
if (!ingredient.isEmpty()) {
ItemStack stack = InventoryTools.extractItem(handler, scanner, ingredient.getCount(), true, false, strictnbt, ingredient, null);
if (!stack.isEmpty()) {
ItemStack remainder = itemHandler.insertItem(realSlot, stack, false);
if (!remainder.isEmpty()) {
InventoryTools.insertItem(handler, scanner, remainder, null);
}
} else {
failed++;
}
}
slot++;
}
return failed;
}
use of mcjty.rftoolscontrol.logic.running.ProgException in project RFToolsControl by McJty.
the class ProcessorTileEntity method setValueInToken.
public void setValueInToken(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()) {
stack.setTagCompound(new NBTTagCompound());
}
Parameter lastValue = program.getLastValue();
if (lastValue == null) {
stack.getTagCompound().removeTag("parameter");
} else {
NBTTagCompound tag = ParameterTools.writeToNBT(lastValue);
stack.getTagCompound().setTag("parameter", tag);
}
}
use of mcjty.rftoolscontrol.logic.running.ProgException in project RFToolsControl by McJty.
the class ProcessorTileEntity method getItemFromCard.
public ItemStack getItemFromCard(IProgram program) {
Parameter lastValue = program.getLastValue();
if (lastValue == null) {
throw new ProgException(EXCEPT_MISSINGLASTVALUE);
}
ItemStack itemStack = TypeConverters.convertToItem(lastValue);
if (itemStack.isEmpty()) {
throw new ProgException(EXCEPT_NOTANITEM);
}
if (itemStack.getItem() instanceof CraftingCardItem) {
return CraftingCardItem.getResult(itemStack);
}
if (itemStack.getItem() instanceof TokenItem && itemStack.hasTagCompound()) {
NBTTagCompound tag = itemStack.getTagCompound().getCompoundTag("parameter");
if (tag.hasNoTags()) {
return ItemStack.EMPTY;
}
Parameter parameter = ParameterTools.readFromNBT(tag);
if (parameter == null || !parameter.isSet()) {
return ItemStack.EMPTY;
}
return TypeConverters.convertToItem(parameter);
}
return ItemStack.EMPTY;
}
use of mcjty.rftoolscontrol.logic.running.ProgException in project RFToolsControl by McJty.
the class CraftingStationTileEntity method craftOk.
public ItemStack craftOk(ProcessorTileEntity processor, String ticket, ItemStack stack) {
CraftingRequest foundRequest = null;
for (CraftingRequest request : activeCraftingRequests) {
if (ticket.equals(request.getTicket())) {
foundRequest = request;
break;
}
}
if (foundRequest != null) {
markDirty();
foundRequest.decrTodo();
if (foundRequest.getTodo() <= 0) {
foundRequest.setOk(System.currentTimeMillis() + 1000);
} else {
processor.fireCraftEvent(ticket, foundRequest.getStack());
}
if (!stack.isEmpty()) {
Inventory inventory = getInventoryFromTicket(ticket);
if (inventory != null) {
IItemHandler handlerAt = processor.getItemHandlerAt(inventory);
if (handlerAt == null) {
throw new ProgException(ExceptionType.EXCEPT_INVALIDINVENTORY);
}
return ItemHandlerHelper.insertItem(handlerAt, stack, false);
} else {
return ItemHandlerHelper.insertItem(getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null), stack, false);
}
}
}
return stack;
}
use of mcjty.rftoolscontrol.logic.running.ProgException in project RFToolsControl by McJty.
the class ProcessorTileEntity method checkIngredients.
public boolean checkIngredients(IProgram program, @Nonnull Inventory cardInv, ItemStack item, int slot1, int slot2) {
if (item.isEmpty()) {
item = getCraftResult(program);
}
if (item.isEmpty()) {
throw new ProgException(EXCEPT_MISSINGCRAFTRESULT);
}
IItemHandler cardHandler = getItemHandlerAt(cardInv);
ItemStack card = findCraftingCard(cardHandler, item);
if (card.isEmpty()) {
throw new ProgException(EXCEPT_MISSINGCRAFTINGCARD);
}
CardInfo info = this.cardInfo[((RunningProgram) program).getCardIndex()];
IItemHandler itemHandler = getItemHandler();
int slot = slot1;
List<ItemStack> ingredients;
if (CraftingCardItem.fitsGrid(card) && (slot2 - slot1 >= 8)) {
// We have something that fits a crafting grid and we have enough room for a 3x3 grid
ingredients = CraftingCardItem.getIngredientsGrid(card);
} else {
ingredients = CraftingCardItem.getIngredients(card);
}
int failed = 0;
for (ItemStack ingredient : ingredients) {
int realSlot = info.getRealSlot(slot);
ItemStack localStack = itemHandler.getStackInSlot(realSlot);
if (!ingredient.isEmpty()) {
if (!ingredient.isItemEqual(localStack)) {
return false;
}
if (ingredient.getCount() != localStack.getCount()) {
return false;
}
} else {
if (!localStack.isEmpty()) {
return false;
}
}
slot++;
}
return true;
}
Aggregations