Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
Palagius

AE2 Level / Auto-crafting

Recommended Posts

It is possible this was implemented elsewhere and I failed to notice it, but I did this as an exercise as exploring OpenComputers.  My son and I play The 1.7.10 Pack for our sandbox fun (in survival mode though), and I wanted to see if I could easily use OpenComputers to replace the typical-and-complex nest of level emitters and crafting cards to maintain minimum amounts of certain items in the AE2 ME network.

This is not terribly sophisticated, and is just "fire-and-forget" with respects to requesting the crafting operations from the ME Network.  As I continue to dabble I may add in checking on the status of the requested jobs and bound the looping to when all requested jobs per loop-pass have been completed.

Edited to include versions (Minecraft 1.7.10) and remove a couple of potentially confusing commented-out lines:

  • OpenComputers 1.6.2.12
  • AE2 rv3 beta6
  • Lots of other stuff outside the scope of this program

Here is what I wrote:

local component = require("component")
local meController = component.proxy(component.me_controller.address)
local gpu = component.gpu

-- Each element of the array is "item", "damage", "number wanted", "max craft size"
-- Damage value should be zero for base items

items = {
    { "minecraft:iron_ingot",       0, 512, 32 },
    { "minecraft:gold_ingot",       0, 256, 32 },
    { "IC2:itemIngot",              0, 512, 32 }, -- Copper
    { "IC2:itemIngot",              1, 256, 32 }, -- Tin
    { "IC2:itemIngot",              2, 512, 32 }, -- Bronze
    { "IC2:itemIngot",              3, 256, 64 }, -- Refined Iron
    { "appliedenergistics2:item.ItemMultiMaterial",        8, 128, 32 }, -- Fluix Dust
    { "appliedenergistics2:item.ItemMultiMaterial",       10, 128, 32 }, -- Pure Certus
    { "appliedenergistics2:item.ItemMultiMaterial",       11, 128, 32 }, -- Pure Nether
    { "appliedenergistics2:item.ItemMultiMaterial",       12, 128, 32 }, -- Pure Fluix
    { "appliedenergistics2:item.ItemMultiMaterial",       22, 128, 32 }, -- Logic Processor
    { "appliedenergistics2:item.ItemMultiMaterial",       23, 128, 32 }, -- Calculation Processor
    { "appliedenergistics2:item.ItemMultiMaterial",       24, 128, 32 }, -- Engineering Processor
    { "appliedenergistics2:item.ItemMultiMaterial",       52, 32, 32 }, -- Blank Pattern
    { "appliedenergistics2:item.ItemMultiPart",       16, 128, 32 }, -- Glass Cable - Fluix
    { "appliedenergistics2:item.ItemMultiPart",       21, 64, 32 }, -- ME Covered Cable - Orange
    { "appliedenergistics2:item.ItemMultiPart",       22, 64, 32 }, -- ME Covered Cable - Magenta
    { "appliedenergistics2:item.ItemMultiPart",       24, 64, 32 }, -- ME Covered Cable - Yellow
    { "appliedenergistics2:item.ItemMultiPart",       25, 64, 32 }, -- ME Covered Cable - Lime
    { "appliedenergistics2:item.ItemMultiPart",       29, 64, 32 }, -- ME Covered Cable - Cyan
    { "appliedenergistics2:item.ItemMultiPart",       30, 64, 32 }, -- ME Covered Cable - Purple
    { "appliedenergistics2:item.ItemMultiPart",       31, 64, 32 }, -- ME Covered Cable - Blue
    { "appliedenergistics2:item.ItemMultiPart",       34, 64, 32 }, -- ME Covered Cable - Red
    { "appliedenergistics2:item.ItemMultiPart",       36, 64, 32 }, -- ME Covered Cable - Fluix
    { "appliedenergistics2:item.ItemMultiPart",      140, 64, 32 }, -- Quartz Fiber
    { "appliedenergistics2:tile.BlockQuartzGlass",     0, 64, 32 }, -- Quartz Glass
    { "minecraft:glass",      0, 512, 256 },
    { "minecraft:sand",       0, 512, 256 }
}

loopDelay = 60 -- Seconds between runs

