MCCTeam / Minecraft-Console-Client

Lightweight console for Minecraft chat and automated scripts
https://mccteam.github.io
Other
1.65k stars 399 forks source link

Copy Inventory #1320

Closed xXjojaXx closed 3 years ago

xXjojaXx commented 3 years ago

Is there any way to get the bot to copy the inventory of another user? Its possible for me to see in their inventory via /invsee if that does matter. Or is it at least possible to get the id and count of blocks/items in the first slot of an inventory? Thanks

ORelio commented 3 years ago

You should be able to by running sending the /invsee command to the server and using the regular inventory API.

ReinforceZwei commented 3 years ago

By the way you cannot get the full inventory items of other players in vanilla server.

Mhowser commented 3 years ago

That's right, the only things that are visible to other clients is armor and held items.

On Sun, Nov 8, 2020, 6:39 PM ReinforceZwei notifications@github.com wrote:

By the way you cannot get the full inventory items of other players in vanilla server.

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/ORelio/Minecraft-Console-Client/issues/1320#issuecomment-723721132, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFYTD5BVRERQGTKSYRIVTHDSO5I6JANCNFSM4TOSS5KQ .

xXjojaXx commented 3 years ago

Ok, thanks. But how does the Inventory API works. Is there any method for a csharp script, which allows me to get the details of an slot of an open inventory? (Like:) MCC. GetItemCount([InventoryNumber], [Slot]) or MCC.GetItemType([InventoryNumber], [Slot])

ReinforceZwei commented 3 years ago

Please use the ChatBot API. See example script with chatbot. For getting the inventories, you can use GetInventories() method to get all opened inventories or GetPlayerInventory() for getting player inventory only. You may want to have a look at the Container Class to see the methods for manipulating inventory.

xXjojaXx commented 3 years ago

Sry, if im not far enough in programming to understand how to use the output of the GetPlayerInventory() method in a chatbot. Would you be able to write me an little example script that uses an chatbot and the inventory methods in a very uncomplicated way? Because i dont know what the output could be used for.

ReinforceZwei commented 3 years ago
//MCCScript 1.0

/* This is a sample script that will load a ChatBot into Minecraft Console Client
 * Simply execute the script once with /script or the script scheduler to load the bot */

MCC.LoadBot(new ExampleBot());

//MCCScript Extensions

/* The ChatBot class must be defined as an extension of the script in the Extensions section
 * The class can override common methods from ChatBot.cs, take a look at MCC's source code */

public class ExampleBot : ChatBot
{
    public override void AfterGameJoined()
    {
        // Get inventory
        Container inventory = GetPlayerInventory();
        // Count how many slot has item
        LogToConsole("Player inventory total " + inventory.Items.Count + " items:");
        // Print out every item inside inventory
        foreach(var item in inventory.Items)
        {
            LogToConsole(string.Format("{0} x{1}", item.Value.Type, item.Value.Count));
        }
    }
}
xXjojaXx commented 3 years ago

Thank you very much. Ill try it this evening and update my comment then.