diff --git a/src/main/java/de/hysky/skyblocker/compatibility/rei/SkyblockCraftingDisplay.java b/src/main/java/de/hysky/skyblocker/compatibility/rei/SkyblockCraftingDisplay.java index 3f4d7dd499..728c8d06b1 100644 --- a/src/main/java/de/hysky/skyblocker/compatibility/rei/SkyblockCraftingDisplay.java +++ b/src/main/java/de/hysky/skyblocker/compatibility/rei/SkyblockCraftingDisplay.java @@ -1,32 +1,36 @@ package de.hysky.skyblocker.compatibility.rei; - import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.Display; import me.shedaniel.rei.api.common.display.DisplaySerializer; import me.shedaniel.rei.api.common.display.SimpleGridMenuDisplay; import me.shedaniel.rei.api.common.display.basic.BasicDisplay; import me.shedaniel.rei.api.common.entry.EntryIngredient; +import org.jetbrains.annotations.Nullable; import java.util.List; -import org.jetbrains.annotations.Nullable; - /** * Skyblock Crafting Recipe display class for REI */ public class SkyblockCraftingDisplay extends BasicDisplay implements SimpleGridMenuDisplay { private final String craftText; + private final String clickCommand; - public SkyblockCraftingDisplay(List input, List output, String craftText) { + public SkyblockCraftingDisplay(List input, List output, String craftText, String clickCommand) { super(input, output); this.craftText = craftText; + this.clickCommand = clickCommand; } public String getCraftText() { return craftText; } + public String getClickCommand() { + return clickCommand; + } + @Override public int getWidth() { return 3; @@ -47,4 +51,4 @@ public CategoryIdentifier getCategoryIdentifier() { public DisplaySerializer getSerializer() { return null; } -} \ No newline at end of file +} diff --git a/src/main/java/de/hysky/skyblocker/compatibility/rei/SkyblockCraftingDisplayGenerator.java b/src/main/java/de/hysky/skyblocker/compatibility/rei/SkyblockCraftingDisplayGenerator.java index 33cee20bd6..d8822d9654 100644 --- a/src/main/java/de/hysky/skyblocker/compatibility/rei/SkyblockCraftingDisplayGenerator.java +++ b/src/main/java/de/hysky/skyblocker/compatibility/rei/SkyblockCraftingDisplayGenerator.java @@ -65,7 +65,7 @@ private List generateDisplays(List SKYBLOCK = CategoryIdentifier.of(SkyblockerMod.NAMESPACE, "skyblock"); + public static final CategoryIdentifier SKYBLOCK = CategoryIdentifier.of(SkyblockerMod.NAMESPACE, "skyblock"); - @Override - public void registerCategories(CategoryRegistry categoryRegistry) { - categoryRegistry.addWorkstations(SKYBLOCK, EntryStacks.of(Items.CRAFTING_TABLE)); - categoryRegistry.add(new SkyblockCategory()); - } + @Override + public void registerCategories(CategoryRegistry categoryRegistry) { + categoryRegistry.addWorkstations(SKYBLOCK, EntryStacks.of(Items.CRAFTING_TABLE)); + categoryRegistry.add(new SkyblockCategory()); + } - @Override - public void registerDisplays(DisplayRegistry displayRegistry) { - displayRegistry.registerDisplayGenerator(SKYBLOCK, new SkyblockCraftingDisplayGenerator()); - } + @Override + public void registerDisplays(DisplayRegistry displayRegistry) { + displayRegistry.registerDisplayGenerator(SKYBLOCK, new SkyblockCraftingDisplayGenerator()); + } - @Override - public void registerEntries(EntryRegistry entryRegistry) { - entryRegistry.addEntries(ItemRepository.getItemsStream().map(EntryStacks::of).toList()); - } + @Override + public void registerTransferHandlers(TransferHandlerRegistry registry) { + registry.register(new SkyblockerTransferHandler()); + } + + @Override + public void registerEntries(EntryRegistry entryRegistry) { + entryRegistry.addEntries(ItemRepository.getItemsStream().map(EntryStacks::of).toList()); + } } diff --git a/src/main/java/de/hysky/skyblocker/compatibility/rei/SkyblockerTransferHandler.java b/src/main/java/de/hysky/skyblocker/compatibility/rei/SkyblockerTransferHandler.java new file mode 100644 index 0000000000..f761cd8f95 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/compatibility/rei/SkyblockerTransferHandler.java @@ -0,0 +1,17 @@ +package de.hysky.skyblocker.compatibility.rei; + +import de.hysky.skyblocker.utils.scheduler.MessageScheduler; +import me.shedaniel.rei.api.client.registry.transfer.TransferHandler; + +public class SkyblockerTransferHandler implements TransferHandler { + @Override + public Result handle(Context context) { + if (!(context.getDisplay() instanceof SkyblockCraftingDisplay skyblockCraftingDisplay)) return Result.createNotApplicable(); + + String clickCommand = skyblockCraftingDisplay.getClickCommand(); + if (clickCommand.isEmpty()) return Result.createNotApplicable(); + + if (context.isActuallyCrafting()) MessageScheduler.INSTANCE.sendMessageAfterCooldown(clickCommand, false); + return Result.createSuccessful(); + } +} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/itemlist/ItemRepository.java b/src/main/java/de/hysky/skyblocker/skyblock/itemlist/ItemRepository.java index 8c071f5979..5ea4a50cac 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/itemlist/ItemRepository.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/itemlist/ItemRepository.java @@ -9,6 +9,8 @@ import io.github.moulberry.repo.data.NEURecipe; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; +import org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -88,6 +90,22 @@ public static String getWikiLink(String neuId) { return null; } + /** + * Returns the click command for the given NEU item id that will show the super craft recipe. + * @param neuId NEU item id + * @return The command with all arguments filled in + */ + @NotNull + public static String getClickCommand(String neuId) { + NEUItem item = NEURepoManager.NEU_REPO.getItems().getItemBySkyblockId(neuId); + // Only skyblock items have supercraft recipes. + if (item == null || item.isVanilla()) return ""; + String clickCommand = item.getClickcommand(); + String skyblockId = item.getSkyblockItemId(); + + return StringUtils.isEmpty(clickCommand) || StringUtils.isEmpty(skyblockId) ? "" : "/" + clickCommand + " " + skyblockId; + } + public static List getRecipes(String neuId) { List result = new ArrayList<>(); for (SkyblockCraftingRecipe recipe : recipes) { diff --git a/src/main/java/de/hysky/skyblocker/skyblock/itemlist/SkyblockCraftingRecipe.java b/src/main/java/de/hysky/skyblocker/skyblock/itemlist/SkyblockCraftingRecipe.java index bc6d797751..bd3a73fc07 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/itemlist/SkyblockCraftingRecipe.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/itemlist/SkyblockCraftingRecipe.java @@ -15,15 +15,20 @@ public class SkyblockCraftingRecipe { private static final Logger LOGGER = LoggerFactory.getLogger(SkyblockCraftingRecipe.class); private final String craftText; + private final String clickCommand; private final List grid = new ArrayList<>(9); private ItemStack result; - public SkyblockCraftingRecipe(String craftText) { + public SkyblockCraftingRecipe(String craftText, String clickCommand) { this.craftText = craftText; + this.clickCommand = clickCommand; } public static SkyblockCraftingRecipe fromNEURecipe(NEUCraftingRecipe neuCraftingRecipe) { - SkyblockCraftingRecipe recipe = new SkyblockCraftingRecipe(neuCraftingRecipe.getExtraText() != null ? neuCraftingRecipe.getExtraText() : ""); + SkyblockCraftingRecipe recipe = new SkyblockCraftingRecipe( + neuCraftingRecipe.getExtraText() != null ? neuCraftingRecipe.getExtraText() : "", + ItemRepository.getClickCommand(neuCraftingRecipe.getOutput().getItemId()) + ); for (NEUIngredient input : neuCraftingRecipe.getInputs()) { recipe.grid.add(getItemStack(input)); } @@ -43,6 +48,10 @@ private static ItemStack getItemStack(NEUIngredient input) { return Items.AIR.getDefaultStack(); } + public String getClickCommand() { + return clickCommand; + } + public List getGrid() { return grid; }