while true do
    for curIdx = 1, #items do
        curName = items[curIdx][1]
        curDamage = items[curIdx][2]
        curMinValue = items[curIdx][3]
        curMaxRequest = items[curIdx][4]

        -- io.write("Checking for " .. curMinValue .. " of " .. curName .. "\n")
        storedItem = meController.getItemsInNetwork({
            name = curName,
            damage = curDamage
            })
        io.write("Network contains ")
        gpu.setForeground(0xCC24C0) -- Purple-ish
        io.write(storedItem[1].size)
        gpu.setForeground(0xFFFFFF) -- White
        io.write(" items with label ")
        gpu.setForeground(0x00FF00) -- Green
        io.write(storedItem[1].label .. "\n")
        gpu.setForeground(0xFFFFFF) -- White
        if storedItem[1].size < curMinValue then
            delta = curMinValue - storedItem[1].size
            craftAmount = delta
            if delta > curMaxRequest then
                craftAmount = curMaxRequest
            end

            io.write("  Need to craft ")
            gpu.setForeground(0xFF0000) -- Red
            io.write(delta)
            gpu.setForeground(0xFFFFFF) -- White
            io.write(", requesting ")
            gpu.setForeground(0xCC24C0) -- Purple-ish
            io.write(craftAmount .. "... ")
            gpu.setForeground(0xFFFFFF) -- White

            craftables = meController.getCraftables({
                name = curName,
                damage = curDamage
                })
            if craftables.n >= 1 then
                cItem = craftables[1]
                retval = cItem.request(craftAmount)
                gpu.setForeground(0x00FF00) -- Green
                io.write("OK\n")
                gpu.setForeground(0xFFFFFF) -- White
            else
                gpu.setForeground(0xFF0000) -- Red
                io.write("    Unable to locate craftable for " .. storedItem[1].name .. "\n")
                gpu.setForeground(0xFFFFFF) -- White
            end
        end
    end
    io.write("Sleeping for " .. loopDelay .. " seconds...\n\n")
    os.sleep(loopDelay)
end

I have also attached a cropped screenshot of it running and the output.  Naturally one will want to turn knobs on the crafting amounts and frequency.  I find the 60 minute cycle to be more than enough for the crafting backlog to be cleared.

 

me_levels_screenshot.png

Share this post


Link to post
Share on other sites

I realise this is an old post, but thank you very much for a working AE2 autocrafting script.

I modified it slightly to store the craft result object, so that it can be checked in the next cycle to see if the job is still active or not, and then skip adding a another job if it's still in progress and it's working perfectly in Minecraft 1.12.2, with OpenComputers 1.7.2.67 and Applied Energistics 2 rv5-stable-11

Here is my modified version if anyone is interested:

-- Original by Palagius : https://oc.cil.li/index.php?/topic/1426-ae2-level-auto-crafting/
-- Modfied by Dalden 2018-07-28 
--           - Store crafting result object to check for status
--           - If crafting job is not yet finished from previous cycle then skip this cycle

local component = require("component")
local meController = component.proxy(component.me_controller.address)
local gpu = component.gpu

-- Each element of the array is "item", "damage", "number wanted", "max craft size"
-- Damage value should be zero for base items

items = {
    { "minecraft:iron_ingot",       0, 16384, 256 },
    { "minecraft:gold_ingot",       0, 16384, 256 },
    { "minecraft:glass",      0, 16384, 256 },
    { "minecraft:quartz",      0, 16384, 256 },
    { "minecraft:diamond",      0, 16384, 256 },
    { "minecraft:emerald",      0, 16384, 256 },
    { "draconicevolution:draconium_ingot",      0, 16384, 256 },
    { "thermalfoundation:material",       128, 1024, 256 }, -- Copper Ingot
    { "thermalfoundation:material",       129, 1024, 256 }, -- Tin Ingot
    { "thermalfoundation:material",       130, 1024, 256 }, -- Silver Ingot
    { "thermalfoundation:material",       131, 1024, 256 }, -- Lead Ingot
    { "thermalfoundation:material",       161, 1024, 256 }, -- Electrum Ingot
    { "thermalfoundation:material",       162, 1024, 256 }, -- Invar Ingot
    { "thermalfoundation:material",       163, 1024, 256 }, -- Bronze Ingot
    { "thermalfoundation:material",       164, 1024, 256 }, -- Constantan Ingot
    { "thermalfoundation:material",       165, 1024, 256 }, -- Signalum Ingot
    { "thermalfoundation:material",       166, 1024, 256 }, -- Lumium Ingot
    { "thermalfoundation:material",       167, 1024, 256 }, -- Enderium Ingot
    { "appliedenergistics2:material",       24, 4096, 256 }, -- Engineering Processor
    { "appliedenergistics2:material",       23, 4096, 256 }, -- Calculation Processor
    { "appliedenergistics2:material",       22, 4096, 256 }, -- Logic Processor
    { "appliedenergistics2:material",       11, 4096, 256 }, -- Pure Nether Quartz Crystal
    { "appliedenergistics2:material",       10, 4096, 256 }, -- Pure Certus Quartz Crystal
    { "appliedenergistics2:material",       7, 4096, 256 }, -- Fluix Crystal
    { "appliedenergistics2:material",       12, 4096, 256 }, -- Pure Fluix Crystal
    { "appliedenergistics2:material",       0, 4096, 256 }, -- Certus Quartz Crystal
    { "appliedenergistics2:material",       1, 4096, 256 }, -- Charged Certus Quartz Crystal
    { "appliedenergistics2:material",       8, 4096, 256 }, -- Fluix Dust
    { "appliedenergistics2:material",       2, 4096, 256 }, -- Certus Quartz Dust
    { "actuallyadditions:item_dust",       5, 4096, 256 }, -- Crushed Quartz
    { "enderio:item_material",       5, 4096, 256 }, -- Silicon
    { "enderio:item_alloy_ingot",       1, 1024, 256 }, -- Energetic Alloy Ingot
    { "enderio:item_alloy_ingot",       2, 1024, 256 }, -- Vibrant Alloy Ingot
    { "enderio:item_alloy_ingot",       5, 1024, 256 }, -- Pulsating Iron Ingot
    { "enderio:item_alloy_ingot",       6, 1024, 256 }, -- Dark Steel Ingot
    { "enderio:item_alloy_ingot",       7, 1024, 256 }, -- Soularium Ingot
    { "enderio:item_alloy_ingot",       8, 1024, 256 }, -- End Steel Ingot
    { "enderio:item_alloy_ingot",       0, 1024, 256 } -- Electrical Steel Ingot
}

loopDelay = 60 -- Seconds between runs

-- Init list with crafting status
for curIdx = 1, #items do
    items[curIdx][5] = false -- Crafting status set to false
    items[curIdx][6] = nil -- Crafting object null
end

while true do
    for curIdx = 1, #items do
        curName = items[curIdx][1]
        curDamage = items[curIdx][2]
        curMinValue = items[curIdx][3]
        curMaxRequest = items[curIdx][4]
        curCrafting = items[curIdx][5]
        curCraftStatus = items[curIdx][6]

        -- io.write("Checking for " .. curMinValue .. " of " .. curName .. "\n")
        storedItem = meController.getItemsInNetwork({
            name = curName,
            damage = curDamage
            })
        io.write("Network contains ")
        gpu.setForeground(0xCC24C0) -- Purple-ish
        io.write(storedItem[1].size)
        gpu.setForeground(0xFFFFFF) -- White
        io.write(" items with label ")
        gpu.setForeground(0x00FF00) -- Green
        io.write(storedItem[1].label .. "\n")
        gpu.setForeground(0xFFFFFF) -- White
        if storedItem[1].size < curMinValue then
            delta = curMinValue - storedItem[1].size
            craftAmount = delta
            if delta > curMaxRequest then
                craftAmount = curMaxRequest
            end

            io.write("  Need to craft ")
            gpu.setForeground(0xFF0000) -- Red
            io.write(delta)
            gpu.setForeground(0xFFFFFF) -- White
            io.write(", requesting ")
            gpu.setForeground(0xCC24C0) -- Purple-ish
            io.write(craftAmount .. "... ")
            gpu.setForeground(0xFFFFFF) -- White

            craftables = meController.getCraftables({
                name = curName,
                damage = curDamage
                })
            if craftables.n >= 1 then
                cItem = craftables[1]
                if curCrafting then
                    if curCraftStatus.isCanceled() or curCraftStatus.isDone() then
                        io.write("Previous Craft completed\n")
                        items[curIdx][5] = false
                        curCrafting = false
                    end
                end
                if curCrafting then
                        io.write("Previous Craft busy\n")
                end
                if not curCrafting then
                    retval = cItem.request(craftAmount)
                    items[curIdx][5] = true
                    items[curIdx][6] = retval
                    gpu.setForeground(0x00FF00) -- Green
                    io.write("Requested - ")
		    --while (not retval.isCanceled()) and (not retval.isDone()) do
	            --		os.sleep(1)
                    --        io.write(".")
		    -- end
                    gpu.setForeground(0xFFFFFF) -- White
                    io.write("Done \n")
                end
            else
                gpu.setForeground(0xFF0000) -- Red
                io.write("    Unable to locate craftable for " .. storedItem[1].name .. "\n")
                gpu.setForeground(0xFFFFFF) -- White
            end
        end
    end
    io.write("Sleeping for " .. loopDelay .. " seconds...\n\n")
    os.sleep(loopDelay)
