1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-04-21 02:03:13 +00:00

Add turtle.getEquipped{Left,Right}

These just return details about the currently equipped *item*. This
allows us to expose information about the currently equipped upgrade,
without having to invent a whole new format.

Docs are a bit consise, but didn't really know how to flesh them out any
further.

Fixes #964, fixes #1613, closes #1692.
This commit is contained in:
Jonathan Coates 2025-03-03 21:30:19 +00:00
parent a892739f8e
commit 0cff73e2fc
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
2 changed files with 35 additions and 1 deletions

View File

@ -57,7 +57,7 @@ junitPlatform = "1.11.4"
jmh = "1.37"
# Build tools
cctJavadoc = "1.8.3"
cctJavadoc = "1.8.4"
checkstyle = "10.21.2"
errorProne-core = "2.36.0"
errorProne-plugin = "4.1.0"

View File

@ -13,7 +13,9 @@ import dan200.computercraft.core.metrics.Metrics;
import dan200.computercraft.core.metrics.MetricsObserver;
import dan200.computercraft.shared.peripheral.generic.methods.AbstractInventoryMethods;
import dan200.computercraft.shared.turtle.core.*;
import org.jspecify.annotations.Nullable;
import java.util.Map;
import java.util.Optional;
/**
@ -659,6 +661,7 @@ public class TurtleAPI implements ILuaAPI {
* @cc.treturn [2] string The reason equipping this item failed.
* @cc.since 1.6
* @see #equipRight()
* @see #getEquippedLeft()
*/
@LuaFunction
public final MethodResult equipLeft() {
@ -678,12 +681,43 @@ public class TurtleAPI implements ILuaAPI {
* @cc.treturn [2] string The reason equipping this item failed.
* @cc.since 1.6
* @see #equipLeft()
* @see #getEquippedRight()
*/
@LuaFunction
public final MethodResult equipRight() {
return trackCommand(new TurtleEquipCommand(TurtleSide.RIGHT));
}
/**
* Get the upgrade currently equipped on the left of the turtle.
* <p>
* This returns information about the currently equipped item, in the same form as
* {@link #getItemDetail(ILuaContext, Optional, Optional)}.
*
* @return Details about the currently equipped item, or {@code nil} if no upgrade is equipped.
* @see #equipLeft()
*/
@LuaFunction(mainThread = true)
public final @Nullable Map<?, ?> getEquippedLeft() {
var upgrade = turtle.getUpgradeWithData(TurtleSide.LEFT);
return upgrade == null ? null : VanillaDetailRegistries.ITEM_STACK.getDetails(upgrade.getUpgradeItem());
}
/**
* Get the upgrade currently equipped on the right of the turtle.
* <p>
* This returns information about the currently equipped item, in the same form as
* {@link #getItemDetail(ILuaContext, Optional, Optional)}.
*
* @return Details about the currently equipped item, or {@code nil} if no upgrade is equipped.
* @see #equipRight()
*/
@LuaFunction(mainThread = true)
public final @Nullable Map<?, ?> getEquippedRight() {
var upgrade = turtle.getUpgradeWithData(TurtleSide.RIGHT);
return upgrade == null ? null : VanillaDetailRegistries.ITEM_STACK.getDetails(upgrade.getUpgradeItem());
}
/**
* Get information about the block in front of the turtle.
*