Adjust dig block API

Attempt to automate dig start and dig complete (#1077)
This commit is contained in:
ORelio 2020-06-20 21:30:23 +02:00
parent 6df5076d19
commit 4cc29a6ee6
11 changed files with 113 additions and 48 deletions

View file

@ -336,8 +336,8 @@ namespace MinecraftClient.Protocol.Handlers
{
int itemID = ReadNextVarInt(cache);
byte itemCount = ReadNextByte(cache);
Dictionary<string, object> NBT = ReadNextNbt(cache);
return new Item(itemID, itemCount, NBT);
Dictionary<string, object> nbt = ReadNextNbt(cache);
return new Item(itemID, itemCount, nbt);
}
else return null;
}
@ -349,8 +349,8 @@ namespace MinecraftClient.Protocol.Handlers
return null;
byte itemCount = ReadNextByte(cache);
short itemDamage = ReadNextShort(cache);
Dictionary<string, object> NBT = ReadNextNbt(cache);
return new Item(itemID, itemCount, NBT);
Dictionary<string, object> nbt = ReadNextNbt(cache);
return new Item(itemID, itemCount, nbt);
}
}
@ -398,14 +398,14 @@ namespace MinecraftClient.Protocol.Handlers
/// </summary>
private Dictionary<string, object> ReadNextNbt(Queue<byte> cache, bool root)
{
Dictionary<string, object> NbtData = new Dictionary<string, object>();
Dictionary<string, object> nbtData = new Dictionary<string, object>();
if (root)
{
if (cache.Peek() == 0) // TAG_End
{
cache.Dequeue();
return NbtData;
return nbtData;
}
if (cache.Peek() != 10) // TAG_Compound
throw new System.IO.InvalidDataException("Failed to decode NBT: Does not start with TAG_Compound");
@ -414,7 +414,7 @@ namespace MinecraftClient.Protocol.Handlers
// NBT root name
string rootName = Encoding.ASCII.GetString(ReadData(ReadNextUShort(cache), cache));
if (!String.IsNullOrEmpty(rootName))
NbtData[""] = rootName;
nbtData[""] = rootName;
}
while (true)
@ -422,14 +422,14 @@ namespace MinecraftClient.Protocol.Handlers
int fieldType = ReadNextByte(cache);
if (fieldType == 0) // TAG_End
return NbtData;
return nbtData;
int fieldNameLength = ReadNextUShort(cache);
string fieldName = Encoding.ASCII.GetString(ReadData(fieldNameLength, cache));
object fieldValue = ReadNbtField(cache, fieldType);
// This will override previous tags with the same name
NbtData[fieldName] = fieldValue;
nbtData[fieldName] = fieldValue;
}
}

View file

@ -703,7 +703,7 @@ namespace MinecraftClient.Protocol.Handlers
return false; //Currently not implemented
}
public bool SendCreativeInventoryAction(int slot, ItemType item, int count, Dictionary<string, object> NBT)
public bool SendCreativeInventoryAction(int slot, ItemType item, int count, Dictionary<string, object> nbt)
{
return false; //Currently not implemented
}

View file

@ -1500,13 +1500,13 @@ namespace MinecraftClient.Protocol.Handlers
catch (ObjectDisposedException) { return false; }
}
public bool SendCreativeInventoryAction(int slot, ItemType itemType, int count, Dictionary<string, object> NBT)
public bool SendCreativeInventoryAction(int slot, ItemType itemType, int count, Dictionary<string, object> nbt)
{
try
{
List<byte> packet = new List<byte>();
packet.AddRange(dataTypes.GetShort((short)slot));
packet.AddRange(dataTypes.GetItemSlot(new Item((int)itemType, count, NBT)));
packet.AddRange(dataTypes.GetItemSlot(new Item((int)itemType, count, nbt)));
SendPacket(PacketOutgoingType.CreativeInventoryAction, packet);
return true;
}
@ -1549,6 +1549,7 @@ namespace MinecraftClient.Protocol.Handlers
catch (System.IO.IOException) { return false; }
catch (ObjectDisposedException) { return false; }
}
public bool SendCloseWindow(int windowId)
{
try
@ -1565,10 +1566,20 @@ namespace MinecraftClient.Protocol.Handlers
catch (System.IO.IOException) { return false; }
catch (ObjectDisposedException) { return false; }
}
public bool SendUpdateSign(Location sign, string line1, string line2, string line3, string line4)
{
try
{
if (line1.Length > 23)
line1 = line1.Substring(0, 23);
if (line2.Length > 23)
line2 = line1.Substring(0, 23);
if (line3.Length > 23)
line3 = line1.Substring(0, 23);
if (line4.Length > 23)
line4 = line1.Substring(0, 23);
List<byte> packet = new List<byte>();
packet.AddRange(dataTypes.GetLocation(sign));
packet.AddRange(dataTypes.GetString(line1));