Skip to content

Commit

Permalink
update Neo and remove NoShadowTextBox
Browse files Browse the repository at this point in the history
  • Loading branch information
IchHabeHunger54 committed Jul 18, 2024
1 parent c7fa5e7 commit 8575167
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 60 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod_version=1.0.0
mod_name=Bibliocraft Legacy
mod_vendor=MinecraftschurliMods
mod_authors=IchHabeHunger54, Minecraftschurli
mod_credits=Nuchaz (original mod author), XFactHD (help with models), the NeoForge Discord team (overall help)
mod_credits=Nuchaz (original mod author), XFactHD (help with models), the NeoForge Discord team and community (overall help)
mod_logo=logo.png
mod_description=Bibliocraft Legacy is a port of the original BiblioCraft Minecraft mod by Nuchaz. It adds various pieces of decorative and functional furniture into the game.
mod_url=https://www.curseforge.com/minecraft/mc-mods/bibliocraft-legacy
Expand All @@ -28,7 +28,7 @@ neoForge.parchment.mappingsVersion=2024.06.23
mc_version=1.21
mc_version_range=[1.21,1.21.1)

neo_version=21.0.42-beta
neo_version=21.0.106-beta
neo_version_range=[21.0.31,21.1)

junit_version=5.7.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,20 @@
import com.github.minecraftschurlimods.bibliocraft.content.clipboard.ClipboardItemSyncPacket;
import com.github.minecraftschurlimods.bibliocraft.init.BCDataComponents;
import com.github.minecraftschurlimods.bibliocraft.util.BCUtil;
import net.minecraft.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.Font;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.EditBox;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.gui.screens.inventory.PageButton;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.network.chat.CommonComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.item.ItemStack;
import net.neoforged.neoforge.network.PacketDistributor;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.function.Consumer;

public class ClipboardScreen extends Screen {
private static final ResourceLocation BACKGROUND = BCUtil.modLoc("textures/gui/clipboard.png");
Expand All @@ -51,7 +45,9 @@ public void onClose() {
@Override
protected void init() {
int x = (width - 192) / 2;
titleBox = addRenderableWidget(new NoShadowEditBox(x + 57, 14, 72, e -> data.setTitle(e)));
titleBox = addRenderableWidget(new EditBox(getMinecraft().font, x + 57, 14, 72, 8, Component.empty()));
titleBox.setTextShadow(false);
titleBox.setResponder(e -> data.setTitle(e));
for (int i = 0; i < ClipboardContent.MAX_LINES; i++) {
final int j = i; // I love Java
checkboxes[i] = addRenderableWidget(new CheckboxButton(x + 30, 15 * i + 26, e -> {
Expand All @@ -62,14 +58,16 @@ protected void init() {
pages.set(data.active(), page.setCheckboxes(checkboxes));
data = data.setPages(pages);
}));
lines[i] = addRenderableWidget(new NoShadowEditBox(x + 45, 15 * i + 28, 109, e -> {
lines[i] = addRenderableWidget(new EditBox(getMinecraft().font, x + 45, 15 * i + 28, 109, 8, Component.empty()));
lines[i].setTextShadow(false);
lines[i].setResponder(e -> {
List<ClipboardContent.Page> pages = new ArrayList<>(data.pages());
ClipboardContent.Page page = pages.get(data.active());
List<String> lines = new ArrayList<>(page.lines());
lines.set(j, e);
pages.set(data.active(), page.setLines(lines));
data = data.setPages(pages);
}));
});
}
forwardButton = addRenderableWidget(new PageButton(x + 116, 159, true, $ -> {
data = data.nextPage();
Expand Down Expand Up @@ -107,55 +105,6 @@ private void updateContents() {
}
}

// Necessary to allow rendering the text without a shadow.
private static class NoShadowEditBox extends EditBox {
private static final int TEXT_COLOR = 0x404040;

public NoShadowEditBox(int x, int y, int width, Consumer<String> responder) {
super(Minecraft.getInstance().font, x, y, width, 8, Component.empty());
setResponder(responder);
}

@Override
public void renderWidget(GuiGraphics graphics, int mouseX, int mouseY, float partialTick) {
if (!isVisible()) return;
Font font = Minecraft.getInstance().font;
int posOnScreen = getCursorPosition() - displayPos;
String visibleText = font.plainSubstrByWidth(getValue().substring(displayPos), getInnerWidth());
boolean cursorInside = posOnScreen >= 0 && posOnScreen <= visibleText.length();
boolean shouldDrawCursor = isFocused() && cursorInside && (Util.getMillis() - focusedTime) / 300L % 2L == 0L;
int x = getX();
int y = getY();
int width = x;
int highlightStart = Mth.clamp(highlightPos - displayPos, 0, visibleText.length());
if (!visibleText.isEmpty()) {
width = graphics.drawString(font, formatter.apply(cursorInside ? visibleText.substring(0, posOnScreen) : visibleText, displayPos), x, y, TEXT_COLOR, false);
}
boolean eol = getCursorPosition() < getValue().length() || getValue().length() >= getMaxLength();
int cursorX = width;
if (!cursorInside) {
cursorX = posOnScreen > 0 ? x + this.width : x;
} else if (eol) {
cursorX = width - 1;
width--;
}
if (!visibleText.isEmpty() && cursorInside && posOnScreen < visibleText.length()) {
graphics.drawString(font, formatter.apply(visibleText.substring(posOnScreen), getCursorPosition()), width, y, TEXT_COLOR, false);
}
if (shouldDrawCursor) {
if (eol) {
graphics.fill(RenderType.guiOverlay(), cursorX, y - 1, cursorX + 1, y + 1 + 9, -3092272);
} else {
graphics.drawString(font, "_", cursorX, y, TEXT_COLOR, false);
}
}
if (highlightStart != posOnScreen) {
int highlight = x + font.width(visibleText.substring(0, highlightStart));
renderHighlight(graphics, cursorX, y - 1, highlight - 1, y + 1 + 9);
}
}
}

private static class CheckboxButton extends Button {
private static final ResourceLocation CHECK_TEXTURE = BCUtil.modLoc("check");
private static final ResourceLocation X_TEXTURE = BCUtil.modLoc("x");
Expand Down

0 comments on commit 8575167

Please sign in to comment.