11package com .portingdeadmods .researchd .client .screens .lines ;
22
3+ import com .portingdeadmods .researchd .api .research .Research ;
34import com .portingdeadmods .researchd .client .screens .ResearchScreenWidget ;
45import com .portingdeadmods .researchd .client .screens .graph .ResearchNode ;
56import com .portingdeadmods .researchd .utils .UniqueArray ;
67import net .minecraft .client .gui .GuiGraphics ;
8+ import net .minecraft .resources .ResourceKey ;
79
810import java .awt .*;
911import java .util .HashSet ;
@@ -14,17 +16,27 @@ public class ResearchHead {
1416 private int x ;
1517 private int y ;
1618 private final boolean isInput ;
19+ private final ResearchNode research ;
1720
1821 /**
1922 *
2023 * @param x Should be based on the x position of the node, split evenly if there are multiple heads
2124 * @param y Should be the y position of the node <br>(+ Node height if it's output)
2225 * @param isInput Should be true if it's an input head, false if it's an output head
26+ * @param research {@link ResearchNode} the research this head is linked to. If the head is made through {@link #inputsOf(ResearchNode)} it will be linked to each of the children of the node, and vice versa
2327 */
28+ public ResearchHead (int x , int y , boolean isInput , ResearchNode research ) {
29+ this .x = x ;
30+ this .y = y ;
31+ this .isInput = isInput ;
32+ this .research = research ;
33+ }
34+
2435 public ResearchHead (int x , int y , boolean isInput ) {
2536 this .x = x ;
2637 this .y = y ;
2738 this .isInput = isInput ;
39+ this .research = null ;
2840 }
2941
3042 public int getX () { return this .x ; }
@@ -60,7 +72,8 @@ public void render(GuiGraphics graphics) {
6072 */
6173 public static UniqueArray <ResearchHead > inputsOf (ResearchNode node ) {
6274 UniqueArray <ResearchHead > positions = new UniqueArray <>();
63- int parentCount = node .getParents ().size ();
75+ UniqueArray <ResearchNode > parents = node .getParents ();
76+ int parentCount = parents .size ();
6477 int width = ResearchScreenWidget .PANEL_WIDTH ; // Node width
6578
6679 if (parentCount == 0 ) return positions ;
@@ -69,7 +82,7 @@ public static UniqueArray<ResearchHead> inputsOf(ResearchNode node) {
6982 if (parentCount == 1 ) {
7083 int x = node .getX () + width / 2 ;
7184 int y = node .getY ();
72- positions .add (new ResearchHead (x , y , true ));
85+ positions .add (new ResearchHead (x , y , true , parents . get ( 0 ) ));
7386 return positions ;
7487 }
7588
@@ -78,7 +91,11 @@ public static UniqueArray<ResearchHead> inputsOf(ResearchNode node) {
7891 startingX -= ((parentCount - 1 ) / 2 ) * 3 ; // 3 px per pair of heads
7992
8093 for (int i = 0 ; i < parentCount ; i ++) {
81- positions .addLast (new ResearchHead (startingX + i * 3 , node .getY (), true ));
94+ positions .addLast (new ResearchHead (startingX + i * 3 ,
95+ node .getY (),
96+ true ,
97+ parents .get (i ))
98+ );
8299 }
83100
84101 return positions ;
@@ -90,7 +107,8 @@ public static UniqueArray<ResearchHead> inputsOf(ResearchNode node) {
90107 */
91108 public static UniqueArray <ResearchHead > outputsOf (ResearchNode node ) {
92109 UniqueArray <ResearchHead > positions = new UniqueArray <>();
93- int childCount = node .getChildren ().size ();
110+ UniqueArray <ResearchNode > children = node .getChildren ();
111+ int childCount = children .size ();
94112 int width = ResearchScreenWidget .PANEL_WIDTH ; // Node width
95113
96114 if (childCount == 0 ) return positions ;
@@ -99,7 +117,7 @@ public static UniqueArray<ResearchHead> outputsOf(ResearchNode node) {
99117 if (childCount == 1 ) {
100118 int x = node .getX () + width / 2 ;
101119 int y = node .getY () + ResearchScreenWidget .PANEL_HEIGHT - 1 ;
102- positions .add (new ResearchHead (x , y , false ));
120+ positions .add (new ResearchHead (x , y , false , children . get ( 0 ) ));
103121 return positions ;
104122 }
105123
@@ -108,7 +126,12 @@ public static UniqueArray<ResearchHead> outputsOf(ResearchNode node) {
108126 startingX -= ((childCount - 1 ) / 2 ) * 3 ; // 2 px per pair of heads
109127
110128 for (int i = 0 ; i < childCount ; i ++) {
111- positions .addLast (new ResearchHead (startingX + i * 3 , node .getY () + ResearchScreenWidget .PANEL_HEIGHT - 1 , false ));
129+ positions .addLast (new ResearchHead (
130+ startingX + i * 3 ,
131+ node .getY () + ResearchScreenWidget .PANEL_HEIGHT - 1 ,
132+ false ,
133+ children .get (i )
134+ ));
112135 }
113136
114137 return positions ;
0 commit comments