Modernize null-check patterns: use 'is null' and 'is not null'

Replace '== null' with 'is null' and '!= null' with 'is not null'
across 19 core files following modern C# pattern matching conventions.

Only literal null comparisons are changed. Assignments, value
comparisons, and LINQ expressions are left untouched.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot] 2026-03-24 00:27:07 +00:00
parent 902e944cbb
commit c5df6a49c6
19 changed files with 111 additions and 111 deletions

View file

@ -82,20 +82,20 @@ namespace MinecraftClient.Inventory
{
get
{
if (Components != null)
if (Components is not null)
{
var customName = Components.OfType<CustomNameComponent>().FirstOrDefault();
if (customName != null && !string.IsNullOrEmpty(customName.CustomName))
if (customName is not null && !string.IsNullOrEmpty(customName.CustomName))
return customName.CustomName;
var itemName = Components.OfType<ItemNameComponent>().FirstOrDefault();
if (itemName != null && !string.IsNullOrEmpty(itemName.ItemName))
if (itemName is not null && !string.IsNullOrEmpty(itemName.ItemName))
return itemName.ItemName;
return null;
}
if (NBT != null && NBT.ContainsKey("display"))
if (NBT is not null && NBT.ContainsKey("display"))
{
if (NBT["display"] is Dictionary<string, object> displayProperties &&
displayProperties.ContainsKey("Name"))
@ -117,17 +117,17 @@ namespace MinecraftClient.Inventory
{
get
{
if (Components != null)
if (Components is not null)
{
var loreComponent = Components.OfType<LoreNameComponent1206>().FirstOrDefault();
if (loreComponent != null && loreComponent.Lines.Count > 0)
if (loreComponent is not null && loreComponent.Lines.Count > 0)
return loreComponent.Lines.ToArray();
return null;
}
List<string> lores = new();
if (NBT != null && NBT.ContainsKey("display"))
if (NBT is not null && NBT.ContainsKey("display"))
{
if (NBT["display"] is Dictionary<string, object> displayProperties &&
displayProperties.ContainsKey("Lore"))
@ -151,19 +151,19 @@ namespace MinecraftClient.Inventory
{
get
{
if (Components != null)
if (Components is not null)
{
var damageComponent = Components.OfType<DamageComponent>().FirstOrDefault();
if (damageComponent != null)
if (damageComponent is not null)
return damageComponent.Damage;
return 0;
}
if (NBT != null && NBT.ContainsKey("Damage"))
if (NBT is not null && NBT.ContainsKey("Damage"))
{
object damage = NBT["Damage"];
if (damage != null)
if (damage is not null)
{
return int.Parse(damage.ToString() ?? string.Empty, NumberStyles.Any,
CultureInfo.CurrentCulture);
@ -183,11 +183,11 @@ namespace MinecraftClient.Inventory
{
get
{
if (Components == null)
if (Components is null)
return null;
var enchComp = Components.OfType<EnchantmentsComponent>().FirstOrDefault();
if (enchComp != null && enchComp.Enchantments.Count > 0)
if (enchComp is not null && enchComp.Enchantments.Count > 0)
return enchComp.Enchantments;
return null;
@ -220,7 +220,7 @@ namespace MinecraftClient.Inventory
try
{
var enchList = EnchantmentList;
if (enchList != null)
if (enchList is not null)
{
foreach (var ench in enchList)
{
@ -229,7 +229,7 @@ namespace MinecraftClient.Inventory
sb.AppendFormat(" | {0} {1}", name, level);
}
}
else if (NBT != null && (NBT.TryGetValue("Enchantments", out object? enchantments) ||
else if (NBT is not null && (NBT.TryGetValue("Enchantments", out object? enchantments) ||
NBT.TryGetValue("StoredEnchantments", out enchantments)))
{
foreach (Dictionary<string, object> enchantment in (object[])enchantments)
@ -242,7 +242,7 @@ namespace MinecraftClient.Inventory
}
}
if (Lores != null && Lores.Length > 0)
if (Lores is not null && Lores.Length > 0)
{
foreach (var lore in Lores)
sb.AppendFormat(" | {0}", lore);

View file

@ -38,9 +38,9 @@ namespace MinecraftClient.Inventory
// Condition: source has item and dest has no item
if (ValidateSlots(source, dest, destContainer) &&
HasItem(source) &&
((destContainer != null && !HasItem(dest, destContainer)) || (destContainer == null && !HasItem(dest))))
((destContainer is not null && !HasItem(dest, destContainer)) || (destContainer is null && !HasItem(dest))))
return mc.DoWindowAction(c.ID, source, WindowActionType.LeftClick)
&& mc.DoWindowAction(destContainer == null ? c.ID : destContainer.ID, dest, WindowActionType.LeftClick);
&& mc.DoWindowAction(destContainer is null ? c.ID : destContainer.ID, dest, WindowActionType.LeftClick);
else return false;
}
@ -56,9 +56,9 @@ namespace MinecraftClient.Inventory
// Condition: Both slot1 and slot2 has item
if (ValidateSlots(slot1, slot2, destContainer) &&
HasItem(slot1) &&
(destContainer != null && HasItem(slot2, destContainer) || (destContainer == null && HasItem(slot2))))
(destContainer is not null && HasItem(slot2, destContainer) || (destContainer is null && HasItem(slot2))))
return mc.DoWindowAction(c.ID, slot1, WindowActionType.LeftClick)
&& mc.DoWindowAction(destContainer == null ? c.ID : destContainer.ID, slot2, WindowActionType.LeftClick)
&& mc.DoWindowAction(destContainer is null ? c.ID : destContainer.ID, slot2, WindowActionType.LeftClick)
&& mc.DoWindowAction(c.ID, slot1, WindowActionType.LeftClick);
else return false;
}
@ -126,7 +126,7 @@ namespace MinecraftClient.Inventory
/// <returns>The compare result</returns>
private bool ValidateSlots(int s1, int s2, Container? s2Container = null)
{
if (s2Container == null)
if (s2Container is null)
return (s1 != s2 && s1 < c.Type.SlotCount() && s2 < c.Type.SlotCount());
else
return (s1 < c.Type.SlotCount() && s2 < s2Container.Type.SlotCount());
@ -153,7 +153,7 @@ namespace MinecraftClient.Inventory
/// <returns>True if they are equal</returns>
private bool ItemTypeEqual(int slot1, int slot2, Container? s2Container = null)
{
if (s2Container == null)
if (s2Container is null)
{
if (HasItem(slot1) && HasItem(slot2))
return c.Items[slot1].Type == c.Items[slot2].Type;