22
33import com .google .common .base .Supplier ;
44import com .google .common .base .Suppliers ;
5- import dev .hephaestus .glowcase .block .HyperlinkBlock ;
6- import dev .hephaestus .glowcase .block .ItemAcceptorBlock ;
7- import dev .hephaestus .glowcase .block .ItemDisplayBlock ;
8- import dev .hephaestus .glowcase .block .OutlineBlock ;
9- import dev .hephaestus .glowcase .block .ParticleDisplayBlock ;
10- import dev .hephaestus .glowcase .block .PopupBlock ;
11- import dev .hephaestus .glowcase .block .SoundPlayerBlock ;
12- import dev .hephaestus .glowcase .block .SpriteBlock ;
13- import dev .hephaestus .glowcase .block .TextBlock ;
14- import dev .hephaestus .glowcase .block .entity .HyperlinkBlockEntity ;
15- import dev .hephaestus .glowcase .block .entity .ItemAcceptorBlockEntity ;
16- import dev .hephaestus .glowcase .block .entity .ItemDisplayBlockEntity ;
17- import dev .hephaestus .glowcase .block .entity .OutlineBlockEntity ;
18- import dev .hephaestus .glowcase .block .entity .ParticleDisplayBlockEntity ;
19- import dev .hephaestus .glowcase .block .entity .PopupBlockEntity ;
20- import dev .hephaestus .glowcase .block .entity .SoundPlayerBlockEntity ;
21- import dev .hephaestus .glowcase .block .entity .SpriteBlockEntity ;
22- import dev .hephaestus .glowcase .block .entity .TextBlockEntity ;
5+ import com .mojang .datafixers .util .Pair ;
6+ import com .mojang .serialization .Codec ;
7+ import dev .hephaestus .glowcase .block .*;
8+ import dev .hephaestus .glowcase .block .entity .*;
239import dev .hephaestus .glowcase .compat .PolydexCompatibility ;
2410import dev .hephaestus .glowcase .item .LockItem ;
11+ import dev .hephaestus .glowcase .item .TabletItem ;
2512import net .fabricmc .api .ModInitializer ;
2613import net .fabricmc .fabric .api .itemgroup .v1 .FabricItemGroup ;
2714import net .fabricmc .loader .api .FabricLoader ;
2815import net .minecraft .block .Block ;
2916import net .minecraft .block .entity .BlockEntity ;
3017import net .minecraft .block .entity .BlockEntityType ;
18+ import net .minecraft .component .ComponentType ;
3119import net .minecraft .item .BlockItem ;
3220import net .minecraft .item .Item ;
3321import net .minecraft .item .ItemGroup ;
3422import net .minecraft .item .ItemStack ;
3523import net .minecraft .item .Items ;
24+ import net .minecraft .network .codec .PacketCodecs ;
3625import net .minecraft .registry .Registries ;
3726import net .minecraft .registry .Registry ;
3827import net .minecraft .registry .RegistryKeys ;
3928import net .minecraft .registry .tag .TagKey ;
4029import net .minecraft .text .Text ;
4130import net .minecraft .util .Identifier ;
31+ import net .minecraft .util .Util ;
32+ import net .minecraft .util .Uuids ;
33+ import net .minecraft .util .dynamic .Codecs ;
34+ import net .minecraft .util .math .BlockPos ;
35+ import org .slf4j .Logger ;
36+ import org .slf4j .LoggerFactory ;
37+
38+ import java .util .Arrays ;
39+ import java .util .List ;
40+ import java .util .UUID ;
4241
4342public class Glowcase implements ModInitializer {
4443 public static final String MODID = "glowcase" ;
44+ public static final Logger LOGGER = LoggerFactory .getLogger (MODID );
4545
46+ public static final GlowcaseConfig CONFIG = GlowcaseConfig .createToml (FabricLoader .getInstance ().getConfigDir (), "" , MODID , GlowcaseConfig .class );
4647 public static GlowcaseCommonProxy proxy = new GlowcaseCommonProxy (); //Overridden in GlowcaseClient
4748
4849 public static final TagKey <Item > ITEM_TAG = TagKey .of (RegistryKeys .ITEM , id ("items" ));
@@ -71,6 +72,10 @@ public class Glowcase implements ModInitializer {
7172 public static final Supplier <BlockItem > POPUP_BLOCK_ITEM = registerItem ("popup_block" , () -> new BlockItem (POPUP_BLOCK .get (), new Item .Settings ()));
7273 public static final Supplier <BlockEntityType <PopupBlockEntity >> POPUP_BLOCK_ENTITY = registerBlockEntity ("popup_block" , () -> BlockEntityType .Builder .create (PopupBlockEntity ::new , POPUP_BLOCK .get ()).build (null ));
7374
75+ public static final Supplier <ScreenBlock > SCREEN_BLOCK = registerBlock ("screen_block" , ScreenBlock ::new );
76+ public static final Supplier <BlockItem > SCREEN_BLOCK_ITEM = registerItem ("screen_block" , () -> new BlockItem (SCREEN_BLOCK .get (), new Item .Settings ()));
77+ public static final Supplier <BlockEntityType <ScreenBlockEntity >> SCREEN_BLOCK_ENTITY = registerBlockEntity ("screen_block" , () -> BlockEntityType .Builder .create (ScreenBlockEntity ::new , SCREEN_BLOCK .get ()).build (null ));
78+
7479 public static final Supplier <SpriteBlock > SPRITE_BLOCK = registerBlock ("sprite_block" , SpriteBlock ::new );
7580 public static final Supplier <BlockItem > SPRITE_BLOCK_ITEM = registerItem ("sprite_block" , () -> new BlockItem (SPRITE_BLOCK .get (), new Item .Settings ()));
7681 public static final Supplier <BlockEntityType <SpriteBlockEntity >> SPRITE_BLOCK_ENTITY = registerBlockEntity ("sprite_block" , () -> BlockEntityType .Builder .create (SpriteBlockEntity ::new , SPRITE_BLOCK .get ()).build (null ));
@@ -85,6 +90,24 @@ public class Glowcase implements ModInitializer {
8590
8691 public static final Supplier <Item > LOCK_ITEM = registerItem ("lock" , () -> new LockItem (new Item .Settings ()));
8792
93+ public static final Supplier <Item > TABLET_ITEM = registerItem ("tablet" , () -> new TabletItem (new Item .Settings ().maxCount (1 )));
94+ public static final Supplier <ComponentType <Pair <UUID , BlockPos >>> LINKED_SCREEN_COMPONENT = registerComponent ("linked_screen" , () -> {
95+ Codec <UUID > uuidCodec = Codec .INT_STREAM .comapFlatMap (stream -> Util .decodeFixedLengthArray (stream , 4 ).map (Uuids ::toUuid ), uuid -> Arrays .stream (Uuids .toIntArray (uuid )));
96+ Codec <Pair <UUID , BlockPos >> codec = Codec .mapPair (uuidCodec .fieldOf ("uuid" ), BlockPos .CODEC .fieldOf ("pos" )).codec ();
97+ return ComponentType .<Pair <UUID , BlockPos >>builder ()
98+ .codec (codec )
99+ .packetCodec (PacketCodecs .registryCodec (codec ))
100+ .build ();
101+ });
102+ public static final Supplier <ComponentType <Integer >> CURRENT_SLIDE_COMPONENT = registerComponent ("current_slide" , () -> ComponentType .<Integer >builder ().codec (Codecs .NONNEGATIVE_INT ).packetCodec (PacketCodecs .registryCodec (Codecs .NONNEGATIVE_INT )).build ());
103+ public static final Supplier <ComponentType <List <Pair <String ,String >>>> SLIDESHOW_COMPONENT = registerComponent ("slideshow" , () -> {
104+ Codec <List <Pair <String , String >>> codec = Codec .mapPair (Codec .STRING .fieldOf ("url" ), Codec .STRING .fieldOf ("alt" )).codec ().listOf ();
105+ return ComponentType .<List <Pair <String ,String >>>builder ()
106+ .codec (codec )
107+ .packetCodec (PacketCodecs .registryCodec (codec ))
108+ .build ();
109+ });
110+
88111 public static final Supplier <ItemGroup > ITEM_GROUP = registerItemGroup ("items" , () -> FabricItemGroup .builder ()
89112 .displayName (Text .translatable ("itemGroup.glowcase.items" ))
90113 .icon (() -> new ItemStack (Items .GLOWSTONE ))
@@ -98,7 +121,9 @@ public class Glowcase implements ModInitializer {
98121 entries .add (ITEM_ACCEPTOR_BLOCK_ITEM .get ());
99122 entries .add (HYPERLINK_BLOCK_ITEM .get ());
100123 entries .add (POPUP_BLOCK_ITEM .get ());
124+ entries .add (SCREEN_BLOCK_ITEM .get ());
101125 entries .add (LOCK_ITEM .get ());
126+ entries .add (TABLET_ITEM .get ());
102127 })
103128 .build ()
104129 );
@@ -115,6 +140,10 @@ public static <T extends Item> Supplier<T> registerItem(String path, Supplier<T>
115140 return Suppliers .ofInstance (Registry .register (Registries .ITEM , id (path ), supplier .get ()));
116141 }
117142
143+ public static <T extends ComponentType <U >, U > Supplier <T > registerComponent (String path , Supplier <T > supplier ) {
144+ return Suppliers .ofInstance (Registry .register (Registries .DATA_COMPONENT_TYPE , id (path ), supplier .get ()));
145+ }
146+
118147 public static <T extends ItemGroup > Supplier <T > registerItemGroup (String path , Supplier <T > supplier ) {
119148 return Suppliers .ofInstance (Registry .register (Registries .ITEM_GROUP , id (path ), supplier .get ()));
120149 }
0 commit comments