Add Entity.Name & /inventory 0 creative <slot> <itemtype> <count> (#1024)

* Update Program.cs

* Update Entity.cs

Add Entity.Name

* Update Program.cs
* Update Entity.cs

Add break;

* Update Entity.cs

* Update Inventory.cs

Add /inventory 0 creative <slot> <item> <count>

* Update PacketOutgoingType.cs

+ CreativeInventoryAction

* Update Protocol16.cs

+ SendCreativeInventorAction

* Update Protocol18.cs

+ SendCreativeInventorAction

* Update IMinecraftCom.cs

+ SendCreativeInventorAction

* Update McTcpClient.cs

+ DoCreativeInventorAction

* Update ChatBot.cs

+ CreativeInventorAction

* Update McTcpClient.cs
* Update ChatBot.cs
* Update Inventory.cs

Add show count

* Update ChatBot.cs

+ ChatBot fix

* Update Inventory.cs

Inventory update and Fix

* Update Entity.cs
* Update McTcpClient.cs
* Update Program.cs
* Update Protocol16.cs
* Update Protocol18.cs
* Update IMinecraftCom.cs
* Update Entity.cs
This commit is contained in:
Рома Данилов 2020-05-26 00:16:53 +05:00 committed by GitHub
parent 65620e2e95
commit d120001d70
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 110 additions and 16 deletions

View file

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -886,6 +886,20 @@ namespace MinecraftClient
return Handler.InteractEntity(EntityID, type); return Handler.InteractEntity(EntityID, type);
} }
/// <summary>
/// Interact with an entity
/// </summary>
/// <param name="slot"></param>
/// <param name="ItemType"></param>
/// <param name="count"></param>
/// <returns></returns>
protected bool CreativeInventoryAction(int slot, ItemType ItemType, int count)
{
Dictionary<string, object> NBT = null;
Item item = new Item((int)ItemType, count, NBT);
return Handler.DoCreativeInventoryAction(slot, item);
}
/// <summary> /// <summary>
/// Use item currently in the player's hand (active inventory bar slot) /// Use item currently in the player's hand (active inventory bar slot)
/// </summary> /// </summary>

View file

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -9,7 +9,7 @@ namespace MinecraftClient.Commands
class Inventory : Command class Inventory : Command
{ {
public override string CMDName { get { return "inventory"; } } public override string CMDName { get { return "inventory"; } }
public override string CMDDesc { get { return "inventory <<id>|player|container> <list|close|drop <slot> <1|all>|click <slot> <left|right|middle>>: Interact with inventories"; } } public override string CMDDesc { get { return "inventory <<id>|player|container> <list|close|drop <slot> <1|all>|click <slot> <left|right|middle>|creativegive <slot> <itemtype> <count>>: Interact with inventories"; } }
public override string Run(McTcpClient handler, string command, Dictionary<string, object> localVars) public override string Run(McTcpClient handler, string command, Dictionary<string, object> localVars)
{ {
@ -110,6 +110,32 @@ namespace MinecraftClient.Commands
} }
} }
else return CMDDesc; else return CMDDesc;
case "creativegive":
if (args.Length >= 3)
{
int slot = int.Parse(args[2]);
ItemType ItemType = ItemType.Stone;
if (Enum.TryParse(args[3], out ItemType))
{
int count = int.Parse(args[4]);
Dictionary<string, object> NBT = null;
Item item = new Item((int)ItemType, count, NBT);
if (handler.DoCreativeInventoryAction(slot, item))
{
return "You have received " + ItemType + " x" + count + " in the slot #" + slot;
}
else
{
return "Failed";
}
}
else;
{
return CMDDesc;
}
}
else return CMDDesc;
default: default:
return CMDDesc; return CMDDesc;
} }

View file

@ -1,7 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MinecraftClient.Mapping namespace MinecraftClient.Mapping
{ {
@ -20,6 +18,11 @@ namespace MinecraftClient.Mapping
/// </summary> /// </summary>
public Guid UUID; public Guid UUID;
/// <summary>
/// Nickname of the entity if it is a player.
/// </summary>
public string Name;
/// <summary> /// <summary>
/// Entity type /// Entity type
/// </summary> /// </summary>
@ -48,12 +51,14 @@ namespace MinecraftClient.Mapping
/// <param name="ID">Entity ID</param> /// <param name="ID">Entity ID</param>
/// <param name="type">Entity Type Enum</param> /// <param name="type">Entity Type Enum</param>
/// <param name="location">Entity location</param> /// <param name="location">Entity location</param>
public Entity(int ID, EntityType type, Location location, Guid uuid) /// <param name="uuid">Player uuid</param>
public Entity(int ID, EntityType type, Location location, Guid uuid, string name)
{ {
this.ID = ID; this.ID = ID;
this.Type = type; this.Type = type;
this.Location = location; this.Location = location;
this.UUID = uuid; this.UUID = uuid;
this.Name = name;
} }
} }
} }

View file

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -1260,7 +1260,16 @@ namespace MinecraftClient
public void OnSpawnPlayer(int EntityID, Guid UUID, Location location, byte Yaw, byte Pitch) public void OnSpawnPlayer(int EntityID, Guid UUID, Location location, byte Yaw, byte Pitch)
{ {
if (entities.ContainsKey(EntityID)) return; if (entities.ContainsKey(EntityID)) return;
Entity entity = new Entity(EntityID, EntityType.Player, location, UUID); string name = "";
Dictionary<string, string> uuids = GetOnlinePlayersWithUUID();
foreach (KeyValuePair<string, string> keyValue in uuids)
{
if (keyValue.Key == UUID.ToString())
{
name = keyValue.Value;
}
}
Entity entity = new Entity(EntityID, EntityType.Player, location, UUID, name);
entities.Add(EntityID, entity); entities.Add(EntityID, entity);
foreach (ChatBot bot in bots.ToArray()) foreach (ChatBot bot in bots.ToArray())
{ {
@ -1489,6 +1498,17 @@ namespace MinecraftClient
return handler.SendWindowAction(windowId, slotId, action, item); return handler.SendWindowAction(windowId, slotId, action, item);
} }
/// <summary>
/// Close the specified inventory window
/// </summary>
/// <param name="slot">Inventory slot</param>
/// <param name="item">Item</param>
/// <returns>TRUE if the window was successfully closed</returns>
public bool DoCreativeInventoryAction(int slot, Item item)
{
return handler.SendCreativeInventoryAction(slot, item);
}
/// <summary> /// <summary>
/// Close the specified inventory window /// Close the specified inventory window
/// </summary> /// </summary>

View file

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -26,6 +26,7 @@ namespace MinecraftClient.Protocol.Handlers
UseItem, UseItem,
ClickWindow, ClickWindow,
CloseWindow, CloseWindow,
PlayerBlockPlacement PlayerBlockPlacement,
CreativeInventoryAction
} }
} }

View file

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -693,6 +693,11 @@ namespace MinecraftClient.Protocol.Handlers
return false; //Currently not implemented return false; //Currently not implemented
} }
public bool SendCreativeInventoryAction(int slot, Item item)
{
return false; //Currently not implemented
}
public bool SendCloseWindow(int windowId) public bool SendCloseWindow(int windowId)
{ {
return false; //Currently not implemented return false; //Currently not implemented

View file

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -724,7 +724,7 @@ namespace MinecraftClient.Protocol.Handlers
} }
catch (Exception innerException) catch (Exception innerException)
{ {
if (innerException is SocketException || innerException.InnerException is SocketException || innerException is ThreadAbortException) if (innerException is SocketException || innerException.InnerException is SocketException)
throw; //Connection lost rather than invalid data throw; //Connection lost rather than invalid data
throw new System.IO.InvalidDataException( throw new System.IO.InvalidDataException(
String.Format("Failed to process incoming packet of type {0}. (PacketID: {1}, Protocol: {2}, LoginPhase: {3}, InnerException: {4}).", String.Format("Failed to process incoming packet of type {0}. (PacketID: {1}, Protocol: {2}, LoginPhase: {3}, InnerException: {4}).",
@ -1377,6 +1377,22 @@ namespace MinecraftClient.Protocol.Handlers
catch (ObjectDisposedException) { return false; } catch (ObjectDisposedException) { return false; }
} }
public bool SendCreativeInventoryAction(int slot, Item item)
{
try
{
List<byte> packet = new List<byte>();
packet.AddRange(dataTypes.GetShort((short)slot));
packet.AddRange(dataTypes.GetItemSlot(item));
SendPacket(PacketOutgoingType.CreativeInventoryAction, packet);
return true;
}
catch (SocketException) { return false; }
catch (System.IO.IOException) { return false; }
catch (ObjectDisposedException) { return false; }
}
public bool SendCloseWindow(int windowId) public bool SendCloseWindow(int windowId)
{ {
try try

View file

@ -1,4 +1,4 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
@ -149,6 +149,13 @@ namespace MinecraftClient.Protocol
/// <returns>True if packet was successfully sent</returns> /// <returns>True if packet was successfully sent</returns>
bool SendWindowAction(int windowId, int slotId, WindowActionType action, Item item); bool SendWindowAction(int windowId, int slotId, WindowActionType action, Item item);
/// <summary>
/// Send a click window slot packet to the server
/// </summary>
/// <param name="slot">Id of inventory slot</param>
/// <param name="item">Id of item </param>
bool SendCreativeInventoryAction(int slot, Item item);
/// <summary> /// <summary>
/// Send a close window packet to the server /// Send a close window packet to the server
/// </summary> /// </summary>