diff options
Diffstat (limited to 'src/main/java/me/xmrvizzy/skyblocker/compatibility')
7 files changed, 306 insertions, 0 deletions
diff --git a/src/main/java/me/xmrvizzy/skyblocker/compatibility/emi/SkyblockEmiRecipe.java b/src/main/java/me/xmrvizzy/skyblocker/compatibility/emi/SkyblockEmiRecipe.java new file mode 100644 index 00000000..6cf91dac --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/compatibility/emi/SkyblockEmiRecipe.java @@ -0,0 +1,38 @@ +package me.xmrvizzy.skyblocker.compatibility.emi; + +import dev.emi.emi.api.recipe.EmiCraftingRecipe; +import dev.emi.emi.api.recipe.EmiRecipeCategory; +import dev.emi.emi.api.stack.Comparison; +import dev.emi.emi.api.stack.EmiIngredient; +import dev.emi.emi.api.stack.EmiStack; +import dev.emi.emi.api.widget.WidgetHolder; +import me.xmrvizzy.skyblocker.skyblock.itemlist.ItemRegistry; +import me.xmrvizzy.skyblocker.skyblock.itemlist.SkyblockCraftingRecipe; +import net.minecraft.client.MinecraftClient; +import net.minecraft.text.Text; +import net.minecraft.util.Identifier; + +public class SkyblockEmiRecipe extends EmiCraftingRecipe { + private final String craftText; + + public SkyblockEmiRecipe(SkyblockCraftingRecipe recipe) { + super(recipe.getGrid().stream().map(EmiStack::of).map(EmiIngredient.class::cast).toList(), EmiStack.of(recipe.getResult()).comparison(Comparison.compareNbt()), Identifier.of("skyblock", ItemRegistry.getInternalName(recipe.getResult()).toLowerCase().replace(';', '_'))); + this.craftText = recipe.getCraftText(); + } + + @Override + public EmiRecipeCategory getCategory() { + return SkyblockerEMIPlugin.SKYBLOCK; + } + + @Override + public int getDisplayHeight() { + return super.getDisplayHeight() + (craftText.isEmpty() ? 0 : 10); + } + + @Override + public void addWidgets(WidgetHolder widgets) { + super.addWidgets(widgets); + widgets.addText(Text.of(craftText), 59 - MinecraftClient.getInstance().textRenderer.getWidth(craftText) / 2, 55, 0xFFFFFF, true); + } +} diff --git a/src/main/java/me/xmrvizzy/skyblocker/compatibility/emi/SkyblockerEMIPlugin.java b/src/main/java/me/xmrvizzy/skyblocker/compatibility/emi/SkyblockerEMIPlugin.java new file mode 100644 index 00000000..526ac885 --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/compatibility/emi/SkyblockerEMIPlugin.java @@ -0,0 +1,29 @@ +package me.xmrvizzy.skyblocker.compatibility.emi; + +import dev.emi.emi.api.EmiPlugin; +import dev.emi.emi.api.EmiRegistry; +import dev.emi.emi.api.recipe.EmiRecipeCategory; +import dev.emi.emi.api.render.EmiTexture; +import dev.emi.emi.api.stack.EmiStack; +import me.xmrvizzy.skyblocker.SkyblockerMod; +import me.xmrvizzy.skyblocker.skyblock.itemlist.ItemRegistry; +import me.xmrvizzy.skyblocker.utils.ItemUtils; +import net.minecraft.item.Items; +import net.minecraft.util.Identifier; + +/** + * EMI integration + */ +public class SkyblockerEMIPlugin implements EmiPlugin { + public static final Identifier SIMPLIFIED_TEXTURES = new Identifier("emi", "textures/gui/widgets.png"); + // TODO: Custom simplified texture for Skyblock + public static final EmiRecipeCategory SKYBLOCK = new EmiRecipeCategory(new Identifier(SkyblockerMod.NAMESPACE, "skyblock"), EmiStack.of(ItemUtils.getSkyblockerStack()), new EmiTexture(SIMPLIFIED_TEXTURES, 240, 240, 16, 16)); + + @Override + public void register(EmiRegistry registry) { + ItemRegistry.getRecipeResultsStream().map(EmiStack::of).forEach(registry::addEmiStack); + registry.addCategory(SKYBLOCK); + registry.addWorkstation(SKYBLOCK, EmiStack.of(Items.CRAFTING_TABLE)); + ItemRegistry.getRecipesStream().map(SkyblockEmiRecipe::new).forEach(registry::addRecipe); + } +} diff --git a/src/main/java/me/xmrvizzy/skyblocker/compatibility/modmenu/ModMenuEntry.java b/src/main/java/me/xmrvizzy/skyblocker/compatibility/modmenu/ModMenuEntry.java new file mode 100644 index 00000000..0cba3d5e --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/compatibility/modmenu/ModMenuEntry.java @@ -0,0 +1,16 @@ +package me.xmrvizzy.skyblocker.compatibility.modmenu; + +import me.shedaniel.autoconfig.AutoConfig; +import com.terraformersmc.modmenu.api.ConfigScreenFactory; +import com.terraformersmc.modmenu.api.ModMenuApi; +import me.xmrvizzy.skyblocker.config.SkyblockerConfig; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; + +@Environment(EnvType.CLIENT) +public class ModMenuEntry implements ModMenuApi { + @Override + public ConfigScreenFactory<?> getModConfigScreenFactory() { + return screen -> AutoConfig.getConfigScreen(SkyblockerConfig.class, screen).get(); + } +}
\ No newline at end of file diff --git a/src/main/java/me/xmrvizzy/skyblocker/compatibility/rei/SkyblockCategory.java b/src/main/java/me/xmrvizzy/skyblocker/compatibility/rei/SkyblockCategory.java new file mode 100644 index 00000000..14c61d23 --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/compatibility/rei/SkyblockCategory.java @@ -0,0 +1,84 @@ +package me.xmrvizzy.skyblocker.compatibility.rei; + +import com.google.common.collect.Lists; +import me.shedaniel.math.Point; +import me.shedaniel.math.Rectangle; +import me.shedaniel.rei.api.client.gui.Renderer; +import me.shedaniel.rei.api.client.gui.widgets.Label; +import me.shedaniel.rei.api.client.gui.widgets.Slot; +import me.shedaniel.rei.api.client.gui.widgets.Widget; +import me.shedaniel.rei.api.client.gui.widgets.Widgets; +import me.shedaniel.rei.api.client.registry.display.DisplayCategory; +import me.shedaniel.rei.api.common.category.CategoryIdentifier; +import me.shedaniel.rei.api.common.entry.EntryIngredient; +import me.shedaniel.rei.api.common.util.EntryStacks; +import me.xmrvizzy.skyblocker.utils.ItemUtils; +import net.minecraft.text.Text; + +import java.util.ArrayList; +import java.util.List; + +/** + * Skyblock recipe category class for REI + */ +public class SkyblockCategory implements DisplayCategory<SkyblockCraftingDisplay> { + @Override + public CategoryIdentifier<SkyblockCraftingDisplay> getCategoryIdentifier() { + return SkyblockerREIClientPlugin.SKYBLOCK; + } + + @Override + public Text getTitle() { + return Text.translatable("emi.category.skyblocker.skyblock"); + } + + @Override + public Renderer getIcon() { + return EntryStacks.of(ItemUtils.getSkyblockerStack()); + } + + @Override + public int getDisplayHeight() { + return 73; + } + + /** + * Draws display for SkyblockCraftingDisplay + * + * @param display the display + * @param bounds the bounds of the display, configurable with overriding the width, height methods. + */ + @Override + public List<Widget> setupDisplay(SkyblockCraftingDisplay display, Rectangle bounds) { + List<Widget> out = new ArrayList<>(); + out.add(Widgets.createRecipeBase(bounds)); + + Point startPoint; + if (!display.getCraftText().isEmpty() && display.getCraftText() != null) { + startPoint = new Point(bounds.getCenterX() - 58, bounds.getCenterY() - 31); + } + else { + startPoint = new Point(bounds.getCenterX() - 58, bounds.getCenterY() - 26); + } + Point resultPoint = new Point(startPoint.x + 95, startPoint.y + 19); + out.add(Widgets.createArrow(new Point(startPoint.x + 60, startPoint.y + 18))); + out.add(Widgets.createResultSlotBackground(resultPoint)); + + // Generate Slots + List<EntryIngredient> input = display.getInputEntries(); + List<Slot> slots = Lists.newArrayList(); + for (int y = 0; y < 3; y++) + for (int x = 0; x < 3; x++) + slots.add(Widgets.createSlot(new Point(startPoint.x + 1 + x * 18, startPoint.y + 1 + y * 18)).markInput()); + for (int i = 0; i < input.size(); i++) { + slots.get(i).entries(input.get(i)).markInput(); + } + out.addAll(slots); + out.add(Widgets.createSlot(resultPoint).entries(display.getOutputEntries().get(0)).disableBackground().markOutput()); + + // Add craftingText Label + Label craftTextLabel = Widgets.createLabel(new Point(bounds.getCenterX(), startPoint.y + 55), Text.of(display.getCraftText())); + out.add(craftTextLabel); + return out; + } +} diff --git a/src/main/java/me/xmrvizzy/skyblocker/compatibility/rei/SkyblockCraftingDisplay.java b/src/main/java/me/xmrvizzy/skyblocker/compatibility/rei/SkyblockCraftingDisplay.java new file mode 100644 index 00000000..35b5c886 --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/compatibility/rei/SkyblockCraftingDisplay.java @@ -0,0 +1,40 @@ +package me.xmrvizzy.skyblocker.compatibility.rei; + + +import me.shedaniel.rei.api.common.category.CategoryIdentifier; +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 java.util.List; + +/** + * Skyblock Crafting Recipe display class for REI + */ +public class SkyblockCraftingDisplay extends BasicDisplay implements SimpleGridMenuDisplay { + private final String craftText; + + public SkyblockCraftingDisplay(List<EntryIngredient> input, List<EntryIngredient> output, String craftText) { + super(input, output); + this.craftText = craftText; + } + + public String getCraftText() { + return craftText; + } + + @Override + public int getWidth() { + return 3; + } + + @Override + public int getHeight() { + return 3; + } + + @Override + public CategoryIdentifier<?> getCategoryIdentifier() { + return SkyblockerREIClientPlugin.SKYBLOCK; + } +}
\ No newline at end of file diff --git a/src/main/java/me/xmrvizzy/skyblocker/compatibility/rei/SkyblockCraftingDisplayGenerator.java b/src/main/java/me/xmrvizzy/skyblocker/compatibility/rei/SkyblockCraftingDisplayGenerator.java new file mode 100644 index 00000000..370e15dc --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/compatibility/rei/SkyblockCraftingDisplayGenerator.java @@ -0,0 +1,65 @@ +package me.xmrvizzy.skyblocker.compatibility.rei; + +import me.shedaniel.rei.api.client.registry.display.DynamicDisplayGenerator; +import me.shedaniel.rei.api.common.entry.EntryIngredient; +import me.shedaniel.rei.api.common.entry.EntryStack; +import me.shedaniel.rei.api.common.util.EntryStacks; +import me.xmrvizzy.skyblocker.skyblock.itemlist.ItemRegistry; +import me.xmrvizzy.skyblocker.skyblock.itemlist.SkyblockCraftingRecipe; +import net.minecraft.item.ItemStack; + +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +public class SkyblockCraftingDisplayGenerator implements DynamicDisplayGenerator<SkyblockCraftingDisplay> { + + @Override + public Optional<List<SkyblockCraftingDisplay>> getRecipeFor(EntryStack<?> entry) { + if (!(entry.getValue() instanceof ItemStack)) return Optional.empty(); + EntryStack<ItemStack> inputItem = EntryStacks.of((ItemStack) entry.getValue()); + List<SkyblockCraftingRecipe> filteredRecipes = ItemRegistry.getRecipesStream() + .filter(recipe -> ItemRegistry.getInternalName(recipe.getResult()).equals(ItemRegistry.getInternalName(inputItem.getValue()))) + .toList(); + + return Optional.of(generateDisplays(filteredRecipes)); + } + + @Override + public Optional<List<SkyblockCraftingDisplay>> getUsageFor(EntryStack<?> entry) { + if (!(entry.getValue() instanceof ItemStack)) return Optional.empty(); + EntryStack<ItemStack> inputItem = EntryStacks.of((ItemStack) entry.getValue()); + List<SkyblockCraftingRecipe> filteredRecipes = ItemRegistry.getRecipesStream() + .filter(recipe -> { + for (ItemStack item : recipe.getGrid()) { + if(!ItemRegistry.getInternalName(item).isEmpty() && ItemRegistry.getInternalName(item).equals(ItemRegistry.getInternalName(inputItem.getValue()))) + return true; + } + return false; + }) + .toList(); + return Optional.of(generateDisplays(filteredRecipes)); + } + + /** + * Generate Displays from a list of recipes + */ + private List<SkyblockCraftingDisplay> generateDisplays(List<SkyblockCraftingRecipe> recipes) { + List<SkyblockCraftingDisplay> displays = new ArrayList<>(); + for (SkyblockCraftingRecipe recipe : recipes) { + List<EntryIngredient> inputs = new ArrayList<>(); + List<EntryIngredient> outputs = new ArrayList<>(); + + ArrayList<EntryStack<ItemStack>> inputEntryStacks = new ArrayList<>(); + recipe.getGrid().forEach((item) -> inputEntryStacks.add(EntryStacks.of(item))); + + for (EntryStack<ItemStack> entryStack : inputEntryStacks) { + inputs.add(EntryIngredient.of(entryStack)); + } + outputs.add(EntryIngredient.of(EntryStacks.of(recipe.getResult()))); + + displays.add(new SkyblockCraftingDisplay(inputs, outputs, recipe.getCraftText())); + } + return displays; + } +} diff --git a/src/main/java/me/xmrvizzy/skyblocker/compatibility/rei/SkyblockerREIClientPlugin.java b/src/main/java/me/xmrvizzy/skyblocker/compatibility/rei/SkyblockerREIClientPlugin.java new file mode 100644 index 00000000..5c97a274 --- /dev/null +++ b/src/main/java/me/xmrvizzy/skyblocker/compatibility/rei/SkyblockerREIClientPlugin.java @@ -0,0 +1,34 @@ +package me.xmrvizzy.skyblocker.compatibility.rei; + +import me.shedaniel.rei.api.client.plugins.REIClientPlugin; +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.common.category.CategoryIdentifier; +import me.shedaniel.rei.api.common.util.EntryStacks; +import me.xmrvizzy.skyblocker.SkyblockerMod; +import me.xmrvizzy.skyblocker.skyblock.itemlist.ItemRegistry; +import net.minecraft.item.Items; + +/** + * REI integration + */ +public class SkyblockerREIClientPlugin implements REIClientPlugin { + 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 registerDisplays(DisplayRegistry displayRegistry) { + displayRegistry.registerDisplayGenerator(SKYBLOCK, new SkyblockCraftingDisplayGenerator()); + } + + @Override + public void registerEntries(EntryRegistry entryRegistry) { + entryRegistry.addEntries(ItemRegistry.getRecipeResultsStream().map(EntryStacks::of).toList()); + } +} |