From 428507038dccf3f8e2a272411c578f5fdabcc759 Mon Sep 17 00:00:00 2001 From: Grimmauld Date: Thu, 19 May 2022 18:44:31 +0200 Subject: [PATCH] T00lb0x - fixed NPE when hitting toolbox hotkey on the same tick as it was placed - fixes #2914 --- .../create/content/curiosities/toolbox/ToolboxHandler.java | 2 ++ .../content/curiosities/toolbox/ToolboxHandlerClient.java | 6 ++---- .../content/curiosities/toolbox/ToolboxTileEntity.java | 5 +++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxHandler.java b/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxHandler.java index d83fa6462..2c80bc741 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxHandler.java +++ b/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxHandler.java @@ -1,6 +1,7 @@ package com.simibubi.create.content.curiosities.toolbox; import java.util.List; +import java.util.Objects; import java.util.WeakHashMap; import java.util.stream.Collectors; @@ -111,6 +112,7 @@ public class ToolboxHandler { .sorted((p1, p2) -> Double.compare(distance(location, p1), distance(location, p2))) .limit(maxAmount) .map(toolboxes.get(world)::get) + .filter(ToolboxTileEntity::isFullyInitialized) .collect(Collectors.toList()); } diff --git a/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxHandlerClient.java b/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxHandlerClient.java index 3bcd6701f..2834b92b7 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxHandlerClient.java +++ b/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxHandlerClient.java @@ -6,6 +6,7 @@ import static com.simibubi.create.foundation.gui.AllGuiTextures.TOOLBELT_SELECTE import static com.simibubi.create.foundation.gui.AllGuiTextures.TOOLBELT_SELECTED_ON; import java.util.Collections; +import java.util.Comparator; import java.util.List; import com.google.common.collect.ImmutableList; @@ -111,10 +112,7 @@ public class ToolboxHandlerClient { Level level = player.level; List toolboxes = ToolboxHandler.getNearest(player.level, player, 8); - - if (!toolboxes.isEmpty()) - Collections.sort(toolboxes, (te1, te2) -> te1.getUniqueId() - .compareTo(te2.getUniqueId())); + toolboxes.sort(Comparator.comparing(ToolboxTileEntity::getUniqueId)); CompoundTag compound = player.getPersistentData() .getCompound("CreateToolboxData"); diff --git a/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxTileEntity.java b/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxTileEntity.java index e80788d53..1d0fed5a3 100644 --- a/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxTileEntity.java +++ b/src/main/java/com/simibubi/create/content/curiosities/toolbox/ToolboxTileEntity.java @@ -380,6 +380,11 @@ public class ToolboxTileEntity extends SmartTileEntity implements MenuProvider, return uniqueId; } + public boolean isFullyInitialized() { + // returns true when uniqueId has been initialized + return uniqueId != null; + } + public void setCustomName(Component customName) { this.customName = customName; }