aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/shedaniel/rei/plugin/autocrafting/AutoCraftingTableBookHandler.java
diff options
context:
space:
mode:
authorUnknown <shekwancheung0528@gmail.com>2019-06-18 19:39:43 +0800
committerUnknown <shekwancheung0528@gmail.com>2019-06-18 19:39:43 +0800
commit6e20fcb8c5a13d2145d8960a00b03507823c8d4d (patch)
treeea7188c9e8136e3778ba938d93515559ad423bbf /src/main/java/me/shedaniel/rei/plugin/autocrafting/AutoCraftingTableBookHandler.java
parent332747a3332eec2f2bff5696f79ef1e38161aa75 (diff)
downloadRoughlyEnoughItems-6e20fcb8c5a13d2145d8960a00b03507823c8d4d.tar.gz
RoughlyEnoughItems-6e20fcb8c5a13d2145d8960a00b03507823c8d4d.tar.bz2
RoughlyEnoughItems-6e20fcb8c5a13d2145d8960a00b03507823c8d4d.zip
auto crafting... still using vanilla recipe book, can't figure how
Diffstat (limited to 'src/main/java/me/shedaniel/rei/plugin/autocrafting/AutoCraftingTableBookHandler.java')
-rw-r--r--src/main/java/me/shedaniel/rei/plugin/autocrafting/AutoCraftingTableBookHandler.java39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/main/java/me/shedaniel/rei/plugin/autocrafting/AutoCraftingTableBookHandler.java b/src/main/java/me/shedaniel/rei/plugin/autocrafting/AutoCraftingTableBookHandler.java
new file mode 100644
index 000000000..b53b1cf33
--- /dev/null
+++ b/src/main/java/me/shedaniel/rei/plugin/autocrafting/AutoCraftingTableBookHandler.java
@@ -0,0 +1,39 @@
+/*
+ * Roughly Enough Items by Danielshe.
+ * Licensed under the MIT License.
+ */
+
+package me.shedaniel.rei.plugin.autocrafting;
+
+import me.shedaniel.rei.api.AutoCraftingHandler;
+import me.shedaniel.rei.api.RecipeDisplay;
+import me.shedaniel.rei.client.ScreenHelper;
+import me.shedaniel.rei.gui.ContainerScreenOverlay;
+import me.shedaniel.rei.listeners.RecipeBookGuiHooks;
+import me.shedaniel.rei.plugin.crafting.DefaultCraftingDisplay;
+import net.minecraft.client.MinecraftClient;
+import net.minecraft.client.gui.screen.Screen;
+import net.minecraft.client.gui.screen.ingame.AbstractContainerScreen;
+import net.minecraft.client.gui.screen.ingame.CraftingTableScreen;
+import net.minecraft.container.CraftingTableContainer;
+
+import java.util.function.Supplier;
+
+public class AutoCraftingTableBookHandler implements AutoCraftingHandler {
+ @Override
+ public boolean handle(Supplier<RecipeDisplay> displaySupplier, MinecraftClient minecraft, Screen recipeViewingScreen, AbstractContainerScreen<?> parentScreen, ContainerScreenOverlay overlay) {
+ DefaultCraftingDisplay display = (DefaultCraftingDisplay) displaySupplier.get();
+ CraftingTableScreen craftingTableScreen = (CraftingTableScreen) parentScreen;
+ minecraft.openScreen(craftingTableScreen);
+ ((RecipeBookGuiHooks) craftingTableScreen.getRecipeBookGui()).rei_getGhostSlots().reset();
+ CraftingTableContainer container = craftingTableScreen.getContainer();
+ minecraft.interactionManager.clickRecipe(container.syncId, display.getOptionalRecipe().get(), Screen.hasShiftDown());
+ ScreenHelper.getLastOverlay().init();
+ return true;
+ }
+
+ @Override
+ public boolean canHandle(Supplier<RecipeDisplay> displaySupplier, MinecraftClient minecraft, Screen recipeViewingScreen, AbstractContainerScreen<?> parentScreen, ContainerScreenOverlay overlay) {
+ return parentScreen instanceof CraftingTableScreen && displaySupplier.get() instanceof DefaultCraftingDisplay && ((DefaultCraftingDisplay) displaySupplier.get()).getOptionalRecipe().isPresent() && minecraft.player.getRecipeBook().contains(((DefaultCraftingDisplay) displaySupplier.get()).getOptionalRecipe().get());
+ }
+}