Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[start setup
- facing: input chest
- above: output chest
- left, right and behind: sorting chests for fluix crystal generation
- ]]
- local downblock = "minecraft:flowing_water";
- local charged_certus = "appliedenergistics2:item.ItemMultiMaterial";
- local nether_quartz = "minecraft:quartz";
- local redstone = "minecraft:redstone";
- function IsRedstone(data)
- return data.name==redstone;
- end
- function IsNetherQuartz(data)
- return data.name==nether_quartz;
- end
- function IsChargedQuartz(data)
- return data.name==charged_certus and data.damage==1
- end
- function IsFluixCreator(data)
- if IsNetherQuartz(data) or
- IsRedstone(data) or
- IsChargedQuartz(data)
- then
- return true;
- else
- return false;
- end
- end
- function PutDownFluixMaterial()
- print("Creating fluix crystals");
- local data=nil;
- local wasputdown = false;
- turtle.select(1);
- if not GetLeft() then
- print("Failed to grab left");
- return;
- end
- turtle.select(2);
- if not GetRight() then
- print("Failed to grab right");
- SortFluix();
- return;
- end
- turtle.select(3);
- if not GetBack() then
- print("Failed to grab back");
- SortFluix();
- return;
- end
- for n=1,3 do
- data = turtle.getItemDetail(n);
- if data then
- if IsFluixCreator(data) then
- turtle.select(n);
- turtle.dropDown();
- wasputdown=true;
- end
- end
- end
- if wasputdown then
- print("put down fluix creation material, waiting 10 seconds");
- os.sleep(10);
- end
- return wasputdown;
- end
- function SuckUpAll()
- print("Sucking up all seeds");
- local sucked = 0;
- for n=1,16 do
- turtle.select(n);
- if not turtle.suckDown() then
- break;
- else
- sucked = sucked + 1;
- end
- end
- SortFluix();
- return sucked;
- end
- function GetItemIsAE2(name)
- return type(tostring(name):find(ae2,1,true))~="nil";
- end
- function ShouldBePutDown(data)
- return data.name=="appliedenergistics2:item.ItemCrystalSeed";
- end
- function EmptyCompleted()
- print("Checking inventory for completed crystals");
- local data=nil;
- for n=1,16 do
- data = turtle.getItemDetail(n);
- if data then
- if IsFluixCreator(data) then
- print("Putting back fluix creation material into front chest");
- turtle.select(n);
- if not turtle.drop() then
- print("front is full, dropping fluix creator up instead");
- turtle.dropUp();
- end
- elseif not ShouldBePutDown(data) then
- print(data.name..":"..tostring(data.damage).." is done or not a seed");
- turtle.select(n);
- turtle.dropUp();
- else
- print(data.name..":"..tostring(data.damage).." is not done, putting down");
- turtle.select(n);
- turtle.dropDown();
- end
- end
- end
- end
- function StackDuplicates()
- local selected = turtle.getSelectedSlot();
- local inslot = turtle.getItemDetail();
- local cursor = nil;
- if not inslot then
- return true;
- end
- for n=1,16 do
- if n~= selected then
- cursor = turtle.getItemDetail(n);
- if cursor and cursor.count <= 64 and cursor.name==inslot.name and cursor.damage==inslot.damage then
- turtle.transferTo(n);
- inslot = turtle.getItemDetail();
- if not inslot then
- return true;
- end
- end
- end
- end
- return false;
- end
- function GetLeft()
- turtle.turnLeft();
- local ret = turtle.suck();
- turtle.turnRight();
- return ret;
- end
- function GetRight()
- turtle.turnRight();
- local ret = turtle.suck();
- turtle.turnLeft();
- return ret;
- end
- function GetBack()
- turtle.turnRight();
- turtle.turnRight();
- local ret = turtle.suck();
- turtle.turnRight();
- turtle.turnRight();
- return ret;
- end
- function PutLeft()
- turtle.turnLeft();
- turtle.drop();
- turtle.turnRight();
- end
- function PutRight()
- turtle.turnRight();
- turtle.drop();
- turtle.turnLeft();
- end
- function PutBack()
- turtle.turnRight();
- turtle.turnRight();
- turtle.drop();
- turtle.turnRight();
- turtle.turnRight();
- end
- function SortFluix()
- local data = nil;
- for n=1,16 do
- turtle.select(n);
- data = turtle.getItemDetail();
- if data then
- if IsRedstone(data) then
- PutLeft();
- elseif IsNetherQuartz(data) then
- PutRight();
- elseif IsChargedQuartz(data) then
- PutBack()
- end
- end
- end
- end
- function GetNewStock()
- local gotsomething = false;
- local data = nil;
- local testedfluix = false;
- while true do
- for n=1,16 do
- turtle.select(n);
- data = turtle.getItemDetail();
- if data then
- gotsomething = true;
- elseif turtle.suck() then
- gotsomething = true;
- if StackDuplicates() then
- n = n - 1;
- end
- else
- break;
- end
- end
- if gotsomething then
- SortFluix();
- return;
- else
- print("Need new stock, put seeds in a chest infront of me (or into me)");
- if testedfluix then
- os.sleep(5);
- elseif PutDownFluixMaterial() then
- return;
- else
- testedfluix=true;
- end
- end
- end
- end
- print("Crystal program starting...");
- if SuckUpAll() <= 0 then
- GetNewStock();
- end
- while true do
- EmptyCompleted();
- print("Sleeping for 10 seconds...");
- print("checking seeds...");
- os.sleep(10);
- if SuckUpAll() <= 0 then
- while PutDownFluixMaterial() do
- print("More...");
- end
- GetNewStock();
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement