From 6883da9738c62425a676facb022c674f0dacc0bf Mon Sep 17 00:00:00 2001 From: P3pp3rF1y Date: Tue, 5 Nov 2024 01:23:50 +0100 Subject: [PATCH] =?UTF-8?q?refactor:=20=E2=99=BB=EF=B8=8F=20Polish=20list/?= =?UTF-8?q?set=20data=20component=20types=20a=20bit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- gradle.properties | 2 +- .../init/ModDataComponents.java | 25 +++++-------------- 2 files changed, 7 insertions(+), 20 deletions(-) diff --git a/gradle.properties b/gradle.properties index 303fc18c7..5b9fa3e31 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ loader_version_range=[4,) mod_id=sophisticatedstorage mod_name=Sophisticated Storage mod_license=GNU General Public License v3.0 -mod_version=0.10.46 +mod_version=0.10.47 mod_group_id=sophisticatedstorage mod_authors=P3pp3rF1y, Ridanisaurus mod_description=Fancy and functional storage containers. diff --git a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/init/ModDataComponents.java b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/init/ModDataComponents.java index 343606172..62aedf93f 100644 --- a/src/main/java/net/p3pp3rf1y/sophisticatedstorage/init/ModDataComponents.java +++ b/src/main/java/net/p3pp3rf1y/sophisticatedstorage/init/ModDataComponents.java @@ -14,13 +14,16 @@ import net.neoforged.neoforge.registries.DeferredHolder; import net.neoforged.neoforge.registries.DeferredRegister; import net.p3pp3rf1y.sophisticatedcore.upgrades.FilterAttributes; +import net.p3pp3rf1y.sophisticatedcore.util.CodecHelper; import net.p3pp3rf1y.sophisticatedstorage.SophisticatedStorage; import net.p3pp3rf1y.sophisticatedstorage.block.BarrelMaterial; import net.p3pp3rf1y.sophisticatedstorage.item.BarrelBlockItem; import net.p3pp3rf1y.sophisticatedstorage.item.StorageToolItem; import net.p3pp3rf1y.sophisticatedstorage.item.WoodStorageBlockItem; -import java.util.*; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; import java.util.function.Supplier; public class ModDataComponents { @@ -55,19 +58,9 @@ private ModDataComponents() { public static final Supplier> FIRST_INVENTORY_SLOT = DATA_COMPONENT_TYPES.register("first_inventory_slot", () -> new DataComponentType.Builder().persistent(Codec.INT).networkSynchronized(ByteBufCodecs.INT).build()); - private static final Codec> DIRECTION_SET_CODEC = setCodec(Direction.CODEC); - public static Codec> setCodec(Codec elementCodec) { - return setOf(elementCodec); - } - - public static Codec> setOf(Codec elementCodec) { - return setFromList(elementCodec.listOf()); - } + private static final Codec> DIRECTION_SET_CODEC = CodecHelper.setOf(Direction.CODEC); - public static Codec> setFromList(Codec> listCodec) { - return listCodec.xmap(HashSet::new, ArrayList::new); - } - private static final StreamCodec> DIRECTION_SET_STREAM_CODEC = new StreamCodec<>() { + private static final StreamCodec> DIRECTION_SET_STREAM_CODEC = new StreamCodec<>() { @Override public Set decode(FriendlyByteBuf buf) { return buf.readCollection(HashSet::new, b -> b.readEnum(Direction.class)); @@ -85,12 +78,6 @@ public void encode(FriendlyByteBuf buf, Set directions) { public static final Supplier>> PUSH_DIRECTIONS = DATA_COMPONENT_TYPES.register("push_directions", () -> new DataComponentType.Builder>().persistent(DIRECTION_SET_CODEC).networkSynchronized(DIRECTION_SET_STREAM_CODEC).build()); - public static final Supplier> DIRECTIONS_INTIALIZED = DATA_COMPONENT_TYPES.register("directions_initialized", - () -> new DataComponentType.Builder().persistent(Codec.BOOL).networkSynchronized(ByteBufCodecs.BOOL).build()); - - public static final Supplier> INPUT_FILTER_ATTRIBUTES = DATA_COMPONENT_TYPES.register("input_filter_attributes", - () -> new DataComponentType.Builder().persistent(FilterAttributes.CODEC).networkSynchronized(FilterAttributes.STREAM_CODEC).build()); - public static final DeferredHolder, DataComponentType> OUTPUT_FILTER_ATTRIBUTES = DATA_COMPONENT_TYPES.register("output_filter_attributes", () -> new DataComponentType.Builder().persistent(FilterAttributes.CODEC).networkSynchronized(FilterAttributes.STREAM_CODEC).build());