1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2025-01-05 23:10:30 +00:00

Fix drive.getAudioTitle returning null for no disk

Historically (and according to the docs) getAudioTitle returned "false"
when the drive was empty (or had invalid media), and "null" when the
disk had no item. This was accidentally changed in a later refactor --
this change fixes that behaviour.
This commit is contained in:
Jonathan Coates 2024-06-21 07:54:18 +01:00
parent e4236824d7
commit 25b8a65c5c
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06
3 changed files with 54 additions and 1 deletions

View File

@ -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;
}
/**

View File

@ -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)

View File

@ -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}"
]
}