Skip to content

Commit

Permalink
Merge pull request #16 from takunology/2.0.0-dev
Browse files Browse the repository at this point in the history
prerelease 2.0.0 - preview 1
  • Loading branch information
Takumi Okawa authored Jun 6, 2022
2 parents 80c9039 + 0246477 commit aa1d15d
Show file tree
Hide file tree
Showing 220 changed files with 1,793 additions and 11,357 deletions.
32 changes: 0 additions & 32 deletions .circleci/config.yml

This file was deleted.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified MinecraftConnection/.vs/MinecraftConnection/v17/.suo
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
10 changes: 2 additions & 8 deletions MinecraftConnection/MinecraftConnection.sln
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30717.126
# Visual Studio Version 17
VisualStudioVersion = 17.1.32210.238
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MinecraftConnection", "MinecraftConnection\MinecraftConnection.csproj", "{B19912A9-A832-4941-BA28-3DA26A810EAD}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestProject", "TestProject\TestProject.csproj", "{14BDEEC5-37FC-436B-92D3-13C874D07D0A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -17,10 +15,6 @@ Global
{B19912A9-A832-4941-BA28-3DA26A810EAD}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B19912A9-A832-4941-BA28-3DA26A810EAD}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B19912A9-A832-4941-BA28-3DA26A810EAD}.Release|Any CPU.Build.0 = Release|Any CPU
{14BDEEC5-37FC-436B-92D3-13C874D07D0A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{14BDEEC5-37FC-436B-92D3-13C874D07D0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{14BDEEC5-37FC-436B-92D3-13C874D07D0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{14BDEEC5-37FC-436B-92D3-13C874D07D0A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
12 changes: 12 additions & 0 deletions MinecraftConnection/MinecraftConnection/Block/Base/BlockBase.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Text;

namespace MinecraftConnection.Block.Base
{
public class BlockBase
{
public string BlockId { get; set; }
public Position Position { get; set; }
}
}
15 changes: 15 additions & 0 deletions MinecraftConnection/MinecraftConnection/Block/BlockItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using MinecraftConnection.Block.Base;
using System;
using System.Collections.Generic;
using System.Text;

namespace MinecraftConnection.Block
{
public class BlockItem : BlockBase
{
public BlockItem(string BlockId)
{
this.BlockId = BlockId;
}
}
}
101 changes: 101 additions & 0 deletions MinecraftConnection/MinecraftConnection/Block/ChestBlock.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using MinecraftConnection.Block.Base;
using MinecraftConnection.Extends;

namespace MinecraftConnection.Block
{
public class ChestBlock : BlockBase
{
public ChestBlock(int x, int y, int z)
{
this.Position = new Position(x, y, z);
}

public ChestBlock(Position position)
{
this.Position = position;
}

public List<ItemStack> GetItems()
{
List<ItemStack> items = new List<ItemStack>();

string result = PublicRcon.Rcon.SendCommand($"data get block {Position.X} {Position.Y} {Position.Z}");
if (!result.Contains("no"))
{
result = PublicRcon.Rcon.SendCommand($"data get block {Position.X} {Position.Y} {Position.Z} Items");
for (int i = 0; i < 27; i++)
{
result = PublicRcon.Rcon.SendCommand($"data get block {Position.X} {Position.Y} {Position.Z} Items[{i}]");
if (!result.Contains("no"))
{
result = PublicRcon.Rcon.SendCommand($"/data get block {Position.X} {Position.Y} {Position.Z} Items[{i}].Slot");
result = result.Substring(result.IndexOf("data"));
ushort ItemSlot = ushort.Parse(Regex.Replace(result, @"[^0-9]", ""));

result = PublicRcon.Rcon.SendCommand($"/data get block {Position.X} {Position.Y} {Position.Z} Items[{i}].id");
result = result.Substring(result.IndexOf("\""));
string ItemID = Regex.Replace(result, @"[^a-zA-Z:_]", "");

result = PublicRcon.Rcon.SendCommand($"/data get block {Position.X} {Position.Y} {Position.Z} Items[{i}].Count");
result = result.Substring(result.IndexOf("data"));
ushort ItemCount = ushort.Parse(Regex.Replace(result, @"[^0-9]", ""));

items.Add(new ItemStack(ItemSlot, ItemID, ItemCount));
}
}

}
else
{
throw new Exception("Chest is not found.");
}

return items;
}

public void SetItems(List<ItemStack> items)
{
string result = PublicRcon.Rcon.SendCommand($"data get block {Position.X} {Position.Y} {Position.Z}");
if (!result.Contains("no"))
{
PublicRcon.Rcon.SendCommand("data merge storage chestitems {Items:[]}");
PublicRcon.Rcon.SendCommand($"data modify block {Position.X} {Position.Y} {Position.Z} Items set from storage chestitems Items");
foreach (var item in items)
{
PublicRcon.Rcon.SendCommand($"data modify storage chestitems Items append value {GetNBT(item)}");
PublicRcon.Rcon.SendCommand($"data modify block {Position.X} {Position.Y} {Position.Z} Items set from storage chestitems Items");
}
}
else
{
throw new Exception("Chest is not found.");
}
}

private class ChestItemsNBT
{
[JsonPropertyName("Slot")]
public ushort _Slot { get; set; }
[JsonPropertyName("id")]
public string _Id { get; set; }
[JsonPropertyName("Count")]
public ushort _Count { get; set; }
}

private string GetNBT(ItemStack item)
{
ChestItemsNBT nbt = new ChestItemsNBT()
{
_Id = item.Id,
_Slot = item.Slot,
_Count = item.Count,
};
return JsonSerializer.Serialize(nbt);
}
}
}
Loading

0 comments on commit aa1d15d

Please sign in to comment.