1010import gregtech .api .metatileentity .multiblock .*;
1111import gregtech .api .mui .GTGuiTextures ;
1212import gregtech .api .mui .GTGuis ;
13- import gregtech .api .mui .sync .FloatSyncValue ;
1413import gregtech .api .util .GTUtility ;
15- import gregtech .api .util .function .FloatUnaryOperator ;
1614import gregtech .client .renderer .texture .Textures ;
1715import gregtech .client .utils .TooltipHelper ;
1816import gregtech .common .ConfigHolder ;
3331import codechicken .lib .render .pipeline .IVertexOperation ;
3432import codechicken .lib .vec .Matrix4 ;
3533import com .cleanroommc .modularui .api .drawable .IKey ;
34+ import com .cleanroommc .modularui .drawable .Rectangle ;
3635import com .cleanroommc .modularui .factory .PosGuiData ;
3736import com .cleanroommc .modularui .screen .ModularPanel ;
37+ import com .cleanroommc .modularui .utils .Color ;
38+ import com .cleanroommc .modularui .value .DoubleValue ;
3839import com .cleanroommc .modularui .value .sync .BooleanSyncValue ;
40+ import com .cleanroommc .modularui .value .sync .DoubleSyncValue ;
3941import com .cleanroommc .modularui .value .sync .InteractionSyncHandler ;
4042import com .cleanroommc .modularui .value .sync .PanelSyncManager ;
4143import com .cleanroommc .modularui .value .sync .SyncHandlers ;
4244import com .cleanroommc .modularui .widget .ParentWidget ;
45+ import com .cleanroommc .modularui .widget .Widget ;
4346import com .cleanroommc .modularui .widgets .ButtonWidget ;
4447import com .cleanroommc .modularui .widgets .ItemSlot ;
48+ import com .cleanroommc .modularui .widgets .SliderWidget ;
4549import com .cleanroommc .modularui .widgets .SlotGroupWidget ;
4650import com .cleanroommc .modularui .widgets .layout .Flow ;
51+ import it .unimi .dsi .fastutil .doubles .DoubleArrayList ;
52+ import it .unimi .dsi .fastutil .doubles .DoubleList ;
4753import org .jetbrains .annotations .ApiStatus ;
4854import org .jetbrains .annotations .NotNull ;
4955import org .jetbrains .annotations .Nullable ;
5056
5157import java .util .List ;
58+ import java .util .function .DoubleUnaryOperator ;
5259import java .util .function .Predicate ;
5360
5461import static gregtech .api .capability .GregtechDataCodes .*;
@@ -65,18 +72,21 @@ public class MetaTileEntityMaintenanceHatch extends MetaTileEntityMultiblockPart
6572 private int timeActive = -1 ;
6673
6774 // Some stats used for the Configurable Maintenance Hatch
68- private float durationMultiplier = 1.0f ;
69- private static final float MAX_DURATION_MULTIPLIER = 1.1f ;
70- private static final float MIN_DURATION_MULTIPLIER = 0.9f ;
71- private static final float DURATION_ACTION_AMOUNT = 0.01f ;
72- private static final FloatUnaryOperator TIME_ACTION = t -> {
75+ private double durationMultiplier = 1.0f ;
76+ private static final double MIN_DURATION_MULTIPLIER = 0.9d ;
77+ private static final double MAX_DURATION_MULTIPLIER = 1.1d ;
78+ private static final DoubleUnaryOperator TIME_ACTION = t -> {
7379 if (t < 1.0f ) {
7480 return -20.0f * t + 21.0f ;
7581 } else {
7682 return -8.0f * t + 9.0f ;
7783 }
7884 };
7985
86+ private static final DoubleList SLIDER_STOPPER_STOPS = new DoubleArrayList (
87+ new double [] { 0.9d , 0.91d , 0.92d , 0.93d , 0.94d , 0.95d , 0.97d , 0.98d , 0.99d , 1.0d , 1.01d , 1.02d , 1.03d ,
88+ 1.04d , 1.05d , 1.06d , 1.07d , 1.08d , 1.09d , 1.1d });
89+
8090 public MetaTileEntityMaintenanceHatch (ResourceLocation metaTileEntityId , boolean isConfigurable ) {
8191 super (metaTileEntityId , isConfigurable ? 3 : 1 );
8292 this .isConfigurable = isConfigurable ;
@@ -293,17 +303,17 @@ public boolean isFullAuto() {
293303 }
294304
295305 @ Override
296- public float getDurationMultiplier () {
306+ public double getDurationMultiplier () {
297307 return durationMultiplier ;
298308 }
299309
300- protected void setDurationMultiplier (float multiplier ) {
310+ protected void setDurationMultiplier (double multiplier ) {
301311 this .durationMultiplier = multiplier ;
302312 }
303313
304314 @ Override
305- public float getTimeMultiplier () {
306- return TIME_ACTION .apply (durationMultiplier );
315+ public double getTimeMultiplier () {
316+ return TIME_ACTION .applyAsDouble (durationMultiplier );
307317 }
308318
309319 @ Override
@@ -345,7 +355,9 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager panelSyncManage
345355 if (panelSyncManager .isClient ()) return ;
346356 fixMaintenanceProblems (guiData .getPlayer ());
347357 });
348- FloatSyncValue multiplierSync = new FloatSyncValue (this ::getDurationMultiplier , this ::setDurationMultiplier );
358+ DoubleSyncValue multiplierSync = SyncHandlers .doubleNumber (this ::getDurationMultiplier ,
359+ this ::setDurationMultiplier );
360+ panelSyncManager .syncValue ("multiplierSync" , 0 , multiplierSync );
349361 panelSyncManager .registerSlotGroup ("tape_slot" , 1 );
350362
351363 return GTGuis .createPanel (this , 176 , 152 )
@@ -369,11 +381,57 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager panelSyncManage
369381 .syncHandler (maintenanceClickSync )
370382 .overlay (GTGuiTextures .MAINTENANCE_ICON )
371383 .addTooltipLine (IKey .lang ("gregtech.machine.maintenance_hatch_tool_slot.tooltip" ))))
372- .childIf (isConfigurable , () -> new ParentWidget <>()
373- .pos (5 , 25 )
374- .coverChildren ()
375- .child (IKey .lang ("e" )
376- .asWidget ()))
384+ .childIf (isConfigurable , () -> {
385+ Widget <?> durationText = IKey .lang ("gregtech.maintenance.configurable_duration" ,
386+ () -> new Object [] { multiplierSync .getDoubleValue () })
387+ .asWidget ()
388+ .tooltipBuilder (tooltip -> {
389+ double multiplier = multiplierSync .getDoubleValue ();
390+ if (multiplier == 1.0f ) {
391+ tooltip .addLine (IKey
392+ .lang ("gregtech.maintenance.configurable_duration.unchanged_description" ));
393+ } else {
394+ tooltip .addLine (
395+ IKey .lang ("gregtech.maintenance.configurable_duration.changed_description" ,
396+ multiplier ));
397+ }
398+ });
399+ Widget <?> timeText = IKey .lang ("gregtech.maintenance.configurable_time" ,
400+ () -> new Object [] { TIME_ACTION .applyAsDouble (multiplierSync .getDoubleValue ()) })
401+ .asWidget ()
402+ .tooltipBuilder (tooltip -> {
403+ double multiplier = TIME_ACTION .applyAsDouble (multiplierSync .getDoubleValue ());
404+ if (multiplier == 1.0f ) {
405+ tooltip .addLine (
406+ IKey .lang ("gregtech.maintenance.configurable_time.unchanged_description" ));
407+ } else {
408+ tooltip .addLine (IKey .lang (
409+ "gregtech.maintenance.configurable_time.changed_description" , multiplier ));
410+ }
411+ });
412+
413+ return new ParentWidget <>()
414+ .pos (5 , 25 )
415+ .coverChildren ()
416+ .child (durationText )
417+ .child (timeText .top (14 ))
418+ .child (new SliderWidget ()
419+ .width (36 )
420+ .pos (4 , 27 )
421+ .bounds (MIN_DURATION_MULTIPLIER , MAX_DURATION_MULTIPLIER )
422+ .stopper (SLIDER_STOPPER_STOPS )
423+ .value (new DoubleValue .Dynamic (multiplierSync ::getDoubleValue , val -> {
424+ multiplierSync .setDoubleValue (val );
425+ durationText .markTooltipDirty ();
426+ timeText .markTooltipDirty ();
427+ }))
428+ .background (new Rectangle ()
429+ .setColor (Color .BLACK .brighter (2 ))
430+ .asIcon ()
431+ .height (2 ))
432+ .stopperSize (1 , 4 )
433+ .sliderHeight (8 ));
434+ })
377435 .child (SlotGroupWidget .playerInventory ()
378436 .left (7 )
379437 .bottom (7 ));
@@ -386,7 +444,7 @@ public NBTTagCompound writeToNBT(NBTTagCompound data) {
386444 data .setTag ("tapeInventory" , tapeHandler .serializeNBT ());
387445
388446 if (isConfigurable ) {
389- data .setFloat ("DurationMultiplier" , durationMultiplier );
447+ data .setDouble ("DurationMultiplier" , durationMultiplier );
390448 }
391449
392450 return data ;
@@ -402,11 +460,7 @@ public void readFromNBT(NBTTagCompound data) {
402460 }
403461
404462 if (isConfigurable ) {
405- if (data .hasKey ("DurationMultiplier" , Constants .NBT .TAG_DOUBLE )) {
406- durationMultiplier = (float ) data .getDouble ("DurationMultiplier" );
407- } else {
408- durationMultiplier = data .getFloat ("DurationMultiplier" );
409- }
463+ durationMultiplier = data .getDouble ("DurationMultiplier" );
410464 }
411465
412466 // Legacy Inventory Handler Support
0 commit comments