-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #16 from takunology/2.0.0-dev
prerelease 2.0.0 - preview 1
- Loading branch information
Showing
220 changed files
with
1,793 additions
and
11,357 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
Binary file modified
BIN
+0 Bytes
(100%)
MinecraftConnection/.vs/MinecraftConnection/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file added
BIN
+55.9 KB
...ction/.vs/MinecraftConnection/FileContentIndex/cb0065d8-f4b7-48a4-8e4e-2720b643088a.vsidx
Binary file not shown.
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file modified
BIN
+58 KB
(1400%)
MinecraftConnection/.vs/MinecraftConnection/v17/TestStore/0/000.testlog
Binary file not shown.
Binary file added
BIN
+196 KB
MinecraftConnection/.vs/ProjectEvaluation/minecraftconnection.metadata.v2
Binary file not shown.
Binary file added
BIN
+710 KB
MinecraftConnection/.vs/ProjectEvaluation/minecraftconnection.projects.v2
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
MinecraftConnection/MinecraftConnection/Block/Base/BlockBase.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
15
MinecraftConnection/MinecraftConnection/Block/BlockItem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
101
MinecraftConnection/MinecraftConnection/Block/ChestBlock.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
Oops, something went wrong.