11package mekanism .common .inventory .container .item ;
22
33import mekanism .api .security .IItemSecurityUtils ;
4- import mekanism .common .content .qio .PortableQIODashboardInventory ;
54import mekanism .common .content .qio .IQIOCraftingWindowHolder ;
5+ import mekanism .common .content .qio .PortableQIODashboardInventory ;
6+ import mekanism .common .content .qio .QIOFrequency ;
67import mekanism .common .inventory .container .QIOItemViewerContainer ;
8+ import mekanism .common .inventory .container .item .MekanismItemContainer .IItemContainerTracker ;
79import mekanism .common .inventory .container .slot .HotBarSlot ;
10+ import mekanism .common .inventory .container .sync .SyncableFrequency ;
811import mekanism .common .inventory .container .sync .SyncableItemStack ;
12+ import mekanism .common .lib .frequency .FrequencyType ;
913import mekanism .common .network .PacketUtils ;
1014import mekanism .common .network .to_server .PacketItemGuiInteract ;
1115import mekanism .common .network .to_server .PacketItemGuiInteract .ItemGuiInteraction ;
1822import net .minecraft .world .inventory .ClickType ;
1923import net .minecraft .world .item .ItemStack ;
2024import org .jetbrains .annotations .NotNull ;
25+ import org .jetbrains .annotations .Nullable ;
2126
2227public class PortableQIODashboardContainer extends QIOItemViewerContainer {
2328
2429 protected final InteractionHand hand ;
2530 protected ItemStack stack ;
31+ private QIOFrequency freq ;
2632
2733 private PortableQIODashboardContainer (int id , Inventory inv , InteractionHand hand , ItemStack stack , boolean remote , IQIOCraftingWindowHolder craftingWindowHolder ) {
2834 super (MekanismContainerTypes .PORTABLE_QIO_DASHBOARD , id , inv , remote , craftingWindowHolder );
2935 this .hand = hand ;
3036 this .stack = stack ;
37+ if (!stack .isEmpty ()) {
38+ //It shouldn't be empty but validate it just in case
39+ addContainerTrackers ();
40+ }
3141 addSlotsAndOpen ();
3242 }
3343
@@ -50,6 +60,31 @@ public PortableQIODashboardContainer recreate() {
5060 return container ;
5161 }
5262
63+ @ Override
64+ protected void sync (QIOItemViewerContainer container ) {
65+ super .sync (container );
66+ if (container instanceof PortableQIODashboardContainer portable ) {
67+ freq = portable .freq ;
68+ }
69+ }
70+
71+ @ Nullable
72+ @ Override
73+ public QIOFrequency getFrequency () {
74+ if (craftingWindowHolder instanceof PortableQIODashboardInventory inventory && inventory .getLevel () != null && inventory .getLevel ().isClientSide ) {
75+ //If we are on the client side, use our local stored frequency
76+ return freq ;
77+ }
78+ return super .getFrequency ();
79+ }
80+
81+ protected void addContainerTrackers () {
82+ if (stack .getItem () instanceof IItemContainerTracker containerTracker ) {
83+ containerTracker .addContainerTrackers (this , stack );
84+ }
85+ track (SyncableFrequency .create (FrequencyType .QIO , this ::getFrequency , f -> freq = f ));
86+ }
87+
5388 @ Override
5489 protected void addInventorySlots (@ NotNull Inventory inv ) {
5590 super .addInventorySlots (inv );
0 commit comments