Unnecessary null check

This commit is contained in:
themode 2022-03-07 22:18:03 +01:00
parent 4ab2f43eed
commit 03cf585121
2 changed files with 8 additions and 4 deletions

View File

@ -202,9 +202,8 @@ record BlockImpl(@NotNull Registry.BlockEntry registry,
private Block compute(byte[] properties) {
if (Arrays.equals(propertiesArray, properties)) return this;
BlockImpl block = possibleProperties().get(new PropertiesHolder(properties));
if (block == null)
throw new IllegalArgumentException("Invalid properties: " + Arrays.toString(properties) + " for block " + this);
final BlockImpl block = possibleProperties().get(new PropertiesHolder(properties));
assert block != null;
return nbt == null && handler == null ? block : new BlockImpl(block.registry(), block.propertiesArray, nbt, handler);
}

View File

@ -33,7 +33,7 @@ public class BlockTest {
}
@Test
public void testProperty() {
public void validProperties() {
Block block = Block.CHEST;
assertEquals(block.properties(), Objects.requireNonNull(Block.fromBlockId(block.id())).properties());
@ -48,8 +48,13 @@ public class BlockTest {
assertEquals(block.withProperty("facing", "north").getProperty("facing"), "north");
assertNotEquals(block.withProperty("facing", "north"), block.withProperty("facing", "south"));
}
@Test
public void invalidProperties() {
Block block = Block.CHEST;
assertThrows(Exception.class, () -> block.withProperty("random", "randomKey"));
assertThrows(Exception.class, () -> block.withProperties(Map.of("random", "randomKey")));
}
@Test