11package dev .quarris .fireandflames .client .screen ;
22
33import dev .quarris .fireandflames .ModRef ;
4+ import dev .quarris .fireandflames .client .screen .components .CrucibleFluidTankComponent ;
45import dev .quarris .fireandflames .world .block .entity .CrucibleControllerBlockEntity ;
56import dev .quarris .fireandflames .world .inventory .menu .CrucibleMenu ;
67import net .minecraft .client .gui .GuiGraphics ;
78import net .minecraft .client .gui .screens .inventory .EffectRenderingInventoryScreen ;
8- import net .minecraft .client .renderer .texture .TextureAtlasSprite ;
99import net .minecraft .network .chat .Component ;
1010import net .minecraft .resources .ResourceLocation ;
1111import net .minecraft .world .entity .player .Inventory ;
1212import net .minecraft .world .inventory .Slot ;
1313import net .minecraft .world .item .ItemStack ;
14- import net .neoforged .neoforge .client .extensions .common .IClientFluidTypeExtensions ;
15- import net .neoforged .neoforge .client .textures .FluidSpriteCache ;
16- import net .neoforged .neoforge .fluids .FluidStack ;
17- import net .neoforged .neoforge .fluids .capability .templates .FluidTank ;
1814import org .jetbrains .annotations .NotNull ;
1915import org .jetbrains .annotations .Nullable ;
2016
@@ -25,6 +21,8 @@ public class CrucibleScreen extends EffectRenderingInventoryScreen<CrucibleMenu>
2521 private static final ResourceLocation SCROLLER_SPRITE = ModRef .res ("container/crucible/scroller" );
2622 private static final ResourceLocation SCROLLER_DISABLED_SPRITE = ModRef .res ("container/crucible/scroller_disabled" );
2723
24+ private CrucibleFluidTankComponent fluidTankComponent ;
25+
2826 public CrucibleScreen (CrucibleMenu menu , Inventory playerInventory , Component title ) {
2927 super (menu , playerInventory , title );
3028
@@ -34,47 +32,20 @@ public CrucibleScreen(CrucibleMenu menu, Inventory playerInventory, Component ti
3432 }
3533
3634 @ Override
37- protected void containerTick () {
38- }
39-
40- @ Override
41- public void render (GuiGraphics pGuiGraphics , int pMouseX , int pMouseY , float pPartialTick ) {
42- super .render (pGuiGraphics , pMouseX , pMouseY , pPartialTick );
43- this .renderTooltip (pGuiGraphics , pMouseX , pMouseY );
44- if (pMouseX >= this .leftPos + 7 && pMouseX < this .leftPos + 57 && pMouseY > this .topPos + 17 && pMouseY < this .topPos + 98 ) {
45- this .setTooltipForNextRenderPass (Component .literal (this .menu .crucible .getFluidTank ().getFluid ().toString ()));
46- }
35+ protected void init () {
36+ super .init ();
37+ this .fluidTankComponent = new CrucibleFluidTankComponent (menu .crucible ::getFluidTank , this .leftPos + 8 , this .topPos + 18 , 48 , 79 );
4738 }
4839
4940 @ Override
50- protected void renderSlotHighlight (GuiGraphics pGraphics , Slot pSlot , int pMouseX , int pMouseY , float pPartialTick ) {
51- if (this .isPlayerSlot (pSlot )) {
52- super .renderSlotHighlight (pGraphics , pSlot , pMouseX , pMouseY , pPartialTick );
53- return ;
54- }
55-
56- if (pSlot .isHighlightable ()) {
57- renderSlotHighlight (pGraphics , pSlot .x , pSlot .y - this .menu .getScroll () * 18 , 0 , getSlotColor (pSlot .index ));
58- }
41+ protected void containerTick () {
5942 }
6043
6144 @ Override
62- protected void renderSlotContents (GuiGraphics pGraphics , ItemStack pStack , Slot pSlot , @ Nullable String pCountString ) {
63- if (this .isPlayerSlot (pSlot )) {
64- super .renderSlotContents (pGraphics , pStack , pSlot , pCountString );
65- return ;
66- }
67-
68- int drawX = pSlot .x ;
69- int drawY = pSlot .y - this .menu .getScroll () * 18 ;
70- int seed = drawX + drawY * this .imageWidth ;
71- if (pSlot .isFake ()) {
72- pGraphics .renderFakeItem (pStack , drawX , drawY , seed );
73- } else {
74- pGraphics .renderItem (pStack , drawX , drawY , seed );
75- }
76-
77- pGraphics .renderItemDecorations (this .font , pStack , drawX , drawY , pCountString );
45+ public void render (GuiGraphics pGraphics , int pMouseX , int pMouseY , float pPartialTick ) {
46+ super .render (pGraphics , pMouseX , pMouseY , pPartialTick );
47+ CrucibleControllerBlockEntity crucible = this .getMenu ().crucible ;
48+ this .fluidTankComponent .render (pGraphics , crucible .getLevel (), crucible .getBlockPos (), pMouseX , pMouseY , pPartialTick );
7849 }
7950
8051 @ Override
@@ -90,25 +61,6 @@ protected void renderBg(GuiGraphics pGuiGraphics, float pPartialTick, int pMouse
9061 int scrollPos = (int ) (this .getMenu ().getScrollBarPosition () * (90 - 15 )); // ... * (scrollBarHeight - scrollHeight)
9162
9263 pGuiGraphics .blitSprite (scrollerSprite , this .leftPos + 156 , this .topPos + 18 + scrollPos , 12 , 15 );
93-
94- CrucibleControllerBlockEntity crucible = this .getMenu ().crucible ;
95- FluidTank fluidTank = this .menu .crucible .getFluidTank ();
96- FluidStack fluid = fluidTank .getFluid ();
97- int tankPosX = this .leftPos + 8 ;
98- int tankPosY = this .topPos + 18 ;
99- int tankWidth = 48 ;
100- int tankHeight = 79 ;
101-
102- TextureAtlasSprite sprite = FluidSpriteCache .getFluidSprites (crucible .getLevel (), crucible .getBlockPos (), fluid .getFluid ().defaultFluidState ())[0 ];
103- IClientFluidTypeExtensions fluidExtensions = IClientFluidTypeExtensions .of (fluid .getFluidType ());
104- int color = fluidExtensions .getTintColor (fluid .getFluid ().defaultFluidState (), crucible .getLevel (), crucible .getBlockPos ());
105-
106- float red = (float ) (color >> 16 & 0xFF ) / 255.0F ;
107- float green = (float ) (color >> 8 & 0xFF ) / 255.0F ;
108- float blue = (float ) (color & 0xFF ) / 255.0F ;
109-
110- pGuiGraphics .blit (tankPosX , tankPosY , 0 , tankWidth , tankHeight , sprite , red , green , blue , 1.0f );
111-
11264 /*
11365 SpriteContents contents = sprite.contents();
11466 int drawX, drawY;
@@ -138,6 +90,37 @@ protected void renderBg(GuiGraphics pGuiGraphics, float pPartialTick, int pMouse
13890 */
13991 }
14092
93+ @ Override
94+ protected void renderSlotHighlight (GuiGraphics pGraphics , Slot pSlot , int pMouseX , int pMouseY , float pPartialTick ) {
95+ if (this .isPlayerSlot (pSlot )) {
96+ super .renderSlotHighlight (pGraphics , pSlot , pMouseX , pMouseY , pPartialTick );
97+ return ;
98+ }
99+
100+ if (pSlot .isHighlightable ()) {
101+ renderSlotHighlight (pGraphics , pSlot .x , pSlot .y - this .menu .getScroll () * 18 , 0 , getSlotColor (pSlot .index ));
102+ }
103+ }
104+
105+ @ Override
106+ protected void renderSlotContents (GuiGraphics pGraphics , ItemStack pStack , Slot pSlot , @ Nullable String pCountString ) {
107+ if (this .isPlayerSlot (pSlot )) {
108+ super .renderSlotContents (pGraphics , pStack , pSlot , pCountString );
109+ return ;
110+ }
111+
112+ int drawX = pSlot .x ;
113+ int drawY = pSlot .y - this .menu .getScroll () * 18 ;
114+ int seed = drawX + drawY * this .imageWidth ;
115+ if (pSlot .isFake ()) {
116+ pGraphics .renderFakeItem (pStack , drawX , drawY , seed );
117+ } else {
118+ pGraphics .renderItem (pStack , drawX , drawY , seed );
119+ }
120+
121+ pGraphics .renderItemDecorations (this .font , pStack , drawX , drawY , pCountString );
122+ }
123+
141124 private boolean isPlayerSlot (Slot pSlot ) {
142125 return pSlot .index >= this .getMenu ().crucible .getInventory ().getSlots ();
143126 }
@@ -158,8 +141,18 @@ public boolean mouseScrolled(double mouseX, double mouseY, double scrollX, doubl
158141 }
159142
160143 @ Override
161- public boolean mouseDragged (double mouseX , double mouseY , int button , double dragX , double dragY ) {
162- return super .mouseDragged (mouseX , mouseY , button , dragX , dragY );
163- }
144+ public boolean mouseClicked (double mouseX , double mouseY , int button ) {
145+ if (!this .fluidTankComponent .isHovering (mouseX , mouseY )) {
146+ return super .mouseClicked (mouseX , mouseY , button );
147+ }
164148
149+ int clickedFluidSlot = this .fluidTankComponent .getHoveringFluidTank (mouseX , mouseY );
150+ if (clickedFluidSlot < 0 || !this .menu .clickMenuButton (this .minecraft .player , clickedFluidSlot )) {
151+ return super .mouseClicked (mouseX , mouseY , button );
152+ }
153+
154+ this .minecraft .gameMode .handleInventoryButtonClick (this .menu .containerId , clickedFluidSlot );
155+ return true ;
156+
157+ }
165158}
0 commit comments