Skip to content

Commit

Permalink
Fix backport
Browse files Browse the repository at this point in the history
  • Loading branch information
Zailer43 committed Sep 16, 2024
1 parent 5130c56 commit 1b5f442
Show file tree
Hide file tree
Showing 9 changed files with 53 additions and 46 deletions.
10 changes: 10 additions & 0 deletions src/main/java/fzmm/zailer/me/builders/DisplayBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,16 @@ public DisplayBuilder addLore(Text lore) {
return this;
}

public DisplayBuilder addLore(List<Text> loreList) {
NbtList oldLore = this.getLore();

for (var lore : loreList) {
oldLore.add(FzmmUtils.toNbtString(lore, true));
}
this.setLore(oldLore);
return this;
}

public DisplayBuilder addLore(Text lore, int messageColor) {
return this.addLore(lore.copy().setStyle(Style.EMPTY.withColor(messageColor)));
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/fzmm/zailer/me/builders/SignBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ private SignBuilder addLine(NbtList list, NbtString nbtString) {
return this;
}

public SignBuilder addFrontLine(Text nbtString, int expectedWidth) {
return this.addLine(this.frontTextList, nbtString, expectedWidth);
public SignBuilder addFrontLine(Text text, int expectedWidth) {
return this.addLine(this.frontTextList, text, expectedWidth);
}

public SignBuilder addBackLine(Text text, int expectedWidth) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package fzmm.zailer.me.client.gui.components.style.component;

import fzmm.zailer.me.client.FzmmClient;
import io.wispforest.owo.ui.component.LabelComponent;
import net.minecraft.text.Text;

Expand All @@ -10,10 +9,10 @@ public StyledLabelComponent(Text text) {
super(text);

// improves text readability with translucent background
boolean oldBackground = FzmmClient.CONFIG.guiStyle.oldBackground();
if (!oldBackground) {
this.shadow(true);
}
// boolean oldBackground = FzmmClient.CONFIG.guiStyle.oldBackground();
// if (!oldBackground) {
// this.shadow(true);
// }
}

private Text applyStyle(Text text) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package fzmm.zailer.me.client.gui.components.style.container;

import fzmm.zailer.me.client.FzmmClient;
import fzmm.zailer.me.client.gui.components.style.StyledContainers;
import io.wispforest.owo.ui.container.FlowLayout;
import io.wispforest.owo.ui.core.OwoUIDrawContext;
Expand Down Expand Up @@ -32,8 +31,9 @@ public Surface styledPanel() {
}

public Surface styledBackground() {
boolean useOldVanillaBackground = FzmmClient.CONFIG.guiStyle.oldBackground();
return useOldVanillaBackground ? Surface.VANILLA_TRANSLUCENT : Surface.OPTIONS_BACKGROUND;
// boolean useOldVanillaBackground = FzmmClient.CONFIG.guiStyle.oldBackground();
// return useOldVanillaBackground ? Surface.VANILLA_TRANSLUCENT : Surface.OPTIONS_BACKGROUND;
return Surface.VANILLA_TRANSLUCENT;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,9 @@ public void updatePreview(boolean isExecute) {

this.generateImagetext(image.get(), isExecute);
Text text = this.imagetextLogic.getText();
List<Text> wrappedText = this.imagetextLogic.getWrappedText();

ItemStack placeholderStack = DisplayBuilder.builder().addLore(text).get();
ItemStack placeholderStack = DisplayBuilder.builder().addLore(wrappedText).get();
String nbtSize = FzmmUtils.getLengthInKB(FzmmUtils.getLengthInBytes(placeholderStack));
String textSize = FzmmUtils.getLengthInKB(Text.Serialization.toJsonString(text).length());

Expand Down Expand Up @@ -373,15 +374,6 @@ private void generateImagetext(BufferedImage image, boolean isExecute) {
if (showResolution) {
this.imagetextLogic.addResolution();
}

Text text = this.imagetextLogic.getText();

ItemStack placeholderStack = DisplayBuilder.builder().addLore(this.imagetextLogic.getText()).get();
String nbtSize = FzmmUtils.getLengthInKB(FzmmUtils.getLengthInBytes(placeholderStack));
String textSize = FzmmUtils.getLengthInKB(Text.Serialization.toJsonString(text).length());

this.previewLabel.text(text);
this.previewLabel.tooltip(Text.translatable("fzmm.gui.imagetext.label.imagetextSize", nbtSize, textSize));
}

private void updateAspectRatio(BufferedImage image) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import net.minecraft.text.Text;
import net.minecraft.util.Hand;

import java.util.List;

public class ImagetextLoreTab implements IImagetextTab {
private static final String LORE_MODE_ID = "loreMode";
private ContextMenuButton loreModeButton;
Expand All @@ -29,7 +31,7 @@ public void generate(IImagetextAlgorithm algorithm, ImagetextLogic logic, Imaget
@Override
public void execute(ImagetextLogic logic) {
ItemStack stack = this.getStack(this.loreMode);
Text imagetext = logic.getText();
List<Text> imagetext = logic.getWrappedText();

DisplayBuilder display = DisplayBuilder.of(stack);
display.addLore(imagetext).get();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/fzmm/zailer/me/config/FzmmConfigModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public static class GuiStyleNest {
// no background, and it lacks application in some parts like in the dropdowns,
// besides it looks inconsistent because the buttons have white text
// public boolean darkMode = true;
public boolean oldBackground = false;
// public boolean oldBackground = false;
public boolean persistentScrollbar = true;
}

Expand Down
51 changes: 28 additions & 23 deletions src/main/java/fzmm/zailer/me/utils/FzmmUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,29 +96,34 @@ public static void giveItem(ItemStack stack) {
MinecraftClient client = MinecraftClient.getInstance();
assert client.player != null;

long sizeLength = getLengthInBytes(stack) + getInventorySizeInBytes();
if (sizeLength > 1950000) {
snackBarManager.add(BaseSnackBarComponent.builder(SnackBarManager.GIVE_ID)
.title(Text.translatable("fzmm.giveItem.error"))
.details(Text.translatable("fzmm.giveItem.exceedLimit",
getLengthInKB(sizeLength),
getLengthInKB(2000000L)
))
.backgroundColor(FzmmStyles.ALERT_ERROR_COLOR)
.keepOnLimit()
.button(snackBar -> Components.button(Text.translatable("fzmm.gui.title.configs.icon"),
buttonComponent -> {
client.setScreen(ConfigScreen.create(FzmmClient.CONFIG, client.currentScreen));
snackBar.close();
}))
.highTimer()
.startTimer()
.closeButton()
.expandDetails()
.build()
);

FzmmClient.LOGGER.warn("[FzmmUtils] An attempt was made to give an item with size of {} bytes", sizeLength);
if (FzmmClient.CONFIG.general.giveItemSizeLimit()) {
long stackSize = getLengthInBytes(stack);
long inventorySize = getInventorySizeInBytes();
if ((stackSize + inventorySize) > 8000000) {
snackBarManager.add(BaseSnackBarComponent.builder(SnackBarManager.GIVE_ID)
.title(Text.translatable("fzmm.giveItem.error"))
.details(Text.translatable("fzmm.giveItem.exceedLimit",
getLengthInKB(stackSize + inventorySize),
getLengthInKB(8000000L)
))
.backgroundColor(FzmmStyles.ALERT_ERROR_COLOR)
.keepOnLimit()
.button(snackBar -> Components.button(Text.translatable("fzmm.gui.title.configs.icon"),
buttonComponent -> {
client.setScreen(ConfigScreen.create(FzmmClient.CONFIG, client.currentScreen));
snackBar.close();
}))
.highTimer()
.startTimer()
.closeButton()
.expandDetails()
.build()
);

FzmmClient.LOGGER.warn("[FzmmUtils] An attempt was made to give an item with size of {} bytes (with {} bytes already in inventory)",
stackSize, inventorySize);
return;
}
}

if (Items.PLAYER_HEAD == stack.getItem())
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/fzmm.accesswidener
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ accessible class net/minecraft/client/gui/EditBox$Substring

accessible method net/minecraft/client/util/ScreenshotRecorder getScreenshotFilename (Ljava/io/File;)Ljava/io/File;
accessible method net/minecraft/client/MinecraftClient doItemUse ()V
accessible method net/minecraft/component/type/WrittenBookContentComponent exceedsSerializedLengthLimit (Lnet/minecraft/text/Text;Lnet/minecraft/registry/RegistryWrapper$WrapperLookup;)Z

accessible field net/minecraft/client/gui/screen/ingame/BookScreen MAX_TEXT_WIDTH I
accessible field net/minecraft/client/gui/screen/ingame/BookScreen MAX_TEXT_HEIGHT I
Expand Down

0 comments on commit 1b5f442

Please sign in to comment.