diff options
Diffstat (limited to 'src/main/java/me')
19 files changed, 399 insertions, 223 deletions
diff --git a/src/main/java/me/shedaniel/rei/api/ClientHelper.java b/src/main/java/me/shedaniel/rei/api/ClientHelper.java index 08ab4fcab..112037403 100644 --- a/src/main/java/me/shedaniel/rei/api/ClientHelper.java +++ b/src/main/java/me/shedaniel/rei/api/ClientHelper.java @@ -6,7 +6,6 @@ package me.shedaniel.rei.api; import me.shedaniel.rei.impl.ClientHelperImpl; -import net.fabricmc.fabric.api.client.keybinding.FabricKeyBinding; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; @@ -126,7 +125,19 @@ public interface ClientHelper { * @param identifier the identifier to find * @return the mod name */ - String getModFromIdentifier(Identifier identifier); + default String getModFromIdentifier(Identifier identifier) { + if (identifier == null) + return ""; + return getModFromModId(identifier.getNamespace()); + } + + /** + * Gets the mod from a modid + * + * @param modid the modid of the mod + * @return the mod name + */ + String getModFromModId(String modid); /** * Finds all recipes and open them in a recipe screen. diff --git a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java index f212a3db2..fb3ec0866 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java @@ -10,6 +10,7 @@ import me.shedaniel.rei.gui.RecipeViewingScreen; import me.shedaniel.rei.gui.entries.RecipeEntry; import me.shedaniel.rei.gui.entries.SimpleRecipeEntry; import me.shedaniel.rei.gui.widget.CategoryBaseWidget; +import me.shedaniel.rei.gui.widget.PanelWidget; import me.shedaniel.rei.gui.widget.RecipeBaseWidget; import me.shedaniel.rei.gui.widget.Widget; import me.shedaniel.rei.impl.ScreenHelper; @@ -77,13 +78,13 @@ public interface RecipeCategory<T extends RecipeDisplay> { * @param delta the delta */ default void drawCategoryBackground(Rectangle bounds, int mouseX, int mouseY, float delta) { - new CategoryBaseWidget(bounds).render(); + PanelWidget.render(bounds, -1); if (ScreenHelper.isDarkModeEnabled()) { DrawableHelper.fill(bounds.x + 17, bounds.y + 5, bounds.x + bounds.width - 17, bounds.y + 17, 0xFF404040); - DrawableHelper.fill(bounds.x + 17, bounds.y + 21, bounds.x + bounds.width - 17, bounds.y + 33, 0xFF404040); + DrawableHelper.fill(bounds.x + 17, bounds.y + 19, bounds.x + bounds.width - 17, bounds.y + 31, 0xFF404040); } else { DrawableHelper.fill(bounds.x + 17, bounds.y + 5, bounds.x + bounds.width - 17, bounds.y + 17, 0xFF9E9E9E); - DrawableHelper.fill(bounds.x + 17, bounds.y + 21, bounds.x + bounds.width - 17, bounds.y + 33, 0xFF9E9E9E); + DrawableHelper.fill(bounds.x + 17, bounds.y + 19, bounds.x + bounds.width - 17, bounds.y + 31, 0xFF9E9E9E); } } diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java index 046412e26..7e51678b2 100644 --- a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java @@ -288,7 +288,8 @@ public class ContainerScreenOverlay extends WidgetWithBounds { widgets.add(new ClickableLabelWidget(new Point(rectangle.x + (rectangle.width / 2), rectangle.y + (ConfigObject.getInstance().getSearchFieldLocation() == SearchFieldLocation.TOP_SIDE ? 24 : 0) + 10), "") { @Override public void render(int mouseX, int mouseY, float delta) { - setText(String.format("%s/%s", ENTRY_LIST_WIDGET.getPage() + 1, ENTRY_LIST_WIDGET.getTotalPages())); + clickable(ENTRY_LIST_WIDGET.getTotalPages() > 1); + setText(String.format("%s/%s", ENTRY_LIST_WIDGET.getPage() + 1, Math.max(ENTRY_LIST_WIDGET.getTotalPages(), 1))); super.render(mouseX, mouseY, delta); } @@ -308,8 +309,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds { public boolean changeFocus(boolean boolean_1) { return false; } - }.clickable(ENTRY_LIST_WIDGET.getTotalPages() != 1)); - buttonLeft.enabled = buttonRight.enabled = ENTRY_LIST_WIDGET.getTotalPages() != 1; + }); } if (ConfigObject.getInstance().isCraftableFilterEnabled()) this.widgets.add(toggleButtonWidget = new CraftableToggleButtonWidget(getCraftableToggleArea()) { @@ -508,7 +508,7 @@ public class ContainerScreenOverlay extends WidgetWithBounds { if (!ScreenHelper.isOverlayVisible()) return; if (!ConfigObject.getInstance().isEntryListWidgetScrolled()) - buttonLeft.enabled = buttonRight.enabled = ENTRY_LIST_WIDGET.getTotalPages() != 1; + buttonLeft.enabled = buttonRight.enabled = ENTRY_LIST_WIDGET.getTotalPages() > 1; for (Widget widget : widgets) { widget.render(int_1, int_2, float_1); } diff --git a/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java index 5f9e876e1..87ec9df22 100644 --- a/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/PreRecipeViewingScreen.java @@ -12,6 +12,7 @@ import me.shedaniel.rei.gui.config.RecipeScreenType; import me.shedaniel.rei.gui.widget.ButtonWidget; import me.shedaniel.rei.gui.widget.Widget; import me.shedaniel.rei.gui.widget.WidgetWithBounds; +import me.shedaniel.rei.impl.ClientHelperImpl; import me.shedaniel.rei.impl.ScreenHelper; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.Element; @@ -33,6 +34,7 @@ public class PreRecipeViewingScreen extends Screen { private final List<Widget> widgets; private boolean original; private Map<RecipeCategory<?>, List<RecipeDisplay>> map; + private EntryStack mainStackToNotice = EntryStack.empty(); public PreRecipeViewingScreen(Map<RecipeCategory<?>, List<RecipeDisplay>> map) { super(new TranslatableText("text.rei.recipe_screen_type.selection")); @@ -41,6 +43,10 @@ public class PreRecipeViewingScreen extends Screen { this.map = map; } + public void addMainStackToNotice(EntryStack mainStackToNotice) { + this.mainStackToNotice = mainStackToNotice; + } + @Override protected void init() { this.children.clear(); @@ -50,7 +56,7 @@ public class PreRecipeViewingScreen extends Screen { public void onPressed() { ConfigObject.getInstance().setRecipeScreenType(original ? RecipeScreenType.ORIGINAL : RecipeScreenType.VILLAGER); ConfigManager.getInstance().saveConfig(); - ClientHelper.getInstance().openRecipeViewingScreen(map); + ((ClientHelperImpl) ClientHelper.getInstance()).openRecipeViewingScreen(map, mainStackToNotice); } }); this.widgets.add(new ScreenTypeSelection(width / 2 - 200 - 5, height / 2 - 112 / 2 - 10, 0)); diff --git a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java index 22acbd310..73d744e56 100644 --- a/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/RecipeViewingScreen.java @@ -49,6 +49,7 @@ public class RecipeViewingScreen extends Screen { @Nullable private CategoryBaseWidget workingStationsBaseWidget; private RecipeCategory<RecipeDisplay> selectedCategory; private ButtonWidget recipeBack, recipeNext, categoryBack, categoryNext; + private EntryStack mainStackToNotice = EntryStack.empty(); public RecipeViewingScreen(Map<RecipeCategory<?>, List<RecipeDisplay>> categoriesMap) { super(new LiteralText("")); @@ -56,7 +57,7 @@ public class RecipeViewingScreen extends Screen { this.preWidgets = Lists.newArrayList(); this.widgets = Lists.newArrayList(); Window window = MinecraftClient.getInstance().getWindow(); - this.bounds = new Rectangle(window.getScaledWidth() / 2 - guiWidth / 2, window.getScaledHeight() / 2 - guiHeight / 2, 176, 186); + this.bounds = new Rectangle(window.getScaledWidth() / 2 - guiWidth / 2, window.getScaledHeight() / 2 - guiHeight / 2, 176, 150); this.categoriesMap = categoriesMap; this.categories = Lists.newArrayList(); for (RecipeCategory<?> category : RecipeHelper.getInstance().getAllCategories()) { @@ -68,6 +69,10 @@ public class RecipeViewingScreen extends Screen { this.choosePageActivated = false; } + public void addMainStackToNotice(EntryStack stack) { + this.mainStackToNotice = stack; + } + @Nullable public CategoryBaseWidget getWorkingStationsBaseWidget() { return workingStationsBaseWidget; @@ -128,10 +133,10 @@ public class RecipeViewingScreen extends Screen { this.preWidgets.clear(); this.widgets.clear(); this.largestWidth = width - 100; - this.largestHeight = height - 40; + this.largestHeight = Math.max(height - 36, 100); int maxWidthDisplay = CollectionUtils.mapAndMax(getCurrentDisplayed(), display -> selectedCategory.getDisplayWidth(display), (Comparator<Integer>) Comparator.naturalOrder()).orElse(150); - this.guiWidth = MathHelper.clamp(maxWidthDisplay + 30, 0, largestWidth); - this.guiHeight = MathHelper.floor(MathHelper.clamp((selectedCategory.getDisplayHeight() + 7d) * (getRecipesPerPage() + 1d) + 40d, 186d, largestHeight)); + this.guiWidth = maxWidthDisplay + 20; + this.guiHeight = MathHelper.floor(MathHelper.clamp((double) (selectedCategory.getDisplayHeight() + 4) * (getRecipesPerPage() + 1) + 36, 100, largestHeight)); this.bounds = new Rectangle(width / 2 - guiWidth / 2, height / 2 - guiHeight / 2, guiWidth, guiHeight); this.page = MathHelper.clamp(page, 0, getTotalPages(selectedCategory) - 1); @@ -212,7 +217,7 @@ public class RecipeViewingScreen extends Screen { categoryBack.enabled = categories.size() > 1; categoryNext.enabled = categories.size() > 1; - widgets.add(recipeBack = new ButtonWidget(new Rectangle(bounds.getX() + 5, bounds.getY() + 21, 12, 12), I18n.translate("text.rei.left_arrow")) { + widgets.add(recipeBack = new ButtonWidget(new Rectangle(bounds.getX() + 5, bounds.getY() + 19, 12, 12), I18n.translate("text.rei.left_arrow")) { @Override public void onPressed() { page--; @@ -226,7 +231,7 @@ public class RecipeViewingScreen extends Screen { return Optional.ofNullable(I18n.translate("text.rei.previous_page")); } }); - widgets.add(new ClickableLabelWidget(new Point(bounds.getCenterX(), bounds.getY() + 23), "") { + widgets.add(new ClickableLabelWidget(new Point(bounds.getCenterX(), bounds.getY() + 21), "") { @Override public void render(int mouseX, int mouseY, float delta) { setText(String.format("%d/%d", page + 1, getTotalPages(selectedCategory))); @@ -245,7 +250,7 @@ public class RecipeViewingScreen extends Screen { RecipeViewingScreen.this.init(); } }.clickable(categoriesMap.get(selectedCategory).size() > getRecipesPerPageByHeight())); - widgets.add(recipeNext = new ButtonWidget(new Rectangle(bounds.getMaxX() - 17, bounds.getY() + 21, 12, 12), I18n.translate("text.rei.right_arrow")) { + widgets.add(recipeNext = new ButtonWidget(new Rectangle(bounds.getMaxX() - 17, bounds.getY() + 19, 12, 12), I18n.translate("text.rei.right_arrow")) { @Override public void onPressed() { page++; @@ -289,8 +294,9 @@ public class RecipeViewingScreen extends Screen { int finalI = i; final Supplier<RecipeDisplay> displaySupplier = () -> currentDisplayed.get(finalI); int displayWidth = selectedCategory.getDisplayWidth(displaySupplier.get()); - final Rectangle displayBounds = new Rectangle(getBounds().getCenterX() - displayWidth / 2, getBounds().y + 40 + recipeHeight * i + 7 * i, displayWidth, recipeHeight); + final Rectangle displayBounds = new Rectangle(getBounds().getCenterX() - displayWidth / 2, getBounds().y - 2 + 36 + recipeHeight * i + 4 * i, displayWidth, recipeHeight); List<Widget> setupDisplay = selectedCategory.setupDisplay(displaySupplier, displayBounds); + transformNotice(setupDisplay, mainStackToNotice); this.widgets.addAll(setupDisplay); if (supplier.isPresent() && supplier.get().get(displayBounds) != null) this.widgets.add(new AutoCraftingButtonWidget(displayBounds, supplier.get().get(displayBounds), supplier.get().getButtonText(), displaySupplier, setupDisplay, selectedCategory)); @@ -306,20 +312,21 @@ public class RecipeViewingScreen extends Screen { int hh = MathHelper.floor((bounds.height - 16) / 18f); int actualHeight = Math.min(hh, workingStations.size()); int innerWidth = MathHelper.ceil(workingStations.size() / ((float) hh)); - int xx = bounds.x - (10 + innerWidth * 18) + 6; + int xx = bounds.x - (8 + innerWidth * 16) + 6; int yy = bounds.y + 16; - preWidgets.add(workingStationsBaseWidget = new CategoryBaseWidget(new Rectangle(xx - 6, yy - 6, 15 + innerWidth * 18, 11 + actualHeight * 18))); + preWidgets.add(workingStationsBaseWidget = new CategoryBaseWidget(new Rectangle(xx - 5, yy - 5, 15 + innerWidth * 16, 10 + actualHeight * 16))); + preWidgets.add(new SlotBaseWidget(new Rectangle(xx - 1, yy - 1, innerWidth * 16 + 2, actualHeight * 16 + 2))); int index = 0; List<String> list = Collections.singletonList(Formatting.YELLOW.toString() + I18n.translate("text.rei.working_station")); - xx += (innerWidth - 1) * 18; + xx += (innerWidth - 1) * 16; for (List<EntryStack> workingStation : workingStations) { - preWidgets.add(EntryWidget.create(xx, yy).entries(CollectionUtils.map(workingStation, stack -> stack.copy().setting(EntryStack.Settings.TOOLTIP_APPEND_EXTRA, s -> list)))); + preWidgets.add(new WorkstationSlotWidget(xx, yy, CollectionUtils.map(workingStation, stack -> stack.copy().setting(EntryStack.Settings.TOOLTIP_APPEND_EXTRA, s -> list)))); index++; - yy += 18; + yy += 16; if (index >= hh) { index = 0; yy = bounds.y + 16; - xx -= 18; + xx -= 16; } } } @@ -330,6 +337,36 @@ public class RecipeViewingScreen extends Screen { children.addAll(preWidgets); } + static void transformNotice(List<Widget> setupDisplay, EntryStack mainStackToNotice) { + if (mainStackToNotice.isEmpty()) + return; + for (Widget widget : setupDisplay) { + if (widget instanceof EntryWidget) { + EntryWidget entry = (EntryWidget) widget; + if (entry.entries().size() > 1) { + EntryStack stack = CollectionUtils.firstOrNullEqualsAll(entry.entries(), mainStackToNotice); + if (stack != null) { + entry.clearStacks(); + entry.entry(stack); + } + } + } + } + } + + public static class WorkstationSlotWidget extends EntryWidget { + public WorkstationSlotWidget(int x, int y, List<EntryStack> widgets) { + super(x, y); + entries(widgets); + noBackground(); + } + + @Override + public boolean containsMouse(double mouseX, double mouseY) { + return getInnerBounds().contains(mouseX, mouseY); + } + } + public List<Widget> getWidgets() { return widgets; } @@ -360,12 +397,12 @@ public class RecipeViewingScreen extends Screen { if (selectedCategory.getFixedRecipesPerPage() > 0) return selectedCategory.getFixedRecipesPerPage() - 1; int height = selectedCategory.getDisplayHeight(); - return MathHelper.clamp(MathHelper.floor(((double) largestHeight - 40d) / ((double) height + 7d)) - 1, 0, Math.min(ConfigObject.getInstance().getMaxRecipePerPage() - 1, selectedCategory.getMaximumRecipePerPage() - 1)); + return MathHelper.clamp(MathHelper.floor(((double) largestHeight - 36) / ((double) height + 4)) - 1, 0, Math.min(ConfigObject.getInstance().getMaxRecipePerPage() - 1, selectedCategory.getMaximumRecipePerPage() - 1)); } private int getRecipesPerPageByHeight() { int height = selectedCategory.getDisplayHeight(); - return MathHelper.clamp(MathHelper.floor(((double) guiHeight - 40d) / ((double) height + 7d)), 0, Math.min(ConfigObject.getInstance().getMaxRecipePerPage() - 1, selectedCategory.getMaximumRecipePerPage() - 1)); + return MathHelper.clamp(MathHelper.floor(((double) guiHeight - 36) / ((double) height + 4)), 0, Math.min(ConfigObject.getInstance().getMaxRecipePerPage() - 1, selectedCategory.getMaximumRecipePerPage() - 1)); } @Override @@ -377,13 +414,13 @@ public class RecipeViewingScreen extends Screen { if (selectedCategory != null) selectedCategory.drawCategoryBackground(bounds, mouseX, mouseY, delta); else { - new CategoryBaseWidget(bounds).render(); + PanelWidget.render(bounds, -1); if (ScreenHelper.isDarkModeEnabled()) { fill(bounds.x + 17, bounds.y + 5, bounds.x + bounds.width - 17, bounds.y + 17, 0xFF404040); - fill(bounds.x + 17, bounds.y + 21, bounds.x + bounds.width - 17, bounds.y + 33, 0xFF404040); + fill(bounds.x + 17, bounds.y + 19, bounds.x + bounds.width - 17, bounds.y + 30, 0xFF404040); } else { fill(bounds.x + 17, bounds.y + 5, bounds.x + bounds.width - 17, bounds.y + 17, 0xFF9E9E9E); - fill(bounds.x + 17, bounds.y + 21, bounds.x + bounds.width - 17, bounds.y + 33, 0xFF9E9E9E); + fill(bounds.x + 17, bounds.y + 19, bounds.x + bounds.width - 17, bounds.y + 31, 0xFF9E9E9E); } } for (TabWidget tab : tabs) { diff --git a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java index 17466fc66..c0b03a252 100644 --- a/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java +++ b/src/main/java/me/shedaniel/rei/gui/VillagerRecipeViewingScreen.java @@ -54,11 +54,12 @@ public class VillagerRecipeViewingScreen extends Screen { private double target; private long start; private long duration; - private float scrollBarAlpha = 0; - private float scrollBarAlphaFuture = 0; + private float scrollBarAlpha; + private float scrollBarAlphaFuture; private long scrollBarAlphaFutureTime = -1; - private boolean draggingScrollBar = false; + private boolean draggingScrollBar; private int tabsPage; + private EntryStack mainStackToNotice = EntryStack.empty(); public VillagerRecipeViewingScreen(Map<RecipeCategory<?>, List<RecipeDisplay>> map) { super(new LiteralText("")); @@ -83,6 +84,10 @@ public class VillagerRecipeViewingScreen extends Screen { }); } + public void addMainStackToNotice(EntryStack stack) { + this.mainStackToNotice = stack; + } + @Override protected void init() { super.init(); @@ -106,18 +111,19 @@ public class VillagerRecipeViewingScreen extends Screen { int w = Math.min(ww, workingStations.size()); int h = MathHelper.ceil(workingStations.size() / ((float) ww)); int xx = bounds.x + 16; - int yy = bounds.y + bounds.height + 5; - widgets.add(new CategoryBaseWidget(new Rectangle(xx - 6, bounds.y + bounds.height - 5, 11 + w * 18, 15 + h * 18))); + int yy = bounds.y + bounds.height + 2; + widgets.add(new CategoryBaseWidget(new Rectangle(xx - 5, bounds.y + bounds.height - 5, 10 + w * 16, 12 + h * 16))); + widgets.add(new SlotBaseWidget(new Rectangle(xx - 1, yy - 1, 2 + w * 16, 2 + h * 16))); int index = 0; List<String> list = Collections.singletonList(Formatting.YELLOW.toString() + I18n.translate("text.rei.working_station")); for (List<EntryStack> workingStation : workingStations) { - widgets.add(EntryWidget.create(xx, yy).entries(CollectionUtils.map(workingStation, stack -> stack.copy().setting(EntryStack.Settings.TOOLTIP_APPEND_EXTRA, s -> list)))); + widgets.add(new RecipeViewingScreen.WorkstationSlotWidget(xx, yy, CollectionUtils.map(workingStation, stack -> stack.copy().setting(EntryStack.Settings.TOOLTIP_APPEND_EXTRA, s -> list)))); index++; - xx += 18; + xx += 16; if (index >= ww) { index = 0; xx = bounds.x + 16; - yy += 18; + yy += 16; } } } @@ -128,6 +134,7 @@ public class VillagerRecipeViewingScreen extends Screen { Rectangle recipeBounds = new Rectangle(bounds.x + 100 + (guiWidth - 100) / 2 - category.getDisplayWidth(display) / 2, bounds.y + bounds.height / 2 - category.getDisplayHeight() / 2, category.getDisplayWidth(display), category.getDisplayHeight()); List<Widget> setupDisplay = category.setupDisplay(() -> display, recipeBounds); + RecipeViewingScreen.transformNotice(setupDisplay, mainStackToNotice); this.widgets.addAll(setupDisplay); Optional<ButtonAreaSupplier> supplier = RecipeHelper.getInstance().getAutoCraftButtonArea(category); if (supplier.isPresent() && supplier.get().get(recipeBounds) != null) diff --git a/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java index 1090d4813..71c7c3dae 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java @@ -8,7 +8,6 @@ package me.shedaniel.rei.gui.widget; import com.google.common.collect.Lists; import com.mojang.blaze3d.systems.RenderSystem; import me.shedaniel.clothconfig2.ClothConfigInitializer; -import me.shedaniel.clothconfig2.api.ModifierKeyCode; import me.shedaniel.clothconfig2.api.ScissorsHandler; import me.shedaniel.clothconfig2.gui.widget.DynamicNewSmoothScrollingEntryListWidget; import me.shedaniel.math.api.Point; @@ -29,19 +28,19 @@ import net.minecraft.client.render.Tessellator; import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.VertexFormats; import net.minecraft.client.resource.language.I18n; -import net.minecraft.client.sound.PositionedSoundInstance; -import net.minecraft.client.util.InputUtil; import net.minecraft.client.util.math.Matrix4f; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.item.ItemGroup; -import net.minecraft.sound.SoundEvents; import net.minecraft.util.ActionResult; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; import org.apache.commons.lang3.StringUtils; import javax.annotation.Nullable; -import java.util.*; +import java.util.Collections; +import java.util.Comparator; +import java.util.List; +import java.util.Locale; import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.Supplier; import java.util.stream.Collectors; @@ -350,6 +349,8 @@ public class EntryListWidget extends WidgetWithBounds { } } } + if (containsMouse(mouseX, mouseY) && ClientHelper.getInstance().isCheating() && !minecraft.player.inventory.getCursorStack().isEmpty() && RoughlyEnoughItemsCore.hasPermissionToUsePackets()) + ScreenHelper.getLastOverlay().addTooltip(QueuedTooltip.create(I18n.translate("text.rei.delete_items"))); } private int getScrollbarMinX() { @@ -593,6 +594,7 @@ public class EntryListWidget extends WidgetWithBounds { if (searchArguments.isEmpty()) return true; String mod = null; + String modName = null; String name = null; String tooltip = null; String[] tags = null; @@ -604,9 +606,17 @@ public class EntryListWidget extends WidgetWithBounds { else if (argument.getArgumentType() == SearchArgument.ArgumentType.MOD) { if (mod == null) mod = stack.getIdentifier().map(Identifier::getNamespace).orElse("").replace(SPACE, EMPTY).toLowerCase(Locale.ROOT); - if (mod != null && !mod.isEmpty() && argument.getFunction(!argument.isInclude()).apply(mod)) { - applicable = false; - break; + if (mod != null && !mod.isEmpty()) { + if (argument.getFunction(!argument.isInclude()).apply(mod)) { + applicable = false; + break; + } + if (modName == null) + modName = ClientHelper.getInstance().getModFromModId(mod).replace(SPACE, EMPTY).toLowerCase(Locale.ROOT); + if (modName != null && !modName.isEmpty() && argument.getFunction(!argument.isInclude()).apply(modName)) { + applicable = false; + break; + } } } else if (argument.getArgumentType() == SearchArgument.ArgumentType.TEXT) { if (name == null) @@ -717,7 +727,7 @@ public class EntryListWidget extends WidgetWithBounds { ClientPlayerEntity player = minecraft.player; if (ClientHelper.getInstance().isCheating() && !player.inventory.getCursorStack().isEmpty() && RoughlyEnoughItemsCore.hasPermissionToUsePackets()) { ClientHelper.getInstance().sendDeletePacket(); - return false; + return true; } if (!player.inventory.getCursorStack().isEmpty() && RoughlyEnoughItemsCore.hasPermissionToUsePackets()) return false; @@ -749,60 +759,16 @@ public class EntryListWidget extends WidgetWithBounds { super.drawHighlighted(mouseX, mouseY, delta); } - private String getLocalizedName(InputUtil.KeyCode value) { - String string_1 = value.getName(); - int int_1 = value.getKeyCode(); - String string_2 = null; - switch (value.getCategory()) { - case KEYSYM: - string_2 = InputUtil.getKeycodeName(int_1); - break; - case SCANCODE: - string_2 = InputUtil.getScancodeName(int_1); - break; - case MOUSE: - String string_3 = I18n.translate(string_1); - string_2 = Objects.equals(string_3, string_1) ? I18n.translate(InputUtil.Type.MOUSE.getName(), int_1 + 1) : string_3; - } - - return string_2 == null ? I18n.translate(string_1) : string_2; - } - @Override protected void queueTooltip(int mouseX, int mouseY, float delta) { if (!ClientHelper.getInstance().isCheating() || minecraft.player.inventory.getCursorStack().isEmpty()) { - QueuedTooltip tooltip = getCurrentTooltip(mouseX, mouseY); - if (tooltip != null) { - if (ConfigObject.getInstance().doDisplayFavoritesTooltip() && !ConfigObject.getInstance().getFavoriteKeyCode().isUnknown()) { - String name = ConfigObject.getInstance().getFavoriteKeyCode().getLocalizedName(); - if (!isFavorites) - tooltip.getText().addAll(Arrays.asList(I18n.translate("text.rei.favorites_tooltip", name).split("\n"))); - else - tooltip.getText().addAll(Arrays.asList(I18n.translate("text.rei.remove_favorites_tooltip", name).split("\n"))); - } - ScreenHelper.getLastOverlay().addTooltip(tooltip); - } + super.queueTooltip(mouseX, mouseY, delta); } } @Override - public boolean keyPressed(int int_1, int int_2, int int_3) { - if (interactable && ConfigObject.getInstance().isFavoritesEnabled() && containsMouse(PointHelper.fromMouse()) && !getCurrentEntry().isEmpty()) { - ModifierKeyCode keyCode = ConfigObject.getInstance().getFavoriteKeyCode(); - if (keyCode.matchesKey(int_1, int_2)) { - if (!isFavorites) { - if (!CollectionUtils.anyMatchEqualsAll(ConfigManager.getInstance().getFavorites(), getCurrentEntry())) - ConfigManager.getInstance().getFavorites().add(getCurrentEntry().copy()); - } else { - ConfigManager.getInstance().getFavorites().remove(getCurrentEntry()); - } - ContainerScreenOverlay.getEntryListWidget().updateSearch(ScreenHelper.getSearchField().getText()); - ConfigManager.getInstance().saveConfig(); - minecraft.getSoundManager().play(PositionedSoundInstance.master(SoundEvents.UI_BUTTON_CLICK, 1.0F)); - return true; - } - } - return super.keyPressed(int_1, int_2, int_3); + protected boolean reverseFavoritesAction() { + return isFavorites; } @Override diff --git a/src/main/java/me/shedaniel/rei/gui/widget/EntryWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/EntryWidget.java index 1ab648467..8b3c556e4 100644 --- a/src/main/java/me/shedaniel/rei/gui/widget/EntryWidget.java +++ b/src/main/java/me/shedaniel/rei/gui/widget/EntryWidget.java @@ -6,20 +6,24 @@ package me.shedaniel.rei.gui.widget; import com.mojang.blaze3d.systems.RenderSystem; +import me.shedaniel.clothconfig2.api.ModifierKeyCode; import me.shedaniel.math.api.Rectangle; import me.shedaniel.math.impl.PointHelper; import me.shedaniel.rei.api.ClientHelper; +import me.shedaniel.rei.api.ConfigManager; import me.shedaniel.rei.api.ConfigObject; import me.shedaniel.rei.api.EntryStack; +import me.shedaniel.rei.gui.ContainerScreenOverlay; import me.shedaniel.rei.impl.ScreenHelper; +import me.shedaniel.rei.utils.CollectionUtils; import net.minecraft.client.gui.Element; +import net.minecraft.client.resource.language.I18n; +import net.minecraft.client.sound.PositionedSoundInstance; +import net.minecraft.sound.SoundEvents; import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.List; +import java.util.*; public class EntryWidget extends WidgetWithBounds { @@ -30,6 +34,7 @@ public class EntryWidget extends WidgetWithBounds { protected boolean tooltips = true; protected boolean background = true; protected boolean interactable = true; + protected boolean interactableFavorites = true; private Rectangle bounds; private List<EntryStack> entryStacks; @@ -48,6 +53,16 @@ public class EntryWidget extends WidgetWithBounds { public EntryWidget interactable(boolean b) { interactable = b; + interactableFavorites = interactableFavorites && interactable; + return this; + } + + public EntryWidget disableFavoritesInteractions() { + return interactableFavorites(false); + } + + public EntryWidget interactableFavorites(boolean b) { + interactableFavorites = b && interactable; return this; } @@ -144,6 +159,13 @@ public class EntryWidget extends WidgetWithBounds { protected void queueTooltip(int mouseX, int mouseY, float delta) { QueuedTooltip tooltip = getCurrentTooltip(mouseX, mouseY); if (tooltip != null) { + if (interactableFavorites && ConfigObject.getInstance().doDisplayFavoritesTooltip() && !ConfigObject.getInstance().getFavoriteKeyCode().isUnknown()) { + String name = ConfigObject.getInstance().getFavoriteKeyCode().getLocalizedName(); + if (reverseFavoritesAction()) + tooltip.getText().addAll(Arrays.asList(I18n.translate("text.rei.remove_favorites_tooltip", name).split("\n"))); + else + tooltip.getText().addAll(Arrays.asList(I18n.translate("text.rei.favorites_tooltip", name).split("\n"))); + } |
