1010import io .josemmo .bukkit .plugin .YamipaPlugin ;
1111import io .josemmo .bukkit .plugin .renderer .FakeImage ;
1212import io .josemmo .bukkit .plugin .renderer .FakeItemFrame ;
13+ import io .josemmo .bukkit .plugin .renderer .ImageRenderer ;
1314import io .josemmo .bukkit .plugin .utils .Internals ;
14- import org .bukkit .Location ;
1515import org .bukkit .block .Block ;
1616import org .bukkit .block .BlockFace ;
1717import org .bukkit .entity .Player ;
1818import org .bukkit .plugin .Plugin ;
19+ import org .bukkit .util .BlockIterator ;
1920import org .jetbrains .annotations .NotNull ;
2021import org .jetbrains .annotations .Nullable ;
21- import java .util .List ;
2222
2323public abstract class SelectFakeItemFrameListener implements PacketListener {
2424 private static final int MAX_BLOCK_DISTANCE = 5 ;
@@ -29,26 +29,27 @@ public abstract class SelectFakeItemFrameListener implements PacketListener {
2929 * @return Fake image instance or <code>null</code> if not found
3030 */
3131 public static @ Nullable FakeImage getFakeImage (@ NotNull Player player ) {
32- // Get target block in range
33- List <Block > lastTwoTargetBlocks = player .getLastTwoTargetBlocks (null , MAX_BLOCK_DISTANCE );
34- if (lastTwoTargetBlocks .size () != 2 ) {
35- return null ;
36- }
37- Block targetBlock = lastTwoTargetBlocks .get (1 );
38- if (!targetBlock .getType ().isSolid ()) {
39- return null ;
40- }
41-
42- // Get target block face
43- Block adjacentBlock = lastTwoTargetBlocks .get (0 );
44- BlockFace targetBlockFace = targetBlock .getFace (adjacentBlock );
45- if (targetBlockFace == null ) {
46- return null ;
32+ ImageRenderer renderer = YamipaPlugin .getInstance ().getRenderer ();
33+
34+ // Get the closest fake image within player's line of sight
35+ BlockIterator iterator = new BlockIterator (player , MAX_BLOCK_DISTANCE );
36+ Block previousBlock = null ;
37+ while (iterator .hasNext ()) {
38+ Block currentBlock = iterator .next ();
39+ if (previousBlock != null ) {
40+ BlockFace currentBlockFace = currentBlock .getFace (previousBlock );
41+ if (currentBlockFace != null ) {
42+ FakeImage image = renderer .getImage (currentBlock .getLocation (), currentBlockFace );
43+ if (image != null ) {
44+ return image ;
45+ }
46+ }
47+ }
48+ previousBlock = currentBlock ;
4749 }
4850
49- // Get fake image instance
50- Location targetBlockLocation = targetBlock .getLocation ();
51- return YamipaPlugin .getInstance ().getRenderer ().getImage (targetBlockLocation , targetBlockFace );
51+ // No fake image found
52+ return null ;
5253 }
5354
5455 /**
0 commit comments