diff --git a/MinecraftClient/ChatBot.cs b/MinecraftClient/ChatBot.cs index 63be582b..b790ebd4 100644 --- a/MinecraftClient/ChatBot.cs +++ b/MinecraftClient/ChatBot.cs @@ -887,17 +887,16 @@ namespace MinecraftClient } /// - /// Interact with an entity + /// Give Creative Mode items into regular/survival Player Inventory /// - /// - /// - /// - /// - protected bool CreativeInventoryAction(int slot, ItemType ItemType, int count) + /// (obviously) requires to be in creative mode + /// Destination inventory slot + /// Item type + /// Item count + /// TRUE if item given successfully + protected bool CreativeGive(int slot, ItemType itemType, int count) { - Dictionary NBT = null; - Item item = new Item((int)ItemType, count, NBT); - return Handler.DoCreativeInventoryAction(slot, item); + return Handler.DoCreativeGive(slot, itemType, count); } /// diff --git a/MinecraftClient/Commands/Inventory.cs b/MinecraftClient/Commands/Inventory.cs index 6f11f640..6e260ee6 100644 --- a/MinecraftClient/Commands/Inventory.cs +++ b/MinecraftClient/Commands/Inventory.cs @@ -9,7 +9,7 @@ namespace MinecraftClient.Commands class Inventory : Command { public override string CMDName { get { return "inventory"; } } - public override string CMDDesc { get { return "inventory <|player|container> <1|all>|click |creativegive >: Interact with inventories"; } } + public override string CMDDesc { get { return "inventory <|player|container> <1|all>|click > | inventory creativegive : Interact with inventories"; } } public override string Run(McTcpClient handler, string command, Dictionary localVars) { @@ -34,6 +34,26 @@ namespace MinecraftClient.Commands inventoryId = availableIds[0]; // one container, use it else return "Cannot find container, please retry with explicit ID"; } + else if (args[0].ToLower() == "creativegive") + { + if (args.Length >= 4) + { + int slot = int.Parse(args[1]); + ItemType itemType = ItemType.Stone; + if (Enum.TryParse(args[2], out itemType)) + { + int count = int.Parse(args[3]); + if (handler.DoCreativeGive(slot, itemType, count)) + return "Requested " + itemType + " x" + count + " in slot #" + slot; + else return "Failed to request Creative Give"; + } + else + { + return CMDDesc; + } + } + else return CMDDesc; + } else inventoryId = int.Parse(args[0]); string action = args.Length > 1 ? args[1].ToLower() @@ -110,32 +130,6 @@ namespace MinecraftClient.Commands } } 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 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: return CMDDesc; } diff --git a/MinecraftClient/Mapping/Entity.cs b/MinecraftClient/Mapping/Entity.cs index df024d2e..34ed4a3e 100644 --- a/MinecraftClient/Mapping/Entity.cs +++ b/MinecraftClient/Mapping/Entity.cs @@ -46,12 +46,13 @@ namespace MinecraftClient.Mapping this.Location = location; } /// - /// Create a new entity based on Entity ID, Entity Type, location and UUID + /// Create a new entity based on Entity ID, Entity Type, location, name and UUID /// /// Entity ID /// Entity Type Enum /// Entity location /// Player uuid + /// Player name public Entity(int ID, EntityType type, Location location, Guid uuid, string name) { this.ID = ID; diff --git a/MinecraftClient/Mapping/EntityPalettes/EntityPalette.cs b/MinecraftClient/Mapping/EntityPalettes/EntityPalette.cs index 9b29f460..df7abd5d 100644 --- a/MinecraftClient/Mapping/EntityPalettes/EntityPalette.cs +++ b/MinecraftClient/Mapping/EntityPalettes/EntityPalette.cs @@ -14,9 +14,9 @@ namespace MinecraftClient.Mapping.EntityPalettes protected abstract Dictionary GetDict(); /// - /// Get mapping dictionary for pre-1.13. May be overriden with proper implementation. + /// Get mapping dictionary for pre-1.14 non-living entities. /// - /// Palette dictionary for non-living entities (pre-1.13) + /// Palette dictionary for non-living entities (pre-1.14) protected virtual Dictionary GetDictNonLiving() { return null; @@ -34,13 +34,13 @@ namespace MinecraftClient.Mapping.EntityPalettes if (entityTypesNonLiving != null && !living) { - //Pre-1.13 non-living entities have a different set of IDs (entityTypesNonLiving != null) + //Pre-1.14 non-living entities have a different set of IDs (entityTypesNonLiving != null) if (entityTypesNonLiving.ContainsKey(id)) return entityTypesNonLiving[id]; } else { - //Post-1.13 entities have the same set of IDs regardless of living status + //1.14+ entities have the same set of IDs regardless of living status if (entityTypes.ContainsKey(id)) return entityTypes[id]; } diff --git a/MinecraftClient/Mapping/EntityPalettes/EntityPalette113.cs b/MinecraftClient/Mapping/EntityPalettes/EntityPalette113.cs index 22135c59..b0253b06 100644 --- a/MinecraftClient/Mapping/EntityPalettes/EntityPalette113.cs +++ b/MinecraftClient/Mapping/EntityPalettes/EntityPalette113.cs @@ -6,7 +6,7 @@ namespace MinecraftClient.Mapping.EntityPalettes /// /// Defines mappings for pre-1.14 entitiy IDs /// Pre-1.14 Minecraft has 2 set of ids: One for non-living objects and one for living mobs - /// Post-1.14 Minecraft has only one set of ids for all types of entities + /// 1.14+ Minecraft has only one set of ids for all types of entities /// public class EntityPalette113 : EntityPalette { diff --git a/MinecraftClient/Mapping/EntityType.cs b/MinecraftClient/Mapping/EntityType.cs index 63ae6de2..09a7f69c 100644 --- a/MinecraftClient/Mapping/EntityType.cs +++ b/MinecraftClient/Mapping/EntityType.cs @@ -9,8 +9,8 @@ namespace MinecraftClient.Mapping /// 1. Generate registries.json using data reporting on Vanilla Minecraft (https://wiki.vg/Data_Generators) /// 2. Generate temporary EntityTypeXXX.cs and EntityPaletteXXX.cs using EntityPaletteGenerator.cs /// 3. Perform a diff with existing versions, add missing entries in EntityType.cs and EntityTypeExtensions.cs - /// 4. If existing entity IDs were not randomized by Mojang, simply add missing state entries to the latest existing PaletteXXX.cs - /// 5. If existing entity IDs were randomized, add a new palette as PaletteXXX.cs into the codebase (worst case) + /// 4. If existing entity IDs were not randomized by Mojang, simply add missing entries to the latest existing EntityPaletteXXX.cs + /// 5. If existing entity IDs were randomized, add a new palette as EntityPaletteXXX.cs into the codebase (worst case) /// public enum EntityType { diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index 20c90acd..9853a145 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -1250,48 +1250,20 @@ namespace MinecraftClient } /// - /// Called when a player was spawned/in the render distance + /// Called when a player spawns or enters the client's render distance /// - /// - /// - /// - /// - /// - 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; - string name = ""; - Dictionary uuids = GetOnlinePlayersWithUUID(); - foreach (KeyValuePair 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); - foreach (ChatBot bot in bots.ToArray()) - { - try - { - bot.OnEntitySpawn(entity); - } - catch (Exception e) - { - if (!(e is ThreadAbortException)) - { - ConsoleIO.WriteLogLine("OnEntitySpawn: Got error from " + bot.ToString() + ": " + e.ToString()); - } - else throw; //ThreadAbortException should not be caught - } - } + string playerName = null; + if (onlinePlayers.ContainsKey(uuid)) + playerName = onlinePlayers[uuid]; + Entity playerEntity = new Entity(entityID, EntityType.Player, location, uuid, playerName); + OnSpawnEntity(playerEntity); } /// /// Called when entities dead/despawn. /// - /// public void OnDestroyEntities(int[] Entities) { foreach (int a in Entities) @@ -1499,14 +1471,16 @@ namespace MinecraftClient } /// - /// Close the specified inventory window + /// Give Creative Mode items into regular/survival Player Inventory /// - /// Inventory slot - /// Item - /// TRUE if the window was successfully closed - public bool DoCreativeInventoryAction(int slot, Item item) + /// (obviously) requires to be in creative mode + /// Destination inventory slot + /// Item type + /// Item count + /// TRUE if item given successfully + public bool DoCreativeGive(int slot, ItemType itemType, int count) { - return handler.SendCreativeInventoryAction(slot, item); + return handler.SendCreativeInventoryAction(slot, itemType, count); } /// diff --git a/MinecraftClient/Protocol/Handlers/Protocol16.cs b/MinecraftClient/Protocol/Handlers/Protocol16.cs index 405596b3..87284d0e 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol16.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol16.cs @@ -693,7 +693,7 @@ namespace MinecraftClient.Protocol.Handlers return false; //Currently not implemented } - public bool SendCreativeInventoryAction(int slot, Item item) + public bool SendCreativeInventoryAction(int slot, ItemType item, int count) { return false; //Currently not implemented } diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index 289dc224..28487bcb 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -215,8 +215,6 @@ namespace MinecraftClient.Protocol.Handlers break; case PacketIncomingType.JoinGame: handler.OnGameJoined(); - // by reinforce - // get client player EntityID int playerEntityID = dataTypes.ReadNextInt(packetData); handler.SetPlayerEntityID(playerEntityID); dataTypes.ReadNextByte(packetData); @@ -1377,13 +1375,13 @@ namespace MinecraftClient.Protocol.Handlers catch (ObjectDisposedException) { return false; } } - public bool SendCreativeInventoryAction(int slot, Item item) + public bool SendCreativeInventoryAction(int slot, ItemType itemType, int count) { try { List packet = new List(); packet.AddRange(dataTypes.GetShort((short)slot)); - packet.AddRange(dataTypes.GetItemSlot(item)); + packet.AddRange(dataTypes.GetItemSlot(new Item((int)itemType, count, null))); SendPacket(PacketOutgoingType.CreativeInventoryAction, packet); return true; diff --git a/MinecraftClient/Protocol/IMinecraftCom.cs b/MinecraftClient/Protocol/IMinecraftCom.cs index 6b61ec13..9a44441d 100644 --- a/MinecraftClient/Protocol/IMinecraftCom.cs +++ b/MinecraftClient/Protocol/IMinecraftCom.cs @@ -150,11 +150,14 @@ namespace MinecraftClient.Protocol bool SendWindowAction(int windowId, int slotId, WindowActionType action, Item item); /// - /// Send a click window slot packet to the server + /// Request Creative Mode item creation into regular/survival Player Inventory /// - /// Id of inventory slot - /// Id of item - bool SendCreativeInventoryAction(int slot, Item item); + /// (obviously) requires to be in creative mode + /// Destination inventory slot + /// Item type + /// Item count + /// TRUE if item given successfully + bool SendCreativeInventoryAction(int slot, ItemType itemType, int count); /// /// Send a close window packet to the server diff --git a/MinecraftClient/Protocol/IMinecraftComHandler.cs b/MinecraftClient/Protocol/IMinecraftComHandler.cs index 778f5d4b..d8998552 100644 --- a/MinecraftClient/Protocol/IMinecraftComHandler.cs +++ b/MinecraftClient/Protocol/IMinecraftComHandler.cs @@ -137,13 +137,13 @@ namespace MinecraftClient.Protocol void OnSpawnEntity(Entity entity); /// - /// Called when a player has spawned + /// Called when a player spawns or enters the client's render distance /// - /// Entity ID - /// Entity UUID + /// Entity ID + /// Entity UUID /// Entity location - /// Player head yaw - /// Player head pitch + /// Player head yaw + /// Player head pitch void OnSpawnPlayer(int entityID, Guid uuid, Location location, byte yaw, byte pitch); /// @@ -160,7 +160,7 @@ namespace MinecraftClient.Protocol /// Y offset /// Z offset /// TRUE if on ground - void OnEntityPosition(int entityID, Double dx, Double dy, Double dz,bool onGround); + void OnEntityPosition(int entityID, Double dx, Double dy, Double dz, bool onGround); /// /// Called when an entity moved to fixed coordinates