- fixed NPE when hitting toolbox hotkey on the same tick as it was placed
- fixes #2914
This commit is contained in:
Grimmauld 2022-05-19 18:44:31 +02:00
parent 283a682d1c
commit 428507038d
3 changed files with 9 additions and 4 deletions

View file

@ -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());
}

View file

@ -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<ToolboxTileEntity> 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");

View file

@ -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;
}