Fixes NPE when spam clicking right click with a chisel#110
Fixes NPE when spam clicking right click with a chisel#110TheFifthRider wants to merge 4 commits intojayugg:masterfrom
Conversation
WalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)
SmithingPlus/BitsRecovery/CollectibleBehaviorScrapeCrucible.cs (2)
30-37: Consider makingblockSelnullable for consistency.
OnHeldInteractStepuses a non-nullableBlockSelectionparameter whileOnHeldInteractStart(line 13) andOnHeldInteractStop(line 42) both accept nullableBlockSelection?. For consistency and defensive coding, consider updating this signature to match the pattern:public override bool OnHeldInteractStep(float secondsUsed, ItemSlot slot, EntityAgent byEntity, - BlockSelection blockSel, + BlockSelection? blockSel, EntitySelection entitySel, ref EnumHandling handling) { + if (blockSel is null) return false; byEntity.StartAnimation("knifecut"); handling = EnumHandling.PreventDefault; return secondsUsed < 1.5; }
130-135: Update method signature to accept nullableBlockSelection?.After the fix,
TryGetSelectedGroundStorageis called at line 52 with aBlockSelection?argument. To avoid potential compiler warnings and maintain consistency, update the method signature:private static BlockEntityGroundStorage? TryGetSelectedGroundStorage(EntityPlayer entityPlayer, - BlockSelection blockSel) + BlockSelection? blockSel) { + if (blockSel?.Position is null) return null; var blockEntity = entityPlayer.World.BlockAccessor.GetBlockEntity(blockSel.Position); return blockEntity as BlockEntityGroundStorage; }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
SmithingPlus/BitsRecovery/CollectibleBehaviorScrapeCrucible.cs(2 hunks)
🔇 Additional comments (2)
SmithingPlus/BitsRecovery/CollectibleBehaviorScrapeCrucible.cs (2)
39-44: Good fix for the NPE issue.Making
blockSelnullable correctly aligns with the base class contract and matches the pattern already used inOnHeldInteractStart(line 13).
51-51: Null check correctly prevents the NPE.The guard clause effectively addresses the server-side crash reported in issue #106 by ensuring both
blockSeland itsPositionproperty are non-null before proceeding.
This should be marked as nullable :(
May resolve #106
Summary by CodeRabbit