mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
Fixed shovel not being able to be used on dirt
This commit is contained in:
parent
a7a3566756
commit
0c9ff137b2
5 changed files with 56 additions and 8 deletions
|
|
@ -1,6 +1,8 @@
|
|||
using Brigadier.NET;
|
||||
using Brigadier.NET.Builder;
|
||||
using MinecraftClient.CommandHandler;
|
||||
using MinecraftClient.Inventory;
|
||||
using MinecraftClient.Mapping;
|
||||
using static MinecraftClient.CommandHandler.CmdResult;
|
||||
|
||||
namespace MinecraftClient.Commands
|
||||
|
|
@ -8,7 +10,7 @@ namespace MinecraftClient.Commands
|
|||
class UseItem : Command
|
||||
{
|
||||
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 void RegisterCommand(CommandDispatcher<CmdResult> dispatcher)
|
||||
|
|
@ -21,6 +23,8 @@ namespace MinecraftClient.Commands
|
|||
|
||||
dispatcher.Register(l => l.Literal(CmdName)
|
||||
.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")
|
||||
.Executes(r => GetUsage(r.Source, string.Empty))
|
||||
.Redirect(dispatcher.GetRoot().GetChild("help").GetChild(CmdName)))
|
||||
|
|
@ -43,8 +47,34 @@ namespace MinecraftClient.Commands
|
|||
if (!handler.GetInventoryEnabled())
|
||||
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();
|
||||
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);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4546,6 +4546,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
try
|
||||
{
|
||||
var packet = new List<byte>();
|
||||
var (cursorX, cursorY, cursorZ) = GetFaceHitCursor(face);
|
||||
|
||||
switch (protocolVersion)
|
||||
{
|
||||
|
|
@ -4581,9 +4582,9 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
break;
|
||||
}
|
||||
|
||||
packet.AddRange(dataTypes.GetFloat(0.5f)); // cursorX
|
||||
packet.AddRange(dataTypes.GetFloat(0.5f)); // cursorY
|
||||
packet.AddRange(dataTypes.GetFloat(0.5f)); // cursorZ
|
||||
packet.AddRange(dataTypes.GetFloat(cursorX)); // cursorX
|
||||
packet.AddRange(dataTypes.GetFloat(cursorY)); // cursorY
|
||||
packet.AddRange(dataTypes.GetFloat(cursorZ)); // cursorZ
|
||||
|
||||
if(protocolVersion >= MC_1_14_Version)
|
||||
packet.Add(0); // insideBlock = false
|
||||
|
|
@ -4611,6 +4612,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)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
|
|
@ -4445,7 +4445,7 @@ namespace MinecraftClient {
|
|||
}
|
||||
|
||||
/// <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>
|
||||
internal static string cmd_useitem_desc {
|
||||
get {
|
||||
|
|
|
|||
|
|
@ -1506,7 +1506,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>
|
||||
</data>
|
||||
<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 name="cmd.useitem.use" xml:space="preserve">
|
||||
<value>Used an item</value>
|
||||
|
|
@ -2299,4 +2299,4 @@ see item details.</value>
|
|||
<data name="tui.inventory.item_count" xml:space="preserve">
|
||||
<value>{0} items</value>
|
||||
</data>
|
||||
</root>
|
||||
</root>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue