- 40
- 3
- 1
Мне нужно добавлять id своё к каждой кнопке, в итоге добавляется к каждой кнопке последнее id;
render:
Button addStrength;
@Override
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) {
for( adaf = 0; adaf < names.size(); adaf++) {
buttons.clear();
buttons.add(addStrength = new GuiPlayersAdafik(adaf,(int)(width/1.4), (int)((height/3.28) + (adaf*cordYY)), width/48,(int)(height/25.45), 0,0, 0, BUTTON_ADD_STATS, (button) -> {
System.out.println(GuiPlayersAdafik.id);
}));
this.addButton(addStrength);
this.addStrength.render(matrixStack, mouseX,mouseY, partialTicks);
}
GuiPlayersAdafik:
copypast imagebutton
public class GuiPlayersAdafik extends Button {
private final ResourceLocation resourceLocation;
private final int xTexStart;
private final int yTexStart;
private final int yDiffTex;
private final int textureWidth;
private final int textureHeight;
public static int id;
public GuiPlayersAdafik(int id,int p_i51134_1_, int p_i51134_2_, int p_i51134_3_, int p_i51134_4_, int p_i51134_5_, int p_i51134_6_, int p_i51134_7_, ResourceLocation p_i51134_8_, Button.IPressable p_i51134_9_) {
this(id,p_i51134_1_, p_i51134_2_, p_i51134_3_, p_i51134_4_, p_i51134_5_, p_i51134_6_, p_i51134_7_, p_i51134_8_, 256, 256, p_i51134_9_);
}
public GuiPlayersAdafik(int id,int p_i51135_1_, int p_i51135_2_, int p_i51135_3_, int p_i51135_4_, int p_i51135_5_, int p_i51135_6_, int p_i51135_7_, ResourceLocation p_i51135_8_, int p_i51135_9_, int p_i51135_10_, Button.IPressable p_i51135_11_) {
this(id,p_i51135_1_, p_i51135_2_, p_i51135_3_, p_i51135_4_, p_i51135_5_, p_i51135_6_, p_i51135_7_, p_i51135_8_, p_i51135_9_, p_i51135_10_, p_i51135_11_, StringTextComponent.EMPTY);
}
public GuiPlayersAdafik(int id,int p_i232261_1_, int p_i232261_2_, int p_i232261_3_, int p_i232261_4_, int p_i232261_5_, int p_i232261_6_, int p_i232261_7_, ResourceLocation p_i232261_8_, int p_i232261_9_, int p_i232261_10_, Button.IPressable p_i232261_11_, ITextComponent p_i232261_12_) {
this(id,p_i232261_1_, p_i232261_2_, p_i232261_3_, p_i232261_4_, p_i232261_5_, p_i232261_6_, p_i232261_7_, p_i232261_8_, p_i232261_9_, p_i232261_10_, p_i232261_11_, NO_TOOLTIP, p_i232261_12_);
}
public GuiPlayersAdafik(int id,int p_i244513_1_, int p_i244513_2_, int p_i244513_3_, int p_i244513_4_, int p_i244513_5_, int p_i244513_6_, int p_i244513_7_, ResourceLocation p_i244513_8_, int p_i244513_9_, int p_i244513_10_, Button.IPressable p_i244513_11_, Button.ITooltip p_i244513_12_, ITextComponent p_i244513_13_) {
super(p_i244513_1_, p_i244513_2_, p_i244513_3_, p_i244513_4_, p_i244513_13_, p_i244513_11_, p_i244513_12_);
this.textureWidth = p_i244513_9_;
this.textureHeight = p_i244513_10_;
this.xTexStart = p_i244513_5_;
this.yTexStart = p_i244513_6_;
this.yDiffTex = p_i244513_7_;
this.resourceLocation = p_i244513_8_;
this.id = id;
}
public void setPosition(int p_191746_1_, int p_191746_2_) {
this.x = p_191746_1_;
this.y = p_191746_2_;
}
public void renderButton(MatrixStack p_230431_1_, int p_230431_2_, int p_230431_3_, float p_230431_4_) {
Minecraft minecraft = Minecraft.getInstance();
minecraft.getTextureManager().bind(this.resourceLocation);
int i = this.yTexStart;
if (this.isHovered()) {
i += this.yDiffTex;
}
RenderSystem.enableDepthTest();
blit(p_230431_1_, this.x, this.y, (float)this.xTexStart, (float)i, this.width, this.height, this.textureWidth, this.textureHeight);
if (this.isHovered()) {
this.renderToolTip(p_230431_1_, p_230431_2_, p_230431_3_);
}
}
}