Repository: movingblocks/terasology
Issue: Improve null handling / logging in ItemPickupAuthoritySystem

Noticed this issue on startup with the new module BasicCrafting enabled. It isn't caused by BC but that module exercises stuff on initialization that triggers it. Some block somewhere isn't fully configured right and that's tripping up that bit of code - it doesn't seem to lead to any issues, but it would be good to be able to log more cleanly what is going on.

```
21:40:17.348 [main] INFO  o.t.w.b.internal.BlockManagerImpl - Registered Block core:RedShroom with id 31
21:40:17.374 [main] ERROR o.t.e.event.internal.EventSystemImpl - Failed to invoke event
java.lang.NullPointerException: null
	at org.terasology.logic.inventory.ItemPickupAuthoritySystem.updateExtentsOnBlockItemBoxShape(ItemPickupAuthoritySystem.java:92)
	at org.terasology.logic.inventory.ItemPickupAuthoritySystemMethodAccess.invoke(Unknown Source)
	at org.terasology.entitySystem.event.internal.EventSystemImpl$ByteCodeEventHandlerInfo.invoke(EventSystemImpl.java:516)
	at org.terasology.entitySystem.event.internal.EventSystemImpl.sendStandardEvent(EventSystemImpl.java:279)
	at org.terasology.entitySystem.event.internal.EventSystemImpl.send(EventSystemImpl.java:270)
	at org.terasology.entitySystem.entity.internal.PojoEntityManager.create(PojoEntityManager.java:166)
	at org.terasology.entitySystem.entity.internal.PojoEntityManager.create(PojoEntityManager.java:274)
	at org.terasology.crafting.systems.IconManagerImpl.loadItems(IconManagerImpl.java:144)
	at org.terasology.crafting.systems.IconManagerImpl.postBegin(IconManagerImpl.java:69)
	at org.terasology.engine.modes.loadProcesses.PostBeginSystems.step(PostBeginSystems.java:53)
	at org.terasology.engine.modes.StateLoading.update(StateLoading.java:242)
	at org.terasology.engine.TerasologyEngine.tick(TerasologyEngine.java:437)
	at org.terasology.engine.TerasologyEngine.mainLoop(TerasologyEngine.java:400)
	at org.terasology.engine.TerasologyEngine.run(TerasologyEngine.java:376)
	at org.terasology.engine.Terasology.main(Terasology.java:154)
21:40:17.439 [main] INFO  o.t.w.b.internal.BlockManagerImpl - Registered BlockFamily[Core:Cotton4]
21:40:17.439 [main] INFO  o.t.w.b.internal.BlockManagerImpl - Registered Block Core:Cotton4 with id 32
```

Goal: Catch and handle the null more gracefully in `ItemPickupAuthoritySystem.updateExtentsOnBlockItemBoxShape` - try to see what other information is available and log the details at WARN level then continue normally instead of throwing the stacktrace.

Running with Core + BC enabled and checking the startup logs shows this issue repeatedly so it shouldn't be hard to trigger the condition.

Good bite-sized issue and we can create a GCI task for it if somebody is interested.

Changed files:
engine/src/main/java/org/terasology/logic/inventory/ItemPickupAuthoritySystem.java

diff --git a/engine/src/main/java/org/terasology/logic/inventory/ItemPickupAuthoritySystem.java b/engine/src/main/java/org/terasology/logic/inventory/ItemPickupAuthoritySystem.java
index f84565863..389923880 100644
--- a/engine/src/main/java/org/terasology/logic/inventory/ItemPickupAuthoritySystem.java
+++ b/engine/src/main/java/org/terasology/logic/inventory/ItemPickupAuthoritySystem.java
@@ -17,6 +17,8 @@
 package org.terasology.logic.inventory;
 
 import com.bulletphysics.collision.shapes.BoxShape;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.terasology.engine.Time;
 import org.terasology.entitySystem.Component;
 import org.terasology.entitySystem.entity.EntityRef;
@@ -44,6 +46,8 @@
  */
 @RegisterSystem(RegisterMode.AUTHORITY)
 public class ItemPickupAuthoritySystem extends BaseComponentSystem {
+    private static final Logger LOGGER = LoggerFactory.getLogger(ItemPickupAuthoritySystem.class);
+
     @In
     private EntitySystemLibrary library;
 
@@ -89,6 +93,12 @@ public void updateExtentsOnBlockItemBoxShape(OnAddedComponent event, EntityRef i
                                                  BlockItemComponent blockItemComponent,
                                                  BoxShapeComponent boxShapeComponent) {
         BlockFamily blockFamily = blockItemComponent.blockFamily;
+
+        if (blockFamily == null) {
+            LOGGER.warn("Prefab " + itemEntity.getParentPrefab().getName() + " does not have a block family");
+            return;
+        }
+
         if (blockFamily.getArchetypeBlock().getCollisionShape() instanceof BoxShape) {
             javax.vecmath.Vector3f extents = ((BoxShape) blockFamily.getArchetypeBlock().getCollisionShape()).getHalfExtentsWithoutMargin(new javax.vecmath.Vector3f());
             extents.scale(2.0f);