Created
September 9, 2024 15:53
-
-
Save Densamisten/fec2061e4a58e587c2892cceabd7ddd0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package exonihility.client.gui; | |
import net.minecraft.client.gui.DrawContext; | |
import net.minecraft.client.gui.screen.Screen; | |
import net.minecraft.client.gui.widget.ButtonWidget; | |
import net.minecraft.entity.Entity; | |
import net.minecraft.text.Text; | |
public class EntityListScreen extends Screen { | |
private ScrollingEntityListWidget scrollingEntityList; | |
private Text selectedEntityName = Text.empty(); | |
public EntityListScreen(Text title) { | |
super(title); | |
} | |
@Override | |
protected void init() { | |
super.init(); | |
// Initialize the scrolling list widget | |
scrollingEntityList = new ScrollingEntityListWidget( | |
this.client, this.width, this.height, 20, this.height - 60, 40 | |
); | |
// Add the widget to the screen | |
this.addSelectableChild(scrollingEntityList); | |
// Add "Confirm" button to save changes | |
ButtonWidget confirmButton = ButtonWidget.builder(Text.literal("Confirm"), button -> { | |
Entity selectedEntity = scrollingEntityList.getSelectedEntity(); | |
if (selectedEntity != null) { | |
// Perform an action with the selected entity | |
System.out.println("Selected Entity Position: " + selectedEntity.getBlockPos()); | |
} else { | |
System.out.println("No entity selected."); | |
} | |
}) | |
.dimensions(this.width / 2 - 20, 50, 200, 20) | |
.build(); | |
addDrawableChild(confirmButton); | |
} | |
@Override | |
public void tick() { | |
scrollingEntityList.refreshList(); // Refresh the list periodically | |
} | |
@Override | |
public void render(DrawContext context, int mouseX, int mouseY, float delta) { | |
this.renderBackground(context, mouseX, mouseY, delta); // Render background | |
scrollingEntityList.render(context, mouseX, mouseY, delta); // Render the scrolling widget | |
// Draw the selected entity name | |
Entity selectedEntity = scrollingEntityList.getSelectedEntity(); | |
if (selectedEntity != null) { | |
selectedEntityName = Text.literal("Selected Entity: " + selectedEntity.getName().getString()); | |
} else { | |
selectedEntityName = Text.literal("No Entity Selected"); | |
} | |
context.drawCenteredTextWithShadow(this.textRenderer, selectedEntityName, this.width / 2, this.height - 20, 0xFFFFFF); | |
super.render(context, mouseX, mouseY, delta); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment