diff --git a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/DiskDrivePeripheral.java b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/DiskDrivePeripheral.java index 31cb03b20..d103baf96 100644 --- a/projects/common/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/DiskDrivePeripheral.java +++ b/projects/common/src/main/java/dan200/computercraft/shared/peripheral/diskdrive/DiskDrivePeripheral.java @@ -129,7 +129,8 @@ public class DiskDrivePeripheral implements IPeripheral { @LuaFunction @Nullable public final Object getAudioTitle() { - return diskDrive.getMedia().getAudioTitle(); + var stack = diskDrive.getMedia(); + return stack.media() != null ? stack.getAudioTitle() : false; } /** diff --git a/projects/common/src/testMod/kotlin/dan200/computercraft/gametest/Disk_Drive_Test.kt b/projects/common/src/testMod/kotlin/dan200/computercraft/gametest/Disk_Drive_Test.kt index 11fd18344..245d56130 100644 --- a/projects/common/src/testMod/kotlin/dan200/computercraft/gametest/Disk_Drive_Test.kt +++ b/projects/common/src/testMod/kotlin/dan200/computercraft/gametest/Disk_Drive_Test.kt @@ -10,6 +10,7 @@ import dan200.computercraft.gametest.api.* import dan200.computercraft.shared.ModRegistry import dan200.computercraft.shared.media.items.DiskItem import dan200.computercraft.shared.peripheral.diskdrive.DiskDriveBlock +import dan200.computercraft.shared.peripheral.diskdrive.DiskDrivePeripheral import dan200.computercraft.shared.peripheral.diskdrive.DiskDriveState import dan200.computercraft.test.core.assertArrayEquals import dan200.computercraft.test.core.computer.getApi @@ -42,6 +43,17 @@ class Disk_Drive_Test { } } + /** + * [DiskDrivePeripheral] returns `false` when the item is not a disk (or is absent). + */ + @GameTest + fun Audio_title_when_empty(helper: GameTestHelper) = helper.sequence { + thenOnComputer { + callPeripheral("right", "getAudioTitle") + .assertArrayEquals(false, message = "Correct audio title") + } + } + @GameTest fun Ejects_disk(helper: GameTestHelper) = helper.sequence { val stackAt = BlockPos(2, 2, 2) diff --git a/projects/common/src/testMod/resources/data/cctest/structures/disk_drive_test.audio_title_when_empty.snbt b/projects/common/src/testMod/resources/data/cctest/structures/disk_drive_test.audio_title_when_empty.snbt new file mode 100644 index 000000000..9583c510b --- /dev/null +++ b/projects/common/src/testMod/resources/data/cctest/structures/disk_drive_test.audio_title_when_empty.snbt @@ -0,0 +1,40 @@ +{ + DataVersion: 2730, + size: [3, 3, 3], + data: [ + {pos: [0, 0, 0], state: "minecraft:polished_andesite"}, + {pos: [0, 0, 1], state: "minecraft:polished_andesite"}, + {pos: [0, 0, 2], state: "minecraft:polished_andesite"}, + {pos: [1, 0, 0], state: "minecraft:polished_andesite"}, + {pos: [1, 0, 1], state: "minecraft:polished_andesite"}, + {pos: [1, 0, 2], state: "minecraft:polished_andesite"}, + {pos: [2, 0, 0], state: "minecraft:polished_andesite"}, + {pos: [2, 0, 1], state: "minecraft:polished_andesite"}, + {pos: [2, 0, 2], state: "minecraft:polished_andesite"}, + {pos: [0, 1, 0], state: "minecraft:air"}, + {pos: [0, 1, 1], state: "computercraft:disk_drive{facing:north,state:full}", nbt: {id: "computercraft:disk_drive"}}, + {pos: [0, 1, 2], state: "minecraft:air"}, + {pos: [1, 1, 0], state: "minecraft:air"}, + {pos: [1, 1, 1], state: "computercraft:computer_advanced{facing:north,state:blinking}", nbt: {ComputerId: 1, Label: "disk_drive_test.audio_title_when_empty", On: 1b, id: "computercraft:computer_advanced"}}, + {pos: [1, 1, 2], state: "minecraft:air"}, + {pos: [2, 1, 0], state: "minecraft:air"}, + {pos: [2, 1, 1], state: "minecraft:air"}, + {pos: [2, 1, 2], state: "minecraft:air"}, + {pos: [0, 2, 0], state: "minecraft:air"}, + {pos: [0, 2, 1], state: "minecraft:air"}, + {pos: [0, 2, 2], state: "minecraft:air"}, + {pos: [1, 2, 0], state: "minecraft:air"}, + {pos: [1, 2, 1], state: "minecraft:air"}, + {pos: [1, 2, 2], state: "minecraft:air"}, + {pos: [2, 2, 0], state: "minecraft:air"}, + {pos: [2, 2, 1], state: "minecraft:air"}, + {pos: [2, 2, 2], state: "minecraft:air"} + ], + entities: [], + palette: [ + "minecraft:polished_andesite", + "minecraft:air", + "computercraft:disk_drive{facing:north,state:full}", + "computercraft:computer_advanced{facing:north,state:blinking}" + ] +}