Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import dan200.computercraft.shared.peripheral.generic.data.ItemData;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.Container;
import net.minecraft.world.Nameable;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.common.capabilities.ICapabilityProvider;
Expand Down Expand Up @@ -265,6 +266,27 @@ public static int pullItems(
return moveItem( from, fromSlot - 1, to, toSlot.orElse( 0 ) - 1, actualLimit );
}

/**
* Get the display name of the current inventory.
*
* This allows you to get the name of inventories renamed in an anvil.
*
* @param peripheral The current peripheral.
* @return The name of the inventory, or nil.
* @cc.usage find a chest, and print it's (custom) name.
* <pre>{@code
* local chest = peripheral.find("minecraft:chest")
*
* print(chest.displayName())
* }</pre>
*/
@LuaFunction( mainThread = true )
public static String displayName(IPeripheral peripheral)
{
if (peripheral.getTarget() instanceof Nameable nameable) return nameable.getDisplayName().getString();
return null;
}

@Nullable
private static IItemHandler extractHandler( @Nullable Object object )
{
Expand Down