AutoSmokerBookHandler.java 1.7 KB

1234567891011121314151617181920212223242526272829303132333435
  1. /*
  2. * Roughly Enough Items by Danielshe.
  3. * Licensed under the MIT License.
  4. */
  5. package me.shedaniel.rei.plugin.autocrafting;
  6. import me.shedaniel.rei.api.AutoTransferHandler;
  7. import me.shedaniel.rei.impl.ScreenHelper;
  8. import me.shedaniel.rei.listeners.RecipeBookGuiHooks;
  9. import me.shedaniel.rei.plugin.smoking.DefaultSmokingDisplay;
  10. import net.minecraft.client.gui.screen.Screen;
  11. import net.minecraft.client.gui.screen.ingame.SmokerScreen;
  12. import net.minecraft.container.SmokerContainer;
  13. public class AutoSmokerBookHandler implements AutoTransferHandler {
  14. @Override
  15. public Result handle(Context context) {
  16. if (!(context.getContainerScreen() instanceof SmokerScreen) || !(context.getRecipe() instanceof DefaultSmokingDisplay))
  17. return Result.createNotApplicable();
  18. if (!((DefaultSmokingDisplay) context.getRecipe()).getOptionalRecipe().isPresent() || !context.getMinecraft().player.getRecipeBook().contains(((DefaultSmokingDisplay) context.getRecipe()).getOptionalRecipe().get()))
  19. return Result.createNotApplicable();
  20. if (!context.isActuallyCrafting())
  21. return Result.createSuccessful();
  22. DefaultSmokingDisplay display = (DefaultSmokingDisplay) context.getRecipe();
  23. SmokerScreen smokerScreen = (SmokerScreen) context.getContainerScreen();
  24. context.getMinecraft().openScreen(smokerScreen);
  25. ((RecipeBookGuiHooks) smokerScreen.getRecipeBookGui()).rei_getGhostSlots().reset();
  26. SmokerContainer container = smokerScreen.getContainer();
  27. context.getMinecraft().interactionManager.clickRecipe(container.syncId, display.getOptionalRecipe().get(), Screen.hasShiftDown());
  28. ScreenHelper.getLastOverlay().init();
  29. return Result.createSuccessful();
  30. }
  31. }