mirror of
				https://github.com/SquidDev-CC/CC-Tweaked
				synced 2025-10-26 03:17:38 +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:
		| @@ -129,7 +129,8 @@ public class DiskDrivePeripheral implements IPeripheral { | |||||||
|     @LuaFunction |     @LuaFunction | ||||||
|     @Nullable |     @Nullable | ||||||
|     public final Object getAudioTitle() { |     public final Object getAudioTitle() { | ||||||
|         return diskDrive.getMedia().getAudioTitle(); |         var stack = diskDrive.getMedia(); | ||||||
|  |         return stack.media() != null ? stack.getAudioTitle() : false; | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /** |     /** | ||||||
|   | |||||||
| @@ -10,6 +10,7 @@ import dan200.computercraft.gametest.api.* | |||||||
| import dan200.computercraft.shared.ModRegistry | import dan200.computercraft.shared.ModRegistry | ||||||
| import dan200.computercraft.shared.media.items.DiskItem | import dan200.computercraft.shared.media.items.DiskItem | ||||||
| import dan200.computercraft.shared.peripheral.diskdrive.DiskDriveBlock | import dan200.computercraft.shared.peripheral.diskdrive.DiskDriveBlock | ||||||
|  | import dan200.computercraft.shared.peripheral.diskdrive.DiskDrivePeripheral | ||||||
| import dan200.computercraft.shared.peripheral.diskdrive.DiskDriveState | import dan200.computercraft.shared.peripheral.diskdrive.DiskDriveState | ||||||
| import dan200.computercraft.test.core.assertArrayEquals | import dan200.computercraft.test.core.assertArrayEquals | ||||||
| import dan200.computercraft.test.core.computer.getApi | 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 |     @GameTest | ||||||
|     fun Ejects_disk(helper: GameTestHelper) = helper.sequence { |     fun Ejects_disk(helper: GameTestHelper) = helper.sequence { | ||||||
|         val stackAt = BlockPos(2, 2, 2) |         val stackAt = BlockPos(2, 2, 2) | ||||||
|   | |||||||
| @@ -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}" | ||||||
|  |     ] | ||||||
|  | } | ||||||
		Reference in New Issue
	
	Block a user
	 Jonathan Coates
					Jonathan Coates