4343import codechicken .lib .render .pipeline .IVertexOperation ;
4444import codechicken .lib .vec .Matrix4 ;
4545import com .cleanroommc .modularui .api .drawable .IKey ;
46+ import com .cleanroommc .modularui .network .NetworkUtils ;
4647import com .cleanroommc .modularui .screen .ModularPanel ;
4748import com .cleanroommc .modularui .value .sync .PanelSyncManager ;
4849import com .cleanroommc .modularui .value .sync .SyncHandler ;
@@ -71,6 +72,7 @@ public class MetaTileEntityQuantumChest extends MetaTileEntityQuantumStorage<IIt
7172 protected IItemHandler outputItemInventory ;
7273 private ItemHandlerList combinedInventory ;
7374 protected ItemStack previousStack ;
75+ protected @ NotNull ItemStack lockedStack = ItemStack .EMPTY ;
7476 protected long previousStackSize ;
7577
7678 public MetaTileEntityQuantumChest (ResourceLocation metaTileEntityId , int tier , long maxStoredItems ) {
@@ -252,6 +254,8 @@ public NBTTagCompound writeToNBT(NBTTagCompound data) {
252254 tagCompound .setTag (NBT_ITEMSTACK , virtualItemStack .writeToNBT (new NBTTagCompound ()));
253255 tagCompound .setLong (NBT_ITEMCOUNT , itemsStoredInside );
254256 }
257+ if (locked && !lockedStack .isEmpty ())
258+ data .setTag ("LockedStack" , lockedStack .serializeNBT ());
255259 return tagCompound ;
256260 }
257261
@@ -264,6 +268,7 @@ public void readFromNBT(NBTTagCompound data) {
264268 this .itemsStoredInside = data .getLong (NBT_ITEMCOUNT );
265269 }
266270 }
271+ if (locked ) this .lockedStack = new ItemStack (data .getCompoundTag ("LockedStack" ));
267272 }
268273
269274 @ Override
@@ -307,11 +312,10 @@ public void writeItemStackData(NBTTagCompound itemStack) {
307312
308313 @ Override
309314 protected void createWidgets (ModularPanel mainPanel , PanelSyncManager syncManager ) {
310- mainPanel
311- .child (createQuantumDisplay ("gregtech.machine.quantum_chest.items_stored" ,
312- () -> IKey .lang (virtualItemStack .getDisplayName ()).get (),
313- textWidget -> !virtualItemStack .isEmpty (),
314- () -> TextFormattingUtil .formatNumbers (itemsStoredInside )))
315+ mainPanel .child (createQuantumDisplay ("gregtech.machine.quantum_chest.items_stored" ,
316+ () -> IKey .lang (virtualItemStack .getDisplayName ()).get (),
317+ textWidget -> !virtualItemStack .isEmpty (),
318+ () -> TextFormattingUtil .formatNumbers (itemsStoredInside )))
315319 .child (new QuantumItemRendererWidget (itemInventory )
316320 .pos (148 , 41 ));
317321 }
@@ -336,6 +340,7 @@ public void writeInitialSyncData(@NotNull PacketBuffer buf) {
336340 super .writeInitialSyncData (buf );
337341 this .virtualItemStack .setCount (1 );
338342 buf .writeItemStack (virtualItemStack );
343+ NetworkUtils .writeItemStack (buf , lockedStack );
339344 buf .writeLong (itemsStoredInside );
340345 }
341346
@@ -348,6 +353,7 @@ public void receiveInitialSyncData(@NotNull PacketBuffer buf) {
348353 GTLog .logger .warn ("Failed to load item from NBT in a quantum chest at " + this .getPos () +
349354 " on initial server/client sync" );
350355 }
356+ this .lockedStack = NetworkUtils .readItemStack (buf );
351357 this .itemsStoredInside = buf .readLong ();
352358 }
353359
@@ -412,6 +418,14 @@ public void setFrontFacing(EnumFacing frontFacing) {
412418 }
413419 }
414420
421+ @ Override
422+ protected void setLocked (boolean locked ) {
423+ super .setLocked (locked );
424+ if (locked && !this .virtualItemStack .isEmpty ())
425+ this .lockedStack = this .virtualItemStack .copy ();
426+ else this .lockedStack = ItemStack .EMPTY ;
427+ }
428+
415429 @ Override
416430 public void clearMachineInventory (@ NotNull List <@ NotNull ItemStack > itemBuffer ) {
417431 clearInventory (itemBuffer , importItems );
@@ -509,6 +523,10 @@ public ItemStack insertItem(int slot, @NotNull ItemStack insertedStack, boolean
509523 return ItemStack .EMPTY ;
510524 }
511525
526+ // check locked and if locked stack matches
527+ if (locked && !areItemStackIdentical (lockedStack , insertedStack ))
528+ return insertedStack ;
529+
512530 // If there is a virtualized stack and the stack to insert does not match it, do not insert anything
513531 if (itemsStoredInside > 0L &&
514532 !virtualItemStack .isEmpty () &&
0 commit comments