Advertisement
Bot213123

Craft

Jan 23rd, 2021
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. if(!this.isWorkAllowed() || !this.data.selectedRecipe || !this.data.selectedRecipe.craftable) return false;
  2.         if(Config.dev)Logger.Log('Providing craft: result: ' + JSON.stringify(this.data.selectedRecipe.result), 'RefinedStorageDebug');
  3.         var netFuncs = RSNetworks[this.data.NETWORK_ID].info;
  4.         var selectedRecipe = this.data.selectedRecipe;
  5.         var javaRecipe = selectedRecipe.javaRecipe;
  6.         var result = selectedRecipe.result;
  7.         this.container.setSlot('WB_result_slot', result.id, result.count, result.data == -1 ? 0 : result.data, result.extra || null);
  8.         result = this.container.getSlot('WB_result_slot');
  9.         var items = javaRecipe.getSortedEntries();
  10.         //var fixedEntries = [];
  11.         var smallItemsMap = {};
  12.         for(i = 0; i < 9; i++){
  13.             if(!items[i] || !items[i].id) {
  14.                 this.container.setSlot('WB_craft_slot' + i, 0,0,0);
  15.                 continue;
  16.             }
  17.             var item = items[i];
  18.             itemData = item.data != -1 ? item.data : ((originalItem = this.originalOnlyItemsMap()[item.id]) ? originalItem[0] : 0);
  19.             var itemUid = item.id+'_'+itemData;
  20.             var itemExtra = (itemExtraExist = this.originalOnlyItemsExtraMap()[itemUid]) ? itemExtraExist[0] : null;
  21.             if(itemExtra) itemUid += '_' + itemExtra.getValue();
  22.             if(smallItemsMap[itemUid])
  23.                 smallItemsMap[itemUid]++;
  24.             else
  25.                 smallItemsMap[itemUid] = 1;
  26.             var itemCount = ((itemI = this.originalItemsMap().indexOf(itemUid)) != -1 && this.container.getSlot(itemI + "slot").count >= smallItemsMap[itemUid]) ? 1 : 0;
  27.             if(!itemCount) {
  28.                 var playerItem = searchItem(item.id, itemData, itemExtra, false, false, player);
  29.                 if(playerItem && playerItem.count >= smallItemsMap[itemUid] - (itemI != -1 ? this.container.getSlot(itemI + "slot").count : 0)){
  30.                     itemExtra = playerItem.extra;
  31.                     itemCount = 1;
  32.                 } else {
  33.                     this.data.selectedRecipe.craftable = false;
  34.                     return false;
  35.                 }
  36.             }
  37.             this.container.setSlot('WB_craft_slot' + i, item.id, itemCount, itemData, itemExtra);
  38.         }
  39.         var playerSlots = {};
  40.         for(var i in smallItemsMap){
  41.             var splited = i.split('_');
  42.             var itemExtra = splited[2] ? ItemExtraData(Number(splited[2])) : null;
  43.             var item = {id: Number(splited[0]), count: smallItemsMap[i], data: Number(splited[1]), extra: itemExtra};
  44.             if(!netFuncs.itemCanBeDeleted(item) && (!(playerSlots[i] = searchItem(item.id, item.data, item.extra, false, false, player)) || playerSlots[i].count < item.count)) return false;
  45.         }
  46.         var fieldApi = new WorkbenchFieldAPI(this.container);
  47.         Callback.invokeCallback("CraftRecipePreProvided", javaRecipe, this.container);
  48.         var fixedEntries = this.container.asScriptableField();
  49.         var cbk = javaRecipe.getCallback();
  50.         if(cbk)cbk.call(/* zhekaCompiler.assureContextForCurrentThread() */UI.getContext(), fieldApi, fixedEntries, result);
  51.         var cbkUsed = false;
  52.         var __PlayerActor = new PlayerActor(player);
  53.         var cbkUsedFunc = function(){
  54.             if(cbk && !cbkUsed){
  55.                 cbkUsed = true;
  56.                 for(var i in fixedEntries){
  57.                     if(!fixedEntries[i]) continue;
  58.                     if(fixedEntries[i].count != 0){
  59.                         var answ = this.pushItem(fixedEntries[i], fixedEntries[i].count, true);
  60.                         if(answ != 0){
  61.                             __PlayerActor.addItemToInventory(fixedEntries[i].id, answ, fixedEntries[i].data, null, false);
  62.                         }
  63.                     }
  64.                 }
  65.             }
  66.         };
  67.         //var refreshRecipe = false;
  68.         for(var i in smallItemsMap){
  69.             var splited = i.split('_');
  70.             var itemExtra = splited[2] ? ItemExtraData(Number(splited[2])) : null;
  71.             var item = {id: Number(splited[0]), count: smallItemsMap[i], data: Number(splited[1]), extra: itemExtra};
  72.             var ndeleted = netFuncs.deleteItem(item, null, true);
  73.             if(ndeleted > 0 && (playerSlotData = playerSlots[i])){
  74.                 __PlayerActor.setInventorySlot(playerSlotData.slot, playerSlotData.id, playerSlotData.count - ndeleted, playerSlotData.data, playerSlotData.extra);
  75.             }
  76.             //if(!netFuncs.itemCanBeDeleted(item))refreshRecipe = true;
  77.         };
  78.         /* if(refreshRecipe){
  79.             cbkUsedFunc.apply(this);
  80.             //this.post_items(true);
  81.             //this.selectRecipe(javaRecipe);
  82.         }; */
  83.         cbkUsedFunc.apply(this);
  84.         Callback.invokeCallback("CraftRecipeProvided", javaRecipe, this.container, fieldApi.isPrevented());
  85.         if(fieldApi.isPrevented()) return false;
  86.         Callback.invokeCallback("VanillaWorkbenchCraft", result, this.container);
  87.         Player.addItemToInventory(result.id, result.count, result.data, result.extra);
  88.         Callback.invokeCallback("VanillaWorkbenchPostCraft", result, this.container);
  89.         return true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement