File tree Expand file tree Collapse file tree 3 files changed +11
-2
lines changed
main/java/mekanism/common/attachments/containers/item Expand file tree Collapse file tree 3 files changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -34,7 +34,7 @@ private MekanismAPI() {
3434 /**
3535 * The version of the api classes - may not always match the mod's version
3636 */
37- public static final String API_VERSION = "10.6.3 " ;
37+ public static final String API_VERSION = "10.6.4 " ;
3838 /**
3939 * Mekanism's Mod ID
4040 */
Original file line number Diff line number Diff line change @@ -59,6 +59,14 @@ private SerializerHelper() {
5959 DataComponentPatch .CODEC .optionalFieldOf (SerializationConstants .COMPONENTS , DataComponentPatch .EMPTY ).forGetter (ItemStack ::getComponentsPatch )
6060 ).apply (instance , ItemStack ::new )));
6161
62+ /**
63+ * Custom codec to allow serializing an item stack without the upper bounds. Allows empty items
64+ *
65+ * @since 10.6.4
66+ */
67+ public static final Codec <ItemStack > OVERSIZED_ITEM_OPTIONAL_CODEC = ExtraCodecs .optionalEmptyMap (OVERSIZED_ITEM_CODEC )
68+ .xmap (optional -> optional .orElse (ItemStack .EMPTY ), stack -> stack .isEmpty () ? Optional .empty () : Optional .of (stack ));
69+
6270 /**
6371 * Helper similar to {@link ItemStack#save(Provider)} but with support for oversized stacks.
6472 *
Original file line number Diff line number Diff line change 55import java .util .Collections ;
66import java .util .List ;
77import mekanism .api .SerializationConstants ;
8+ import mekanism .api .SerializerHelper ;
89import mekanism .api .annotations .NothingNullByDefault ;
910import mekanism .common .attachments .containers .IAttachedContainers ;
1011import net .minecraft .core .NonNullList ;
@@ -18,7 +19,7 @@ public record AttachedItems(List<ItemStack> containers) implements IAttachedCont
1819 public static final AttachedItems EMPTY = new AttachedItems (Collections .emptyList ());
1920
2021 public static final Codec <AttachedItems > CODEC = RecordCodecBuilder .create (instance -> instance .group (
21- ItemStack . OPTIONAL_CODEC .listOf ().fieldOf (SerializationConstants .ITEMS ).forGetter (AttachedItems ::containers )
22+ SerializerHelper . OVERSIZED_ITEM_OPTIONAL_CODEC .listOf ().fieldOf (SerializationConstants .ITEMS ).forGetter (AttachedItems ::containers )
2223 ).apply (instance , AttachedItems ::new ));
2324 public static final StreamCodec <RegistryFriendlyByteBuf , AttachedItems > STREAM_CODEC = ItemStack .OPTIONAL_LIST_STREAM_CODEC
2425 .map (AttachedItems ::new , AttachedItems ::containers );
You can’t perform that action at this time.
0 commit comments