Jump to content

Recommended Posts

Posted

I'm trying to create a custom screen for the first time and I came across two problems.

  1. How can I add a picture in the center? ( I want to have like 3 layers:     black background (this.renderBackground(PoseStack)) ---> texture.png on top of black background ---> Text/Buttons on top of everything [ if this isn't posible with Screen, tell me with what I can realise that pls ])
  2. How can I fix my Button problem

 

Code:

public class QuestScreen extends Screen {
	private final ResourceLocation backgroundTexture = new ResourceLocation(Tutorialmod.MODID, "textures/screens/quest_background.png");

	public QuestScreen(String title) {
		super(Component.literal(title).withStyle(ChatFormatting.GOLD));
	}
	
	@Override
	protected void init() {
		addRenderableWidget(new Button(this.width/2 - 100, this.height/2 + 50, 100, 50, Component.literal("Accept"), QuestScreen::onAccept));
	}
	
	public void render(PoseStack p_96692_, int p_96693_, int p_96694_, float p_96695_) {
	      this.renderBackground(p_96692_);
	      drawCenteredString(p_96692_, this.font, this.title, this.width / 2, 20, 16777215);
	      super.render(p_96692_, p_96693_, p_96694_, p_96695_);
	}
	
	private static void onAccept(Button button) {
	}
	
	@Override
	public boolean isPauseScreen() {
		return false;
	}
}

 

Posted (edited)

For the background look at something like the ErrorScreen which uses fillGradient()

Looks like there is also a plain fill() method in GuiComponent

 

For the image look at something like the AdvancementScreen which uses blit() to put this image on screen

https://github.com/misode/mcmeta/blob/assets/assets/minecraft/textures/gui/advancements/window.png

 

Your button is broken because you made it too tall.

If you look at AbstractWidgets.renderButton() and the widgets image, the button is 20 "pixels". See Button.DEFAULT_HEIGHT

Above that are different variants of the button meant for animating the press. You are using 50 so you are drawing more of this image than you want.

https://github.com/misode/mcmeta/blob/assets/assets/minecraft/textures/gui/widgets.png

Edited by warjort

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Posted

Ok Thank you I will have a look into that. There is only one last question I need answered.

What is the last paramter for in the method drawCenteredString() (I looked at minecraft code and they set it either to -1 or 16777215) and is there a way I can make only ONE Component.translatable() with text that goes multiple lines, because sadly it doesn't work with \n

 

For example: "This is the first line.\nThis is the second line"

Output:

This is the first line.

This is the second line

Posted

I don't answer "what does this parameter do" questions unless it is non-trivial. You can read the code just as well as I can.

Or you can install parchment to get more meaningful parameter names and some javadoc.

https://parchmentmc.org/

 

There is no multi line button in vanilla minecraft AFAIK. If you want one, you will have to write it yourself, see the other MultiLine* widgets.

Or you can you use a library mod that somebody else has written that has this feature.

 

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.