PixelPilot.Structures 0.0.1

There is a newer version of this package available.
See the version list below for details.
dotnet add package PixelPilot.Structures --version 0.0.1                
NuGet\Install-Package PixelPilot.Structures -Version 0.0.1                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="PixelPilot.Structures" Version="0.0.1" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PixelPilot.Structures --version 0.0.1                
#r "nuget: PixelPilot.Structures, 0.0.1"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install PixelPilot.Structures as a Cake Addin
#addin nuget:?package=PixelPilot.Structures&version=0.0.1

// Install PixelPilot.Structures as a Cake Tool
#tool nuget:?package=PixelPilot.Structures&version=0.0.1                

PixelPilot.Structures

Structures are used to load and save blocks. This is an optional package.

📄 Documentation

JSON Format

This is an example. This example has been shortened to fit here so it might not actually be a valid and working save file.

{
  // Version of this save
  "Version": 1,
  // Width & Height of this structure
  "Width": 1,
  "Height": 1,
  // Meta tags to be defined by the user
  "Meta": {
    "key": "value"
  },
  // If this structure has saved empty blocks
  "ContainsEmpty": false,
  "Blocks": {
    // Mapping of blocks. ID's in blockdata are replaced by temporary IDs.
    // BricksGrass: 0, Coin: 1
    "Mapping": [
      "BricksGrass",
      "Coin"
    ],
    // Blockdata as found in the world buffer in INIT.
    "BlockData": [
      "AQAAAAsAAAABAAAAAAAAAA==",
      "AgAAAAgAAAABAAAAAQAAAA=="
    ]
  }
}

Example bot:

using System.Drawing;
using System.Text.Json;
using Microsoft.Extensions.Configuration;
using PixelPilot.Common.Logging;
using PixelPilot.PixelGameClient;
using PixelPilot.PixelGameClient.Messages;
using PixelPilot.PixelGameClient.Messages.Received;
using PixelPilot.PixelGameClient.Messages.Send;
using PixelPilot.PixelGameClient.Players.Basic;
using PixelPilot.PixelGameClient.World;
using PixelPilot.Structures.Converters.PilotSimple;
using PixelPilot.Structures.Extensions;
using PixelPilotExample;

// Load the configuration. Don't store your account token in the code :)
var configuration = new ConfigurationBuilder()
    .AddJsonFile("config.json")
    .AddEnvironmentVariables()
    .Build();

LogManager.Configure(configuration.GetSection("Logging"));
var config = configuration.Get<BasicConfig>();
if (config == null)
{
    Console.WriteLine("The configuration file could not be loaded.");
    return;
}

// Create a client.
var client = new PixelPilotClient(config.AccountToken, false);

// Player manager allows you to easily keep track of player stats.
// For advanced users, it can be extended to include relevant information for you.
var playerManager = new PlayerManager();
client.OnPacketReceived += playerManager.HandlePacket;

// Create a PixelWorld class and attach the client to it.
// Allow it to listen to client updates. Not required!
var world = new PixelWorld();
client.OnPacketReceived += world.HandlePacket;
world.OnBlockPlaced += (_, playerId, oldBlock, _) =>
{
    
};


// Executed when the client receives a packet!
var p1 = new Point(8, 8);
var p2 = new Point(16, 19);
client.OnPacketReceived += async (_, packet) =>
{
    var playerPacket = packet as IPixelGamePlayerPacket;
    if (playerPacket == null) return;

    var player = playerManager.GetPlayer(playerPacket.PlayerId);
    if (player == null) return;
    
    // Make use of strongly typed packets!
    switch (packet)
    {
        case PlayerChatPacket { Message: ".stop" }:
            client.Disconnect();
            Environment.Exit(0);
            return;
        case PlayerChatPacket { Message: ".test" }:
            playerManager.Players
                .Where(p => p.Deaths > 2)
                .ToList()
                .ForEach(p =>
                {
                    Task.Run(async () =>
                    {
                        client.Send(new PlayerChatOutPacket($"/pm {p.Username} Man you should die less often!"));
                        await Task.Delay(1000);
                        client.Send(new PlayerChatOutPacket($"/reset {p.Username}"));
                        client.Send(new PlayerChatOutPacket($"/pm {p.Username} Or maybe..."));
                        await Task.Delay(1000);
                        client.Send(new PlayerChatOutPacket($"/kick {p.Username}"));
                    });
                });
            return;
        case PlayerChatPacket { Message: ".p1" } chat:
        {
            p1 = new Point((int)(player.X / 16), (int)(player.Y / 16));
            client.Send(new PlayerChatOutPacket(p1.ToString()));
            break;
        }
        case PlayerChatPacket { Message: ".p2" } chat:
        {
            p2 = new Point((int)(player.X / 16), (int)(player.Y / 16));
            client.Send(new PlayerChatOutPacket(p2.ToString()));
            break;
        }
        case PlayerChatPacket { Message: ".save" } chat:
        {
            var structure = world.GetStructure(p1, p2, copyEmpty: false);
            
            // Save
            var json = PilotSaveSerializer.Serialize(structure);
            File.WriteAllText("test-struct.json", json);
            client.Send(new PlayerChatOutPacket("Struct saved!"));
            break;
        }
        case PlayerChatPacket { Message: ".load" } chat:
        {
            string json = File.ReadAllText("test-struct.json");
            var structure = PilotSaveSerializer.Deserialize(json);
            
            client.Send(new PlayerChatOutPacket("Struct pasting..."));
            world.GetDifference(structure, (int) player.X / 16,  (int) player.Y / 16).PasteShuffled(client, new Point((int)(player.X / 16), (int)(player.Y / 16)), 5);
            
            break;
        }
        case PlayerChatPacket { Message: ".diff" } chat:
        {
            string json = File.ReadAllText("test-struct.json");
            var structure = PilotSaveSerializer.Deserialize(json);

            if (structure == null) return;
            client.Send(new PlayerChatOutPacket("Struct pasting..."));
            world.GetDifference(structure, (int) player.X / 16,  (int) player.Y / 16).ForEach(b => Console.WriteLine(JsonSerializer.Serialize(b)));
            break;
        }
        case PlayerJoinPacket join:
            client.Send(new PlayerChatOutPacket($"/giveedit {join.Username}"));
            break;
    }
};

// Executed once the client receives INIT
// Make a platform and do some silly loops.
client.OnClientConnected += (_) =>
{
    client.Send(new PlayerChatOutPacket("Hello world using the PixelPilot API."));
};

// Connect to a room.
await client.Connect("mknckr7oqxq24xa");

// Don't terminate.
Thread.Sleep(-1);
Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.9.3 83 9/21/2024
1.9.2 107 9/4/2024
1.9.1 92 9/3/2024
1.9.0 104 8/26/2024
1.8.3 112 8/22/2024
1.8.2 114 8/22/2024
1.8.1 119 8/17/2024
1.8.0 117 8/15/2024
1.7.9 47 7/31/2024
1.7.8 62 7/29/2024
1.7.7 79 7/29/2024
1.7.6 81 7/28/2024
1.7.5 89 7/26/2024
1.7.4 69 7/23/2024
1.7.3 110 7/21/2024
1.7.2 91 7/21/2024
1.7.1 88 7/21/2024
1.7.0 89 7/20/2024
1.6.5 122 7/5/2024
1.6.4 123 6/20/2024
1.6.3 105 6/15/2024
1.6.2 103 6/15/2024
1.6.1 85 6/14/2024
1.6.0 83 6/14/2024
1.5.2 89 6/11/2024
1.5.1 82 6/11/2024
1.5.0 98 6/6/2024
1.4.1 100 6/5/2024
1.4.0 92 6/3/2024
1.3.0 95 5/29/2024
0.0.1 93 5/29/2024