Skip to content

Commit 179a83d

Browse files
committed
Fix NPE when dropping null
1 parent 24a9c39 commit 179a83d

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

loader/src/main/java/com/fox2code/foxloader/internal/InternalInteractionHooks.java

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,42 +163,51 @@ public static boolean onHandleClickSlot(Container container, int slotId, int mou
163163

164164
public static boolean onDropCurrentItem(EntityPlayer player) {
165165
if (PLAYER_DROP_ITEM_EVENT.isEmpty()) return false;
166+
ItemStack currentItem = player.inventory.getCurrentItem();
167+
if (currentItem == null) return false;
166168
PlayerDropItemEvent playerDropItemEvent = new PlayerDropItemEvent(
167-
player, player.inventory.getCurrentItem(), player.inventory.currentItem, 1, false, true);
169+
player, currentItem, player.inventory.currentItem, 1, false, true);
168170
PLAYER_DROP_ITEM_EVENT.callEvent(playerDropItemEvent);
169171
updateSlotItemIfCancelled(playerDropItemEvent);
170172
return playerDropItemEvent.isCancelled();
171173
}
172174

173175
public static boolean onDropCurrentItemStack(EntityPlayer player) {
174176
if (PLAYER_DROP_ITEM_EVENT.isEmpty()) return false;
177+
ItemStack currentItem = player.inventory.getCurrentItem();
178+
if (currentItem == null) return false;
175179
PlayerDropItemEvent playerDropItemEvent = new PlayerDropItemEvent(
176-
player, player.inventory.getCurrentItem(), player.inventory.currentItem, 64, false, true);
180+
player, currentItem, player.inventory.currentItem, 64, false, true);
177181
PLAYER_DROP_ITEM_EVENT.callEvent(playerDropItemEvent);
178182
updateSlotItemIfCancelled(playerDropItemEvent);
179183
return playerDropItemEvent.isCancelled();
180184
}
181185

182186
public static boolean onDropCursorItem(EntityPlayer player) {
183187
if (PLAYER_DROP_ITEM_EVENT.isEmpty()) return false;
188+
ItemStack cursorItem = player.inventory.getCursorStack();
189+
if (cursorItem == null) return false;
184190
PlayerDropItemEvent playerDropItemEvent = new PlayerDropItemEvent(
185-
player, player.inventory.getCursorStack(), -999, 1, false, false);
191+
player, cursorItem, -999, 1, false, false);
186192
PLAYER_DROP_ITEM_EVENT.callEvent(playerDropItemEvent);
187193
updateSlotItemIfCancelled(playerDropItemEvent);
188194
return playerDropItemEvent.isCancelled();
189195
}
190196

191197
public static boolean onDropCursorItemStack(EntityPlayer player) {
192198
if (PLAYER_DROP_ITEM_EVENT.isEmpty()) return false;
199+
ItemStack cursorItem = player.inventory.getCursorStack();
200+
if (cursorItem == null) return false;
193201
PlayerDropItemEvent playerDropItemEvent = new PlayerDropItemEvent(
194-
player, player.inventory.getCursorStack(), -999, 64, false, false);
202+
player, cursorItem, -999, 64, false, false);
195203
PLAYER_DROP_ITEM_EVENT.callEvent(playerDropItemEvent);
196204
updateSlotItemIfCancelled(playerDropItemEvent);
197205
return playerDropItemEvent.isCancelled();
198206
}
199207

200208
public static boolean onDropCreativeItemStack(EntityPlayer player, ItemStack itemStack) {
201209
if (PLAYER_DROP_ITEM_EVENT.isEmpty()) return false;
210+
if (itemStack == null) return false;
202211
PlayerDropItemEvent playerDropItemEvent = new PlayerDropItemEvent(
203212
player, itemStack, -999, 64, true, false);
204213
PLAYER_DROP_ITEM_EVENT.callEvent(playerDropItemEvent);

0 commit comments

Comments
 (0)