Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(!this.isWorkAllowed() || !this.data.selectedRecipe || !this.data.selectedRecipe.craftable) return false;
- if(Config.dev)Logger.Log('Providing craft: result: ' + JSON.stringify(this.data.selectedRecipe.result), 'RefinedStorageDebug');
- var netFuncs = RSNetworks[this.data.NETWORK_ID].info;
- var selectedRecipe = this.data.selectedRecipe;
- var javaRecipe = selectedRecipe.javaRecipe;
- var result = selectedRecipe.result;
- this.container.setSlot('WB_result_slot', result.id, result.count, result.data == -1 ? 0 : result.data, result.extra || null);
- result = this.container.getSlot('WB_result_slot');
- var items = javaRecipe.getSortedEntries();
- //var fixedEntries = [];
- var smallItemsMap = {};
- for(i = 0; i < 9; i++){
- if(!items[i] || !items[i].id) {
- this.container.setSlot('WB_craft_slot' + i, 0,0,0);
- continue;
- }
- var item = items[i];
- itemData = item.data != -1 ? item.data : ((originalItem = this.originalOnlyItemsMap()[item.id]) ? originalItem[0] : 0);
- var itemUid = item.id+'_'+itemData;
- var itemExtra = (itemExtraExist = this.originalOnlyItemsExtraMap()[itemUid]) ? itemExtraExist[0] : null;
- if(itemExtra) itemUid += '_' + itemExtra.getValue();
- if(smallItemsMap[itemUid])
- smallItemsMap[itemUid]++;
- else
- smallItemsMap[itemUid] = 1;
- var itemCount = ((itemI = this.originalItemsMap().indexOf(itemUid)) != -1 && this.container.getSlot(itemI + "slot").count >= smallItemsMap[itemUid]) ? 1 : 0;
- if(!itemCount) {
- var playerItem = searchItem(item.id, itemData, itemExtra, false, false, player);
- if(playerItem && playerItem.count >= smallItemsMap[itemUid] - (itemI != -1 ? this.container.getSlot(itemI + "slot").count : 0)){
- itemExtra = playerItem.extra;
- itemCount = 1;
- } else {
- this.data.selectedRecipe.craftable = false;
- return false;
- }
- }
- this.container.setSlot('WB_craft_slot' + i, item.id, itemCount, itemData, itemExtra);
- }
- var playerSlots = {};
- for(var i in smallItemsMap){
- var splited = i.split('_');
- var itemExtra = splited[2] ? ItemExtraData(Number(splited[2])) : null;
- var item = {id: Number(splited[0]), count: smallItemsMap[i], data: Number(splited[1]), extra: itemExtra};
- if(!netFuncs.itemCanBeDeleted(item) && (!(playerSlots[i] = searchItem(item.id, item.data, item.extra, false, false, player)) || playerSlots[i].count < item.count)) return false;
- }
- var fieldApi = new WorkbenchFieldAPI(this.container);
- Callback.invokeCallback("CraftRecipePreProvided", javaRecipe, this.container);
- var fixedEntries = this.container.asScriptableField();
- var cbk = javaRecipe.getCallback();
- if(cbk)cbk.call(/* zhekaCompiler.assureContextForCurrentThread() */UI.getContext(), fieldApi, fixedEntries, result);
- var cbkUsed = false;
- var __PlayerActor = new PlayerActor(player);
- var cbkUsedFunc = function(){
- if(cbk && !cbkUsed){
- cbkUsed = true;
- for(var i in fixedEntries){
- if(!fixedEntries[i]) continue;
- if(fixedEntries[i].count != 0){
- var answ = this.pushItem(fixedEntries[i], fixedEntries[i].count, true);
- if(answ != 0){
- __PlayerActor.addItemToInventory(fixedEntries[i].id, answ, fixedEntries[i].data, null, false);
- }
- }
- }
- }
- };
- //var refreshRecipe = false;
- for(var i in smallItemsMap){
- var splited = i.split('_');
- var itemExtra = splited[2] ? ItemExtraData(Number(splited[2])) : null;
- var item = {id: Number(splited[0]), count: smallItemsMap[i], data: Number(splited[1]), extra: itemExtra};
- var ndeleted = netFuncs.deleteItem(item, null, true);
- if(ndeleted > 0 && (playerSlotData = playerSlots[i])){
- __PlayerActor.setInventorySlot(playerSlotData.slot, playerSlotData.id, playerSlotData.count - ndeleted, playerSlotData.data, playerSlotData.extra);
- }
- //if(!netFuncs.itemCanBeDeleted(item))refreshRecipe = true;
- };
- /* if(refreshRecipe){
- cbkUsedFunc.apply(this);
- //this.post_items(true);
- //this.selectRecipe(javaRecipe);
- }; */
- cbkUsedFunc.apply(this);
- Callback.invokeCallback("CraftRecipeProvided", javaRecipe, this.container, fieldApi.isPrevented());
- if(fieldApi.isPrevented()) return false;
- Callback.invokeCallback("VanillaWorkbenchCraft", result, this.container);
- Player.addItemToInventory(result.id, result.count, result.data, result.extra);
- Callback.invokeCallback("VanillaWorkbenchPostCraft", result, this.container);
- return true;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement