Fixed shovel not creating paths from grass when used

This commit is contained in:
Anon 2026-03-27 16:48:34 +01:00 committed by GitHub
commit ce7bf0f400
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 56 additions and 8 deletions

View file

@ -1,6 +1,8 @@
using Brigadier.NET; using Brigadier.NET;
using Brigadier.NET.Builder; using Brigadier.NET.Builder;
using MinecraftClient.CommandHandler; using MinecraftClient.CommandHandler;
using MinecraftClient.Inventory;
using MinecraftClient.Mapping;
using static MinecraftClient.CommandHandler.CmdResult; using static MinecraftClient.CommandHandler.CmdResult;
namespace MinecraftClient.Commands namespace MinecraftClient.Commands
@ -8,7 +10,7 @@ namespace MinecraftClient.Commands
class UseItem : Command class UseItem : Command
{ {
public override string CmdName { get { return "useitem"; } } public override string CmdName { get { return "useitem"; } }
public override string CmdUsage { get { return "useitem"; } } public override string CmdUsage { get { return "useitem [x] [y] [z]"; } }
public override string CmdDesc { get { return Translations.cmd_useitem_desc; } } public override string CmdDesc { get { return Translations.cmd_useitem_desc; } }
public override void RegisterCommand(CommandDispatcher<CmdResult> dispatcher) public override void RegisterCommand(CommandDispatcher<CmdResult> dispatcher)
@ -21,6 +23,8 @@ namespace MinecraftClient.Commands
dispatcher.Register(l => l.Literal(CmdName) dispatcher.Register(l => l.Literal(CmdName)
.Executes(r => DoUseItem(r.Source)) .Executes(r => DoUseItem(r.Source))
.Then(l => l.Argument("Location", MccArguments.Location())
.Executes(r => DoUseItemAtLocation(r.Source, MccArguments.GetLocation(r, "Location"))))
.Then(l => l.Literal("_help") .Then(l => l.Literal("_help")
.Executes(r => GetUsage(r.Source, string.Empty)) .Executes(r => GetUsage(r.Source, string.Empty))
.Redirect(dispatcher.GetRoot().GetChild("help").GetChild(CmdName))) .Redirect(dispatcher.GetRoot().GetChild("help").GetChild(CmdName)))
@ -43,8 +47,34 @@ namespace MinecraftClient.Commands
if (!handler.GetInventoryEnabled()) if (!handler.GetInventoryEnabled())
return r.SetAndReturn(Status.FailNeedInventory); return r.SetAndReturn(Status.FailNeedInventory);
if (handler.GetTerrainEnabled())
{
const double maxDistance = 4.5;
var raycast = RaycastHelper.RaycastBlock(handler, maxDistance, false);
if (raycast.Item1 && raycast.Item3.Type != Material.Air)
{
handler.PlaceBlock(raycast.Item2, Direction.Up, lookAtBlock: true);
handler.DoAnimation((int)Hand.MainHand);
return r.SetAndReturn(Status.Done, Translations.cmd_useitem_use);
}
}
handler.UseItemOnHand(); handler.UseItemOnHand();
return r.SetAndReturn(Status.Done, Translations.cmd_useitem_use); return r.SetAndReturn(Status.Done, Translations.cmd_useitem_use);
} }
private int DoUseItemAtLocation(CmdResult r, Location block)
{
McClient handler = CmdResult.currentHandler!;
if (!handler.GetTerrainEnabled())
return r.SetAndReturn(Status.FailNeedTerrain);
Location current = handler.GetCurrentLocation();
block = block.ToAbsolute(current).ToFloor();
handler.PlaceBlock(block, Direction.Up, lookAtBlock: true);
handler.DoAnimation((int)Hand.MainHand);
return r.SetAndReturn(Status.Done, Translations.cmd_useitem_use);
}
} }
} }

View file

@ -4563,6 +4563,7 @@ namespace MinecraftClient.Protocol.Handlers
try try
{ {
var packet = new List<byte>(); var packet = new List<byte>();
var (cursorX, cursorY, cursorZ) = GetFaceHitCursor(face);
switch (protocolVersion) switch (protocolVersion)
{ {
@ -4598,9 +4599,9 @@ namespace MinecraftClient.Protocol.Handlers
break; break;
} }
packet.AddRange(dataTypes.GetFloat(0.5f)); // cursorX packet.AddRange(dataTypes.GetFloat(cursorX)); // cursorX
packet.AddRange(dataTypes.GetFloat(0.5f)); // cursorY packet.AddRange(dataTypes.GetFloat(cursorY)); // cursorY
packet.AddRange(dataTypes.GetFloat(0.5f)); // cursorZ packet.AddRange(dataTypes.GetFloat(cursorZ)); // cursorZ
if(protocolVersion >= MC_1_14_Version) if(protocolVersion >= MC_1_14_Version)
packet.Add(0); // insideBlock = false packet.Add(0); // insideBlock = false
@ -4628,6 +4629,17 @@ namespace MinecraftClient.Protocol.Handlers
} }
} }
private static (float x, float y, float z) GetFaceHitCursor(Direction face) => face switch
{
Direction.Up => (0.5f, 1.0f, 0.5f),
Direction.Down => (0.5f, 0.0f, 0.5f),
Direction.North => (0.5f, 0.5f, 0.0f),
Direction.South => (0.5f, 0.5f, 1.0f),
Direction.West => (0.0f, 0.5f, 0.5f),
Direction.East => (1.0f, 0.5f, 0.5f),
_ => (0.5f, 0.5f, 0.5f),
};
public bool SendHeldItemChange(short slot) public bool SendHeldItemChange(short slot)
{ {
try try

View file

@ -4481,7 +4481,7 @@ namespace MinecraftClient {
} }
/// <summary> /// <summary>
/// Looks up a localized string similar to Use (left click) an item on the hand. /// Looks up a localized string similar to Use the item in your hand, optionally on a specific block.
/// </summary> /// </summary>
internal static string cmd_useitem_desc { internal static string cmd_useitem_desc {
get { get {

View file

@ -1518,7 +1518,7 @@ You can use "/chunk status {0:0.0} {1:0.0} {2:0.0}" to check the chunk loading s
<value>Useblock at ({0:0.0}, {1:0.0}, {2:0.0}) {3}.</value> <value>Useblock at ({0:0.0}, {1:0.0}, {2:0.0}) {3}.</value>
</data> </data>
<data name="cmd.useitem.desc" xml:space="preserve"> <data name="cmd.useitem.desc" xml:space="preserve">
<value>Use (left click) an item on the hand</value> <value>Use the item in your hand, optionally on a specific block</value>
</data> </data>
<data name="cmd.useitem.use" xml:space="preserve"> <data name="cmd.useitem.use" xml:space="preserve">
<value>Used an item</value> <value>Used an item</value>
@ -2347,4 +2347,4 @@ see item details.</value>
<data name="effect.name.with_amplifier" xml:space="preserve"> <data name="effect.name.with_amplifier" xml:space="preserve">
<value>{0} {1}</value> <value>{0} {1}</value>
</data> </data>
</root> </root>

View file

@ -837,7 +837,7 @@ In scripts and remote control, no slash is needed to perform the command, eg. `q
- **Description:** - **Description:**
Use item in the hand, this can be used to do a right click on items which open menus on servers. Use the item in your hand, including use-on-block actions like shovel flattening.
<div class="custom-container note"><p class="custom-container-title">Note</p> <div class="custom-container note"><p class="custom-container-title">Note</p>
@ -857,6 +857,12 @@ In scripts and remote control, no slash is needed to perform the command, eg. `q
/useitem /useitem
``` ```
Use the item on a specific block:
```
/useitem <x> <y> <z>
```
</details> </details>
<details> <details>