@@ -67,24 +67,24 @@ public void detectAndSendChanges(boolean init) {
6767 } else if (lastFluid != null && current .amount != lastFluid .amount ) {
6868 lastFluid .amount = current .amount ;
6969 syncToClient (UPDATE_AMOUNT , buffer -> buffer .writeInt (current .amount ));
70- }
70+ } else if (!isPhantom () && canLockFluid () &&
71+ !GTUtility .areFluidStacksEqual (this .phantomFluid , this .lockedFluid .get ())) {
72+ this .phantomFluid = this .lockedFluid .get ();
73+ sync (LOCK_FLUID , buffer -> {
74+ buffer .writeBoolean (this .isLocked .getAsBoolean ());
75+ NetworkUtils .writeFluidStack (buffer , this .phantomFluid );
76+ });
77+ }
7178 }
7279
73- public void lockFluid (FluidStack stack , boolean sync ) {
80+ public void lockFluid (FluidStack stack ) {
7481 if (!canLockFluid ()) return ;
7582 this .jeiHandler .accept (stack );
76- if (sync ) sync (LOCK_FLUID , buffer -> {
77- buffer .writeBoolean (stack != null );
78- NetworkUtils .writeFluidStack (buffer , stack );
79- });
8083 }
8184
82- public void lockFluid (boolean locked , boolean sync ) {
85+ public void lockFluid (boolean locked ) {
86+ if (!canLockFluid ()) return ;
8387 this .lockHandler .accept (locked );
84- if (sync ) sync (LOCK_FLUID , buffer -> {
85- buffer .writeBoolean (locked );
86- NetworkUtils .writeFluidStack (buffer , null );
87- });
8888 }
8989
9090 public GTFluidSyncHandler handleLocking (@ NotNull Supplier <FluidStack > lockedFluid ,
@@ -106,10 +106,13 @@ public void setFluid(FluidStack fluid) {
106106 fluidTank .setFluid (fluid );
107107 } else {
108108 tank .drain (Integer .MAX_VALUE , true );
109- if (fluid != null ) tank .fill (fluid , true );
109+ if (!GTUtility .isEmpty (fluid )) tank .fill (fluid , true );
110+ }
111+ if (canLockFluid () && isLocked .getAsBoolean () && !GTUtility .isEmpty (fluid )) {
112+ lockFluid (fluid );
110113 }
111- if (!isPhantom () || fluid == null ) return ;
112- if (this .phantomFluid == null || this .phantomFluid .getFluid () != fluid .getFluid ()) {
114+ if (!isPhantom () || GTUtility . isEmpty ( fluid ) ) return ;
115+ if (GTUtility . isEmpty ( this .phantomFluid ) || this .phantomFluid .getFluid () != fluid .getFluid ()) {
113116 this .phantomFluid = fluid ;
114117 }
115118 }
@@ -153,9 +156,16 @@ public boolean isPhantom() {
153156 return phantom ;
154157 }
155158
159+ public GTFluidSyncHandler showAmount (boolean inSlot , boolean inTooltip ) {
160+ return showAmount (() -> inSlot , () -> inTooltip );
161+ }
162+
163+ public GTFluidSyncHandler showAmount (BooleanSupplier inSlot , BooleanSupplier inTooltip ) {
164+ return showAmountOnSlot (inSlot ).showAmountInTooltip (inTooltip );
165+ }
166+
156167 public GTFluidSyncHandler showAmountInTooltip (boolean showAmount ) {
157- this .showAmountInTooltip = () -> showAmount ;
158- return this ;
168+ return showAmountInTooltip (() -> showAmount );
159169 }
160170
161171 public GTFluidSyncHandler showAmountInTooltip (BooleanSupplier showAmount ) {
@@ -170,8 +180,7 @@ public boolean showAmountInTooltip() {
170180 }
171181
172182 public GTFluidSyncHandler showAmountOnSlot (boolean showAmount ) {
173- this .showAmountOnSlot = () -> showAmount ;
174- return this ;
183+ return showAmountOnSlot (() -> showAmount );
175184 }
176185
177186 public GTFluidSyncHandler showAmountOnSlot (BooleanSupplier showAmount ) {
@@ -237,6 +246,7 @@ public int getFluidAmount() {
237246
238247 public void handleTooltip (@ NotNull RichTooltip tooltip ) {
239248 IKey nameKey = getFluidNameKey ();
249+
240250 if (nameKey != IKey .EMPTY ) {
241251 tooltip .addLine (nameKey );
242252 }
@@ -277,7 +287,8 @@ public void readOnClient(int id, PacketBuffer buf) {
277287 onChange (getFluid ());
278288 }
279289 case LOCK_FLUID -> {
280- lockFluid (NetworkUtils .readFluidStack (buf ), false );
290+ lockHandler .accept (buf .readBoolean ());
291+ lockFluid (NetworkUtils .readFluidStack (buf ));
281292 FluidStack stack = getFluid ();
282293 onChange (stack == null ? getLockedFluid () : stack );
283294 }
@@ -323,8 +334,7 @@ public void tryClickPhantom(MouseData data) {
323334 EntityPlayer player = getSyncManager ().getPlayer ();
324335 ItemStack currentStack = player .inventory .getItemStack ();
325336 FluidStack currentFluid = this .tank .getFluid ();
326- if (currentStack .getCount () > 1 ) currentStack = GTUtility .copy (1 , currentStack );
327- var fluidHandlerItem = FluidUtil .getFluidHandler (currentStack );
337+ IFluidHandlerItem fluidHandlerItem = FluidUtil .getFluidHandler (currentStack );
328338
329339 switch (data .mouseButton ) {
330340 case 0 -> {
@@ -579,18 +589,17 @@ public boolean canLockFluid() {
579589
580590 public void toggleLockFluid () {
581591 var cursorItem = getSyncManager ().getCursorItem ();
582- if (getLockedFluid () == null ) {
583- if (cursorItem .isEmpty ()) return ;
584- if (cursorItem .getCount () > 1 ) cursorItem = GTUtility .copy (1 , cursorItem );
585-
586- var fluidHandler = FluidUtil .getFluidHandler (cursorItem );
587- if (fluidHandler == null ) return ;
588-
589- var fluidStack = fluidHandler .getTankProperties ()[0 ].getContents ();
590- if (fluidStack == null ) return ;
591- lockFluid (fluidStack .copy (), true );
592- } else if (cursorItem .isEmpty ()) {
593- lockFluid (null , true );
592+ FluidStack stack ;
593+ if (GTUtility .isEmpty (getLockedFluid ()) && !cursorItem .isEmpty ()) {
594+ var fluidStack = FluidUtil .getFluidContained (cursorItem );
595+ stack = !GTUtility .isEmpty (fluidStack ) ? fluidStack .copy () : null ;
596+ } else {
597+ stack = null ;
594598 }
599+ lockFluid (stack );
600+ sync (LOCK_FLUID , buffer -> {
601+ buffer .writeBoolean (this .isLocked .getAsBoolean ());
602+ NetworkUtils .writeFluidStack (buffer , stack );
603+ });
595604 }
596605}
0 commit comments