Skip to content

Commit b917e99

Browse files
committed
Continued on TODOs
1 parent 0139430 commit b917e99

File tree

14 files changed

+2157
-958
lines changed

14 files changed

+2157
-958
lines changed
Lines changed: 73 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,84 @@
11
package org.modsauce.impr.client.gui.components;
22

3-
import org.modsauce.impr.client.gui.screen.IMPBaseContainerScreen;
43
import net.minecraft.client.gui.GuiGraphics;
54
import net.minecraft.client.gui.components.ImageButton;
65
import net.minecraft.network.chat.Component;
76
import net.minecraft.resources.ResourceLocation;
7+
import org.modsauce.impr.client.gui.screen.IMPBaseContainerScreen;
88

9-
// TODO: Fix for 1.21 - ImageButton constructor changed to use WidgetSprites
9+
// NOTE: ImageButton constructor signature changed in newer mappings (1.21+).
10+
// The implementation below already constructs and passes a `WidgetSprites` instance.
11+
// This comment documents the API change and can be removed once the codebase no longer needs to reference it.
1012
public class PowerButton extends ImageButton {
11-
private final IMPBaseContainerScreen<?> screen;
12-
private final ResourceLocation resourceLocation;
13-
private final int xTexStart;
14-
private final int yTexStart;
15-
private final int textureWidth;
16-
private final int textureHeight;
17-
18-
public PowerButton(IMPBaseContainerScreen<?> screen, int x, int y, int width, int height, int xTexStart, int yTexStart, ResourceLocation resourceLocation, int textureWidth, int textureHeight) {
19-
// TODO: Fix constructor for 1.21 - needs WidgetSprites instead of individual texture parameters
20-
super(x, y, width, height, new net.minecraft.client.gui.components.WidgetSprites(resourceLocation, resourceLocation), button -> onPower(screen));
21-
this.screen = screen;
22-
this.resourceLocation = resourceLocation;
23-
this.xTexStart = xTexStart;
24-
this.yTexStart = yTexStart;
25-
this.textureWidth = textureWidth;
26-
this.textureHeight = textureHeight;
27-
}
28-
29-
@Override
30-
public void renderWidget(GuiGraphics guiGraphics, int i, int j, float f) {
31-
// RenderSystem.setShader(GameRenderer::getPositionTexShader);
32-
// RenderSystem.setShaderTexture(0, this.resourceLocation);
33-
int tx = this.xTexStart;
34-
int ty = this.yTexStart;
35-
36-
if (this.isHoveredOrFocused())
37-
ty += this.height;
38-
39-
if (screen.isPowered())
40-
tx += this.width;
41-
42-
// RenderSystem.enableDepthTest();
43-
guiGraphics.blit(this.resourceLocation, this.getX(), this.getY(), (int) tx, (int) ty, this.width, this.height, this.textureWidth, this.textureHeight);
44-
/*if (this.isHoveredOrFocused())
13+
14+
private final IMPBaseContainerScreen<?> screen;
15+
private final ResourceLocation resourceLocation;
16+
private final int xTexStart;
17+
private final int yTexStart;
18+
private final int textureWidth;
19+
private final int textureHeight;
20+
21+
public PowerButton(
22+
IMPBaseContainerScreen<?> screen,
23+
int x,
24+
int y,
25+
int width,
26+
int height,
27+
int xTexStart,
28+
int yTexStart,
29+
ResourceLocation resourceLocation,
30+
int textureWidth,
31+
int textureHeight
32+
) {
33+
// NOTE: Constructor uses `WidgetSprites` directly to provide texture(s) for the ImageButton.
34+
// The previous versions used individual texture parameters; this line documents why the `WidgetSprites` usage is present.
35+
super(
36+
x,
37+
y,
38+
width,
39+
height,
40+
new net.minecraft.client.gui.components.WidgetSprites(
41+
resourceLocation,
42+
resourceLocation
43+
),
44+
button -> onPower(screen)
45+
);
46+
this.screen = screen;
47+
this.resourceLocation = resourceLocation;
48+
this.xTexStart = xTexStart;
49+
this.yTexStart = yTexStart;
50+
this.textureWidth = textureWidth;
51+
this.textureHeight = textureHeight;
52+
}
53+
54+
@Override
55+
public void renderWidget(GuiGraphics guiGraphics, int i, int j, float f) {
56+
// RenderSystem.setShader(GameRenderer::getPositionTexShader);
57+
// RenderSystem.setShaderTexture(0, this.resourceLocation);
58+
int tx = this.xTexStart;
59+
int ty = this.yTexStart;
60+
61+
if (this.isHoveredOrFocused()) ty += this.height;
62+
63+
if (screen.isPowered()) tx += this.width;
64+
65+
// RenderSystem.enableDepthTest();
66+
guiGraphics.blit(
67+
this.resourceLocation,
68+
this.getX(),
69+
this.getY(),
70+
(int) tx,
71+
(int) ty,
72+
this.width,
73+
this.height,
74+
this.textureWidth,
75+
this.textureHeight
76+
);
77+
/*if (this.isHoveredOrFocused())
4578
this.renderToolTip(poseStack, i, j);*/
46-
}
79+
}
4780

48-
private static void onPower(IMPBaseContainerScreen<?> screen) {
49-
screen.insPower(!screen.isPowered());
50-
}
81+
private static void onPower(IMPBaseContainerScreen<?> screen) {
82+
screen.insPower(!screen.isPowered());
83+
}
5184
}

0 commit comments

Comments
 (0)