Skip to content

Instantly share code, notes, and snippets.

@Ensamisten
Created June 2, 2026 10:53
Show Gist options
  • Select an option

  • Save Ensamisten/40f4c6c4736c3fd7133ba34bff21e3f8 to your computer and use it in GitHub Desktop.

Select an option

Save Ensamisten/40f4c6c4736c3fd7133ba34bff21e3f8 to your computer and use it in GitHub Desktop.
package io.github.ensamisten.client.gui;
import io.github.ensamisten.Allyship;
import io.github.ensamisten.client.AllyshipClient;
import io.github.ensamisten.client.gui.widget.ScrollingEntityListWidget;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphicsExtractor;
import net.minecraft.client.gui.components.ImageButton;
import net.minecraft.client.gui.components.Tooltip;
import net.minecraft.client.gui.components.WidgetSprites;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.Identifier;
import net.minecraft.world.entity.Entity;
import org.jspecify.annotations.NonNull;
public class EntityListScreen extends Screen {
private final Screen parent;
private ScrollingEntityListWidget scrollingEntityList;
// ── Button sprites ────────────────────────────────────────────
private static final WidgetSprites UUID_SPRITES = new WidgetSprites(
Identifier.fromNamespaceAndPath(Allyship.MOD_ID, "uuid_button")
);
private static final WidgetSprites POSITION_SPRITES = new WidgetSprites(
Identifier.fromNamespaceAndPath(Allyship.MOD_ID,"position_button")
);
public EntityListScreen(Component title, Screen parent) {
super(title);
this.parent = parent;
}
@Override
protected void init() {
super.init();
int listX = 10;
int listY = 30;
int listW = this.width - 20;
int listH = this.height - listY - 60;
scrollingEntityList = new ScrollingEntityListWidget(
this.minecraft, listX, listY, listW, listH
);
this.addRenderableWidget(scrollingEntityList);
// ── Back button ───────────────────────────────────────────
addRenderableWidget(net.minecraft.client.gui.components.Button.builder(
Component.literal("Back"),
_ -> minecraft.setScreen(parent))
.bounds(this.width / 2 - 50, this.height - 46, 100, 20)
.build());
// ── Position image button ─────────────────────────────────
// Copies "X Y Z" to clipboard
// Sprite: assets/allyship/textures/gui/sprites/position_button.png
ImageButton positionButton = getPositionButton();
addRenderableWidget(positionButton);
// ── UUID image button ─────────────────────────────────────
// Copies UUID string to clipboard
// Sprite: assets/allyship/textures/gui/sprites/uuid_button.png
ImageButton uuidButton = getUuidButton();
addRenderableWidget(uuidButton);
}
private @NonNull ImageButton getUuidButton() {
ImageButton uuidButton = new ImageButton(
this.width / 2 + 56, // x — right of Back button
this.height - 46, // y — same row
20, // width
20, // height
UUID_SPRITES,
_ -> {
Entity selected = scrollingEntityList.getSelectedEntity();
if (selected != null) {
Minecraft.getInstance().keyboardHandler.setClipboard(
selected.getUUID().toString());
}
},
Component.literal("Copy UUID")
);
uuidButton.setTooltip(Tooltip.create(
Component.literal("Copy entity UUID to clipboard")));
return uuidButton;
}
private @NonNull ImageButton getPositionButton() {
ImageButton positionButton = new ImageButton(
this.width / 2 - 76, // x — left of Back button
this.height - 46, // y — same row
20, // width
20, // height
POSITION_SPRITES,
_ -> {
Entity selected = scrollingEntityList.getSelectedEntity();
if (selected != null) {
var pos = selected.blockPosition();
String coords = pos.getX() + " " + pos.getY() + " " + pos.getZ();
Minecraft.getInstance().keyboardHandler.setClipboard(coords);
}
},
Component.literal("Copy Position")
);
positionButton.setTooltip(Tooltip.create(
Component.literal("Copy entity position to clipboard")));
return positionButton;
}
@Override
public void tick() {
scrollingEntityList.refreshList();
}
@Override
public void extractRenderState(@NonNull GuiGraphicsExtractor graphics,
int mouseX, int mouseY, float delta) {
super.extractRenderState(graphics, mouseX, mouseY, delta);
// Screen title
graphics.centeredText(this.font, this.title,
this.width / 2, 10, 0xFFFFFF);
// Selected entity label
Entity selected = scrollingEntityList.getSelectedEntity();
Component label = selected != null
? Component.literal("Selected: " + selected.getName().getString())
: Component.literal("No Entity Selected");
graphics.centeredText(this.font, label,
this.width / 2, this.height - 20, 0xAAAAAA);
}
@Override
public void onClose() {
super.onClose();
Minecraft.getInstance().setScreen(parent);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment