Skip to content

Commit

Permalink
Dontcrash (#10525)
Browse files Browse the repository at this point in the history
Dont crash with empty stack, but log error so we can find origin more easily. Better log spam than exceptions
  • Loading branch information
Raycoms authored Dec 11, 2024
1 parent e187d0c commit 102dc51
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.minecolonies.api.colony.requestsystem.factory.IFactoryController;
import com.minecolonies.api.crafting.ItemStorage;
import com.minecolonies.api.util.ItemStackUtils;
import com.minecolonies.api.util.Log;
import com.minecolonies.api.util.ReflectionUtils;
import com.minecolonies.api.util.constant.TypeConstants;
import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -160,7 +161,7 @@ public Stack(final ItemStack stack, final boolean matchDamage, final boolean mat
{
if (ItemStackUtils.isEmpty(stack))
{
throw new IllegalArgumentException("Cannot deliver Empty Stack.");
Log.getLogger().error("Created Empty Stack", new Exception());
}

this.theStack = stack.copy();
Expand Down Expand Up @@ -221,6 +222,11 @@ public static Stack deserialize(final IFactoryController controller, final Compo
minCount = compound.getInt(NBT_MINCOUNT);
}

if (stack.isEmpty())
{
Log.getLogger().error("Deserialized bad stack", compound.toString());
}

return new Stack(stack, matchMeta, matchNBT, result, count, minCount, canBeResolved);
}

Expand Down Expand Up @@ -265,6 +271,12 @@ public static Stack deserialize(final IFactoryController controller, final Frien

int count = buffer.readInt();
int minCount = buffer.readInt();

if (stack.isEmpty())
{
Log.getLogger().error("Deserialized bad stack", stack.toString());
}

return new Stack(stack, matchMeta, matchNBT, result, count, minCount, canBeResolved);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.minecolonies.api.colony.requestsystem.requestable.IRequestable;
import com.minecolonies.api.colony.requestsystem.token.IToken;
import com.minecolonies.api.util.ItemStackUtils;
import com.minecolonies.api.util.Log;
import net.minecraft.world.item.ItemStack;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -57,12 +58,14 @@ public AbstractCrafting(@NotNull final ItemStack stack, final int count, final i
this.minCount = minCount;
this.recipeToken = recipeToken;

if (ItemStackUtils.isEmpty(stack))
if (stack.isEmpty())
{
throw new IllegalArgumentException("Cannot deliver Empty Stack.");
Log.getLogger().error("Created Empty Stack", new Exception());
}
else
{
this.theStack.setCount(Math.min(this.theStack.getCount(), this.theStack.getMaxStackSize()));
}

this.theStack.setCount(Math.min(this.theStack.getCount(), this.theStack.getMaxStackSize()));
}

@NotNull
Expand Down

0 comments on commit 102dc51

Please sign in to comment.