@@ -63,10 +63,13 @@ public class AutoPlaceMapArt/* extends MapLayoutFinder*/{
6363 private int attemptIdx , lastAttemptIdx ;
6464 private int ticksSinceInvAction , ticksWaitingForManualClick ;
6565 private boolean hasWarnedMissingIfe ;
66- private final Predicate <ItemStack > handRestockFallback ;
66+ private final Function <ItemStack , ItemStack > handRestockFallback ; // lastPlacedStack -> restockedStack (or null)
67+ private ItemStack lastHandRestockFallbackStack ;
6768 private boolean calledRecalcLayout , handRestockFailed , warnedNoValidPos ;
6869
69- public AutoPlaceMapArt (Predicate <ItemStack > moveNextMapToMainHand ){
70+ private boolean extraInfoLogs = false ;
71+
72+ public AutoPlaceMapArt (Function <ItemStack , ItemStack > moveNextMapToMainHand ){
7073 handRestockFallback = moveNextMapToMainHand ;
7174
7275 TickListener .register (new TickListener (){
@@ -283,8 +286,11 @@ private final boolean calcWidthUsingAdjIFrames(PlayerEntity player, AxisData cur
283286 Main .LOGGER .info ("AutoPlaceMapArt: determined col isNeg=" +colIsNeg +" from available ifes" );
284287 if (axisMatch ) varAxis2Neg = colIsNeg ; else varAxis1Neg = colIsNeg ;
285288 }
286- rowWidth = candidateWidth ;
287- return true ;
289+ if (b == 0 || b == ofSize -1 ){
290+ rowWidth = candidateWidth ;
291+ return true ;
292+ }
293+ return false ;
288294 }
289295
290296 public final boolean recalcLayout (final PlayerEntity player , final ItemFrameEntity currIfe , final ItemStack currStack ){
@@ -388,7 +394,7 @@ public final boolean recalcLayout(final PlayerEntity player, final ItemFrameEnti
388394 Main .LOGGER .warn ("AutoPlaceMapArt: Invalid 1d X/SIZE pos! a=" +a +",b=" +b );
389395 disableAndReset (); return false ;
390396 }
391- // Main.LOGGER.info("AutoPlaceMapArt: for X/SIZE, curr(a)="+a+", last(b)="+b+", ifeOffset1="+ifeOffset1+", ifeOffset2="+ifeOffset2);
397+ Main .LOGGER .info ("AutoPlaceMapArt: for X/SIZE, curr(a)=" +a +", last(b)=" +b +", ifeOffset1=" +ifeOffset1 +", ifeOffset2=" +ifeOffset2 );
392398 final int posOffset = a -b ;
393399 if (ifeOffset1 == 0 || ifeOffset2 == 0 ){
394400 final int ifeOffset = ifeOffset1 + ifeOffset2 ; // one of them is 0
@@ -433,7 +439,10 @@ else if(varAxis2Neg != isNeg){
433439 final int candidateRowWidth = Math .abs (rowOffset )+1 ;
434440 if (ofSize % candidateRowWidth == 0 ){
435441 final boolean determinedWidth = calcWidthUsingAdjIFrames (player , currAxisData , a , b );
436- if (determinedWidth ) assert rowWidth != null && rowWidth != 0 ;
442+ if (determinedWidth ){
443+ assert rowWidth != null && rowWidth != 0 ;
444+ Main .LOGGER .info ("AutoPlaceMapArt: determined rowWidth=" +rowWidth +" from calcWidthUsingAdjIFrames()" );
445+ }
437446 }
438447 // A little hack to maximize future rowOffset; might not be necessary anymore, but used to help the logic above
439448 if (rowWidth == null ) updateLastIfe = false ;
@@ -578,15 +587,15 @@ else if(varAxis2Neg != isNeg){
578587 }
579588 }
580589
581- if (!stacksHashesForCurrentData .isEmpty ()) return true ; // Already ongoing and all values are defined
590+ if (!stacksHashesForCurrentData .isEmpty ()) return true ; // Already ongoing, and hashlist has ahready been defined
582591
583592 assert !allMapItems .isEmpty ();
584593 assert stacksHashesForCurrentData .isEmpty ();
585594 stacksHashesForCurrentData .ensureCapacity (currentData .slots ().size ());
586595 currentData .slots ().stream ().map (i -> ItemStack .hashCode (allMapItems .get (i ))).forEach (stacksHashesForCurrentData ::add );
587596 assert !stacksHashesForCurrentData .isEmpty ();
588597
589- Main .LOGGER .info ("AutoPlaceMapArt: activated! varAxis1Neg=" +varAxis1Neg +",varAxis2Neg=" +varAxis2Neg );
598+ Main .LOGGER .info ("AutoPlaceMapArt: activated! axisMatch=" + axisMatch + ", varAxis1Neg=" +varAxis1Neg +",varAxis2Neg=" +varAxis2Neg );
590599 return true ;
591600 }
592601 finally {
@@ -678,7 +687,7 @@ private final Vec3d getPlaceAgainstSurface(BlockPos ifeBp){
678687 };
679688 }
680689
681- record MapPlacementData (int slot , int bundleSlot , ItemFrameEntity ife , BlockPos bp ){}
690+ private record MapPlacementData (int slot , int bundleSlot , ItemFrameEntity ife , BlockPos bp ){}
682691 public final MapPlacementData getNearestMapPlacement (PlayerEntity player , final boolean ALLOW_OUTSIDE_MAX_REACH , final boolean ALLOW_MAP_IN_HAND ){
683692 final List <ItemStack > slots = player .playerScreenHandler .slots .stream ().map (Slot ::getStack ).toList ();
684693
@@ -797,7 +806,8 @@ private final void getMapIntoMainHand(ClientPlayerEntity player, int slot, int b
797806
798807 final int TICKS_BETWEEN_INV_ACTIONS = Configs .Generic .MAPART_AUTOPLACE_INV_DELAY .getIntegerValue ();
799808 if (ticksSinceInvAction < TICKS_BETWEEN_INV_ACTIONS ){
800- Main .LOGGER .info ("AutoPlaceMapArt: waiting for inv action cooldown (" +ticksSinceInvAction +"ticks)" );
809+ if (extraInfoLogs || ticksSinceInvAction == TICKS_BETWEEN_INV_ACTIONS -1 )
810+ Main .LOGGER .info ("AutoPlaceMapArt: waiting for inv action cooldown (" +ticksSinceInvAction +"ticks)" );
801811 return ;
802812 }
803813 final Runnable onDone = TICKS_BETWEEN_INV_ACTIONS == 0 ? ()->placeNearestMap (player ) : ()->ticksSinceInvAction =0 ;
@@ -889,7 +899,8 @@ private final void placeNearestMap(ClientPlayerEntity player){
889899 // Sadly this doesn't work after the last manual map, since UseEntityCallback.EVENT isn't triggered by AutoMapArtPlace for some reason.
890900 // And yeah, I tried setting it manually, but since the code can't guarantee a map gets placed, it can get it stuck.
891901 if (!player .isInCreativeMode () && UpdateInventoryHighlights .hasCurrentlyBeingPlacedMapArt () && ++ticksWaitingForManualClick <= MANUAL_CLICK_WAIT_TIMEOUT ){
892- Main .LOGGER .info ("AutoPlaceMapArt: waiting for last manually-placed mapart to vanish from mainhand (" +ticksWaitingForManualClick +"ticks)" );
902+ if (extraInfoLogs || ticksWaitingForManualClick == MANUAL_CLICK_WAIT_TIMEOUT )
903+ Main .LOGGER .info ("AutoPlaceMapArt: waiting for last manually-placed mapart to vanish from mainhand (" +ticksWaitingForManualClick +"ticks)" );
893904 return ;
894905 }
895906 ticksWaitingForManualClick = 0 ;
@@ -902,7 +913,8 @@ private final void placeNearestMap(ClientPlayerEntity player){
902913 Entity e = player .getWorld ().getEntityById (recentPlaceAttempts [lastAttemptIdx ]);
903914 if (e != null && e instanceof ItemFrameEntity ife && ItemStack .areEqual (player .getMainHandStack (), ife .getHeldItemStack ())){
904915 final int waited = lastAttemptIdx < attemptIdx ? attemptIdx -lastAttemptIdx : recentPlaceAttempts .length +attemptIdx -lastAttemptIdx ;
905- Main .LOGGER .info ("AutoPlaceMapArt: waiting for current map to vanish from mainhand (" +waited +"ticks)" );
916+ if (extraInfoLogs || waited == recentPlaceAttempts .length -1 )
917+ Main .LOGGER .info ("AutoPlaceMapArt: waiting for current map to vanish from mainhand (" +waited +"ticks)" );
906918 return ;
907919 }
908920 }
@@ -915,7 +927,8 @@ private final void placeNearestMap(ClientPlayerEntity player){
915927 if (e != null && e instanceof ItemFrameEntity ife && ife .getHeldItemStack ().isEmpty ()){
916928// final int rem = attemptIdx < i ? i-attemptIdx : recentPlaceAttempts.length+i-attemptIdx;
917929 final int waited = i < attemptIdx ? attemptIdx -i : recentPlaceAttempts .length +attemptIdx -i ;
918- Main .LOGGER .info ("AutoPlaceMapArt: waiting for current map to appear in iFrame (" +waited +"ticks)" );
930+ if (extraInfoLogs || waited == recentPlaceAttempts .length -1 )
931+ Main .LOGGER .info ("AutoPlaceMapArt: waiting for current map to appear in iFrame (" +waited +"ticks)" );
919932 return ;
920933 }
921934 if (++i == recentPlaceAttempts .length ) i = 0 ;
@@ -932,7 +945,9 @@ private final void placeNearestMap(ClientPlayerEntity player){
932945 }
933946 else if (player .getMainHandStack ().getItem () != Items .FILLED_MAP && handRestockFallback != null && !handRestockFailed ){
934947 Main .LOGGER .info ("AutoPlaceMapArt: Unable to determine placement, calling handRestockFallback" );
935- if (!handRestockFallback .test (lastStackAuto != null ? lastStackAuto : lastStack )) handRestockFailed = true ;
948+ final ItemStack handRestock = handRestockFallback .apply (lastStackAuto != null ? lastStackAuto : lastStack );
949+ if (handRestock == null || handRestock == lastHandRestockFallbackStack ) handRestockFailed = true ;
950+ else lastHandRestockFallbackStack = handRestock ;
936951 }
937952 return ;
938953 }
0 commit comments