Welcome to Keen Software House Forums! Log in or Sign up to interact with the KSH community.
  1. You are currently browsing our forum as a guest. Create your own forum account to access all forum functionality.

Possible new filter block with new modding API

Discussion in 'Modding' started by Cattasraafe, Sep 19, 2014.

Thread Status:
This last post in this thread was made more than 31 days old.
  1. Cattasraafe Trainee Engineer

    Messages:
    20
    Soooo.. I don't know crap about modding.... or coding. I was wondering that if I were to learn how to do such things would a filter block say for sending ores to specific containers and ingots to specific containers and so on be possible now with the new modding API?
     
  2. Killili Trainee Engineer

    Messages:
    15
    I think thats a question everyone wants to be answerd.

    So i look into into the stuff and its "maybe". I found the interface for Inventory interaction and conveyor stuff but i have to take a deeper look into it because it does not look easy to override default behavior.
     
  3. Killili Trainee Engineer

    Messages:
    15
    Ok after 2 hours of coding i'm down to this:

    • we can read the contens of storages
    • we can find specific items in storages
    • i found a way to interact with the conveyor system
    • but we cant change whats inside a storage (adding/removing)
    plz. correct me if im wrong (i hope i'm wrong), maybe next week.

    I think that the ObjectBuilder is a deserialized version of the actual game object and changes to it are not reflected in the game. And IMyStorage has no methodes yet to do anything usefull.

    The relevant code for the interessted:
    Code:
    var inputFace = (MyObjectBuilder_CargoContainer)input.GetObjectBuilderCubeBlock();
    var inputInventory = inputFace.Inventory;
    var outputFace = (MyObjectBuilder_CargoContainer)output.GetObjectBuilderCubeBlock();
    var outputInventory = outputFace.Inventory;
    if(inputInventory.Items.Count > 0) {
       var item = inputInventory.Items[0];
       inputInventory.Items.Remove(item); // removeAt(0) does nothing,too.
       outputInventory.Items.Add(item); // does nothing
    }
    
    
     
  4. Draygo Senior Engineer

    Messages:
    1,297
    You need to modify the backing object, not its object builder.
     
  5. Cattasraafe Trainee Engineer

    Messages:
    20
    Help an uneducated fool out a bit. A friend of mine that I play SE with knows some C++ and we might be able to mess with some stuff. What are you using to look at the coding itself? It sounds like your using a program to look at the file coding, or are you just looking in each individual file using a program like notepad++?


    p.s Thank you for the sensible replies.... sometimes forums and the people in them scare me.
     
  6. waterlimon Senior Engineer

    Messages:
    1,499
    You have to decompress the mod file with 7zip or something (I had to use 7zip file browser to browse into the mod because otherwise it just opened in notepad...) and use an IDE (ms visual studio express) to modify the code (you need to add a reference to the sandbox.common.dll in the bin folder of SE to get intellisense and ability to see the full exposed API)
     
  7. ThatGuy Trainee Engineer

    Messages:
    56
    The reactors are only made to contain uranium and weapons ammunition maybe you could make a "storage block" that only holds one specific item like the reactor and weapons and use this as a filter
     
  8. Albino Trainee Engineer

    Messages:
    22
    Im actually working on a filter block since the ModAPI was released.

    It takes time because im unfimaliar with C# and working with librairies, but I currently have a connector block that can act as a filter if you rename it as needed. For instance : "Connector12 FilterOre Gold Delay 1000" will eject a certain volume of gold ore every 1000 milliseconds.

    What's left to do it the inventory part which im still investigating. As soon as its done & tested ill release it on the workshop.

    <del>ThatGuy</del> killili (oops) > Thanks for the code.
     
  9. Killili Trainee Engineer

    Messages:
    15
    So i'm right about that i only get a marshaled object and not the real one.
    But am i right about that there is no methode to actually change the inventory of an object for now?

    Besides deleting the original object an creating in new from the changed backing object?
     
  10. ThatGuy Trainee Engineer

    Messages:
    56
    The code is in a quote it's from killili
     
  11. Albino2 Trainee Engineer

    Messages:
    16
    ThatGuy > Oops

    Killili, how would you do to access the inventory of a block that you obtained in the form of a IMySlimBlock / FatBlock ? I suppose it has something to do typecast or objects with multiples types, but since im new to C# I have no idea how to proceed.
     
  12. Killili Trainee Engineer

    Messages:
    15
    @Albino: Here is the whole project

    https://github.com/Killili/SimplexFilter

    Maybe we should coordinate our efforts because we are basicaly trying to do the same thing?
    I can add you to the GitHub contributers, just PM me.
     
  13. Albino2 Trainee Engineer

    Messages:
    16
    Killili > Yeah I guess it would only be beneficial. Currently my script is not in a working state as Im trying to access the inventory of bocks with no success so far. I should be able to present you with non-broken version tomorrow.

    Edit: my problem is that I have a list of blocks, but they are of various types, so I cant blindly typecast to a MyObjectBuilder_CargoContainer, so im not sure how to proveed.
     
  14. Killili Trainee Engineer

    Messages:
    15
    Never mind we can stop there for now.

    Quote from a Dev:
     
  15. Albino2 Trainee Engineer

    Messages:
    16
    Dammit.
     
  16. eobando Trainee Engineer

    Messages:
    96
    I'm actually waiting for Inventory access in order to read what is inside an Assembler object. Currently (I'm still trying though), it only allows very minimal information. If someone can guide me, that would be appreciated.
     
  17. tyrsis Junior Engineer

    Messages:
    862
    You can view the complete inventory of any production block by viewing it's ObjectBuilder. These are read only, but you can at least display information if you'd like. Here is a quick function I threw together that I tested that shows inventories of all Assemblers / Refineries in game.

    Code:
        public static void viewInventory()
        {
            HashSet&lt;IMyEntity> entities = new HashSet&lt;IMyEntity>();
            MyAPIGateway.Entities.GetEntities(entities, null);
            foreach (IMyEntity entity in entities)
            {
                if (entity is IMyCubeGrid)
                {
                    IMyCubeGrid grid = (IMyCubeGrid)entity;
                    var gridObject = (MyObjectBuilder_CubeGrid)grid.GetObjectBuilder();
                    foreach (MyObjectBuilder_CubeBlock block in gridObject.CubeBlocks)
                    {
                        if (block is MyObjectBuilder_ProductionBlock) // Assembler or Refinery, or any subtype of those
                        {
                            MyObjectBuilder_ProductionBlock production = (MyObjectBuilder_ProductionBlock)block;
    
                            if (production.Inventory != null)
                            {
                                foreach (MyObjectBuilder_InventoryItem item in production.Inventory.Items)
                                {
                                    // All inventory items
                                    MyAPIGateway.Utilities.ShowMessage("Inventory", String.Format("{0} - {1}", item.PhysicalContent.SubtypeName, item.Amount));
                                }
                            }
    
                            if (production.InputInventory != null)
                            {
                                foreach (MyObjectBuilder_InventoryItem item in production.InputInventory.Items)
                                {
                                    // All Input Inventory Items
                                    MyAPIGateway.Utilities.ShowMessage("Inventory", String.Format("{0} - {1}", item.PhysicalContent.SubtypeName, item.Amount));
                                }
                            }
    
                            if (production.OutputInventory != null)
                            {
                                foreach (MyObjectBuilder_InventoryItem item in production.OutputInventory.Items)
                                {
                                    // All Output Inventory Items
                                    MyAPIGateway.Utilities.ShowMessage("Inventory", String.Format("{0} - {1}", item.PhysicalContent.SubtypeName, item.Amount));
                                }
                            }
    
                            if (production.Queue != null)
                            {
                                foreach (MyObjectBuilder_ProductionBlock.QueueItem item in production.Queue)
                                {
                                    // Production Queue
                                    MyAPIGateway.Utilities.ShowMessage("Queue", String.Format("{0} - {1}", item.Id.SubtypeName, item.Amount));
                                }
                            }
                        }
                    }
                }
            }
        }
    
     
  18. botelhorui Trainee Engineer

    Messages:
    53
    thank you for sharing
     
  19. soat7ch Junior Engineer

    Messages:
    605
    What about the blast furnaces? They should contain the information that they can only accept Iron ore, if you compare that to guns and the inventory of reactors it should be a visible pattern showing what to change for specialized containers
     
  20. tyrsis Junior Engineer

    Messages:
    862
    That information would be in the definitions. You would have to dig into that a bit but check out the MyDefinitionsManager.Static as that contains basically the deserialized data from all the data .sbc files.
     
  21. eobando Trainee Engineer

    Messages:
    96
    Fantastic! Thanks for the sample!
     
  22. eobando Trainee Engineer

    Messages:
    96
    Tyrsis, thanks for the sample code. That truly helped two-fold. I will include you in my notes for my mod. Thanks!
     
  23. Killili Trainee Engineer

    Messages:
    15
    Last edited by a moderator: Oct 7, 2014
Thread Status:
This last post in this thread was made more than 31 days old.