Jump to content

How to have a scrollable list of options on a screen? [1.19.2] [SOLVED]


RInventor7

Recommended Posts

Hi! I have a custom block entity, which has a screen. I have managed to get the EditBox and a CheckBox working. Now I want to add a scrollable list of strings where the player can choose between options and finally select one, which would then open another screen according to the selection made by the player.  How to achieve this long list with a  scrollbar that would open another screen after selecting? What GUI component should I use for that? And are there any examples available somewhere? Thanks in advance. 

Edited by RInventor7
Link to comment
Share on other sites

ObjectSelectionList. e.g. CreateBuffetWorldScreen.BiomeList

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.

Link to comment
Share on other sites

Thanks, that did the trick. Everything works fine, but it renders the dirt background for some reason. I want to render my own texture and it actually does render below the dirt background. Is there any way to stop the dirt background from rendering?

 

Here's my code:

package com.rinventor....;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Nullable;

import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.rinventor.transportmod.MyMod;
import com.rinventor.transportmod.core.init.ModNetwork;

import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiComponent;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.ObjectSelectionList;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

public class CScreen8 extends AbstractContainerScreen<CMenu8> {
	private final Player entity;
	private final Component data;
	private CScreen8.LinesList list;
	String line;
	List<String> lines;

	public CScreen8(CMenu8 container, Inventory inventory, Component text) {
		super(container, inventory, text);
		this.entity = container.entity;
		this.imageWidth = 320;
		this.imageHeight = 240;
		this.data = text;
		this.line = "";
		this.lines = new ArrayList<String>(List.of("A", "B", "C"));
	}

	private static final ResourceLocation texture = new ResourceLocation(MyMod.MOD_ID + ":textures/cmenu.png");

	@Override
	public void render(PoseStack ms, int mouseX, int mouseY, float partialTicks) {
		this.renderBackground(ms);
		super.render(ms, mouseX, mouseY, partialTicks);
		this.renderTooltip(ms, mouseX, mouseY);
		this.list.render(ms, mouseX, mouseY, partialTicks);
	}

	@Override
	protected void renderBg(PoseStack ms, float partialTicks, int gx, int gy) {
		RenderSystem.setShaderColor(1, 1, 1, 1);
		RenderSystem.setShaderTexture(0, texture);
		GuiComponent.blit(ms, this.leftPos, this.topPos, 0, 0, imageWidth, 198, imageWidth, imageHeight);
	}

	@Override
	public boolean keyPressed(int key, int b, int c) {
		if (key == 256) {
			this.minecraft.player.closeContainer();
			return true;
		}
		return super.keyPressed(key, b, c);
	}

	@Override
	protected void renderLabels(PoseStack ps, int mouseX, int mouseY) {
		String id = "menu1.transport";
		String id = data.getString().trim();
		this.font.draw(ps, Component.translatable(id).getString(), 7, 7, -16711792);
	}

	@SuppressWarnings("resource")
	@Override
	public void onClose() {
		super.onClose();
		Minecraft.getInstance().keyboardHandler.setSendRepeatsToGui(false);
	}

	@Override
	public void init() {
		super.init();
		this.minecraft.keyboardHandler.setSendRepeatsToGui(true);

		this.list = new CScreen8.LinesList();
		this.addWidget(this.list);

		this.addRenderableWidget(new Button(leftPos + imageWidth - 24, topPos + 4, 20, 20, Component.literal("<-"), e -> {
			ModNetwork.INSTANCE.sendToServer(new CScreenButtonMessage(7, ""));
			CScreenButtonMessage.handleButtonAction(entity, 7, "");
		}));
	}

	@OnlyIn(Dist.CLIENT)
	class LinesList extends ObjectSelectionList<CScreen8.LinesList.Entry> {
		LinesList() {
			super(CScreen8.this.minecraft, CScreen8.this.width-150, CScreen8.this.height-150, 50, CScreen8.this.height - 37, 16);
			for (String l : CScreen8.this.lines) {
				this.addEntry(new CScreen8.LinesList.Entry(l));
			}
		}

		protected boolean isFocused() {
			return CScreen8.this.getFocused() == this;
		}

		public void setSelected(@Nullable CScreen8.LinesList.Entry entry) {
			super.setSelected(entry);
			if (entry != null) {
				CScreen8.this.line = entry.line;
			}
			// AFTER SELECTED ->
//			ModNetwork.INSTANCE.sendToServer(new CScreenButtonMessage(0, "test"));
//			CScreenButtonMessage.handleButtonAction(entity, 0, "test");
		}

		@OnlyIn(Dist.CLIENT)
		class Entry extends ObjectSelectionList.Entry<CScreen8.LinesList.Entry> {
			final String line;

			public Entry(String entry) {
				this.line = entry;
			}

			public Component getNarration() {
				return Component.translatable("narrator.select", this.line);
			}

			public void render(PoseStack p_95802_, int p_95803_, int p_95804_, int p_95805_, int p_95806_, int p_95807_, int p_95808_, int p_95809_,
					boolean p_95810_, float p_95811_) {
				GuiComponent.drawString(p_95802_, CScreen8.this.font, this.line, p_95805_ + 5, p_95804_ + 2, 16777215);
			}

