@@ -218,7 +218,7 @@ default ItemStack get(Material material) {
218218
219219 // Set behaviours
220220 NBTTagCompound behaviourTag = getBehaviorsTag (stack );
221- getToolStats (). getBehaviors ().forEach (behavior -> behavior .addBehaviorNBT (stack , behaviourTag ));
221+ getBehaviors (stack ).forEach (behavior -> behavior .addBehaviorNBT (stack , behaviourTag ));
222222
223223 if (aoeDefinition != AoESymmetrical .none ()) {
224224 behaviourTag .setInteger (MAX_AOE_COLUMN_KEY , aoeDefinition .column );
@@ -420,14 +420,14 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {
420420 }
421421
422422 default boolean definition$hitEntity (ItemStack stack , EntityLivingBase target , EntityLivingBase attacker ) {
423- getToolStats (). getBehaviors ().forEach (behavior -> behavior .hitEntity (stack , target , attacker ));
423+ getBehaviors (stack ).forEach (behavior -> behavior .hitEntity (stack , target , attacker ));
424424 damageItem (stack , attacker , getToolStats ().getToolDamagePerAttack (stack ));
425425 return true ;
426426 }
427427
428428 default boolean definition$onBlockStartBreak (ItemStack stack , BlockPos pos , EntityPlayer player ) {
429429 if (player .world .isRemote ) return false ;
430- getToolStats (). getBehaviors ().forEach (behavior -> behavior .onBlockStartBreak (stack , pos , player ));
430+ getBehaviors (stack ).forEach (behavior -> behavior .onBlockStartBreak (stack , pos , player ));
431431
432432 if (!player .isSneaking ()) {
433433 EntityPlayerMP playerMP = (EntityPlayerMP ) player ;
@@ -469,7 +469,7 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {
469469 default boolean definition$onBlockDestroyed (ItemStack stack , World worldIn , IBlockState state , BlockPos pos ,
470470 EntityLivingBase entityLiving ) {
471471 if (!worldIn .isRemote ) {
472- getToolStats (). getBehaviors ()
472+ getBehaviors (stack )
473473 .forEach (behavior -> behavior .onBlockDestroyed (stack , worldIn , state , pos , entityLiving ));
474474
475475 if ((double ) state .getBlockHardness (worldIn , pos ) != 0.0D ) {
@@ -533,7 +533,7 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {
533533
534534 default boolean definition$canDisableShield (ItemStack stack , ItemStack shield , EntityLivingBase entity ,
535535 EntityLivingBase attacker ) {
536- return getToolStats (). getBehaviors ().stream ()
536+ return getBehaviors (stack ).stream ()
537537 .anyMatch (behavior -> behavior .canDisableShield (stack , shield , entity , attacker ));
538538 }
539539
@@ -581,7 +581,7 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {
581581 }
582582
583583 default boolean definition$onEntitySwing (EntityLivingBase entityLiving , ItemStack stack ) {
584- getToolStats (). getBehaviors ().forEach (behavior -> behavior .onEntitySwing (entityLiving , stack ));
584+ getBehaviors (stack ).forEach (behavior -> behavior .onEntitySwing (entityLiving , stack ));
585585 return false ;
586586 }
587587
@@ -633,7 +633,7 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {
633633 if (isElectric ()) {
634634 providers .add (ElectricStats .createElectricItem (0L , getElectricTier ()).createProvider (stack ));
635635 }
636- for (IToolBehavior behavior : getToolStats (). getBehaviors ()) {
636+ for (IToolBehavior behavior : getBehaviors (stack )) {
637637 ICapabilityProvider behaviorProvider = behavior .createProvider (stack , nbt );
638638 if (behaviorProvider != null ) {
639639 providers .add (behaviorProvider );
@@ -644,14 +644,15 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {
644644 return new CombinedCapabilityProvider (providers );
645645 }
646646
647+ @ NotNull
648+ default List <IToolBehavior > getBehaviors (ItemStack stack ) {
649+ return getToolStats ().getBehaviors ();
650+ }
651+
647652 default EnumActionResult definition$onItemUseFirst (@ NotNull EntityPlayer player , @ NotNull World world ,
648653 @ NotNull BlockPos pos , @ NotNull EnumFacing facing , float hitX ,
649654 float hitY , float hitZ , @ NotNull EnumHand hand ) {
650- ItemStack stack = toolbeltPassthrough (player .getHeldItem (hand ));
651- List <IToolBehavior > behaviors ;
652- if (stack .getItem () instanceof IGTTool tool ) behaviors = tool .getToolStats ().getBehaviors ();
653- else return EnumActionResult .PASS ;
654- for (IToolBehavior behavior : behaviors ) {
655+ for (IToolBehavior behavior : getBehaviors (player .getHeldItem (hand ))) {
655656 if (behavior .onItemUseFirst (player , world , pos , facing , hitX , hitY , hitZ , hand ) ==
656657 EnumActionResult .SUCCESS ) {
657658 return EnumActionResult .SUCCESS ;
@@ -663,12 +664,7 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {
663664
664665 default EnumActionResult definition$onItemUse (EntityPlayer player , World world , BlockPos pos , EnumHand hand ,
665666 EnumFacing facing , float hitX , float hitY , float hitZ ) {
666- ItemStack stack = toolbeltPassthrough (player .getHeldItem (hand ));
667- List <IToolBehavior > behaviors ;
668- if (stack .getItem () instanceof IGTTool tool ) behaviors = tool .getToolStats ().getBehaviors ();
669- else return EnumActionResult .PASS ;
670-
671- for (IToolBehavior behavior : behaviors ) {
667+ for (IToolBehavior behavior : getBehaviors (player .getHeldItem (hand ))) {
672668 if (behavior .onItemUse (player , world , pos , hand , facing , hitX , hitY , hitZ ) ==
673669 EnumActionResult .SUCCESS ) {
674670 return EnumActionResult .SUCCESS ;
@@ -680,25 +676,20 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {
680676
681677 default ActionResult <ItemStack > definition$onItemRightClick (World world , EntityPlayer player , EnumHand hand ) {
682678 ItemStack stack = player .getHeldItem (hand );
683- ItemStack original = stack ;
684- stack = toolbeltPassthrough (stack );
685679 if (!world .isRemote ) {
686680 // TODO: relocate to keybind action when keybind PR happens
687681 if (player .isSneaking () && getMaxAoEDefinition (stack ) != AoESymmetrical .none ()) {
688682 ItemGuiFactory .open ((EntityPlayerMP ) player , hand );
689- return ActionResult .newResult (EnumActionResult .SUCCESS , original );
683+ return ActionResult .newResult (EnumActionResult .SUCCESS , stack );
690684 }
691685 }
692- List <IToolBehavior > behaviors ;
693- if (stack .getItem () instanceof IGTTool tool ) behaviors = tool .getToolStats ().getBehaviors ();
694- else return ActionResult .newResult (EnumActionResult .PASS , original );
695686
696- for (IToolBehavior behavior : behaviors ) {
687+ for (IToolBehavior behavior : getBehaviors ( stack ) ) {
697688 if (behavior .onItemRightClick (world , player , hand ).getType () == EnumActionResult .SUCCESS ) {
698- return ActionResult .newResult (EnumActionResult .SUCCESS , original );
689+ return ActionResult .newResult (EnumActionResult .SUCCESS , stack );
699690 }
700691 }
701- return ActionResult .newResult (EnumActionResult .PASS , original );
692+ return ActionResult .newResult (EnumActionResult .PASS , stack );
702693 }
703694
704695 default void definition$getSubItems (@ NotNull NonNullList <ItemStack > items ) {
@@ -788,10 +779,10 @@ default AoESymmetrical getAoEDefinition(ItemStack stack) {
788779 tooltip .add (I18n .format ("item.gt.tool.behavior.relocate_mining" ));
789780 }
790781
791- if (!addedBehaviorNewLine && !toolStats . getBehaviors ().isEmpty ()) {
782+ if (!addedBehaviorNewLine && !getBehaviors (stack ).isEmpty ()) {
792783 tooltip .add ("" );
793784 }
794- toolStats . getBehaviors ().forEach (behavior -> behavior .addInformation (stack , world , tooltip , flag ));
785+ getBehaviors (stack ).forEach (behavior -> behavior .addInformation (stack , world , tooltip , flag ));
795786
796787 // unique tooltip
797788 String uniqueTooltip = "item.gt.tool." + getToolId () + ".tooltip" ;
0 commit comments