Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prototype of a way to get the name of inventories #1114

Draft
wants to merge 1 commit into
base: mc-1.19.x
Choose a base branch
from
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