MineColonies

MineColonies

65M Downloads

Exception when delivery to Postbox

Closed this issue ยท 0 comments

commented

Is there an existing issue for this?

  • I have searched the existing issues.

Are you using the latest MineColonies Version?

  • I am running the latest beta/release version of MineColonies for my Minecraft version.
    I am also running the latest versions of other mods that are part of my problem.

Did you check on the Wiki? or ask on Discord?

  • I checked the MineColonies Wiki and made sure my issue is not covered there. Or I was sent from discord to open an issue here.

What were you playing at the time? Were you able to reproduce it in both settings?

  • Single Player
  • Multi Player

Minecraft Version

1.20

MineColonies Version

1.20.1-1.1.978-snapshot

Structurize Version

1.20.1-1.0.775-snapshot

Related Mods and their Versions

No related.

Current Behavior

Exception occurred.

[Server thread/WARN] [minecolonies/]: Statemachine for state DELIVERY threw an exception:
java.lang.NullPointerException: Cannot invoke "net.minecraftforge.common.util.NonNullSupplier.get()" because "other" is null
	at net.minecraftforge.common.util.LazyOptional.orElseGet(LazyOptional.java:238) ~[forge-1.20.1-47.4.3-universal.jar%23177!/:?] {re:classloading}
	at com.minecolonies.core.entity.ai.workers.service.EntityAIWorkDeliveryman.deliver(EntityAIWorkDeliveryman.java:398) ~[minecolonies-1.20.1-1.1.978-snapshot.jar%23168!/:1.20.1-1.1.978-snapshot] {re:classloading}

Expected Behavior

Delivery successfully without exception.

Reproduction Steps

  1. Create a new Colony.
  2. Build Courier's Hut and Warehouse.
  3. Hire a citizen at Warehouse.
  4. Place a Postbox anywhere.
  5. Request any item on Postbox GUI.
  6. Insert items the same name with you request into warehouse.
  7. Wait for the D-Man to delivery items.
  8. Boom.

Logs

https://mclo.gs/07PEedL

Anything else?

I think this bug is created by #10951.
After that PR, Postbox was be not child of AbstractBlockHut.
So in AbstractBuilding#getTileEntity, Postbox can't pass conditions and return null.

@Override
public AbstractTileEntityColonyBuilding getTileEntity()
{
if (tileEntity != null && tileEntity.isRemoved())
{
tileEntity = null;
}
if ((tileEntity == null)
&& colony != null
&& colony.getWorld() != null
&& getPosition() != null
&& WorldUtil.isBlockLoaded(colony.getWorld(), getPosition())
&& !(colony.getWorld().getBlockState(getPosition()).getBlock() instanceof AirBlock)
&& colony.getWorld().getBlockState(this.getPosition()).getBlock() instanceof AbstractBlockHut)

Because of this return LazyOptional.empty() in AbstractBuildingContainer#getCapability.

@Nonnull
@Override
public <T> LazyOptional<T> getCapability(@Nonnull final Capability<T> cap, @Nullable final Direction side)
{
if (cap == ForgeCapabilities.ITEM_HANDLER && getTileEntity() != null)
{
return tileEntity.getCapability(cap, side);
}
return LazyOptional.empty();
}

Finally, The NPE was occurred on EntityAIWorkDeliveryman#deliver.

if (targetBuilding instanceof AbstractBuilding)
{
insertionResultStack = InventoryUtils.forceItemStackToItemHandler(
targetBuilding.getCapability(ForgeCapabilities.ITEM_HANDLER, null).orElseGet(null), stack, ((IBuilding) targetBuilding)::isItemStackInRequest);
}

Footer


Viewers

  • Add a thumbs-up to the bug report if you are also affected. This helps the bug report become more visible to the team and doesn't clutter the comments.
  • Add a comment if you have any insights or background information that isn't already part of the conversation.