diff options
Diffstat (limited to 'src/main/java')
32 files changed, 560 insertions, 190 deletions
diff --git a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java index 1e6f9e966..e967bf32c 100644 --- a/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java +++ b/src/main/java/me/shedaniel/rei/RoughlyEnoughItemsCore.java @@ -42,6 +42,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.concurrent.CompletableFuture; import java.util.stream.Collectors; public class RoughlyEnoughItemsCore implements ClientModInitializer { @@ -206,7 +207,10 @@ public class RoughlyEnoughItemsCore implements ClientModInitializer { private void registerClothEvents() { ClothClientHooks.SYNC_RECIPES.register((minecraftClient, recipeManager, synchronizeRecipesS2CPacket) -> { - ((RecipeHelperImpl) RoughlyEnoughItemsCore.getRecipeHelper()).recipesLoaded(recipeManager); + if (RoughlyEnoughItemsCore.getConfigManager().getConfig().registerRecipesInAnotherThread) + CompletableFuture.runAsync(() -> ((RecipeHelperImpl) RoughlyEnoughItemsCore.getRecipeHelper()).recipesLoaded(recipeManager)); + else + ((RecipeHelperImpl) RoughlyEnoughItemsCore.getRecipeHelper()).recipesLoaded(recipeManager); }); ClothClientHooks.SCREEN_ADD_BUTTON.register((minecraftClient, screen, abstractButtonWidget) -> { if (RoughlyEnoughItemsCore.getConfigManager().getConfig().disableRecipeBook && screen instanceof AbstractContainerScreen && abstractButtonWidget instanceof RecipeBookButtonWidget) diff --git a/src/main/java/me/shedaniel/rei/api/DisplayVisibility.java b/src/main/java/me/shedaniel/rei/api/DisplayVisibility.java index 8f1149e26..0bfdb024c 100644 --- a/src/main/java/me/shedaniel/rei/api/DisplayVisibility.java +++ b/src/main/java/me/shedaniel/rei/api/DisplayVisibility.java @@ -7,7 +7,7 @@ package me.shedaniel.rei.api; public enum DisplayVisibility { ALWAYS_VISIBLE, - CONFIG_OPTIONAL, + @Deprecated CONFIG_OPTIONAL, NEVER_VISIBLE, PASS } diff --git a/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java b/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java index 8f6156891..429306ff2 100644 --- a/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java +++ b/src/main/java/me/shedaniel/rei/api/DisplayVisibilityHandler.java @@ -20,7 +20,6 @@ public interface DisplayVisibilityHandler { * Handles the visibility of the display. * {@link DisplayVisibility#PASS} to pass the handling to another handler * {@link DisplayVisibility#ALWAYS_VISIBLE} to always display it - * {@link DisplayVisibility#CONFIG_OPTIONAL} to allow user to configure the visibility * {@link DisplayVisibility#NEVER_VISIBLE} to never display it * * @param category the category of the display diff --git a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java index 27a68eafd..9db9a349f 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeCategory.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeCategory.java @@ -5,6 +5,7 @@ package me.shedaniel.rei.api; +import me.shedaniel.rei.RoughlyEnoughItemsCore; import me.shedaniel.rei.gui.RecipeViewingScreen; import me.shedaniel.rei.gui.renderables.RecipeRenderer; import me.shedaniel.rei.gui.widget.CategoryBaseWidget; @@ -87,8 +88,13 @@ public interface RecipeCategory<T extends RecipeDisplay> { */ default void drawCategoryBackground(Rectangle bounds, int mouseX, int mouseY, float delta) { new CategoryBaseWidget(bounds).render(); - DrawableHelper.fill(bounds.x + 17, bounds.y + 5, bounds.x + bounds.width - 17, bounds.y + 17, RecipeViewingScreen.SUB_COLOR.getRGB()); - DrawableHelper.fill(bounds.x + 17, bounds.y + 21, bounds.x + bounds.width - 17, bounds.y + 33, RecipeViewingScreen.SUB_COLOR.getRGB()); + if (RoughlyEnoughItemsCore.getConfigManager().getConfig().darkTheme) { + 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); + } 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); + } } /** diff --git a/src/main/java/me/shedaniel/rei/api/RecipeDisplay.java b/src/main/java/me/shedaniel/rei/api/RecipeDisplay.java index 9e17159bc..cd8ab6efb 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeDisplay.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeDisplay.java @@ -18,7 +18,7 @@ public interface RecipeDisplay<T extends Recipe> { /** * @return the optional recipe */ - Optional<T> getRecipe(); + Optional<? extends Recipe> getRecipe(); /** * @return a list of items @@ -35,6 +35,7 @@ public interface RecipeDisplay<T extends Recipe> { * * @return the list of required items */ + @Deprecated default List<List<ItemStack>> getRequiredItems() { return Lists.newArrayList(); } diff --git a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java index a57b7146f..cfbda23f0 100644 --- a/src/main/java/me/shedaniel/rei/api/RecipeHelper.java +++ b/src/main/java/me/shedaniel/rei/api/RecipeHelper.java @@ -14,6 +14,7 @@ import net.minecraft.util.Identifier; import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.function.Function; public interface RecipeHelper { @@ -52,6 +53,24 @@ public interface RecipeHelper { void registerCategory(RecipeCategory category); /** + * Registers the working stations of a category + * + * @param category the category + * @param workingStations the working stations + */ + void registerWorkingStations(Identifier category, List<ItemStack>... workingStations); + + /** + * Registers the working stations of a category + * + * @param category the category + * @param workingStations the working stations + */ + void registerWorkingStations(Identifier category, ItemStack... workingStations); + + List<List<ItemStack>> getWorkingStations(Identifier category); + + /** * Registers a recipe display * * @param categoryIdentifier the category to display in @@ -106,10 +125,10 @@ public interface RecipeHelper { void registerSpeedCraftButtonArea(Identifier category, ButtonAreaSupplier rectangle); /** - * Registers a default speed crafting button area, which is bottom right - * * @param category the category of the button area + * @deprecated Not required anymore */ + @Deprecated void registerDefaultSpeedCraftButtonArea(Identifier category); /** @@ -162,10 +181,20 @@ public interface RecipeHelper { * @param display the display to be checked * @param respectConfig whether it should respect the user's config * @return whether the display should be visible + * @deprecated {@link RecipeHelper#isDisplayVisible(RecipeDisplay)} )} */ + @Deprecated boolean isDisplayVisible(RecipeDisplay display, boolean respectConfig); /** + * Checks if the display is visible by asking recipe visibility handlers + * + * @param display the display to be checked + * @return whether the display should be visible + */ + boolean isDisplayVisible(RecipeDisplay display); + + /** * Gets the cached category setting by the category identifier * * @param category the identifier of the category @@ -173,6 +202,15 @@ public interface RecipeHelper { */ Optional<DisplaySettings> getCachedCategorySettings(Identifier category); + /** + * Registers a live recipe generator. + * + * @param liveRecipeGenerator the generator to register + * @apiNote Still work in progress + */ void registerLiveRecipeGenerator(LiveRecipeGenerator liveRecipeGenerator); + <T extends Recipe<?>> void registerRecipes(Identifier category, Class<T> recipeClass, Function<T, RecipeDisplay> mappingFunction); + + <T extends Recipe<?>> void registerRecipes(Identifier category, Function<Recipe, Boolean> recipeFilter, Function<T, RecipeDisplay> mappingFunction); } diff --git a/src/main/java/me/shedaniel/rei/client/ConfigObject.java b/src/main/java/me/shedaniel/rei/client/ConfigObject.java index 4cde9df00..252d630f6 100644 --- a/src/main/java/me/shedaniel/rei/client/ConfigObject.java +++ b/src/main/java/me/shedaniel/rei/client/ConfigObject.java @@ -42,14 +42,16 @@ public class ConfigObject { @Comment("Disable Recipe Book") public boolean disableRecipeBook = false; - public boolean preferVisibleRecipes = false; - - @Comment("Force enable 2019 REI April Fools' joke") public boolean aprilFoolsFish2019 = false; - public ItemCheatingMode itemCheatingMode = ItemCheatingMode.REI_LIKE; public boolean lightGrayRecipeBorder = false; + public boolean villagerScreenPermanentScrollBar = false; + + public boolean darkTheme = false; + + public boolean registerRecipesInAnotherThread = true; + public RecipeScreenType screenType = RecipeScreenType.UNSET; @Comment( diff --git a/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java b/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java index f7891670f..7f4a0ee80 100644 --- a/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java +++ b/src/main/java/me/shedaniel/rei/client/RecipeHelperImpl.java @@ -18,6 +18,7 @@ import java.awt.*; import java.util.List; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; +import java.util.function.Function; import java.util.stream.Collectors; public class RecipeHelperImpl implements RecipeHelper { @@ -35,12 +36,14 @@ public class RecipeHelperImpl implements RecipeHelper { VISIBILITY_HANDLER_COMPARATOR = comparator.reversed(); } + public final List<RecipeFunction> recipeFunctions = Lists.newArrayList(); private final AtomicInteger recipeCount = new AtomicInteger(); private final Map<Identifier, List<RecipeDisplay>> recipeCategoryListMap = Maps.newHashMap(); private final Map<Identifier, DisplaySettings> categoryDisplaySettingsMap = Maps.newHashMap(); private final List<RecipeCategory> categories = Lists.newArrayList(); private final Map<Identifier, ButtonAreaSupplier> speedCraftAreaSupplierMap = Maps.newHashMap(); private final Map<Identifier, List<SpeedCraftFunctional>> speedCraftFunctionalMap = Maps.newHashMap(); + private final Map<Identifier, List<List<ItemStack>>> categoryWorkingStations = Maps.newHashMap(); private final List<DisplayVisibilityHandler> displayVisibilityHandlers = Lists.newArrayList(); private final List<LiveRecipeGenerator> liveRecipeGenerators = Lists.newArrayList(); private RecipeManager recipeManager; @@ -80,6 +83,22 @@ public class RecipeHelperImpl implements RecipeHelper { categories.add(category); categoryDisplaySettingsMap.put(category.getIdentifier(), category.getDisplaySettings()); recipeCategoryListMap.put(category.getIdentifier(), Lists.newLinkedList()); + categoryWorkingStations.put(category.getIdentifier(), Lists.newLinkedList()); + } + + @Override + public void registerWorkingStations(Identifier category, List<ItemStack>... workingStations) { + categoryWorkingStations.get(category).addAll(Arrays.asList(workingStations)); + } + + @Override + public void registerWorkingStations(Identifier category, ItemStack... workingStations) { + categoryWorkingStations.get(category).addAll(Arrays.asList(workingStations).stream().map(Collections::singletonList).collect(Collectors.toList())); + } + + @Override + public List<List<ItemStack>> getWorkingStations(Identifier category) { + return categoryWorkingStations.get(category); } @Override @@ -90,6 +109,13 @@ public class RecipeHelperImpl implements RecipeHelper { recipeCategoryListMap.get(categoryIdentifier).add(display); } + private void registerDisplay(Identifier categoryIdentifier, RecipeDisplay display, int index) { + if (!recipeCategoryListMap.containsKey(categoryIdentifier)) + return; + recipeCount.incrementAndGet(); + recipeCategoryListMap.get(categoryIdentifier).add(index, display); + } + @Override public Map<RecipeCategory, List<RecipeDisplay>> getRecipesFor(ItemStack stack) { Map<Identifier, List<RecipeDisplay>> categoriesMap = new HashMap<>(); @@ -106,7 +132,7 @@ public class RecipeHelperImpl implements RecipeHelper { Map<RecipeCategory, List<RecipeDisplay>> recipeCategoryListMap = Maps.newLinkedHashMap(); categories.forEach(category -> { if (categoriesMap.containsKey(category.getIdentifier()) && !categoriesMap.get(category.getIdentifier()).isEmpty()) - recipeCategoryListMap.put(category, categoriesMap.get(category.getIdentifier()).stream().filter(display -> isDisplayVisible(display, true)).collect(Collectors.toList())); + recipeCategoryListMap.put(category, categoriesMap.get(category.getIdentifier()).stream().filter(display -> isDisplayVisible(display)).collect(Collectors.toList())); }); for(RecipeCategory category : Lists.newArrayList(recipeCategoryListMap.keySet())) if (recipeCategoryListMap.get(category).isEmpty()) @@ -149,7 +175,7 @@ public class RecipeHelperImpl implements RecipeHelper { Map<RecipeCategory, List<RecipeDisplay>> recipeCategoryListMap = Maps.newLinkedHashMap(); categories.forEach(category -> { if (categoriesMap.containsKey(category.getIdentifier()) && !categoriesMap.get(category.getIdentifier()).isEmpty()) - recipeCategoryListMap.put(category, categoriesMap.get(category.getIdentifier()).stream().filter(display -> isDisplayVisible(display, true)).collect(Collectors.toList())); + recipeCategoryListMap.put(category, categoriesMap.get(category.getIdentifier()).stream().filter(display -> isDisplayVisible(display)).collect(Collectors.toList())); }); for(RecipeCategory category : Lists.newArrayList(recipeCategoryListMap.keySet())) if (recipeCategoryListMap.get(category).isEmpty()) @@ -165,13 +191,17 @@ public class RecipeHelperImpl implements RecipeHelper { @Override public Optional<ButtonAreaSupplier> getSpeedCraftButtonArea(RecipeCategory category) { if (!speedCraftAreaSupplierMap.containsKey(category.getIdentifier())) - return Optional.empty(); + return Optional.ofNullable(bounds -> new Rectangle((int) bounds.getMaxX() - 16, (int) bounds.getMaxY() - 16, 10, 10)); return Optional.ofNullable(speedCraftAreaSupplierMap.get(category.getIdentifier())); } @Override public void registerSpeedCraftButtonArea(Identifier category, ButtonAreaSupplier rectangle) { - speedCraftAreaSupplierMap.put(category, rectangle); + if (rectangle == null) { + if (speedCraftAreaSupplierMap.containsKey(category)) + speedCraftAreaSupplierMap.remove(category); + } else + speedCraftAreaSupplierMap.put(category, rectangle); } @Override @@ -200,8 +230,10 @@ public class RecipeHelperImpl implements RecipeHelper { this.recipeCategoryListMap.clear(); this.categories.clear(); this.speedCraftAreaSupplierMap.clear(); + this.categoryWorkingStations.clear(); this.speedCraftFunctionalMap.clear(); this.categoryDisplaySettingsMap.clear(); + this.recipeFunctions.clear(); this.displayVisibilityHandlers.clear(); this.liveRecipeGenerators.clear(); ((DisplayHelperImpl) RoughlyEnoughItemsCore.getDisplayHelper()).resetCache(); @@ -234,6 +266,17 @@ public class RecipeHelperImpl implements RecipeHelper { RoughlyEnoughItemsCore.LOGGER.error("[REI] " + identifier.toString() + " plugin failed to load!", e); } }); + if (!recipeFunctions.isEmpty()) { + List<Recipe> allSortedRecipes = getAllSortedRecipes(); + Collections.reverse(allSortedRecipes); + recipeFunctions.forEach(recipeFunction -> { + try { + allSortedRecipes.stream().filter(recipe -> recipeFunction.recipeFilter.apply(recipe)).forEach(t -> registerDisplay(recipeFunction.category, (RecipeDisplay) recipeFunction.mappingFunction.apply(t), 0)); + } catch (Exception e) { + RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to add recipes!", e); + } + }); + } if (getDisplayVisibilityHandlers().isEmpty()) registerRecipeVisibilityHandler(new DisplayVisibilityHandler() { @Override @@ -265,7 +308,7 @@ public class RecipeHelperImpl implements RecipeHelper { Map<RecipeCategory, List<RecipeDisplay>> map = Maps.newLinkedHashMap(); categories.forEach(recipeCategory -> { if (recipeCategoryListMap.containsKey(recipeCategory.getIdentifier())) { - List<RecipeDisplay> list = recipeCategoryListMap.get(recipeCategory.getIdentifier()).stream().filter(display -> isDisplayVisible(display, true)).collect(Collectors.toList()); + List<RecipeDisplay> list = recipeCategoryListMap.get(recipeCategory.getIdentifier()).stream().filter(display -> isDisplayVisible(display)).collect(Collectors.toList()); if (!list.isEmpty()) map.put(recipeCategory, list); } @@ -288,22 +331,40 @@ public class RecipeHelperImpl implements RecipeHelper { return Collections.unmodifiableList(displayVisibilityHandlers); } + @SuppressWarnings("deprecation") @Override public boolean isDisplayVisible(RecipeDisplay display, boolean respectConfig) { + return isDisplayVisible(display); + } + + @SuppressWarnings("deprecation") + @Override + public boolean isDisplayVisible(RecipeDisplay display) { RecipeCategory category = getCategory(display.getRecipeCategory()); List<DisplayVisibilityHandler> list = getDisplayVisibilityHandlers().stream().sorted(VISIBILITY_HANDLER_COMPARATOR).collect(Collectors.toList()); for(DisplayVisibilityHandler displayVisibilityHandler : list) { - DisplayVisibility visibility = displayVisibilityHandler.handleDisplay(category, display); - if (visibility != DisplayVisibility.PASS) { - if (visibility == DisplayVisibility.CONFIG_OPTIONAL) - return RoughlyEnoughItemsCore.getConfigManager().getConfig().preferVisibleRecipes || !respectConfig; - return visibility == DisplayVisibility.ALWAYS_VISIBLE; + try { + DisplayVisibility visibility = displayVisibilityHandler.handleDisplay(category, display); + if (visibility != DisplayVisibility.PASS) + return visibility == DisplayVisibility.ALWAYS_VISIBLE || visibility == DisplayVisibility.CONFIG_OPTIONAL; + } catch (Throwable throwable) { + RoughlyEnoughItemsCore.LOGGER.error("[REI] Failed to check if the recipe is visible!", throwable); } } return true; } @Override + public <T extends Recipe<?>> void registerRecipes(Identifier category, Class<T> recipeClass, Function<T, RecipeDisplay> mappingFunction) { + recipeFunctions.add(new RecipeFunction(category, recipe -> recipeClass.isAssignableFrom(recipe.getClass()), mappingFunction)); + } + + @Override + public <T extends Recipe<?>> void registerRecipes(Identifier category, Function<Recipe, Boolean> recipeFilter, Function<T, RecipeDisplay> mappingFunction) { + recipeFunctions.add(new RecipeFunction(category, recipeFilter, mappingFunction)); + } + + @Override public Optional<DisplaySettings> getCachedCategorySettings(Identifier category) { return categoryDisplaySettingsMap.entrySet().stream().filter(entry -> entry.getKey().equals(category)).map(Map.Entry::getValue).findAny(); } @@ -313,4 +374,16 @@ public class RecipeHelperImpl implements RecipeHelper { liveRecipeGenerators.add(liveRecipeGenerator); } + private class RecipeFunction { + Identifier category; + Function<Recipe, Boolean> recipeFilter; + Function mappingFunction; + + public RecipeFunction(Identifier category, Function<Recipe, Boolean> recipeFilter, Function<?, RecipeDisplay> mappingFunction) { + this.category = category; + this.recipeFilter = recipeFilter; + this.mappingFunction = mappingFunction; + } + } + } diff --git a/src/main/java/me/shedaniel/rei/client/ScreenHelper.java b/src/main/java/me/shedaniel/rei/client/ScreenHelper.java index 81c5c8df4..4b6572fd4 100644 --- a/src/main/java/me/shedaniel/rei/client/ScreenHelper.java +++ b/src/main/java/me/shedaniel/rei/client/ScreenHelper.java @@ -66,13 +66,13 @@ public class ScreenHelper implements ClientModInitializer { } public static void drawHoveringWidget(Dimension dimension, int x, int y, TriConsumer<Integer, Integer, Float> consumer, int width, int height, float delta) { - int int_5 = x + 12; - int int_6 = y - 12; - if (int_5 + width > dimension.width) - int_5 -= 28 + width; - if (int_6 + height + 6 > dimension.height) - int_6 = dimension.height - height - 6; - consumer.accept(int_5, int_6, delta); + int actualX = Math.max(x + 12, 6); + int actualY = Math.min(y - height / 2, dimension.height - height - 6); + if (actualX + width > dimension.width) + actualX -= 24 + width; + if (actualY < 6) + actualY += 24; + consumer.accept(actualX, actualY, delta); } @Override diff --git a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java index fe4824ca9..727a5307a 100644 --- a/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java +++ b/src/main/java/me/shedaniel/rei/gui/ContainerScreenOverlay.java @@ -183,31 +183,35 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra return false; } }); - widgets.add(new ButtonWidget(RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel ? window.getScaledWidth() - 80 : 60, 10, 20, 20, "") { - @Override - public void onPressed() { - MinecraftClient.getInstance().player.sendChatMessage(RoughlyEnoughItemsCore.getConfigManager().getConfig().weatherCommand.replaceAll("\\{weather}", getNextWeather().name().toLowerCase())); - } - - @Override - public void render(int mouseX, int mouseY, float delta) { - super.render(mouseX, mouseY, delta); - GuiLighting.disable(); - MinecraftClient.getInstance().getTextureManager().bindTexture(CHEST_GUI_TEXTURE); - GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); - blit(getBounds().x + 3, getBounds().y + 3, getCurrentWeather().getId() * 14, 14, 14, 14); - } - - @Override - public Optional<String> getTooltips() { - return Optional.ofNullable(I18n.translate("text.rei.weather_button.tooltip", I18n.translate(getNextWeather().getTranslateKey()))); - } - - @Override - public boolean changeFocus(boolean boolean_1) { - return false; - } - }); + int xxx = RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel ? window.getScaledWidth() -30 : 10; + for(Weather weather : Weather.values()) { + widgets.add(new ButtonWidget(xxx, 35, 20, 20, "") { + @Override + public void onPressed() { + MinecraftClient.getInstance().player.sendChatMessage(RoughlyEnoughItemsCore.getConfigManager().getConfig().weatherCommand.replaceAll("\\{weather}", weather.name().toLowerCase())); + } + + @Override + public void render(int mouseX, int mouseY, float delta) { + super.render(mouseX, mouseY, delta); + GuiLighting.disable(); + MinecraftClient.getInstance().getTextureManager().bindTexture(CHEST_GUI_TEXTURE); + GlStateManager.color4f(1.0F, 1.0F, 1.0F, 1.0F); + blit(getBounds().x + 3, getBounds().y + 3, weather.getId() * 14, 14, 14, 14); + } + + @Override + public Optional<String> getTooltips() { + return Optional.ofNullable(I18n.translate("text.rei.weather_button.tooltip", I18n.translate(weather.getTranslateKey()))); + } + + @Override + public boolean changeFocus(boolean boolean_1) { + return false; + } + }); + xxx += RoughlyEnoughItemsCore.getConfigManager().getConfig().mirrorItemPanel ? -25 : 25; + } } widgets.add(new ClickableLabelWidget(rectangle.x + (rectangle.width / 2), rectangle.y + 10, "", getTotalPage() > 0) { @Override @@ -373,28 +377,24 @@ public class ContainerScreenOverlay extends AbstractParentElement implements Dra QUEUED_TOOLTIPS.clear(); } + @SuppressWarnings("deprecation") public void renderTooltip(QueuedTooltip tooltip) { - renderTooltip(tooltip.getText(), tooltip.getX(), tooltip.getY()); + if (tooltip.getConsumer() == null) + renderTooltip(tooltip.getText(), tooltip.getX(), tooltip.getY()); + else + tooltip.getConsumer().accept(tooltip); } public void renderTooltip(List<String> lines, int mouseX, int mouseY) { + if (lines.isEmpty()) + return; TextRenderer font = MinecraftClient.getInstance().textRenderer; - if (!lines.isEmpty()) { + int width = lines.stream().map(font::getStringWidth).max(Integer::compareTo).get(); + int height = lines.size() <= 1 ? 8 : lines.size() * 10; + ScreenHelper.drawHoveringWidget(mouseX, mouseY, (x, y, aFloat) -> { GlStateManager.disableRescaleNormal(); GuiLighting.disable(); GlStateManager.disableLighting(); - int width = 0; - for(String line : lines) - if (font.getStringWidth(line) > width) - width = font.getStringWidth(line); - int height = lines.size() <= 1 ? 8 : lines.size() * 10; - int x = Math.max(mouseX + 12, 6); - int y = Math.min(mouseY - 12, window.getScaledHeight() - height - 6); - if (x + width > window.getScaledWidth()) - x -= 24 + width;< |
