1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-08-29 08:42:17 +00:00

Reverted change to how GenericPeripherals report type. Instead, added generic lua function that returns the name of Nameable targets. Might not be at home in InventoryMethods since it could apply to other types of targets.

This commit is contained in:
David Queneau
2021-01-30 20:45:08 -08:00
parent 664df62d5d
commit f6a26f75c3
2 changed files with 15 additions and 12 deletions

View File

@@ -5,10 +5,7 @@
*/
package dan200.computercraft.shared.peripheral.generic;
import dan200.computercraft.api.lua.IArguments;
import dan200.computercraft.api.lua.ILuaContext;
import dan200.computercraft.api.lua.LuaException;
import dan200.computercraft.api.lua.MethodResult;
import dan200.computercraft.api.lua.*;
import dan200.computercraft.api.peripheral.IComputerAccess;
import dan200.computercraft.api.peripheral.IDynamicPeripheral;
import dan200.computercraft.api.peripheral.IPeripheral;
@@ -35,14 +32,7 @@ class GenericPeripheral implements IDynamicPeripheral
{
Identifier type = BlockEntityType.getId(tile.getType());
this.tile = tile;
if ( tile instanceof Nameable && ((Nameable) tile).hasCustomName() )
{
this.type = ((Nameable) tile).getName().asString();
} else {
this.type = type == null ? "unknown" : type.toString();
}
this.type = type == null ? "unknown" : type.toString();
this.methods = methods;
}

View File

@@ -16,6 +16,7 @@ import dan200.computercraft.shared.peripheral.generic.data.ItemData;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier;
import net.minecraft.util.Nameable;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
@@ -54,6 +55,18 @@ public class InventoryMethods implements GenericSource
return inventory.size();
}
/**
* Get the name of this inventory.
*
* @param inventory The current inventory.
* @return The name of this inventory, or {@code nil} if not present.
*/
@LuaFunction( mainThread = true )
public static String name( Nameable inventory )
{
return inventory.hasCustomName() ? inventory.getName().asString() : null;
}
/**
* List all items in this inventory. This returns a table, with an entry for each slot.
*