Skip to content

Commit

Permalink
Catch exceptions when sending items to clients
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Oct 9, 2024
1 parent e1147e6 commit 90ef012
Showing 1 changed file with 8 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import net.minecraft.world.inventory.ResultSlot;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import org.apache.logging.log4j.Level;
import org.cyclops.colossalchests.ColossalChestsInstance;
import org.cyclops.colossalchests.GeneralConfig;
import org.cyclops.colossalchests.RegistryEntries;
Expand Down Expand Up @@ -249,8 +250,13 @@ public void updateCraftingInventory(ServerPlayer player, List<ItemStack> allItem
if (itemStack != null) {
CompoundTag tag = new CompoundTag();
tag.putInt("slot", i);
tag.put("stack", ItemStack.OPTIONAL_CODEC.encodeStart(NbtOps.INSTANCE, itemStack)
.getOrThrow(JsonParseException::new));
try {
tag.put("stack", ItemStack.OPTIONAL_CODEC.encodeStart(NbtOps.INSTANCE, itemStack)
.getOrThrow(JsonParseException::new));
} catch (JsonParseException e) {
ColossalChestsInstance.MOD.log(Level.ERROR, "Error while attempting to send a stack to a client " + itemStack);
e.printStackTrace();
}
int tagSize = getTagSize(tag);
if (bufferSize + tagSize + 100 < maxBufferSize) {
sendList.add(tag);
Expand Down

0 comments on commit 90ef012

Please sign in to comment.