5
5
import gregtech .api .capability .GregtechCapabilities ;
6
6
import gregtech .api .capability .impl .CombinedCapabilityProvider ;
7
7
import gregtech .api .capability .impl .ElectricItem ;
8
- import gregtech .api .gui .GuiTextures ;
9
- import gregtech .api .gui .ModularUI ;
10
- import gregtech .api .gui .widgets .ClickButtonWidget ;
11
- import gregtech .api .gui .widgets .DynamicLabelWidget ;
12
8
import gregtech .api .items .gui .ItemUIFactory ;
13
- import gregtech .api .items .gui .PlayerInventoryHolder ;
14
9
import gregtech .api .items .metaitem .ElectricStats ;
15
10
import gregtech .api .items .toolitem .aoe .AoESymmetrical ;
16
11
import gregtech .api .items .toolitem .behavior .IToolBehavior ;
12
+ import gregtech .api .mui .GTGuiTextures ;
13
+ import gregtech .api .mui .GTGuis ;
17
14
import gregtech .api .recipes .ModHandler ;
18
15
import gregtech .api .unification .OreDictUnifier ;
19
16
import gregtech .api .unification .material .Material ;
63
60
import appeng .api .implementations .items .IAEWrench ;
64
61
import buildcraft .api .tools .IToolWrench ;
65
62
import cofh .api .item .IToolHammer ;
63
+ import com .cleanroommc .modularui .api .drawable .IKey ;
64
+ import com .cleanroommc .modularui .api .widget .IWidget ;
65
+ import com .cleanroommc .modularui .factory .HandGuiData ;
66
+ import com .cleanroommc .modularui .factory .ItemGuiFactory ;
67
+ import com .cleanroommc .modularui .screen .ModularPanel ;
68
+ import com .cleanroommc .modularui .utils .Alignment ;
69
+ import com .cleanroommc .modularui .value .sync .IntSyncValue ;
70
+ import com .cleanroommc .modularui .value .sync .PanelSyncManager ;
71
+ import com .cleanroommc .modularui .widgets .ButtonWidget ;
72
+ import com .cleanroommc .modularui .widgets .TextWidget ;
73
+ import com .cleanroommc .modularui .widgets .layout .Flow ;
66
74
import com .enderio .core .common .interfaces .IOverlayRenderAware ;
67
75
import com .google .common .collect .HashMultimap ;
68
76
import com .google .common .collect .Multimap ;
@@ -207,7 +215,7 @@ default ItemStack get(Material material) {
207
215
208
216
// Set behaviours
209
217
NBTTagCompound behaviourTag = getBehaviorsTag (stack );
210
- getToolStats (). getBehaviors ().forEach (behavior -> behavior .addBehaviorNBT (stack , behaviourTag ));
218
+ getBehaviors (stack ).forEach (behavior -> behavior .addBehaviorNBT (stack , behaviourTag ));
211
219
212
220
if (aoeDefinition != AoESymmetrical .none ()) {
213
221
behaviourTag .setInteger (MAX_AOE_COLUMN_KEY , aoeDefinition .column );
@@ -409,14 +417,14 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {
409
417
}
410
418
411
419
default boolean definition$hitEntity (ItemStack stack , EntityLivingBase target , EntityLivingBase attacker ) {
412
- getToolStats (). getBehaviors ().forEach (behavior -> behavior .hitEntity (stack , target , attacker ));
420
+ getBehaviors (stack ).forEach (behavior -> behavior .hitEntity (stack , target , attacker ));
413
421
damageItem (stack , attacker , getToolStats ().getToolDamagePerAttack (stack ));
414
422
return true ;
415
423
}
416
424
417
425
default boolean definition$onBlockStartBreak (ItemStack stack , BlockPos pos , EntityPlayer player ) {
418
426
if (player .world .isRemote ) return false ;
419
- getToolStats (). getBehaviors ().forEach (behavior -> behavior .onBlockStartBreak (stack , pos , player ));
427
+ getBehaviors (stack ).forEach (behavior -> behavior .onBlockStartBreak (stack , pos , player ));
420
428
421
429
if (!player .isSneaking ()) {
422
430
EntityPlayerMP playerMP = (EntityPlayerMP ) player ;
@@ -458,7 +466,7 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {
458
466
default boolean definition$onBlockDestroyed (ItemStack stack , World worldIn , IBlockState state , BlockPos pos ,
459
467
EntityLivingBase entityLiving ) {
460
468
if (!worldIn .isRemote ) {
461
- getToolStats (). getBehaviors ()
469
+ getBehaviors (stack )
462
470
.forEach (behavior -> behavior .onBlockDestroyed (stack , worldIn , state , pos , entityLiving ));
463
471
464
472
if ((double ) state .getBlockHardness (worldIn , pos ) != 0.0D ) {
@@ -522,7 +530,7 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {
522
530
523
531
default boolean definition$canDisableShield (ItemStack stack , ItemStack shield , EntityLivingBase entity ,
524
532
EntityLivingBase attacker ) {
525
- return getToolStats (). getBehaviors ().stream ()
533
+ return getBehaviors (stack ).stream ()
526
534
.anyMatch (behavior -> behavior .canDisableShield (stack , shield , entity , attacker ));
527
535
}
528
536
@@ -570,7 +578,7 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {
570
578
}
571
579
572
580
default boolean definition$onEntitySwing (EntityLivingBase entityLiving , ItemStack stack ) {
573
- getToolStats (). getBehaviors ().forEach (behavior -> behavior .onEntitySwing (entityLiving , stack ));
581
+ getBehaviors (stack ).forEach (behavior -> behavior .onEntitySwing (entityLiving , stack ));
574
582
return false ;
575
583
}
576
584
@@ -622,7 +630,7 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {
622
630
if (isElectric ()) {
623
631
providers .add (ElectricStats .createElectricItem (0L , getElectricTier ()).createProvider (stack ));
624
632
}
625
- for (IToolBehavior behavior : getToolStats (). getBehaviors ()) {
633
+ for (IToolBehavior behavior : getBehaviors (stack )) {
626
634
ICapabilityProvider behaviorProvider = behavior .createProvider (stack , nbt );
627
635
if (behaviorProvider != null ) {
628
636
providers .add (behaviorProvider );
@@ -633,10 +641,15 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {
633
641
return new CombinedCapabilityProvider (providers );
634
642
}
635
643
644
+ @ NotNull
645
+ default List <IToolBehavior > getBehaviors (ItemStack stack ) {
646
+ return getToolStats ().getBehaviors ();
647
+ }
648
+
636
649
default EnumActionResult definition$onItemUseFirst (@ NotNull EntityPlayer player , @ NotNull World world ,
637
650
@ NotNull BlockPos pos , @ NotNull EnumFacing facing , float hitX ,
638
651
float hitY , float hitZ , @ NotNull EnumHand hand ) {
639
- for (IToolBehavior behavior : getToolStats (). getBehaviors ( )) {
652
+ for (IToolBehavior behavior : getBehaviors ( player . getHeldItem ( hand ) )) {
640
653
if (behavior .onItemUseFirst (player , world , pos , facing , hitX , hitY , hitZ , hand ) ==
641
654
EnumActionResult .SUCCESS ) {
642
655
return EnumActionResult .SUCCESS ;
@@ -648,8 +661,9 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {
648
661
649
662
default EnumActionResult definition$onItemUse (EntityPlayer player , World world , BlockPos pos , EnumHand hand ,
650
663
EnumFacing facing , float hitX , float hitY , float hitZ ) {
651
- for (IToolBehavior behavior : getToolStats ().getBehaviors ()) {
652
- if (behavior .onItemUse (player , world , pos , hand , facing , hitX , hitY , hitZ ) == EnumActionResult .SUCCESS ) {
664
+ for (IToolBehavior behavior : getBehaviors (player .getHeldItem (hand ))) {
665
+ if (behavior .onItemUse (player , world , pos , hand , facing , hitX , hitY , hitZ ) ==
666
+ EnumActionResult .SUCCESS ) {
653
667
return EnumActionResult .SUCCESS ;
654
668
}
655
669
}
@@ -662,12 +676,12 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {
662
676
if (!world .isRemote ) {
663
677
// TODO: relocate to keybind action when keybind PR happens
664
678
if (player .isSneaking () && getMaxAoEDefinition (stack ) != AoESymmetrical .none ()) {
665
- PlayerInventoryHolder . openHandItemUI ( player , hand );
679
+ ItemGuiFactory . INSTANCE . open (( EntityPlayerMP ) player , hand );
666
680
return ActionResult .newResult (EnumActionResult .SUCCESS , stack );
667
681
}
668
682
}
669
683
670
- for (IToolBehavior behavior : getToolStats (). getBehaviors ()) {
684
+ for (IToolBehavior behavior : getBehaviors (stack )) {
671
685
if (behavior .onItemRightClick (world , player , hand ).getType () == EnumActionResult .SUCCESS ) {
672
686
return ActionResult .newResult (EnumActionResult .SUCCESS , stack );
673
687
}
@@ -762,10 +776,10 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {
762
776
tooltip .add (I18n .format ("item.gt.tool.behavior.relocate_mining" ));
763
777
}
764
778
765
- if (!addedBehaviorNewLine && !toolStats . getBehaviors ().isEmpty ()) {
779
+ if (!addedBehaviorNewLine && !getBehaviors (stack ).isEmpty ()) {
766
780
tooltip .add ("" );
767
781
}
768
- toolStats . getBehaviors ().forEach (behavior -> behavior .addInformation (stack , world , tooltip , flag ));
782
+ getBehaviors (stack ).forEach (behavior -> behavior .addInformation (stack , world , tooltip , flag ));
769
783
770
784
// unique tooltip
771
785
String uniqueTooltip = "item.gt.tool." + getToolId () + ".tooltip" ;
@@ -878,6 +892,7 @@ default ModelResourceLocation getModelLocation() {
878
892
879
893
// Sound Playing
880
894
default void playCraftingSound (EntityPlayer player , ItemStack stack ) {
895
+ stack = toolbeltPassthrough (stack );
881
896
// player null check for things like auto-crafters
882
897
if (ConfigHolder .client .toolCraftingSounds && getSound () != null && player != null ) {
883
898
if (canPlaySound (stack )) {
@@ -903,45 +918,76 @@ default void playSound(EntityPlayer player) {
903
918
}
904
919
}
905
920
906
- default ModularUI createUI (PlayerInventoryHolder holder , EntityPlayer entityPlayer ) {
907
- NBTTagCompound tag = getBehaviorsTag (holder .getCurrentItem ());
908
- AoESymmetrical defaultDefinition = getMaxAoEDefinition (holder .getCurrentItem ());
909
- return ModularUI .builder (GuiTextures .BORDERED_BACKGROUND , 120 , 80 )
910
- .label (6 , 10 , "item.gt.tool.aoe.columns" )
911
- .label (49 , 10 , "item.gt.tool.aoe.rows" )
912
- .label (79 , 10 , "item.gt.tool.aoe.layers" )
913
- .widget (new ClickButtonWidget (15 , 24 , 20 , 20 , "+" , data -> {
914
- AoESymmetrical .increaseColumn (tag , defaultDefinition );
915
- holder .markAsDirty ();
916
- }))
917
- .widget (new ClickButtonWidget (15 , 44 , 20 , 20 , "-" , data -> {
918
- AoESymmetrical .decreaseColumn (tag , defaultDefinition );
919
- holder .markAsDirty ();
920
- }))
921
- .widget (new ClickButtonWidget (50 , 24 , 20 , 20 , "+" , data -> {
922
- AoESymmetrical .increaseRow (tag , defaultDefinition );
923
- holder .markAsDirty ();
924
- }))
925
- .widget (new ClickButtonWidget (50 , 44 , 20 , 20 , "-" , data -> {
926
- AoESymmetrical .decreaseRow (tag , defaultDefinition );
927
- holder .markAsDirty ();
928
- }))
929
- .widget (new ClickButtonWidget (85 , 24 , 20 , 20 , "+" , data -> {
930
- AoESymmetrical .increaseLayer (tag , defaultDefinition );
931
- holder .markAsDirty ();
932
- }))
933
- .widget (new ClickButtonWidget (85 , 44 , 20 , 20 , "-" , data -> {
934
- AoESymmetrical .decreaseLayer (tag , defaultDefinition );
935
- holder .markAsDirty ();
936
- }))
937
- .widget (new DynamicLabelWidget (23 , 65 , () -> Integer .toString (
938
- 1 + 2 * AoESymmetrical .getColumn (getBehaviorsTag (holder .getCurrentItem ()), defaultDefinition ))))
939
- .widget (new DynamicLabelWidget (58 , 65 , () -> Integer .toString (
940
- 1 + 2 * AoESymmetrical .getRow (getBehaviorsTag (holder .getCurrentItem ()), defaultDefinition ))))
941
- .widget (new DynamicLabelWidget (93 , 65 ,
942
- () -> Integer .toString (1 +
943
- AoESymmetrical .getLayer (getBehaviorsTag (holder .getCurrentItem ()), defaultDefinition ))))
944
- .build (holder , entityPlayer );
921
+ @ Override
922
+ default ModularPanel buildUI (HandGuiData guiData , PanelSyncManager manager ) {
923
+ final var usedStack = guiData .getUsedItemStack ();
924
+ final var behaviorsTag = getBehaviorsTag (usedStack );
925
+ final var defaultDefinition = getMaxAoEDefinition (usedStack );
926
+
927
+ var columnValue = new IntSyncValue (
928
+ () -> AoESymmetrical .getColumn (behaviorsTag , defaultDefinition ),
929
+ i -> AoESymmetrical .setColumn (behaviorsTag , i , defaultDefinition ));
930
+ var rowValue = new IntSyncValue (
931
+ () -> AoESymmetrical .getRow (behaviorsTag , defaultDefinition ),
932
+ i -> AoESymmetrical .setRow (behaviorsTag , i , defaultDefinition ));
933
+ var layerValue = new IntSyncValue (
934
+ () -> AoESymmetrical .getLayer (behaviorsTag , defaultDefinition ),
935
+ i -> AoESymmetrical .setLayer (behaviorsTag , i , defaultDefinition ));
936
+
937
+ manager .syncValue ("row_value" , rowValue );
938
+ manager .syncValue ("column_value" , columnValue );
939
+ manager .syncValue ("layer_value" , layerValue );
940
+
941
+ return GTGuis .createPanel (usedStack .getTranslationKey (), 120 , 80 )
942
+ .child (Flow .row ()
943
+ .widthRel (1f )
944
+ .margin (4 , 0 )
945
+ .alignY (0.5f )
946
+ .coverChildrenHeight ()
947
+ .mainAxisAlignment (Alignment .MainAxis .SPACE_BETWEEN )
948
+ .child (createColumn (columnValue , "columns" , true , defaultDefinition .column ))
949
+ .child (createColumn (rowValue , "rows" , true , defaultDefinition .row ))
950
+ .child (createColumn (layerValue , "layers" , false , defaultDefinition .layer )));
951
+ }
952
+
953
+ default Flow createColumn (IntSyncValue syncValue , String lang , boolean shouldDouble , int max ) {
954
+ final var display = IKey .dynamic (
955
+ () -> String .valueOf (1 + (shouldDouble ? 2 * syncValue .getIntValue () : syncValue .getIntValue ())));
956
+
957
+ IWidget increaseButton = new ButtonWidget <>()
958
+ .size (9 , 18 )
959
+ .background (GTGuiTextures .MC_BUTTON )
960
+ .overlay (GTGuiTextures .PLUS )
961
+ .disableHoverBackground ()
962
+ .onMousePressed (data -> {
963
+ int val = syncValue .getIntValue ();
964
+ if (val < max ) syncValue .setIntValue (++val );
965
+ return true ;
966
+ });
967
+
968
+ IWidget decreaseButton = new ButtonWidget <>()
969
+ .size (9 , 18 )
970
+ .background (GTGuiTextures .MC_BUTTON )
971
+ .overlay (GTGuiTextures .MINUS )
972
+ .disableHoverBackground ()
973
+ .onMousePressed (data -> {
974
+ int val = syncValue .getIntValue ();
975
+ if (val > 0 ) syncValue .setIntValue (--val );
976
+ return true ;
977
+ });
978
+
979
+ return Flow .column ()
980
+ .coverChildren ()
981
+ .child (new TextWidget (IKey .lang ("item.gt.tool.aoe." + lang ))
982
+ .marginBottom (5 ))
983
+ .child (Flow .row ()
984
+ .coverChildren ()
985
+ .marginBottom (5 )
986
+ .child (increaseButton )
987
+ .child (decreaseButton ))
988
+ .child (new TextWidget (display )
989
+ .alignment (Alignment .Center )
990
+ .widthRel (1f ));
945
991
}
946
992
947
993
Set <String > getToolClasses (ItemStack stack );
0 commit comments