Skip to content

Commit 6bb96ac

Browse files
committed
Add null check bug fix
1 parent b934d6f commit 6bb96ac

File tree

2 files changed

+1
-4
lines changed

2 files changed

+1
-4
lines changed

Minecraft2D/Functions.pde

-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ void makeViewDistanceFitZoomLevel() {
3535
setViewDistance(numBlocksVisible + 4);
3636
}
3737

38-
// This function is called each frame.
39-
// I tried to only call this each time the state.player stepped on a new block, but it did not seem to improve the fps.
40-
// That also introduced other problems (block would not be mined until stepped new block), so I chose to keep it like this.
4138
void loadVisibleBlocks() {
4239
for (int x = 0; x < settings.viewDistance; x++) {
4340
for (int y = 0; y < settings.viewDistance; y++) {

Minecraft2D/Player.pde

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public class Player extends Body {
115115

116116
boolean selectedItemIsBlock() {
117117
ItemSlot slot = getSelectedItemSlot();
118-
return slot.item.itemType == ItemType.BLOCK;
118+
return slot.item != null && slot.item.itemType == ItemType.BLOCK;
119119
}
120120

121121
ItemSlot getSelectedItemSlot() {

0 commit comments

Comments
 (0)