Fix crash

This commit is contained in:
modmuss50 2023-06-01 10:27:55 +01:00
parent bfd93753eb
commit 8ad2147c42
4 changed files with 20 additions and 8 deletions

View file

@ -70,7 +70,7 @@ public class CheckBoxElement extends ElementBase {
sprite = checkBoxSprite.ticked();
}
drawSprite(drawContext, gui, sprite, getX(), getY() );
drawText(drawContext, gui, label, getX() + getWidth() + 5, ((getY() + getHeight() / 2) - (gui.getTextRenderer().fontHeight / 2)), 0xFFFFFFFF);
drawText(drawContext, gui, label, getX() + 18, ((getY() + getHeight() / 2) - (gui.getTextRenderer().fontHeight / 2)), 0xFFFFFFFF);
}
}

View file

@ -26,6 +26,7 @@ package reborncore.client.gui.builder.slot.elements;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.texture.Sprite;
import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.text.Text;
import reborncore.client.gui.builder.GuiBase;
@ -59,11 +60,11 @@ public class ElementBase {
}
public int getWidth() {
return sprite.getSprite().getContents().getWidth();
return getGuiSprite(sprite).getContents().getWidth();
}
public int getHeight() {
return sprite.getSprite().getContents().getHeight();
return getGuiSprite(sprite).getContents().getHeight();
}
public boolean onClick(GuiBase<?> gui, double mouseX, double mouseY) {
@ -92,8 +93,17 @@ public class ElementBase {
drawContext.drawText(gui.getTextRenderer(), text, x, y, color, false);
}
public void drawSprite(DrawContext drawContext, GuiBase<?> gui, SpriteIdentifier sprite, int x, int y) {
drawContext.drawSprite(x + gui.getGuiLeft(), y + gui.getGuiTop(), 0, getWidth(), getHeight(), sprite.getSprite());
public void drawSprite(DrawContext drawContext, GuiBase<?> gui, SpriteIdentifier spriteIdentifier, int x, int y) {
final Sprite sprite = getGuiSprite(spriteIdentifier);
drawContext.drawSprite(
x + gui.getGuiLeft(),
y + gui.getGuiTop(),
0,
sprite.getContents().getWidth(),
sprite.getContents().getHeight(),
sprite
);
}
public void drawDefaultBackground(DrawContext drawContext, Screen gui, int x, int y, int width, int height) {
@ -102,4 +112,8 @@ public class ElementBase {
drawContext.drawTexture(GuiBuilder.defaultTextureSheet, x, y + height / 2, 0, 150 - height / 2, width / 2, height / 2);
drawContext.drawTexture(GuiBuilder.defaultTextureSheet, x + width / 2, y + height / 2, 150 - width / 2, 150 - height / 2, width / 2, height / 2);
}
private Sprite getGuiSprite(SpriteIdentifier spriteIdentifier) {
return GuiSpriteAtlasHolder.INSTANCE.getSprite(sprite.getTextureId());
}
}

View file

@ -28,10 +28,8 @@ import net.minecraft.client.texture.Sprite;
import net.minecraft.client.texture.SpriteAtlasHolder;
import net.minecraft.client.texture.TextureManager;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;
public class GuiSpriteAtlasHolder extends SpriteAtlasHolder {
@Nullable
public static GuiSpriteAtlasHolder INSTANCE;
public static final Identifier ATLAS_ID = new Identifier("reborncore", "textures/atlas/gui.png");

View file

@ -48,7 +48,7 @@ public class MixinMinecraftClient {
@Inject(method = "<init>", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/texture/PaintingManager;<init>(Lnet/minecraft/client/texture/TextureManager;)V"))
private void init(RunArgs args, CallbackInfo ci) {
GuiSpriteAtlasHolder.INSTANCE = new GuiSpriteAtlasHolder(this.textureManager);
this.resourceManager.registerReloader(GuiSpriteAtlasHolder.INSTANCE );
this.resourceManager.registerReloader(GuiSpriteAtlasHolder.INSTANCE);
}
@Inject(method = "close", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/texture/PaintingManager;close()V"))