			public boolean mouseClicked(double p_95798_, double p_95799_, int p_95800_) {
				if (p_95800_ == 0) {
					LinesList.this.setSelected(this);
					return true;
				}
				else {
					return false;
				}
			}
		}
	}

}

 

Link to comment
Share on other sites

AbstractSelectionList.setRenderBackground()

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.

Link to comment
Share on other sites

  • RInventor7 changed the title to How to have a scrollable list of options on a screen? [1.19.2] [SOLVED]

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.



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • So, I started a Forge server which is hosted by cloudnord (don't know it this information is necessary or not). Everything's working fine, the mods are getting loaded, I can join and play on it. Then I wanted to give myself OP. That's where the problems began. I typed "op mc_nicky_com" in the console and just saw, that I automatically disconnected... Weird, I thought and promptly updated the forge version to the client sided version, 47.2.17. Nothing resolved. Thought of downgrading the server to 47.2.0 but still didn't work. Now the server is on 47.2.0 and I can play without OP, which is totally fine but if I want to do something only OPs can do, I have to put it into the console, where I don't have auto-completion. The error it is throwing is the following: io.netty.handler.codec.DecoderException: java.lang.IndexOutOfBoundsException: readerIndex(31613) + length(1) exceeds writerIndex(31613): UnpooledHeapByteBuf(ridx: 31613, widx: 31613, cap: 31613/31613) I don't know how to fix this and I am thankful for every help attempt that comes here.  With best regards nicky.gg
    • Official Website Link ➲➲➲  https://groups.google.com/a/chromium.org/g/chromium-reviews/c/Zyy6WGX5-gA   Product Name ➲➲➲ Keto Candies ACV Gummies It assists with smothering undesirable food desires and close to home dietary patterns.   Official facebook Link ➲➲➲  https://www.facebook.com/KetoCandiesACVGummiesUS/   Official Blogs ➲➲➲ https://groups.google.com/a/chromium.org/g/chromium-reviews/c/4LZAdq7rQSg https://groups.google.com/g/mozilla.dev.platform/c/Uy2KvvUkCbA https://groups.google.com/g/mozilla.dev.platform/c/L-RBHHTlJm0 https://groups.google.com/g/comp.protocols.time.ntp/c/aqbT3woiM9w https://groups.google.com/g/comp.protocols.time.ntp/c/L3J_LIFnET0 https://groups.google.com/a/chromium.org/g/chromium-reviews/c/Zyy6WGX5-gA https://groups.google.com/a/chromium.org/g/chromium-reviews/c/4LZAdq7rQSg https://keto-candies-acv-gummies-2b37b5.webflow.io/ https://keto-candies-acv-gummies-1.jimdosite.com/ https://groups.google.com/g/getketocandiesacvgummies/c/PaSsvPpQsYw https://groups.google.com/g/getketocandiesacvgummies/c/YLKzSrTdeRI   Blue Vibe CBD Gummies Official Links ➲➲➲  https://www.deccanherald.com/brandspot/sponsored-health/blue-vibe-cbd-gummies-reviews-moneyworth-product-or-not-blue-vibe-cbd-gummies-for-sale-consumer-reports-mega-sale-2673730 https://www.facebook.com/GetBlueVibeCBDGummiesUS/ https://www.facebook.com/BlueVibeCBDGummiesUS/ https://www.facebook.com/BlueVibeCBDGummiesInUS/ https://www.facebook.com/events/334310428943928 https://groups.google.com/a/chromium.org/g/chromium-reviews/c/eq2xmAl5Mm4 https://groups.google.com/a/chromium.org/g/chromium-reviews/c/yb2GhvIIBvI Group Google ➲➲  https://groups.google.com/a/chromium.org/g/chromium-reviews/c/LEwhDmgZLHs Group Google ➲➲  https://groups.google.com/a/chromium.org/g/chromium-reviews/c/gREHzPUfMsw Group Google ➲➲  https://groups.google.com/a/chromium.org/g/chromium-reviews/c/FNtpXHp_r7c Group Google ➲➲  https://groups.google.com/a/chromium.org/g/chromium-reviews/c/KqdhsIEuP8k Group Google ➲➲  https://groups.google.com/a/chromium.org/g/chromium-reviews/c/XfZtZqnG-rM Group Google ➲➲ https://groups.google.com/g/comp.os.vms/c/DGXPLV27qCU Group Google ➲➲ https://groups.google.com/g/comp.os.vms/c/t-W4cjZOFSs Group Google ➲➲ https://groups.google.com/g/comp.os.vms/c/i0Ta7Qy4izw
    • Make a test without practical_plushies_mobs, practical_plushies_animals and dark-waters - looks like it is not working with sinytra connector
    • VIP Call Girlfriend in Abu Dhabi ☮➡+971557861567(㎓) Escorts In Abu Dhabi   VIP Call Girlfriend in Abu Dhabi ☮➡+971557861567(㎓) Escorts In Abu Dhabi   VIP Call Girlfriend in Abu Dhabi ☮➡+971557861567(㎓) Escorts In Abu Dhabi
  • Topics

×
×
  • Create New...

Important Information

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