44import gregtech .api .gui .IRenderContext ;
55import gregtech .api .gui .Widget ;
66import gregtech .api .gui .resources .TextureArea ;
7+ import gregtech .api .situation .Situation ;
78import gregtech .api .situation .SituationTypes ;
89import gregtech .api .util .Position ;
910import gregtech .api .util .Size ;
1011import net .minecraft .client .resources .I18n ;
1112import net .minecraft .network .PacketBuffer ;
1213import net .minecraftforge .fml .relauncher .Side ;
1314import net .minecraftforge .fml .relauncher .SideOnly ;
14- import java .util .function .IntSupplier ;
15-
16- import static gregtech .api .situation .Situation .getSituationFromId ;
17- import static gregtech .api .situation .SituationTypes .*;
15+ import java .util .function .Supplier ;
1816
1917public class SituationWidget extends Widget {
2018
21- private final IntSupplier currentSituationId ;
19+ private final Supplier <Situation > currentSituationSupplier ;
20+ private Situation currentSituation ;
2221 protected String tooltipHoverString ;
23- protected int currentError ;
22+ protected int currentId ;
2423
2524 protected TextureArea area ;
2625 private boolean isVisible = true ;
2726
28- public SituationWidget (int xPosition , int yPosition , int width , int height , IntSupplier getSituationId ) {
27+ public < T extends Situation > SituationWidget (int xPosition , int yPosition , int width , int height , Supplier < Situation > getSituation ) {
2928 super (new Position (xPosition , yPosition ), new Size (width , height ));
30- this .currentSituationId = () -> getSituationId .getAsInt ();
29+ this .currentSituationSupplier = getSituation ;
30+ this .currentSituation = getSituation .get ();
3131 setTooltipHoverString ();
3232 setImage ();
3333 }
3434
3535 public void setTooltipHoverString () {
36- this .tooltipHoverString = I18n .format (getSituationFromId ( currentError ) .situationLocaleName );
36+ this .tooltipHoverString = I18n .format (this . currentSituation .situationLocaleName );
3737 }
3838
3939 public SituationWidget setImage () {
40- SituationTypes iconTextures = getSituationFromId ( currentError ) .situationTypes ;
40+ SituationTypes iconTextures = this . currentSituation .situationTypes ;
4141 switch (iconTextures ) {
4242 case IDLE :
4343 this .area = GuiTextures .STATUS_IDLING ;
@@ -60,17 +60,18 @@ public SituationWidget setImage() {
6060 @ Override
6161 public void detectAndSendChanges () {
6262 super .detectAndSendChanges ();
63- if (currentSituationId . getAsInt () != currentError ) {
64- this .currentError = currentSituationId . getAsInt () ;
65- writeUpdateInfo (1 , buf -> buf .writeVarInt (currentError ));
63+ if (currentSituationSupplier . get (). id != currentId ) {
64+ this .currentId = currentSituationSupplier . get (). id ;
65+ writeUpdateInfo (1 , buf -> buf .writeVarInt (currentId ));
6666 }
6767 }
6868
6969 @ Override
7070 public void readUpdateInfo (int id , PacketBuffer buffer ) {
7171 super .readUpdateInfo (id , buffer );
7272 if (id == 1 ) {
73- this .currentError = buffer .readVarInt ();
73+ this .currentId = buffer .readVarInt ();
74+ this .currentSituation = Situation .getSituationFromId (this .currentId );
7475 setTooltipHoverString ();
7576 setImage ();
7677 }
0 commit comments