11package gregtech .common .metatileentities .storage ;
22
33import gregtech .api .capability .GregtechTileCapabilities ;
4- import gregtech .api .capability .IActiveOutputSide ;
54import gregtech .api .capability .impl .ItemHandlerList ;
65import gregtech .api .capability .impl .ItemHandlerProxy ;
76import gregtech .api .cover .CoverRayTracer ;
109import gregtech .api .metatileentity .ITieredMetaTileEntity ;
1110import gregtech .api .metatileentity .MetaTileEntity ;
1211import gregtech .api .metatileentity .interfaces .IGregTechTileEntity ;
13- import gregtech .api .mui .GTGuis ;
1412import gregtech .api .mui .widget .QuantumItemRendererWidget ;
1513import gregtech .api .util .GTLog ;
1614import gregtech .api .util .GTTransferUtils ;
4543import codechicken .lib .render .pipeline .IVertexOperation ;
4644import codechicken .lib .vec .Matrix4 ;
4745import com .cleanroommc .modularui .api .drawable .IKey ;
48- import com .cleanroommc .modularui .factory .PosGuiData ;
4946import com .cleanroommc .modularui .screen .ModularPanel ;
50- import com .cleanroommc .modularui .value .sync .BooleanSyncValue ;
5147import com .cleanroommc .modularui .value .sync .PanelSyncManager ;
5248import com .cleanroommc .modularui .value .sync .SyncHandler ;
53- import com .cleanroommc .modularui .widgets .SlotGroupWidget ;
5449import org .apache .commons .lang3 .ArrayUtils ;
5550import org .apache .commons .lang3 .tuple .Pair ;
5651import org .jetbrains .annotations .NotNull ;
6358import static gregtech .api .capability .GregtechDataCodes .*;
6459
6560public class MetaTileEntityQuantumChest extends MetaTileEntityQuantumStorage <IItemHandler >
66- implements ITieredMetaTileEntity , IActiveOutputSide , IFastRenderMetaTileEntity {
61+ implements ITieredMetaTileEntity , IFastRenderMetaTileEntity {
6762
6863 private final int tier ;
6964 protected final long maxStoredItems ;
7065 /** The ItemStack that the Quantum Chest is storing */
7166 protected ItemStack virtualItemStack = ItemStack .EMPTY ;
7267 protected long itemsStoredInside = 0L ;
73- private boolean autoOutputItems ;
74- private EnumFacing outputFacing ;
75- private boolean allowInputFromOutputSide = false ;
7668 private static final String NBT_ITEMSTACK = "ItemStack" ;
7769 private static final String NBT_PARTIALSTACK = "PartialStack" ;
7870 private static final String NBT_ITEMCOUNT = "ItemAmount" ;
79- private static final String IS_VOIDING = "IsVoiding" ;
8071 protected IItemHandler outputItemInventory ;
8172 private ItemHandlerList combinedInventory ;
8273 protected ItemStack previousStack ;
8374 protected long previousStackSize ;
84- protected boolean voiding ;
8575
8676 public MetaTileEntityQuantumChest (ResourceLocation metaTileEntityId , int tier , long maxStoredItems ) {
8777 super (metaTileEntityId );
@@ -106,6 +96,7 @@ public void renderMetaTileEntity(CCRenderState renderState, Matrix4 translation,
10696 new ColourMultiplier (GTUtility .convertRGBtoOpaqueRGBA_CL (getPaintingColorForRendering ()))),
10797 this );
10898 Textures .QUANTUM_CHEST_OVERLAY .renderSided (EnumFacing .UP , renderState , translation , pipeline );
99+ var outputFacing = getOutputFacing ();
109100 if (outputFacing != null ) {
110101 Textures .PIPE_OUT_OVERLAY .renderSided (outputFacing , renderState , translation , pipeline );
111102 if (isAutoOutputItems ()) {
@@ -156,7 +147,7 @@ public void update() {
156147 pushItemsIntoNearbyHandlers (currentOutputFacing );
157148 }
158149
159- if (this . voiding && !importItems .getStackInSlot (0 ).isEmpty ()) {
150+ if (isVoiding () && !importItems .getStackInSlot (0 ).isEmpty ()) {
160151 importItems .setStackInSlot (0 , ItemStack .EMPTY );
161152 }
162153
@@ -257,32 +248,22 @@ protected IItemHandlerModifiable createExportItemHandler() {
257248 @ Override
258249 public NBTTagCompound writeToNBT (NBTTagCompound data ) {
259250 NBTTagCompound tagCompound = super .writeToNBT (data );
260- data .setInteger ("OutputFacing" , getOutputFacing ().getIndex ());
261- data .setBoolean ("AutoOutputItems" , autoOutputItems );
262- data .setBoolean ("AllowInputFromOutputSide" , allowInputFromOutputSide );
263251 if (!virtualItemStack .isEmpty () && itemsStoredInside > 0L ) {
264252 tagCompound .setTag (NBT_ITEMSTACK , virtualItemStack .writeToNBT (new NBTTagCompound ()));
265253 tagCompound .setLong (NBT_ITEMCOUNT , itemsStoredInside );
266254 }
267- data .setBoolean (IS_VOIDING , voiding );
268255 return tagCompound ;
269256 }
270257
271258 @ Override
272259 public void readFromNBT (NBTTagCompound data ) {
273260 super .readFromNBT (data );
274- this .outputFacing = EnumFacing .VALUES [data .getInteger ("OutputFacing" )];
275- this .autoOutputItems = data .getBoolean ("AutoOutputItems" );
276- this .allowInputFromOutputSide = data .getBoolean ("AllowInputFromOutputSide" );
277261 if (data .hasKey ("ItemStack" , NBT .TAG_COMPOUND )) {
278262 this .virtualItemStack = new ItemStack (data .getCompoundTag ("ItemStack" ));
279263 if (!virtualItemStack .isEmpty ()) {
280264 this .itemsStoredInside = data .getLong (NBT_ITEMCOUNT );
281265 }
282266 }
283- if (data .hasKey (IS_VOIDING )) {
284- this .voiding = data .getBoolean (IS_VOIDING );
285- }
286267 }
287268
288269 @ Override
@@ -315,7 +296,7 @@ public void writeItemStackData(NBTTagCompound itemStack) {
315296 itemStack .setTag (NBT_PARTIALSTACK , partialStack .writeToNBT (new NBTTagCompound ()));
316297 }
317298
318- if (this . voiding ) {
299+ if (isVoiding () ) {
319300 itemStack .setBoolean (IS_VOIDING , true );
320301 }
321302
@@ -325,39 +306,14 @@ public void writeItemStackData(NBTTagCompound itemStack) {
325306 }
326307
327308 @ Override
328- public boolean usesMui2 () {
329- return true ;
330- }
331-
332- @ Override
333- public ModularPanel buildUI (PosGuiData guiData , PanelSyncManager guiSyncManager ) {
334- var autoOutput = new BooleanSyncValue (this ::isAutoOutputItems , this ::setAutoOutputItems );
335- var isLocked = new BooleanSyncValue (() -> false , b -> {});
336- var isVoiding = new BooleanSyncValue (this ::isVoiding , this ::setVoiding );
337-
338- return GTGuis .createQuantumPanel (this )
339- .child (GTGuis .createQuantumDisplay ("gregtech.machine.quantum_chest.items_stored" ,
309+ protected void createWidgets (ModularPanel mainPanel , PanelSyncManager syncManager ) {
310+ mainPanel
311+ .child (createQuantumDisplay ("gregtech.machine.quantum_chest.items_stored" ,
340312 () -> IKey .lang (virtualItemStack .getDisplayName ()).get (),
341313 textWidget -> !virtualItemStack .isEmpty (),
342314 () -> TextFormattingUtil .formatNumbers (itemsStoredInside )))
343- .child (GTGuis .createQuantumIO (importItems , exportItems ))
344315 .child (new QuantumItemRendererWidget (itemInventory )
345- .pos (148 , 41 ))
346- .child (GTGuis .createQuantumButtonRow (false , autoOutput , isLocked , isVoiding ))
347- .child (SlotGroupWidget .playerInventory ().left (7 ));
348- }
349-
350- public EnumFacing getOutputFacing () {
351- return outputFacing == null ? frontFacing .getOpposite () : outputFacing ;
352- }
353-
354- public void setOutputFacing (EnumFacing outputFacing ) {
355- this .outputFacing = outputFacing ;
356- if (!getWorld ().isRemote ) {
357- notifyBlockUpdate ();
358- writeCustomData (UPDATE_OUTPUT_FACING , buf -> buf .writeByte (outputFacing .getIndex ()));
359- markDirty ();
360- }
316+ .pos (148 , 41 ));
361317 }
362318
363319 @ Override
@@ -378,27 +334,21 @@ public boolean onWrenchClick(EntityPlayer playerIn, EnumHand hand, EnumFacing fa
378334 @ Override
379335 public void writeInitialSyncData (@ NotNull PacketBuffer buf ) {
380336 super .writeInitialSyncData (buf );
381- buf .writeByte (getOutputFacing ().getIndex ());
382- buf .writeBoolean (autoOutputItems );
383337 this .virtualItemStack .setCount (1 );
384338 buf .writeItemStack (virtualItemStack );
385339 buf .writeLong (itemsStoredInside );
386- buf .writeBoolean (voiding );
387340 }
388341
389342 @ Override
390343 public void receiveInitialSyncData (@ NotNull PacketBuffer buf ) {
391344 super .receiveInitialSyncData (buf );
392- this .outputFacing = EnumFacing .VALUES [buf .readByte ()];
393- this .autoOutputItems = buf .readBoolean ();
394345 try {
395346 this .virtualItemStack = buf .readItemStack ();
396347 } catch (IOException ignored ) {
397348 GTLog .logger .warn ("Failed to load item from NBT in a quantum chest at " + this .getPos () +
398349 " on initial server/client sync" );
399350 }
400351 this .itemsStoredInside = buf .readLong ();
401- this .voiding = buf .readBoolean ();
402352 }
403353
404354 @ Override
@@ -411,42 +361,14 @@ public boolean isValidFrontFacing(EnumFacing facing) {
411361 @ Override
412362 public void receiveCustomData (int dataId , @ NotNull PacketBuffer buf ) {
413363 super .receiveCustomData (dataId , buf );
414- if (dataId == UPDATE_OUTPUT_FACING ) {
415- this .outputFacing = EnumFacing .VALUES [buf .readByte ()];
416- scheduleRenderUpdate ();
417- } else if (dataId == UPDATE_AUTO_OUTPUT_ITEMS ) {
418- this .autoOutputItems = buf .readBoolean ();
419- scheduleRenderUpdate ();
420- } else if (dataId == UPDATE_ITEM ) {
364+ if (dataId == UPDATE_ITEM ) {
421365 try {
422366 this .virtualItemStack = buf .readItemStack ();
423367 } catch (IOException e ) {
424368 GTLog .logger .error ("Failed to read item stack in a quantum chest!" );
425369 }
426370 } else if (dataId == UPDATE_ITEM_COUNT ) {
427371 this .itemsStoredInside = buf .readLong ();
428- } else if (dataId == UPDATE_IS_VOIDING ) {
429- setVoiding (buf .readBoolean ());
430- }
431- }
432-
433- public void setAutoOutputItems (boolean autoOutputItems ) {
434- this .autoOutputItems = autoOutputItems ;
435- if (!getWorld ().isRemote ) {
436- writeCustomData (UPDATE_AUTO_OUTPUT_ITEMS , buf -> buf .writeBoolean (autoOutputItems ));
437- markDirty ();
438- }
439- }
440-
441- protected boolean isVoiding () {
442- return this .voiding ;
443- }
444-
445- protected void setVoiding (boolean isVoiding ) {
446- this .voiding = isVoiding ;
447- if (!getWorld ().isRemote ) {
448- writeCustomData (UPDATE_IS_VOIDING , buf -> buf .writeBoolean (this .voiding ));
449- markDirty ();
450372 }
451373 }
452374
@@ -490,25 +412,6 @@ public void setFrontFacing(EnumFacing frontFacing) {
490412 }
491413 }
492414
493- public boolean isAutoOutputItems () {
494- return autoOutputItems ;
495- }
496-
497- @ Override
498- public boolean isAutoOutputFluids () {
499- return false ;
500- }
501-
502- @ Override
503- public boolean isAllowInputFromOutputSideItems () {
504- return allowInputFromOutputSide ;
505- }
506-
507- @ Override
508- public boolean isAllowInputFromOutputSideFluids () {
509- return false ;
510- }
511-
512415 @ Override
513416 public void clearMachineInventory (@ NotNull List <@ NotNull ItemStack > itemBuffer ) {
514417 clearInventory (itemBuffer , importItems );
@@ -536,13 +439,6 @@ public boolean onScrewdriverClick(EntityPlayer playerIn, EnumHand hand, EnumFaci
536439 return super .onScrewdriverClick (playerIn , hand , facing , hitResult );
537440 }
538441
539- public void setAllowInputFromOutputSide (boolean allowInputFromOutputSide ) {
540- this .allowInputFromOutputSide = allowInputFromOutputSide ;
541- if (!getWorld ().isRemote ) {
542- markDirty ();
543- }
544- }
545-
546442 @ Override
547443 public Type getType () {
548444 return Type .ITEM ;
0 commit comments