From be7b641955a197d55251c3cbd4a314476cf94fb3 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Thu, 30 Apr 2020 01:08:07 +0800 Subject: Update to 20w18a and add recipe exporter Signed-off-by: shedaniel --- .../shedaniel/rei/RoughlyEnoughItemsNetwork.java | 8 +- .../shedaniel/rei/gui/ContainerScreenOverlay.java | 22 +- .../me/shedaniel/rei/gui/OverlaySearchField.java | 4 +- .../shedaniel/rei/gui/PreRecipeViewingScreen.java | 2 +- .../shedaniel/rei/gui/RecipeDisplayExporter.java | 147 +++-------- .../me/shedaniel/rei/gui/RecipeViewingScreen.java | 6 +- .../rei/gui/VillagerRecipeViewingScreen.java | 6 +- .../shedaniel/rei/gui/WarningAndErrorScreen.java | 14 +- .../rei/gui/config/entry/FilteringEntry.java | 15 +- .../rei/gui/credits/CreditsEntryListWidget.java | 8 +- .../shedaniel/rei/gui/credits/CreditsScreen.java | 2 +- .../rei/gui/modules/GameModeMenuEntry.java | 108 -------- .../java/me/shedaniel/rei/gui/modules/Menu.java | 280 +++++++++++++++++++++ .../me/shedaniel/rei/gui/modules/MenuEntry.java | 44 ++++ .../rei/gui/modules/WeatherMenuEntry.java | 109 -------- .../entries/EntryStackSubsetsMenuEntry.java | 140 +++++++++++ .../rei/gui/modules/entries/GameModeMenuEntry.java | 108 ++++++++ .../gui/modules/entries/SubSubsetsMenuEntry.java | 233 +++++++++++++++++ .../rei/gui/modules/entries/WeatherMenuEntry.java | 109 ++++++++ .../me/shedaniel/rei/gui/subsets/SubsetsMenu.java | 280 --------------------- .../rei/gui/subsets/SubsetsMenuEntry.java | 44 ---- .../gui/subsets/entries/EntryStackMenuEntry.java | 140 ----------- .../rei/gui/subsets/entries/SubMenuEntry.java | 233 ----------------- .../rei/gui/toast/ExportRecipeIdentifierToast.java | 76 ++++++ .../rei/gui/widget/ClickableLabelWidget.java | 10 +- .../shedaniel/rei/gui/widget/EntryListWidget.java | 10 +- .../rei/gui/widget/FavoritesListWidget.java | 5 +- .../me/shedaniel/rei/gui/widget/LabelWidget.java | 12 +- .../rei/gui/widget/RecipeChoosePageWidget.java | 6 +- .../rei/gui/widget/ScrollingContainer.java | 203 --------------- .../me/shedaniel/rei/gui/widget/TabWidget.java | 2 +- .../shedaniel/rei/gui/widget/TextFieldWidget.java | 16 +- .../me/shedaniel/rei/impl/ClientHelperImpl.java | 4 +- .../me/shedaniel/rei/impl/ConfigObjectImpl.java | 2 +- .../java/me/shedaniel/rei/impl/ItemEntryStack.java | 22 +- .../java/me/shedaniel/rei/impl/RenderingEntry.java | 4 +- .../me/shedaniel/rei/impl/widgets/LabelWidget.java | 16 +- .../plugin/beacon/DefaultBeaconBaseCategory.java | 5 +- .../rei/plugin/brewing/DefaultBrewingDisplay.java | 6 +- .../composting/DefaultCompostingCategory.java | 2 +- .../rei/plugin/cooking/DefaultCookingDisplay.java | 2 +- .../rei/plugin/fuel/DefaultFuelCategory.java | 2 +- .../information/DefaultInformationCategory.java | 11 +- .../assets/roughlyenoughitems/lang/bg_bg.json | 2 +- .../assets/roughlyenoughitems/lang/de_de.json | 2 +- .../assets/roughlyenoughitems/lang/en_ud.json | 2 +- .../assets/roughlyenoughitems/lang/en_us.json | 7 +- .../assets/roughlyenoughitems/lang/et_ee.json | 2 +- .../assets/roughlyenoughitems/lang/fr_fr.json | 2 +- .../assets/roughlyenoughitems/lang/ja_jp.json | 2 +- .../assets/roughlyenoughitems/lang/lol_us.json | 2 +- .../assets/roughlyenoughitems/lang/nn_no.json | 2 +- .../assets/roughlyenoughitems/lang/pl_pl.json | 2 +- .../assets/roughlyenoughitems/lang/pt_br.json | 2 +- .../assets/roughlyenoughitems/lang/pt_pt.json | 2 +- .../assets/roughlyenoughitems/lang/ru_ru.json | 2 +- .../assets/roughlyenoughitems/lang/zh_cn.json | 2 +- .../assets/roughlyenoughitems/lang/zh_tw.json | 2 +- 58 files changed, 1146 insertions(+), 1367 deletions(-) delete mode 100644 src/main/java/me/shedaniel/rei/gui/modules/GameModeMenuEntry.java create mode 100644 src/main/java/me/shedaniel/rei/gui/modules/Menu.java create mode 100644 src/main/java/me/shedaniel/rei/gui/modules/MenuEntry.java delete mode 100644 src/main/java/me/shedaniel/rei/gui/modules/WeatherMenuEntry.java create mode 100644 src/main/java/me/shedaniel/rei/gui/modules/entries/EntryStackSubsetsMenuEntry.java create mode 100644 src/main/java/me/shedaniel/rei/gui/modules/entries/GameModeMenuEntry.java create mode 100644 src/main/java/me/shedaniel/rei/gui/modules/entries/SubSubsetsMenuEntry.java create mode 100644 src/main/java/me/shedaniel/rei/gui/modules/entries/WeatherMenuEntry.java delete mode 100644 src/main/java/me/shedaniel/rei/gui/subsets/SubsetsMenu.java delete mode 100644 src/main/java/me/shedaniel/rei/gui/subsets/SubsetsMenuEntry.java delete mode 100644 src/main/java/me/shedaniel/rei/gui/subsets/entries/EntryStackMenuEntry.java delete mode 100644 src/main/java/me/shedaniel/rei/gui/subsets/entries/SubMenuEntry.java create mode 100644 src/main/java/me/shedaniel/rei/gui/toast/ExportRecipeIdentifierToast.java delete mode 100644 src/main/java/me/shedaniel/rei/gui/widget/ScrollingContainer.java (limited to 'src') diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java index bce41cdf1..2898983b7 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsNetwork.java @@ -65,7 +65,7 @@ public class RoughlyEnoughItemsNetwork implements ModInitializer { ServerSidePacketRegistry.INSTANCE.register(DELETE_ITEMS_PACKET, (packetContext, packetByteBuf) -> { ServerPlayerEntity player = (ServerPlayerEntity) packetContext.getPlayer(); if (player.getServer().getPermissionLevel(player.getGameProfile()) < player.getServer().getOpPermissionLevel()) { - player.sendMessage(new TranslatableText("text.rei.no_permission_cheat").method_27692(Formatting.RED), false); + player.sendMessage(new TranslatableText("text.rei.no_permission_cheat").formatted(Formatting.RED), false); return; } if (!player.inventory.getCursorStack().isEmpty()) @@ -74,7 +74,7 @@ public class RoughlyEnoughItemsNetwork implements ModInitializer { ServerSidePacketRegistry.INSTANCE.register(CREATE_ITEMS_PACKET, (packetContext, packetByteBuf) -> { ServerPlayerEntity player = (ServerPlayerEntity) packetContext.getPlayer(); if (player.getServer().getPermissionLevel(player.getGameProfile()) < player.getServer().getOpPermissionLevel()) { - player.sendMessage(new TranslatableText("text.rei.no_permission_cheat").method_27692(Formatting.RED), false); + player.sendMessage(new TranslatableText("text.rei.no_permission_cheat").formatted(Formatting.RED), false); return; } ItemStack stack = packetByteBuf.readItemStack(); @@ -118,9 +118,9 @@ public class RoughlyEnoughItemsNetwork implements ModInitializer { ServerSidePacketRegistry.INSTANCE.sendToPlayer(player, NOT_ENOUGH_ITEMS_PACKET, buf); } } catch (IllegalStateException e) { - player.sendSystemMessage(new TranslatableText(e.getMessage()).method_27692(Formatting.RED)); + player.sendSystemMessage(new TranslatableText(e.getMessage()).formatted(Formatting.RED)); } catch (Exception e) { - player.sendSystemMessage(new TranslatableText("error.rei.internal.error", e.getMessage()).method_27692(Formatting.RED)); + player.sendSystemMessage(new TranslatableText("error.rei.internal.error", e.getMessage()).formatted(Formatting.RED)); e.printStackTrace(); } } catch (Exception e) { diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java index 9ae7775d8..3d742bfbb 100644 --- a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java @@ -34,9 +34,9 @@ import me.shedaniel.rei.api.widgets.Button; import me.shedaniel.rei.api.widgets.Tooltip; import me.shedaniel.rei.api.widgets.Widgets; import me.shedaniel.rei.gui.config.SearchFieldLocation; -import me.shedaniel.rei.gui.modules.GameModeMenuEntry; -import me.shedaniel.rei.gui.modules.WeatherMenuEntry; -import me.shedaniel.rei.gui.subsets.SubsetsMenu; +import me.shedaniel.rei.gui.modules.entries.GameModeMenuEntry; +import me.shedaniel.rei.gui.modules.entries.WeatherMenuEntry; +import me.shedaniel.rei.gui.modules.Menu; import me.shedaniel.rei.gui.widget.*; import me.shedaniel.rei.impl.ClientHelperImpl; import me.shedaniel.rei.impl.InternalWidgets; @@ -126,17 +126,17 @@ public class ContainerScreenOverlay extends WidgetWithBounds { private Rectangle subsetsButtonBounds; @ApiStatus.Experimental @Nullable - private SubsetsMenu subsetsMenu = null; + private Menu subsetsMenu = null; private Widget wrappedSubsetsMenu = null; @Nullable - private SubsetsMenu weatherMenu = null; + private Menu weatherMenu = null; private Widget wrappedWeatherMenu = null; private boolean renderWeatherMenu = false; private Button weatherButton = null; @Nullable - private SubsetsMenu gameModeMenu = null; + private Menu gameModeMenu = null; private Widget wrappedGameModeMenu = null; private boolean renderGameModeMenu = false; private Button gameModeButton = null; @@ -152,7 +152,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds { @ApiStatus.Experimental @Nullable - public SubsetsMenu getSubsetsMenu() { + public Menu getSubsetsMenu() { return subsetsMenu; } @@ -273,7 +273,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds { renderGameModeMenu = !renderWeatherMenu && (button.isFocused() || button.containsMouse(PointHelper.ofMouse()) || (wrappedGameModeMenu != null && wrappedGameModeMenu.containsMouse(PointHelper.ofMouse()))); if (tmpRender != renderGameModeMenu) { if (renderGameModeMenu) { - this.gameModeMenu = new SubsetsMenu(new Point(button.getBounds().x, button.getBounds().getMaxY()), + this.gameModeMenu = new Menu(new Point(button.getBounds().x, button.getBounds().getMaxY()), CollectionUtils.filterAndMap(Arrays.asList(GameMode.values()), mode -> mode != GameMode.NOT_SET, GameModeMenuEntry::new)); if (ConfigObject.getInstance().isLeftHandSidePanel()) this.gameModeMenu.menuStartPoint.x -= this.gameModeMenu.getBounds().width - this.gameModeButton.getBounds().width; @@ -294,7 +294,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds { renderWeatherMenu = !renderGameModeMenu && (button.isFocused() || button.containsMouse(PointHelper.ofMouse()) || (wrappedWeatherMenu != null && wrappedWeatherMenu.containsMouse(PointHelper.ofMouse()))); if (tmpRender != renderWeatherMenu) { if (renderWeatherMenu) { - this.weatherMenu = new SubsetsMenu(new Point(button.getBounds().x, button.getBounds().getMaxY()), + this.weatherMenu = new Menu(new Point(button.getBounds().x, button.getBounds().getMaxY()), CollectionUtils.map(Weather.values(), WeatherMenuEntry::new)); if (ConfigObject.getInstance().isLeftHandSidePanel()) this.weatherMenu.menuStartPoint.x -= this.weatherMenu.getBounds().width - this.weatherButton.getBounds().width; @@ -319,7 +319,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds { widgets.add(InternalWidgets.wrapLateRenderable(InternalWidgets.wrapTranslate(Widgets.createButton(subsetsButtonBounds, ((ClientHelperImpl) ClientHelper.getInstance()).isAprilFools.get() ? new TranslatableText("text.rei.tiny_potato") : new TranslatableText("text.rei.subsets")) .onClick(button -> { if (subsetsMenu == null) { - wrappedSubsetsMenu = InternalWidgets.wrapTranslate(InternalWidgets.wrapLateRenderable(this.subsetsMenu = SubsetsMenu.createFromRegistry(new Point(this.subsetsButtonBounds.x, this.subsetsButtonBounds.getMaxY()))), 0, 0, 400); + wrappedSubsetsMenu = InternalWidgets.wrapTranslate(InternalWidgets.wrapLateRenderable(this.subsetsMenu = Menu.createSubsetsMenuFromRegistry(new Point(this.subsetsButtonBounds.x, this.subsetsButtonBounds.getMaxY()))), 0, 0, 400); this.widgets.add(this.wrappedSubsetsMenu); } else { this.widgets.remove(this.wrappedSubsetsMenu); @@ -560,7 +560,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds { public void renderTooltip(MatrixStack matrices, List lines, int mouseX, int mouseY) { if (lines.isEmpty()) return; - tooltipWidth = lines.stream().map(font::method_27525).max(Integer::compareTo).get(); + tooltipWidth = lines.stream().map(font::getWidth).max(Integer::compareTo).get(); tooltipHeight = lines.size() <= 1 ? 8 : lines.size() * 10; tooltipLines = lines; ScreenHelper.drawHoveringWidget(matrices, mouseX, mouseY, renderTooltipCallback, tooltipWidth, tooltipHeight, 0); diff --git a/src/main/java/me/shedaniel/rei/gui/OverlaySearchField.java b/src/main/java/me/shedaniel/rei/gui/OverlaySearchField.java index d5d9174cd..2f186c138 100644 --- a/src/main/java/me/shedaniel/rei/gui/OverlaySearchField.java +++ b/src/main/java/me/shedaniel/rei/gui/OverlaySearchField.java @@ -84,9 +84,9 @@ public class OverlaySearchField extends TextFieldWidget { @Override protected void renderSuggestion(MatrixStack matrices, int x, int y) { if (containsMouse(PointHelper.ofMouse()) || isFocused()) - this.font.drawWithShadow(matrices, this.font.method_27523(this.getSuggestion(), this.getWidth()), x, y, REIHelper.getInstance().isDarkThemeEnabled() ? 0xccddaa3d : 0xddeaeaea); + this.font.drawWithShadow(matrices, this.font.trimToWidth(this.getSuggestion(), this.getWidth()), x, y, REIHelper.getInstance().isDarkThemeEnabled() ? 0xccddaa3d : 0xddeaeaea); else - this.font.drawWithShadow(matrices, this.font.method_27523(this.getSuggestion(), this.getWidth()), x, y, -6250336); + this.font.drawWithShadow(matrices, this.font.trimToWidth(this.getSuggestion(), this.getWidth()), x, y, -6250336); } @Override diff --git a/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java index 0fd4f6a0c..bdf3bf4e2 100644 --- a/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java @@ -127,7 +127,7 @@ public class PreRecipeViewingScreen extends Screen { this.method_27534(matrices, this.textRenderer, this.title, this.width / 2, 20, 16777215); if (showTips) { int i = 30; - for (Text s : this.textRenderer.wrapStringToWidthAsList(new TranslatableText("text.rei.recipe_screen_type.selection.sub").method_27692(Formatting.GRAY), width - 30)) { + for (Text s : this.textRenderer.wrapLines(new TranslatableText("text.rei.recipe_screen_type.selection.sub").formatted(Formatting.GRAY), width - 30)) { this.method_27534(matrices, this.textRenderer, s, width / 2, i, -1); i += 10; } diff --git a/src/main/java/me/shedaniel/rei/gui/RecipeDisplayExporter.java b/src/main/java/me/shedaniel/rei/gui/RecipeDisplayExporter.java index 20c48d5f6..b42bd6601 100644 --- a/src/main/java/me/shedaniel/rei/gui/RecipeDisplayExporter.java +++ b/src/main/java/me/shedaniel/rei/gui/RecipeDisplayExporter.java @@ -23,26 +23,20 @@ package me.shedaniel.rei.gui; -import com.mojang.blaze3d.platform.GlStateManager; import com.mojang.blaze3d.systems.RenderSystem; import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.gui.toast.ExportRecipeIdentifierToast; import me.shedaniel.rei.gui.widget.Widget; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gl.Framebuffer; import net.minecraft.client.gui.Element; import net.minecraft.client.render.DiffuseLighting; -import net.minecraft.client.render.OverlayTexture; -import net.minecraft.client.render.VertexConsumerProvider; -import net.minecraft.client.render.model.BakedModel; -import net.minecraft.client.render.model.json.ModelTransformation; +import net.minecraft.client.resource.language.I18n; import net.minecraft.client.texture.NativeImage; -import net.minecraft.client.texture.SpriteAtlasTexture; +import net.minecraft.client.util.Window; import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; import net.minecraft.resource.ResourceImpl; import org.jetbrains.annotations.ApiStatus; -import org.lwjgl.opengl.GL11; import java.io.File; import java.io.IOException; @@ -59,6 +53,7 @@ public final class RecipeDisplayExporter extends Widget { public static void exportRecipeDisplay(Rectangle rectangle, List widgets) { INSTANCE.exportRecipe(rectangle, widgets); + ExportRecipeIdentifierToast.addToast(I18n.translate("msg.rei.exported_recipe"), I18n.translate("msg.rei.exported_recipe.desc")); } private static File getExportFilename(File directory) { @@ -66,7 +61,7 @@ public final class RecipeDisplayExporter extends Widget { int i = 1; while (true) { - File file = new File(directory, "REI_" + string + (i == 1 ? "" : "_" + i) + ".png"); + File file = new File(directory, string + (i == 1 ? "" : "_" + i) + ".png"); if (!file.exists()) { return file; } @@ -77,134 +72,48 @@ public final class RecipeDisplayExporter extends Widget { @SuppressWarnings("deprecation") private void exportRecipe(Rectangle rectangle, List widgets) { - MatrixStack matrices = new MatrixStack(); - Framebuffer framebuffer = new Framebuffer(rectangle.width * 8, rectangle.height * 8, true, MinecraftClient.IS_SYSTEM_MAC); - framebuffer.setClearColor(0, 0, 0, 0); - // int color = REIHelper.getInstance().isDarkThemeEnabled() ? -13750738 : -3750202; - // framebuffer.setClearColor(((color >> 16) & 0xFF) / 255f, ((color >> 8) & 0xFF) / 255f, (color & 0xFF) / 255f, ((color >> 24) & 0xFF) / 255f); - framebuffer.clear(MinecraftClient.IS_SYSTEM_MAC); RenderSystem.pushMatrix(); - // RenderSystem.clear(16640, MinecraftClient.IS_SYSTEM_MAC); + MinecraftClient client = MinecraftClient.getInstance(); + Window window = client.getWindow(); + Framebuffer framebuffer = new Framebuffer(window.getFramebufferWidth(), window.getFramebufferHeight(), false, false); framebuffer.beginWrite(true); - - // Fresh matrices - // RenderSystem.clear(256, MinecraftClient.IS_SYSTEM_MAC); - RenderSystem.matrixMode(GL11.GL_PROJECTION); - RenderSystem.pushMatrix(); + RenderSystem.viewport(0, 0, window.getFramebufferWidth(), window.getFramebufferHeight()); + RenderSystem.clear(256, MinecraftClient.IS_SYSTEM_MAC); + RenderSystem.matrixMode(5889); RenderSystem.loadIdentity(); - // RenderSystem.ortho(0.0D, rectangle.width * 8, rectangle.height * 8, 0.0D, -1, 1); - // RenderSystem.scalef(1, -1,0); - // RenderSystem.ortho(-1, 1, 1, -1, -1, 1); - // RenderSystem.ortho(-1, 1, 1, -1, -1, 1); - RenderSystem.matrixMode(GL11.GL_MODELVIEW); - RenderSystem.pushMatrix(); + RenderSystem.ortho(0.0D, (double) window.getFramebufferWidth() / window.getScaleFactor(), (double) window.getFramebufferHeight() / window.getScaleFactor(), 0.0D, 1000.0D, 3000.0D); + RenderSystem.matrixMode(5888); RenderSystem.loadIdentity(); - // RenderSystem.translatef(0.0F, 0.0F, -2000.0F); - // RenderSystem.rotatef(180, 1, 0, 0); - RenderSystem.scalef(2f / rectangle.width, -2f / rectangle.height, 0); - // RenderSystem.scalef(1f / rectangle.width, -1f / rectangle.height, 0); - // RenderSystem.translatef(10,10,0); - RenderSystem.translatef(-rectangle.x, -rectangle.y, 0); - // RenderSystem.translatef(rectangle.x, rectangle.y, 0); - RenderSystem.translatef(-rectangle.width / 2f, -rectangle.height / 2f, 0); - - // RenderSystem.enableAlphaTest(); - // RenderSystem.alphaFunc(516, 0.1F); - // RenderSystem.enableBlend(); - // RenderSystem.blendFuncSeparate(GlStateManager.SrcFactor.ONE_MINUS_DST_ALPHA, GlStateManager.DstFactor.DST_ALPHA, GlStateManager.SrcFactor.ONE, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA); - RenderSystem.enableAlphaTest(); - RenderSystem.defaultAlphaFunc(); - RenderSystem.enableBlend(); - RenderSystem.enableDepthTest(); - RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA); - RenderSystem.depthMask(false); - RenderSystem.disableCull(); - RenderSystem.pushLightingAttributes(); + RenderSystem.translatef(0.0F, 0.0F, -2000.0F); + DiffuseLighting.enableGuiDepthLighting(); + MatrixStack matrices = new MatrixStack(); for (Widget widget : widgets) { - widget.render(matrices, -1, -1, minecraft.getTickDelta()); - } - { - ItemStack stack = new ItemStack(Items.OAK_STAIRS); - final BakedModel model = minecraft.getItemRenderer().getHeldItemModel(stack, minecraft.world, minecraft.player); - minecraft.getTextureManager().bindTexture(SpriteAtlasTexture.BLOCK_ATLAS_TEX); - minecraft.getTextureManager().getTexture(SpriteAtlasTexture.BLOCK_ATLAS_TEX).setFilter(false, false); - - RenderSystem.enableRescaleNormal(); - RenderSystem.enableAlphaTest(); - RenderSystem.defaultAlphaFunc(); - RenderSystem.enableBlend(); - RenderSystem.enableDepthTest(); - RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA); - - RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); - matrices.push(); - - matrices.translate(rectangle.x + 8, rectangle.y + 8, 0); - matrices.scale(16, -16, 1F); - - boolean disableGuiLight = !model.isSideLit(); - if (disableGuiLight) { - DiffuseLighting.disableGuiDepthLighting(); - } - - VertexConsumerProvider.Immediate immediate = MinecraftClient.getInstance().getBufferBuilders().getEntityVertexConsumers(); - minecraft.getItemRenderer().renderItem(stack, ModelTransformation.Mode.GUI, false, matrices, immediate, 15728880, OverlayTexture.DEFAULT_UV, model); - immediate.draw(); - matrices.pop(); - - RenderSystem.enableDepthTest(); - - if (disableGuiLight) { - DiffuseLighting.enableGuiDepthLighting(); - } - - RenderSystem.disableAlphaTest(); - RenderSystem.disableRescaleNormal(); + widget.render(matrices, -1, -1, 0); } - // fillGradient(0, 0, 10, 10, -1, -1); - // fillGradient(rectangle.x, rectangle.y, rectangle.x + 10, rectangle.y + 10, -16777216, -16777216); - RenderSystem.depthMask(true); - RenderSystem.disableAlphaTest(); - RenderSystem.disableRescaleNormal(); - RenderSystem.disableDepthTest(); - // RenderSystem.disableAlphaTest(); - // RenderSystem.disableBlend(); - - // Reset matrices - RenderSystem.matrixMode(GL11.GL_PROJECTION); RenderSystem.popMatrix(); - RenderSystem.matrixMode(GL11.GL_MODELVIEW); - RenderSystem.popMatrix(); - - framebuffer.endWrite(); - RenderSystem.popMatrix(); - RenderSystem.viewport(0, 0, minecraft.getWindow().getFramebufferWidth(), minecraft.getWindow().getFramebufferHeight()); - NativeImage nativeImage = new NativeImage(rectangle.width * 8, rectangle.height * 8, false); + NativeImage nativeImage = new NativeImage(framebuffer.textureWidth, framebuffer.textureHeight, false); RenderSystem.bindTexture(framebuffer.colorAttachment); nativeImage.loadFromTextureImage(0, false); - { - int width = rectangle.width * 8; - int height = rectangle.height * 8; - for (int y = 0; y < height; ++y) { - for (int x = 0; x < width; ++x) { - if (x > 24 && x < width - 24 && y > 24 && y < height - 24) - nativeImage.setPixelRgba(x, y, nativeImage.getPixelRgba(x, y) | 255 << NativeImage.Format.RGBA.getAlphaChannelOffset()); - } + nativeImage.mirrorVertically(); + int outWidth = (int) (rectangle.width * window.getScaleFactor()); + int outHeight = (int) (rectangle.height * window.getScaleFactor()); + NativeImage strippedImage = new NativeImage(outWidth, outHeight, false); + for (int y = 0; y < outHeight; ++y) { + for (int x = 0; x < outWidth; ++x) { + strippedImage.setPixelRgba(x, y, nativeImage.getPixelRgba(x + (int) (rectangle.x * window.getScaleFactor()), y + (int) (rectangle.y * window.getScaleFactor()))); } } - - nativeImage.mirrorVertically(); ResourceImpl.RESOURCE_IO_EXECUTOR.execute(() -> { try { - File export = new File(minecraft.runDirectory, "export"); - //noinspection ResultOfMethodCallIgnored + File export = new File(minecraft.runDirectory, "rei_exports"); export.mkdirs(); - nativeImage.writeFile(getExportFilename(export)); + strippedImage.writeFile(getExportFilename(export)); } catch (IOException e) { e.printStackTrace(); } finally { nativeImage.close(); + strippedImage.close(); RenderSystem.recordRenderCall(framebuffer::delete); } }); diff --git a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java index 87c134700..cdb4eb1cc 100644 --- a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java @@ -342,7 +342,7 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen { preWidgets.add(workingStationsBaseWidget = Widgets.createCategoryBase(new Rectangle(xx - 5, yy - 5, 15 + innerWidth * 16, 10 + actualHeight * 16))); preWidgets.add(Widgets.createSlotBase(new Rectangle(xx - 1, yy - 1, innerWidth * 16 + 2, actualHeight * 16 + 2))); int index = 0; - List list = Collections.singletonList(new TranslatableText("text.rei.working_station").method_27692(Formatting.YELLOW)); + List list = Collections.singletonList(new TranslatableText("text.rei.working_station").formatted(Formatting.YELLOW)); xx += (innerWidth - 1) * 16; for (List workingStation : workingStations) { preWidgets.add(new WorkstationSlotWidget(xx, yy, CollectionUtils.map(workingStation, stack -> stack.copy().setting(EntryStack.Settings.TOOLTIP_APPEND_EXTRA, s -> list)))); @@ -436,12 +436,12 @@ public class RecipeViewingScreen extends Screen implements RecipeScreen { setZOffset(470); if (bounds.contains(mouseX, mouseY)) { fillGradient(matrices, bounds.x, bounds.y, bounds.getMaxX(), bounds.getMaxY(), 1744822402, 1744822402); - Text text = new TranslatableText("text.rei.release_export", export.getLocalizedName()); + Text text = new TranslatableText("text.rei.release_export", export.getLocalizedName().copy().getString()); VertexConsumerProvider.Immediate immediate = VertexConsumerProvider.immediate(Tessellator.getInstance().getBuffer()); matrices.push(); matrices.translate(0.0D, 0.0D, 480); Matrix4f matrix4f = matrices.peek().getModel(); - textRenderer.draw(text, bounds.getCenterX() - textRenderer.method_27525(text) / 2f, bounds.getCenterY() - 4.5f, 0xff000000, false, matrix4f, immediate, false, 0, 15728880); + textRenderer.draw(text, bounds.getCenterX() - textRenderer.getWidth(text) / 2f, bounds.getCenterY() - 4.5f, 0xff000000, false, matrix4f, immediate, false, 0, 15728880); immediate.draw(); matrices.pop(); } else { diff --git a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java index db505e0af..ae6d396a6 100644 --- a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java @@ -27,6 +27,7 @@ import com.google.common.collect.Lists; import com.mojang.blaze3d.systems.RenderSystem; import me.shedaniel.clothconfig2.ClothConfigInitializer; import me.shedaniel.clothconfig2.api.ScissorsHandler; +import me.shedaniel.clothconfig2.api.ScrollingContainer; import me.shedaniel.math.Point; import me.shedaniel.math.Rectangle; import me.shedaniel.math.impl.PointHelper; @@ -35,7 +36,6 @@ import me.shedaniel.rei.api.widgets.Button; import me.shedaniel.rei.api.widgets.Tooltip; import me.shedaniel.rei.api.widgets.Widgets; import me.shedaniel.rei.gui.entries.RecipeEntry; -import me.shedaniel.rei.gui.widget.ScrollingContainer; import me.shedaniel.rei.gui.widget.TabWidget; import me.shedaniel.rei.gui.widget.Widget; import me.shedaniel.rei.impl.ClientHelperImpl; @@ -171,7 +171,7 @@ public class VillagerRecipeViewingScreen extends Screen implements RecipeScreen widgets.add(Widgets.createCategoryBase(new Rectangle(xx - 5, bounds.y + bounds.height - 5, 10 + w * 16, 12 + h * 16))); widgets.add(Widgets.createSlotBase(new Rectangle(xx - 1, yy - 1, 2 + w * 16, 2 + h * 16))); int index = 0; - List list = Collections.singletonList(new TranslatableText("text.rei.working_station").method_27692(Formatting.YELLOW)); + List list = Collections.singletonList(new TranslatableText("text.rei.working_station").formatted(Formatting.YELLOW)); for (List workingStation : workingStations) { widgets.add(new RecipeViewingScreen.WorkstationSlotWidget(xx, yy, CollectionUtils.map(workingStation, stack -> stack.copy().setting(EntryStack.Settings.TOOLTIP_APPEND_EXTRA, s -> list)))); index++; @@ -352,7 +352,7 @@ public class VillagerRecipeViewingScreen extends Screen implements RecipeScreen Optional.ofNullable(recipeRenderers.get(i).getTooltip(new Point(mouseX, mouseY))).ifPresent(Tooltip::queue); } } - scrolling.renderScrollBar(0, scrollBarAlpha); + scrolling.renderScrollBar(0, scrollBarAlpha, REIHelper.getInstance().isDarkThemeEnabled() ? 0.8f : 1f); ScissorsHandler.INSTANCE.removeLastScissor(); RenderSystem.popMatrix(); ScreenHelper.getLastOverlay().lateRender(matrices, mouseX, mouseY, delta); diff --git a/src/main/java/me/shedaniel/rei/gui/WarningAndErrorScreen.java b/src/main/java/me/shedaniel/rei/gui/WarningAndErrorScreen.java index 1794078e0..d45c3e24e 100644 --- a/src/main/java/me/shedaniel/rei/gui/WarningAndErrorScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/WarningAndErrorScreen.java @@ -66,13 +66,13 @@ public class WarningAndErrorScreen extends Screen { } private void addText(Text string) { - for (Text s : textRenderer.wrapStringToWidthAsList(string, width - 80)) { + for (Text s : textRenderer.wrapLines(string, width - 80)) { listWidget.creditsAddEntry(new TextItem(s)); } } private void addLink(Text string, String link) { - for (Text s : textRenderer.wrapStringToWidthAsList(string, width - 80)) { + for (Text s : textRenderer.wrapLines(string, width - 80)) { listWidget.creditsAddEntry(new LinkItem(s.getString(), link)); } } @@ -84,7 +84,7 @@ public class WarningAndErrorScreen extends Screen { listWidget.creditsClearEntries(); listWidget.creditsAddEntry(new EmptyItem()); if (!RoughlyEnoughItemsState.getWarnings().isEmpty()) - listWidget.creditsAddEntry(new TextItem(new LiteralText("Warnings:").method_27692(Formatting.RED))); + listWidget.creditsAddEntry(new TextItem(new LiteralText("Warnings:").formatted(Formatting.RED))); for (Pair pair : RoughlyEnoughItemsState.getWarnings()) { addText(new LiteralText(pair.getLeft())); if (pair.getRight() != null) @@ -97,7 +97,7 @@ public class WarningAndErrorScreen extends Screen { listWidget.creditsAddEntry(new EmptyItem()); } if (!RoughlyEnoughItemsState.getErrors().isEmpty()) - listWidget.creditsAddEntry(new TextItem(new LiteralText("Errors:").method_27692(Formatting.RED))); + listWidget.creditsAddEntry(new TextItem(new LiteralText("Errors:").formatted(Formatting.RED))); for (Pair pair : RoughlyEnoughItemsState.getErrors()) { addText(new LiteralText(pair.getLeft())); if (pair.getRight() != null) @@ -218,7 +218,7 @@ public class WarningAndErrorScreen extends Screen { @Override public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta) { - MinecraftClient.getInstance().textRenderer.method_27517(matrices, text, x + 5, y, -1); + MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, text, x + 5, y, -1); } @Override @@ -233,7 +233,7 @@ public class WarningAndErrorScreen extends Screen { @Override public int getWidth() { - return MinecraftClient.getInstance().textRenderer.method_27525(text) + 10; + return MinecraftClient.getInstance().textRenderer.getWidth(text) + 10; } } @@ -270,7 +270,7 @@ public class WarningAndErrorScreen extends Screen { @Override public int getWidth() { - return MinecraftClient.getInstance().textRenderer.getStringWidth(text) + 10; + return MinecraftClient.getInstance().textRenderer.getWidth(text) + 10; } @Override diff --git a/src/main/java/me/shedaniel/rei/gui/config/entry/FilteringEntry.java b/src/main/java/me/shedaniel/rei/gui/config/entry/FilteringEntry.java index 8b3d08594..96176953c 100644 --- a/src/main/java/me/shedaniel/rei/gui/config/entry/FilteringEntry.java +++ b/src/main/java/me/shedaniel/rei/gui/config/entry/FilteringEntry.java @@ -36,10 +36,11 @@ import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.ConfigObject; import me.shedaniel.rei.api.EntryRegistry; import me.shedaniel.rei.api.EntryStack; +import me.shedaniel.rei.api.REIHelper; import me.shedaniel.rei.api.widgets.Tooltip; import me.shedaniel.rei.gui.OverlaySearchField; import me.shedaniel.rei.gui.widget.EntryWidget; -import me.shedaniel.rei.gui.widget.ScrollingContainer; +import me.shedaniel.clothconfig2.api.ScrollingContainer; import me.shedaniel.rei.impl.ScreenHelper; import me.shedaniel.rei.impl.SearchArgument; import me.shedaniel.rei.utils.CollectionUtils; @@ -111,21 +112,21 @@ public class FilteringEntry extends AbstractConfigListEntry> { this.searchField = new OverlaySearchField(0, 0, 0, 0); { Text selectAllText = new TranslatableText("config.roughlyenoughitems.filteredEntries.selectAll"); - this.selectAllButton = new ButtonWidget(0, 0, MinecraftClient.getInstance().textRenderer.method_27525(selectAllText) + 10, 20, selectAllText, button -> { + this.selectAllButton = new ButtonWidget(0, 0, MinecraftClient.getInstance().textRenderer.getWidth(selectAllText) + 10, 20, selectAllText, button -> { this.selectionPoint = new Point(-Integer.MAX_VALUE / 2, -Integer.MAX_VALUE / 2); this.secondPoint = new Point(Integer.MAX_VALUE / 2, Integer.MAX_VALUE / 2); }); } { Text selectNoneText = new TranslatableText("config.roughlyenoughitems.filteredEntries.selectNone"); - this.selectNoneButton = new ButtonWidget(0, 0, MinecraftClient.getInstance().textRenderer.method_27525(selectNoneText) + 10, 20, selectNoneText, button -> { + this.selectNoneButton = new ButtonWidget(0, 0, MinecraftClient.getInstance().textRenderer.getWidth(selectNoneText) + 10, 20, selectNoneText, button -> { this.selectionPoint = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE); this.secondPoint = new Point(Integer.MAX_VALUE, Integer.MAX_VALUE); }); } { Text hideText = new TranslatableText("config.roughlyenoughitems.filteredEntries.hide"); - this.hideButton = new ButtonWidget(0, 0, MinecraftClient.getInstance().textRenderer.method_27525(hideText) + 10, 20, hideText, button -> { + this.hideButton = new ButtonWidget(0, 0, MinecraftClient.getInstance().textRenderer.getWidth(hideText) + 10, 20, hideText, button -> { for (int i = 0; i < entryStacks.size(); i++) { EntryStack stack = entryStacks.get(i); EntryListEntry entry = entries.get(i); @@ -139,7 +140,7 @@ public class FilteringEntry extends AbstractConfigListEntry> { } { Text showText = new TranslatableText("config.roughlyenoughitems.filteredEntries.show"); - this.showButton = new ButtonWidget(0, 0, MinecraftClient.getInstance().textRenderer.method_27525(showText) + 10, 20, showText, button -> { + this.showButton = new ButtonWidget(0, 0, MinecraftClient.getInstance().textRenderer.getWidth(showText) + 10, 20, showText, button -> { for (int i = 0; i < entryStacks.size(); i++) { EntryStack stack = entryStacks.get(i); EntryListEntry entry = entries.get(i); @@ -217,7 +218,7 @@ public class FilteringEntry extends AbstractConfigListEntry> { nextIndex++; } updatePosition(delta); - scrolling.renderScrollBar(0xff000000, 1); + scrolling.renderScrollBar(0xff000000, 1, REIHelper.getInstance().isDarkThemeEnabled() ? 0.8f : 1f); matrices.push(); matrices.translate(0, 0, 300); this.searchField.laterRender(matrices, mouseX, mouseY, delta); @@ -249,7 +250,7 @@ public class FilteringEntry extends AbstractConfigListEntry> { @Override public boolean mouseDragged(double mouseX, double mouseY, int button, double dx, double dy) { - if (scrolling.mouseDragged(mouseX, mouseY, button, dx, dy, true)) + if (scrolling.mouseDragged(mouseX, mouseY, button, dx, dy, ConfigObject.getInstance().doesSnapToRows(), entrySize())) return true; return super.mouseDragged(mouseX, mouseY, button, dx, dy); } diff --git a/src/main/java/me/shedaniel/rei/gui/credits/CreditsEntryListWidget.java b/src/main/java/me/shedaniel/rei/gui/credits/CreditsEntryListWidget.java index 7505694e0..158ac014b 100644 --- a/src/main/java/me/shedaniel/rei/gui/credits/CreditsEntryListWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/credits/CreditsEntryListWidget.java @@ -92,7 +92,7 @@ public class CreditsEntryListWidget extends DynamicNewSmoothScrollingEntryListWi @Override public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta) { - MinecraftClient.getInstance().textRenderer.method_27517(matrices, text, x + 5, y + 5, -1); + MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, text, x + 5, y + 5, -1); } @Override @@ -113,16 +113,16 @@ public class CreditsEntryListWidget extends DynamicNewSmoothScrollingEntryListWi public TranslationCreditsItem(Text language, Text translators, int width, int maxWidth) { this.language = language; - this.translators = MinecraftClient.getInstance().textRenderer.wrapStringToWidthAsList(translators, width); + this.translators = MinecraftClient.getInstance().textRenderer.wrapLines(translators, width); this.maxWidth = maxWidth; } @Override public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean isSelected, float delta) { - MinecraftClient.getInstance().textRenderer.method_27517(matrices, language, x + 5, y + 5, -1); + MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, language, x + 5, y + 5, -1); int yy = y + 5; for (Text translator : translators) { - MinecraftClient.getInstance().textRenderer.method_27517(matrices, translator, x + 5 + maxWidth, yy, -1); + MinecraftClient.getInstance().textRenderer.drawWithShadow(matrices, translator, x + 5 + maxWidth, yy, -1); yy += 12; } } diff --git a/src/main/java/me/shedaniel/rei/gui/credits/CreditsScreen.java b/src/main/java/me/shedaniel/rei/gui/credits/CreditsScreen.java index ee7e954cf..bb677a4d2 100644 --- a/src/main/java/me/shedaniel/rei/gui/credits/CreditsScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/credits/CreditsScreen.java @@ -104,7 +104,7 @@ public class CreditsScreen extends Screen { for (StackTraceElement traceElement : exception[0].getStackTrace()) entryListWidget.creditsAddEntry(new TextCreditsItem(new LiteralText(" at " + traceElement))); } else { - int maxWidth = translatorsMapped.stream().mapToInt(pair -> textRenderer.getStringWidth(pair.getLeft())).max().orElse(0) + 5; + int maxWidth = translatorsMapped.stream().mapToInt(pair -> textRenderer.getWidth(pair.getLeft())).max().orElse(0) + 5; for (Pair pair : translatorsMapped) { entryListWidget.creditsAddEntry(new TranslationCreditsItem(new TranslatableText(pair.getLeft()), new TranslatableText(pair.getRight()), i - maxWidth - 10, maxWidth)); } diff --git a/src/main/java/me/shedaniel/rei/gui/modules/GameModeMenuEntry.java b/src/main/java/me/shedaniel/rei/gui/modules/GameModeMenuEntry.java deleted file mode 100644 index 90b02b73a..000000000 --- a/src/main/java/me/shedaniel/rei/gui/modules/GameModeMenuEntry.java +++ /dev/null @@ -1,108 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - * SOFTWARE. - */ - -package me.shedaniel.rei.gui.modules; - -import me.shedaniel.rei.api.ConfigObject; -import me.shedaniel.rei.api.REIHelper; -import me.shedaniel.rei.api.widgets.Tooltip; -import me.shedaniel.rei.gui.subsets.SubsetsMenuEntry; -import me.shedaniel.rei.impl.ScreenHelper; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.gui.Element; -import net.minecraft.client.sound.PositionedSoundInstance; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.sound.SoundEvents; -import net.minecraft.text.TranslatableText; -import net.minecraft.world.GameMode; - -import java.util.Collections; -import java.util.List; -import java.util.Locale; - -public class GameModeMenuEntry extends SubsetsMenuEntry { - public final String text; - public final GameMode gameMode; - private int x, y, width; - private boolean selected, containsMouse, rendering; - private int textWidth = -69; - - public GameModeMenuEntry(GameMode gameMode) { - this.text = gameMode.getTranslatableName().getString(); - this.gameMode = gameMode; - } - - private int getTextWidth() { - if (textWidth == -69) { - this.textWidth = Math.max(0, font.getStringWidth(text)); - } - return this.textWidth; - } - - @Override - public int getEntryWidth() { - return getTextWidth() + 4; - } - - @Override - public int getEntryHeight() { - return 12; - } - - @Override - public List children() { - return Collections.emptyList(); - } - - @Override - public void updateInformation(int xPos, int yPos, boolean selected, boolean containsMouse, boolean rendering, int width) { - this.x = xPos; - this.y = yPos; - this.selected = selected; - this.containsMouse = containsMouse; - this.rendering = rendering; - this.width = width; - } - - @Override - public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { - if (selected) { - fill(matrices, x, y, x + width, y + 12, -12237499); - } - if (selected && containsMouse) { - REIHelper.getInstance().queueTooltip(Tooltip.create(new TranslatableText("text.rei.gamemode_button.tooltip.entry", text))); - } - font.draw(matrices, text, x + 2, y + 2, selected ? 16777215 : 8947848); - } - - @Override - public boolean mouseClicked(double mouseX, double mouseY, int button) { - if (rendering && mouseX >= x && mouseX <= x + width && mouseY >= y && mouseY <= y + 12) { - MinecraftClient.getInstance().player.sendChatMessage(ConfigObject.getInstance().getGamemodeCommand().replaceAll("\\{gamemode}", gameMode.name().toLowerCase(Locale.ROOT))); - minecraft.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F)); - ScreenHelper.getLastOverlay().removeGameModeMenu(); - return true; - } - return super.mouseClicked(mouseX, mouseY, button); - } -} diff --git a/src/main/java/me/shedaniel/rei/gui/modules/Menu.java b/src/main/java/me/shedaniel/rei/gui/modules/Menu.java new file mode 100644 index 000000000..16bc8e218 --- /dev/null +++ b/src/main/java/me/shedaniel/rei/gui/modules/Menu.java @@ -0,0 +1,280 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.gui.modules; + +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import me.shedaniel.clothconfig2.ClothConfigInitializer; +import me.shedaniel.clothconfig2.api.ScissorsHandler; +import me.shedaniel.clothconfig2.api.ScrollingContainer; +import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.RoughlyEnoughItemsCore; +import me.shedaniel.rei.api.EntryRegistry; +import me.shedaniel.rei.api.EntryStack; +import me.shedaniel.rei.api.REIHelper; +import me.shedaniel.rei.api.subsets.SubsetsRegistry; +import me.shedaniel.rei.gui.modules.entries.EntryStackSubsetsMenuEntry; +import me.shedaniel.rei.gui.modules.entries.SubSubsetsMenuEntry; +import me.shedaniel.rei.gui.widget.LateRenderable; +import me.shedaniel.rei.gui.widget.WidgetWithBounds; +import me.shedaniel.rei.impl.EntryRegistryImpl; +import me.shedaniel.rei.utils.CollectionUtils; +import net.minecraft.client.resource.language.I18n; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.item.ItemStack; +import net.minecraft.util.collection.DefaultedList; +import net.minecraft.util.registry.Registry; +import org.jetbrains.annotations.ApiStatus; +import org.jetbrains.annotations.NotNull; + +import java.util.*; + +@ApiStatus.Experimental +@ApiStatus.Internal +public class Menu extends WidgetWithBounds implements LateRenderable { + public final Point menuStartPoint; + private final List entries = Lists.newArrayList(); + public final ScrollingContainer scrolling = new ScrollingContainer() { + @Override + public int getMaxScrollHeight() { + int i = 0; + for (MenuEntry entry : children()) { + i += entry.getEntryHeight(); + } + return i; + } + + @Override + public Rectangle getBounds() { + return Menu.this.getInnerBounds(); + } + + @Override + public boolean hasScrollBar() { + return Menu.this.hasScrollBar(); + } + }; + + public Menu(Point menuStartPoint, Collection entries) { + this.menuStartPoint = menuStartPoint; + buildEntries(entries); + } + + public static Menu createSubsetsMenuFromRegistry(Point menuStartPoint) { + List stacks = EntryRegistry.getInstance().getStacksList(); + Map entries = Maps.newHashMap(); + { + // All Entries group + Map allEntries = getOrCreateSubEntryInMap(entries, "roughlyenoughitems:all_entries"); + for (EntryStack stack : stacks) { + putEntryInMap(allEntries, stack); + } + } + { + // Item Groups group + Map itemGroups = getOrCreateSubEntryInMap(entries, "roughlyenoughitems:item_groups"); + for (Item item : Registry.ITEM) { + ItemGroup group = item.getGroup(); + if (group == null) + continue; + DefaultedList list; + try { + list = new EntryRegistryImpl.DefaultedLinkedList<>(Lists.newLinkedList(), null); + item.appendStacks(group, list); + if (list.isEmpty()) + list.add(item.getStackForRender()); + Map groupMenu = getOrCreateSubEntryInMap(itemGroups, "_item_group_" + group.getId()); + for (ItemStack stack : list) { + putEntryInMap(groupMenu, EntryStack.create(stack)); + } + } catch (Exception e) { + e.printStackTrace(); + } + } + } + Set paths = SubsetsRegistry.INSTANCE.getPaths(); + for (String path : paths) { + Map lastMap = entries; + String[] pathSegments = path.split("/"); + for (String pathSegment : pathSegments) { + lastMap = getOrCreateSubEntryInMap(lastMap, pathSegment); + } + for (EntryStack entry : SubsetsRegistry.INSTANCE.getPathEntries(path)) { + EntryStack firstStack = CollectionUtils.findFirstOrNullEqualsEntryIgnoreAmount(stacks, entry); + if (firstStack != null) + putEntryInMap(lastMap, firstStack); + } + } + return new Menu(menuStartPoint, buildEntries(entries)); + } + + private static Map getOrCreateSubEntryInMap(Map parent, String pathSegment) { + putEntryInMap(parent, pathSegment); + return (Map) parent.get(pathSegment); + } + + private static void putEntryInMap(Map parent, String pathSegment) { + if (!parent.containsKey(pathSegment)) { + parent.put(pathSegment, Maps.newHashMap()); + } + } + + private static void putEntryInMap(Map parent, EntryStack stack) { + Set items = (Set) parent.get("items"); + if (items == null) { + items = Sets.newLinkedHashSet(); + parent.put("items", items); + } + items.add(stack); + } + + private static List buildEntries(Map map) { + List entries = Lists.newArrayList(); + for (Map.Entry entry : map.entrySet()) { + if (entry.getKey().equals("items")) { + Set items = (Set) entry.getValue(); + for (EntryStack item : items) { + entries.add(new EntryStackSubsetsMenuEntry(item)); + } + } else { + Map entryMap = (Map) entry.getValue(); + if (entry.getKey().startsWith("_item_group_")) { + entries.add(new SubSubsetsMenuEntry(I18n.translate(entry.getKey().replace("_item_group_", "itemGroup.")), buildEntries(entryMap))); + } else { + String translationKey = "subsets.rei." + entry.getKey().replace(':', '.'); + if (!I18n.hasTranslation(translationKey)) + RoughlyEnoughItemsCore.LOGGER.warn("Subsets menu " + translationKey + " does not have a translation"); + entries.add(new SubSubsetsMenuEntry(I18n.translate(translationKey), buildEntries(entryMap))); + } + } + } + return entries; + } + + @SuppressWarnings("deprecation") + private void buildEntries(Collection entries) { + this.entries.clear(); + this.entries.addAll(entries); + this.entries.sort(Comparator.comparing(entry -> entry instanceof SubSubsetsMenuEntry ? 0 : 1).thenComparing(entry -> entry instanceof SubSubsetsMenuEntry ? ((SubSubsetsMenuEntry) entry).text : "")); + for (MenuEntry entry : this.entries) { + entry.parent = this; + } + } + + @Override + public @NotNull Rectangle getBounds() { + return new Rectangle(menuStartPoint.x, menuStartPoint.y, getMaxEntryWidth() + 2 + (hasScrollBar() ? 6 : 0), getInnerHeight() + 2); + } + + public Rectangle getInnerBounds() { + return new Rectangle(menuStartPoint.x + 1, menuStartPoint.y + 1, getMaxEntryWidth() + (hasScrollBar() ? 6 : 0), getInnerHeight()); + } + + public boolean hasScrollBar() { + return scrolling.getMaxScrollHeight() > getInnerHeight(); + } + + public int getInnerHeight() { + return Math.min(scrolling.getMaxScrollHeight(), minecraft.currentScreen.height - 20 - menuStartPoint.y); + } + + public int getMaxEntryWidth() { + int i = 0; + for (MenuEntry entry : children()) { + if (entry.getEntryWidth() > i) + i = entry.getEntryWidth(); + } + return Math.max(10, i); + } + + @Override + public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) { + Rectangle bounds = getBounds(); + Rectangle innerBounds = getInnerBounds(); + fill(matrices, bounds.x, bounds.y, bounds.getMaxX(), bounds.getMaxY(), containsMouse(mouseX, mouseY) ? (REIHelper.getInstance().isDarkThemeEnabled() ? -17587 : -1) : -6250336); + fill(matrices, innerBounds.x, innerBounds.y, innerBounds.getMaxX(), innerBounds.getMaxY(), -16777216); + boolean contains = innerBounds.contains(mouseX, mouseY); + MenuEntry focused = getFocused() instanceof MenuEntry ? (MenuEntry) getFocused() : null; + int currentY = (int) (innerBounds.y - scrolling.scrollAmount); + for (MenuEntry child : children()) { + boolean containsMouse = contains && mouseY >= currentY && mouseY < currentY + child.getEntryHeight(); + if (containsMouse) { + focused = child; + } + currentY += child.getEntryHeight(); + } + currentY = (int) (innerBounds.y - scrolling.scrollAmount); + ScissorsHandler.INSTANCE.scissor(scrolling.getScissorBounds()); + for (MenuEntry child : children()) { + boolean rendering = currentY + child.getEntryHeight() >= innerBounds.y && currentY <= innerBounds.getMaxY(); + boolean containsMouse = contains && mouseY >= currentY && mouseY < currentY + child.getEntryHeight(); + child.updateInformation(innerBounds.x, currentY, focused == child || containsMouse, containsMouse, rendering, getMaxEntryWidth()); + if (rendering) + child.render(matrices, mouseX, mouseY, delta); + currentY += child.getEntryHeight(); + } + ScissorsHandler.INSTANCE.removeLastScissor(); + setFocused(focused); + scrolling.renderScrollBar(0, 1, REIHelper.getInstance().isDarkThemeEnabled() ? 0.8f : 1f); + scrolling.updatePosition(delta); + } + + @Override + public boolean mouseClicked(double mouseX, double mouseY, int button) { + if (scrolling.updateDraggingState(mouseX, mouseY, button)) + return true; + return super.mouseClicked(mouseX, mouseY, button); + } + + @Override + public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { + if (scrolling.mouseDragged(mouseX, mouseY, button, deltaX, deltaY)) + return true; + return super.mouseDragged(mouseX, mouseY, button, deltaX, deltaY); + } + + @Override + public boolean mouseScrolled(double mouseX, double mouseY, double amount) { + if (getInnerBounds().contains(mouseX, mouseY)) { + scrolling.offset(ClothConfigInitializer.getScrollStep() * -amount, true); + return true; + } + for (MenuEntry child : children()) { + if (child instanceof SubSubsetsMenuEntry) { + if (child.mouseScrolled(mouseX, mouseY, amount)) + return true; + } + } + return super.mouseScrolled(mouseX, mouseY, amount); + } + + @Override + public List children() { + return entries; + } +} diff --git a/src/main/java/me/shedaniel/rei/gui/modules/MenuEntry.java b/src/main/java/me/shedaniel/rei/gui/modules/MenuEntry.java new file mode 100644 index 000000000..455dae30b --- /dev/null +++ b/src/main/java/me/shedaniel/rei/gui/modules/MenuEntry.java @@ -0,0 +1,44 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.gui.modules; + +import me.shedaniel.rei.gui.widget.Widget; +import org.jetbrains.annotations.ApiStatus; + +@ApiStatus.Experimental +@ApiStatus.Internal +public abstract class MenuEntry extends Widget { + @Deprecated + Menu parent = null; + + public final Menu getParent() { + return parent; + } + + public abstract int getEntryWidth(); + + public abstract int getEntryHeight(); + + public abstract void updateInformation(int xPos, int yPos, boolean selected, boolean containsMouse, boolean rendering, int width); +} diff --git a/src/main/java/me/shedaniel/rei/gui/modules/WeatherMenuEntry.java b/src/main/java/me/shedaniel/rei/gui/modules/WeatherMenuEntry.java deleted file mode 100644 index 80cb2832d..000000000 --- a/src/main/java/me/shedaniel/rei/gui/modules/WeatherMenuEntry.java +++ /dev/null @@ -1,109 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020 shedaniel - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all - * copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,