Commit graph

629 commits

Author SHA1 Message Date
BruceChen
967f67190c Add FileInputBot for non-interactive debugging and fix NbtToString crash
FileInputBot (ChatBots/FileInputBot.cs):
- New ChatBot that monitors a text file (default: mcc_input.txt) for
  commands, enabling MCC control from Cursor Shell or any non-interactive
  environment where stdin is not available
- Activated by setting MCC_FILE_INPUT env var (e.g. MCC_FILE_INPUT=1)
- Polls every ~500ms for new lines appended to the file
- Lines starting with "/" are sent as server chat/commands
- Other lines are executed as MCC internal commands (same as console input)
- File path overridable via MCC_INPUT_FILE env var

McClient.cs:
- Load FileInputBot when MCC_FILE_INPUT environment variable is set

ChatParser.cs - NbtToString:
- Fix InvalidCastException when NBT "text" or nameless root tag values
  are Int32 instead of String (happens with 1.20.6 SystemChat packets
  containing numeric values in the chat component tree)
- Replace direct (string) casts with ?.ToString() ?? string.Empty

Made-with: Cursor
2026-03-19 00:45:51 +08:00
BruceChen
8eac21b4a4 Wire up 1.20.6 structured components to Item and fix GetItemSlot serialization
In 1.20.6+, items use structured components instead of NBT for metadata.
Previously, ReadNextItemSlot parsed the components but never stored them
on the Item instance, leaving DisplayName/Lores/Damage/Enchantments all
empty. GetItemSlot also still used the pre-1.20.6 format (bool + VarInt +
byte + NBT), causing the server to reject any item operation packets.

Changes:

Item.cs:
- Add List<StructuredComponent>? Components field to hold the raw
  component list for round-trip serialization
- DisplayName property: read from CustomNameComponent (with
  ItemNameComponent as fallback) when Components is present
- Lores property: read from LoreNameComponent1206 when Components is
  present
- Damage property: read from DamageComponent when Components is present
- Add EnchantmentList property: read from EnchantmentsComponent (covers
  both normal and StoredEnchantmentsComponent for enchanted books)
- ToFullString(): use EnchantmentList with EnchantmentMapping for display
  when available, fall back to NBT path for older versions
- Add CloneWithCount() method that preserves both NBT and Components

DataTypes.cs - ReadNextItemSlot:
- Assign parsed strcturedComponentsToAdd to item.Components

DataTypes.cs - GetItemSlot:
- Add 1.20.6+ branch: write VarInt(count) + VarInt(itemId) + component
  counts + serialized components (using each component's TypeId and
  Serialize() method)
- Empty slot sends VarInt(0) per the 1.20.6 protocol spec

StructuredComponent.cs:
- Add int TypeId property (default -1) to store the registry type ID
  assigned during parsing, enabling round-trip serialization

StructuredComponentRegistry.cs:
- Set component.TypeId = id after instantiation in ParseComponent()

McClient.cs:
- Replace manual Item constructor calls (new Item(type, count, nbt))
  with Item.CloneWithCount() to preserve Components during inventory
  operations like slot moves, stack splits, and right-click placement

Made-with: Cursor
2026-03-19 00:34:10 +08:00
BruceChen
bb18399523 Use dynamic dimension registry lookup in JoinGame and Respawn packets
The JoinGame and Respawn packet handlers for 1.20.6+ used hardcoded
switch expressions to map dimension type VarInt IDs to names:
  0 => overworld, 1 => overworld_caves, 2 => the_end, 3 => the_nether

This only works for vanilla servers with exactly 4 default dimensions.
Modded servers (Forge/Fabric/NeoForge) or servers with custom
datapacks can register additional dimensions with IDs beyond 0-3,
causing the switch to fall through to the default "overworld" for
any non-vanilla dimension. This means players in modded dimensions
would have incorrect world parameters (height, lighting, etc.).

Fix: Replace both hardcoded switch expressions with
World.GetDimensionNameById(), which looks up the VarInt ID in
the dimension ID map populated during the RegistryData phase.

Also fixes two pre-existing issues in the SetDimension dispatch:
- JoinGame (pre-1.20.2 path): The `case < MC_1_20_6_Version` guard
  was technically correct within its enclosing `if` block, but
  changed to `default` for clarity and future-proofing.
- Respawn: The `case <= MC_1_20_6_Version` guard excluded protocol
  versions above 766 (e.g. 1.21 / protocol 767), meaning
  SetDimension was never called for those versions. Changed to
  `default` so all versions >= 1.19 properly update the dimension.

Made-with: Cursor
2026-03-19 00:13:57 +08:00
BruceChen
41a701b6b2 Fix RegistryData parsing and KnownDataPacks negotiation for 1.20.6
Two critical issues in the 1.20.6 configuration phase that could cause
connection instability and packet desync:

1. RegistryData: The handler used an early `break` when it encountered
   a registryId other than "minecraft:dimension_type" or
   "minecraft:chat_type". This skipped reading the remaining entries
   for that registry, leaving unconsumed data in the packet buffer.
   Subsequent packet reads would start at the wrong offset, causing
   cascading parse failures and eventual disconnection.

   Fix: Always read all entries (entryId + hasData + optional NBT)
   for every registry, regardless of whether we process it. For
   dimension_type entries, if the server sends inline NBT data (i.e.
   non-vanilla dimensions from mods/datapacks), parse and store
   the dimension directly via World.StoreOneDimension(). Only fall
   back to hardcoded defaults when no dimension data was received.

2. KnownDataPacks: The client echoed back ALL packs the server
   listed, including non-vanilla ones. This told the server "I have
   these packs cached" when the client actually did not, so the
   server would skip sending full registry data for those packs.
   The result: incomplete registries for modded/datapack content.

   Fix: Filter the response to only include packs with the
   "minecraft" namespace. Non-vanilla packs are omitted, forcing
   the server to send their full registry data inline.

Also adds supporting methods to World.cs:
- SetDimensionIdMap(): Store VarInt ID -> dimension name mapping
  from RegistryData entries (needed by JoinGame/Respawn)
- GetDimensionNameById(): Look up dimension name by numeric ID
- HasAnyDimension(): Check if any dimensions were loaded from
  server-provided data

Made-with: Cursor
2026-03-19 00:13:22 +08:00
BruceChen
a7a95d991c Fix EntityProperties attribute ID mapping for 1.20.6
The 1.20.6 EntityProperties packet sends attribute IDs as VarInts
instead of strings. The existing mapping dictionary had three issues:

1. IDs 5/6/7 used the wrong prefix "generic." but the official
   1.20.6 registry uses "player." for these attributes:
   - 5: player.block_break_speed (was generic.block_break_speed)
   - 6: player.block_interaction_range (was generic.block_interaction_range)
   - 7: player.entity_interaction_range (was generic.entity_interaction_range)

2. IDs 22-24 (submerged_mining_speed, sweeping_damage_ratio,
   water_movement_efficiency) do not exist in the 1.20.6 attribute
   registry — they were introduced in 1.21. Their presence could
   cause incorrect attribute resolution.

3. Direct dictionary indexing (attributeDictionary[id]) throws
   KeyNotFoundException if the server sends an unknown attribute ID,
   crashing the packet handler. Replaced with TryGetValue and a
   safe fallback to "unknown".

Made-with: Cursor
2026-03-19 00:12:06 +08:00
BruceChen
ff1c570a78 Handle non-interactive terminal environments gracefully
When MCC runs in non-interactive terminals (e.g. CI runners, IDE
embedded shells, piped input), several Console APIs throw exceptions
because there is no real console attached.

Changes:
- Program.cs: Wrap Console.KeyAvailable / Console.ReadKey in
  HandleFailure() with try-catch so MCC does not crash on startup
  failure in headless environments.
- Chunk.cs: Wrap Console.BufferWidth / BufferHeight in try-catch
  with fallback values (120x50) to prevent exceptions when rendering
  chunk maps without a console buffer.
- Map.cs: Same treatment for the map rendering path - use safe
  fallback values when Console.BufferWidth/Height are unavailable.
- ReplayHandler.cs: Replace Array.Reverse() (returns void in newer
  .NET) with .AsEnumerable().Reverse() to fix compilation with
  .NET 10 SDK where the void return breaks the fluent chain.

Made-with: Cursor
2026-03-19 00:11:13 +08:00
breadbyte
494be0930b
Merge branch 'master' into 1.20.6 2025-12-02 00:06:16 +08:00
Tasuku Bobcorn
19781985f7 Fix reading window items packet in versions below 1.17.1 2025-04-29 13:56:38 +08:00
breadbyte
a5ab30f3da Fix session cache serializer failure 2024-12-25 01:28:28 +08:00
Anon
7152072598 Ported to .NET 8 2024-12-22 13:20:04 +01:00
Anon
f83e7c5707 Preliminary 1.21 Support 2024-12-06 16:45:48 +01:00
vinicius
d0c9695a79 Fixed bug in SetDimension method of World class, where it would crash if joining a paper server. Added error handling. 2024-12-05 02:13:21 +00:00
Anon
7bd213a154 Fixed the potion component crash 2024-12-04 21:25:22 +01:00
Anon
0da4a718cb Implemented all structured components, renamed them all to a better format 2024-10-05 13:37:52 +02:00
Anon
4dea688ca2 Added more structured components 2024-09-11 20:58:24 +02:00
Anon
49319fe781 Added more components + added item palette reference 2024-09-11 20:35:23 +02:00
Anon
76e873ed54 WIP: Added some strctured components 2024-09-11 19:12:31 +02:00
breadbyte
27e66433cd
Hotfix for 'minecraft:chat_type' not present in the dictionary (#2794) 2024-09-07 03:45:45 +08:00
Anon
63b027d84a First Version of Structured Components 2024-09-01 20:42:39 +02:00
breadbyte
c50b360eae
Fix minor bugs (#2759)
* add miscellaneous fixes

* Fixed connecting to server when compression threshold is set to 0

The client assumes that 0 means disabled, when on a notchian (vanilla) server, it is possible to set the compression threshold to 0 (compress all packets).

* Try to capture all exceptions through Sentry

No exceptions are being logged through Sentry, so be more aggressive when sending exceptions

(cherry picked from commit eb1c2f5e771760fb3be32ffea79f8292adca92f1)

* Call OnSpawnPlayer packet when a player is spawned using the SpawnEntity packet

references #2721

(cherry picked from commit ef28ae09ac89e8988dd612de61f2849a9f0e528c)
2024-07-14 01:30:16 +08:00
Anon
5a6fd577e5 Inventory, Terrain and Entity handling 2024-07-02 11:08:46 +02:00
Anon
58a5260b5b Merge branch 'master' of github.com:milutinke/Minecraft-Console-Client into 1.20.6 2024-06-30 11:57:57 +02:00
Anon
67e36a92d2 First working version, not fully tested 2024-06-30 11:26:41 +02:00
breadbyte
08551097c6
Add Sentry Error Tracking (#2670)
* Add Sentry Error Tracking

* Omit personally identifiable information and add additional sentry context

* Remove debug message

* Make sentry opt-out and add related notices and strings

Also add Minecraft Version to error context

* Update build to send release info to sentry

* Adjust sentry error tracking

- Send the user-friendly Minecraft Version in the error logs
- Capture exceptions in more parts of the application

We now capture exceptions from the following locations:
- Protocol18 (1.8+) Packet errors
- Errors during client initialization phase (When client is about to start, session keys are NEVER sent to sentry)

* Make Sentry DSN configurable and repository-specific

The Sentry DSN will automatically be filled out on the main repository through the Github Actions build.

* Update build-and-release.yml

Update sed command

* style: change variable name

nitpick, just to make it a little bit more descriptive

* Add Sentry branding in README.

* remove old code (merge conflict)
2024-06-22 06:41:13 +08:00
Anon
08c5c15557 1.20.6 - Not working yet 2024-06-16 01:19:09 +02:00
Anon
8270a2d9a3
Item Mappings for 1.8 - 1.12 + Crash Fix
Item Mappings for 1.8 - 1.12 + Crash Fix
2024-06-08 21:34:33 +00:00
yaggod
d0caf4c9ee fixed typo in word heAlper lol 2024-04-16 21:21:08 +03:00
oldkingOK
bf54def51f
Fix(PacketType18Handler.cs): 1.20 Packet Palette (#2715) 2024-03-20 14:10:06 +08:00
breadbyte
dc71332dd3 fix mcc not showing the disconnect message
The fix is to remove the ParseText call from the OnConnectionLost call, as the ReadNextChat function already calls ParseText. Calling ParseText on an unparsable string returns an empty string, therefore the disconnect message never gets propagated to the user.
2024-03-17 02:09:20 +08:00
Anon
5044ec965b Un-commended try-catch block 2024-03-12 19:07:20 +01:00
Anon
2ce0311949 Fixed a crash in SendPlayerBlockPlacement 2024-03-12 15:05:47 +01:00
Anon
691f1a136e Added Item Palette for 1.11 2024-03-12 14:04:36 +01:00
Anon
c9c16818a4 Added item Mappings for 1.10 2024-03-12 13:49:47 +01:00
Anon
221d5948e2 Added Item mappings for 1.12 2024-03-12 13:28:17 +01:00
Anon
a19a91e37f Added Item palette for 1.9 2024-03-12 12:58:29 +01:00
Anon
6891d446a5 Added 1.8 Item Mappings and Support 2024-03-12 11:15:05 +01:00
oldkingOK
4bb25c377e feat(DeclareCommands.cs): Add 1.20.3+ version check 2024-03-10 12:03:07 +08:00
oldkingOK
79910b50f7
Merge branch 'MCCTeam:master' into forge-cmds 2024-03-10 08:07:01 +08:00
Anon
e2b6dc27c8
[skipci]Forge Code Cleanup
Optimize code and edit comments
2024-03-05 22:50:06 +01:00
Anon
744de0dbd4 Removed debug logs 2024-02-28 11:49:50 +01:00
Anon
bc0781cee9 Fixed translations crash 2024-02-28 11:48:23 +01:00
Anon
620e8bf274 More debug info 2024-02-26 23:46:08 +01:00
Anon
1db0792d7b Temporary Debug info 2024-02-26 23:39:20 +01:00
Anon
ecc88fac06 Fixed a crash on Entity Metadata 2024-02-25 16:11:33 +01:00
Anon
3522a16b0d Removed a comment 2024-02-21 17:40:39 +01:00
Anon
13de67b6f8 Fixed a crash on chat parsing.
Returned the commended try catch block.
2024-02-21 17:38:32 +01:00
oldkingOK
8e1822b0d2 feat(DeclareCommands.cs): Remove 1.20.2+ version check 2024-02-21 10:10:03 +08:00
oldkingOK
8be66daab1 fix(Protocol18Forge.cs): Version bigger or equal 1.18 is FML3 2024-02-20 22:23:46 +08:00
oldkingOK
092854532a docs(Protocol18Forge.cs): Move comment to mechod head 2024-02-20 22:22:11 +08:00
oldkingOK
6949276779 docs(Protocol18Forge.cs): Replace code with packet definition 2024-02-20 22:13:10 +08:00