end

 

Share this post


Link to post
Share on other sites
On 10/1/2018 at 3:37 PM, IceG4merBR said:

What is the damage and how i find it?

In JEI when you mouse over an item it should be the number after the slash ( / ) at the top of the item frame.

I realize I have not been a good citizen and keeping up with this.  I actually significantly improved this script in a 1.12.2 modpack and will post it when I have a chance.  I also actually pared things down with better functions--thought I did not fold in the changes Dalden made for tracking current crafting.  I shall try to pull that in as well and post the whole thing on Github.

 

Share this post


Link to post
Share on other sites

@Palagius the current version (and you may have fixed it since) displays a decimal place in the output.  I added a function to fix that, if you want to incorporate it:

 

function remove_dec(num)
  return string.format("%.0f", num)
end

 

 

Share this post


Link to post
Share on other sites

hi have a small issue every time I populate the data base with any thing the program crashes what am I doing wrong I am using 1.7.10 and the right versions of the mods

2019-08-22_15_26_07.thumb.png.78e2c9e408cb11d800d18d1759b5f965.png

2019-08-22_15_28_12.thumb.png.0d1a05687617df3336b1b3d9fc3a1898.png

 

Share this post


Link to post
Share on other sites
4 hours ago, duz_holger said:

hi have a small issue every time I populate the data base with any thing the program crashes what am I doing wrong I am using 1.7.10 and the right versions of the mods

 

I keep forgetting to post my significantly-improved versions of this.  Sorry about that.

My memory is that in 1.7.10 you actually cannot use the name-only item descriptor.  In your test example try using the item ID for sand rather than "minecraft:sand".  Does that make sense?  So using NEI / JEI / whatever look up sand, and if it is item ID 27 then just use that.  Might need to be (for example) minecraft:27 in that theoretical example. 

But what is going on with that crash is there is no error checking when the script attempts to check how many items you have of the requested ID.  The call is returning nothing, and I did not have a sanity check in there for "item not found" which is breaking things.

But when I did this in 1.7.10 long ago I think I had to use item IDs rather than names.

Just now, Palagius said:

I keep forgetting to post my significantly-improved versions of this.  Sorry about that.

My memory is that in 1.7.10 you actually cannot use the name-only item descriptor.  In your test example try using the item ID for sand rather than "minecraft:sand".  Does that make sense?  So using NEI / JEI / whatever look up sand, and if it is item ID 27 then just use that.  Might need to be (for example) minecraft:27 in that theoretical example. 

But what is going on with that crash is there is no error checking when the script attempts to check how many items you have of the requested ID.  The call is returning nothing, and I did not have a sanity check in there for "item not found" which is breaking things.

But when I did this in 1.7.10 long ago I think I had to use item IDs rather than names.

Actually, I just looked at an old version I used on The 1.7.10 Pack and it's still using the names.

Do you have an OpenComputers interface directly attached to your ME controller?  

Share this post


Link to post
Share on other sites
3 hours ago, Palagius said:

 

Actually, I just looked at an old version I used on The 1.7.10 Pack and it's still using the names.

Do you have an OpenComputers interface directly attached to your ME controller?  

yes I do via some P2p tunels bus otherwise yes

Share this post


Link to post
Share on other sites
20 hours ago, duz_holger said:

yes I do via some P2p tunels bus otherwise yes

I misunderstood, and using the wrong words in my question made things worse not better.

My setups always had an OC "Adapter" directly connected to my ME Controller.  As a consequence, at the very beginning of the script we are getting the component to proxy that communication.

If your OC Adapter is connected to an ME Interface (rather than directly touching the controller) than at the beginning you need to have the component.proxy thing connect to an ME Interface rather than the controller.

Having said that, I do not know if my script will work talking to the ME Interface, because I am not sure you can request crafting jobs to the ME Controller through an ME Interface.

My suggestion is you retool your configuration to run an OpenComputers Cable from your computer to an OC Adapter directly touching your AE2 ME Controller.  That is what the script was written to accommodate and utilize.

 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.