diff options
| author | Unknown <shekwancheung0528@gmail.com> | 2019-06-08 20:30:53 +0800 |
|---|---|---|
| committer | Unknown <shekwancheung0528@gmail.com> | 2019-06-08 20:30:53 +0800 |
| commit | 4710c557f449703362665a520bf68b85b2a7cdc1 (patch) | |
| tree | ed9555c626be11c7bc0d230d2b905856269bd916 /src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java | |
| parent | 28adfa726bcdb27eea4ffa39962c881d5c3d929b (diff) | |
| download | RoughlyEnoughItems-4710c557f449703362665a520bf68b85b2a7cdc1.tar.gz RoughlyEnoughItems-4710c557f449703362665a520bf68b85b2a7cdc1.tar.bz2 RoughlyEnoughItems-4710c557f449703362665a520bf68b85b2a7cdc1.zip | |
We are going to break lots of mods
Diffstat (limited to 'src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java')
| -rw-r--r-- | src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java b/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java new file mode 100644 index 000000000..d62ac654f --- /dev/null +++ b/src/main/java/me/shedaniel/rei/gui/widget/AutoCraftingButtonWidget.java @@ -0,0 +1,57 @@ +/* + * Roughly Enough Items by Danielshe. + * Licensed under the MIT License. + */ + +package me.shedaniel.rei.gui.widget; + +import me.shedaniel.rei.api.RecipeDisplay; +import me.shedaniel.rei.client.ScreenHelper; +import net.minecraft.ChatFormat; +import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen; +import net.minecraft.client.resource.language.I18n; +import net.minecraft.util.Identifier; + +import java.awt.*; +import java.util.Optional; +import java.util.function.Supplier; + +public class AutoCraftingButtonWidget extends ButtonWidget { + + private final Supplier<RecipeDisplay> displaySupplier; + private String extraTooltip; + private AbstractContainerScreen containerScreen; + + public AutoCraftingButtonWidget(Rectangle rectangle, String text, Supplier<RecipeDisplay> displaySupplier) { + super(rectangle, text); + this.displaySupplier = displaySupplier; + Optional<Identifier> recipe = displaySupplier.get().getRecipeLocation(); + extraTooltip = recipe.isPresent() ? I18n.translate("text.rei.recipe_id", ChatFormat.GRAY.toString(), recipe.get().toString()) : ""; + this.containerScreen = ScreenHelper.getLastContainerScreen(); + } + + @Override + public void onPressed() { + minecraft.openScreen(containerScreen); + ScreenHelper.getLastOverlay().init(); + } + + @Override + public void render(int mouseX, int mouseY, float delta) { + this.enabled = true; + super.render(mouseX, mouseY, delta); + } + + @Override + public Optional<String> getTooltips() { + if (this.minecraft.options.advancedItemTooltips) + if (enabled) + return Optional.ofNullable(I18n.translate("text.auto_craft.move_items") + extraTooltip); + else + return Optional.ofNullable(I18n.translate("text.auto_craft.failed_move_items") + extraTooltip); + if (enabled) + return Optional.ofNullable(I18n.translate("text.auto_craft.move_items")); + else + return Optional.ofNullable(I18n.translate("text.auto_craft.failed_move_items")); + } +} |
