Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add supercraft button to recipe viewers #1044

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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<EntryIngredient> input, List<EntryIngredient> output, String craftText) {
public SkyblockCraftingDisplay(List<EntryIngredient> input, List<EntryIngredient> 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;
Expand All @@ -47,4 +51,4 @@ public CategoryIdentifier<?> getCategoryIdentifier() {
public DisplaySerializer<? extends Display> getSerializer() {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private List<SkyblockCraftingDisplay> generateDisplays(List<SkyblockCraftingReci
}
outputs.add(EntryIngredient.of(EntryStacks.of(recipe.getResult())));

displays.add(new SkyblockCraftingDisplay(inputs, outputs, recipe.getCraftText()));
displays.add(new SkyblockCraftingDisplay(inputs, outputs, recipe.getCraftText(), recipe.getClickCommand()));
}
return displays;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import me.shedaniel.rei.api.client.registry.category.CategoryRegistry;
import me.shedaniel.rei.api.client.registry.display.DisplayRegistry;
import me.shedaniel.rei.api.client.registry.entry.EntryRegistry;
import me.shedaniel.rei.api.client.registry.transfer.TransferHandlerRegistry;
import me.shedaniel.rei.api.common.category.CategoryIdentifier;
import me.shedaniel.rei.api.common.util.EntryStacks;
import net.minecraft.item.Items;
Expand All @@ -14,21 +15,26 @@
* REI integration
*/
public class SkyblockerREIClientPlugin implements REIClientPlugin {
public static final CategoryIdentifier<SkyblockCraftingDisplay> SKYBLOCK = CategoryIdentifier.of(SkyblockerMod.NAMESPACE, "skyblock");
public static final CategoryIdentifier<SkyblockCraftingDisplay> 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());
}
}
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<SkyblockCraftingRecipe> getRecipes(String neuId) {
List<SkyblockCraftingRecipe> result = new ArrayList<>();
for (SkyblockCraftingRecipe recipe : recipes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ItemStack> 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));
}
Expand All @@ -43,6 +48,10 @@ private static ItemStack getItemStack(NEUIngredient input) {
return Items.AIR.getDefaultStack();
}

public String getClickCommand() {
return clickCommand;
}

public List<ItemStack> getGrid() {
return grid;
}
Expand Down