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

Emi integration #278

Merged
merged 2 commits into from
Sep 7, 2023
Merged
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
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ dependencies {
modCompileOnly "me.shedaniel:RoughlyEnoughItems-api-fabric:${project.rei_version}"
modRuntimeOnly "me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}"

// EMI
modCompileOnly "dev.emi:emi-fabric:${project.emi_version}+${project.minecraft_version}:api"
modLocalRuntime "dev.emi:emi-fabric:${project.emi_version}+${project.minecraft_version}"

// Renderer (https://github.com/0x3C50/Renderer)
include modImplementation("com.github.0x3C50:Renderer:${project.renderer_version}") {
exclude group: "io.github.ladysnake" exclude module: "satin"
Expand Down
6 changes: 4 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ loader_version=0.14.21
fabric_api_version=0.86.0+1.20.1

# Dependencies
## Cloth Api (https://www.curseforge.com/minecraft/mc-mods/cloth-config/files)
## Cloth Api (https://modrinth.com/mod/cloth-config/versions)
clothconfig_version=11.1.106
## Mod Menu (https://www.curseforge.com/minecraft/mc-mods/modmenu/files)
## Mod Menu (https://modrinth.com/mod/modmenu/versions)
mod_menu_version=7.0.1
## REI (https://www.curseforge.com/minecraft/mc-mods/roughly-enough-items/files)
rei_version=12.0.625
## EMI (https://modrinth.com/mod/emi/versions)
emi_version = 1.0.19
## Renderer (https://github.com/0x3C50/Renderer)
renderer_version = master-SNAPSHOT

Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.xmrvizzy.skyblocker.config.modmenu;
package me.xmrvizzy.skyblocker.compatibility.modmenu;

import me.shedaniel.autoconfig.AutoConfig;
import com.terraformersmc.modmenu.api.ConfigScreenFactory;
Expand All @@ -9,7 +9,6 @@

@Environment(EnvType.CLIENT)
public class ModMenuEntry implements ModMenuApi {

@Override
public ConfigScreenFactory<?> getModConfigScreenFactory() {
return screen -> AutoConfig.getConfigScreen(SkyblockerConfig.class, screen).get();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package me.xmrvizzy.skyblocker.skyblock.rei;
package me.xmrvizzy.skyblocker.compatibility.rei;

import com.google.common.collect.Lists;
import com.mojang.brigadier.exceptions.CommandSyntaxException;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.client.gui.Renderer;
Expand All @@ -13,14 +12,11 @@
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.config.SkyblockerConfig;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.StringNbtReader;
import me.xmrvizzy.skyblocker.utils.ItemUtils;
import net.minecraft.text.Text;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

/**
* Skyblock recipe category class for REI
Expand All @@ -33,21 +29,12 @@ public CategoryIdentifier<SkyblockCraftingDisplay> getCategoryIdentifier() {

@Override
public Text getTitle() {
return Text.translatable("key.categories.skyblocker");
return Text.translatable("emi.category.skyblocker.skyblock");
}

@Override
public Renderer getIcon() {
// TODO separate icon from quickNav
SkyblockerConfig.ItemData iconItem = SkyblockerConfig.get().quickNav.button7.item;
String nbtString = "{id:\"minecraft:" + iconItem.itemName.toLowerCase(Locale.ROOT) + "\",Count:1";
if (iconItem.nbt.length() > 2) nbtString += "," + iconItem.nbt;
nbtString += "}";
try {
return EntryStacks.of(ItemStack.fromNbt(StringNbtReader.parse(nbtString)));
} catch (CommandSyntaxException e) {
throw new RuntimeException(e);
}
return EntryStacks.of(ItemUtils.getSkyblockerStack());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.xmrvizzy.skyblocker.skyblock.rei;
package me.xmrvizzy.skyblocker.compatibility.rei;


import me.shedaniel.rei.api.common.category.CategoryIdentifier;
Expand All @@ -12,12 +12,13 @@
* 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;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package me.xmrvizzy.skyblocker.skyblock.rei;
package me.xmrvizzy.skyblocker.compatibility.rei;

import me.shedaniel.rei.api.client.registry.display.DynamicDisplayGenerator;
import me.shedaniel.rei.api.common.entry.EntryIngredient;
Expand All @@ -18,8 +18,7 @@ public class SkyblockCraftingDisplayGenerator implements DynamicDisplayGenerator
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.getRecipes()
.stream()
List<SkyblockCraftingRecipe> filteredRecipes = ItemRegistry.getRecipesStream()
.filter(recipe -> ItemRegistry.getInternalName(recipe.getResult()).equals(ItemRegistry.getInternalName(inputItem.getValue())))
.toList();

Expand All @@ -30,11 +29,10 @@ public Optional<List<SkyblockCraftingDisplay>> getRecipeFor(EntryStack<?> entry)
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.getRecipes()
.stream()
List<SkyblockCraftingRecipe> filteredRecipes = ItemRegistry.getRecipesStream()
.filter(recipe -> {
for (ItemStack item : recipe.getGrid()) {
if(!ItemRegistry.getInternalName(item).equals("") && ItemRegistry.getInternalName(item).equals(ItemRegistry.getInternalName(inputItem.getValue())))
if(!ItemRegistry.getInternalName(item).isEmpty() && ItemRegistry.getInternalName(item).equals(ItemRegistry.getInternalName(inputItem.getValue())))
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
package me.xmrvizzy.skyblocker.skyblock.rei;
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.entry.EntryStack;
import me.shedaniel.rei.api.common.util.EntryStacks;
import me.xmrvizzy.skyblocker.SkyblockerMod;
import me.xmrvizzy.skyblocker.skyblock.itemlist.ItemRegistry;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;

import java.util.ArrayList;

/**
* REI integration
*/
Expand All @@ -33,8 +29,6 @@ public void registerDisplays(DisplayRegistry displayRegistry) {

@Override
public void registerEntries(EntryRegistry entryRegistry) {
ArrayList<EntryStack<ItemStack>> entries = new ArrayList<>();
ItemRegistry.getRecipes().forEach(recipe -> entries.add(EntryStacks.of(recipe.getResult())));
entryRegistry.addEntries(entries);
entryRegistry.addEntries(ItemRegistry.getRecipeResultsStream().map(EntryStacks::of).toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,15 @@

@Mixin(HandledScreen.class)
public interface HandledScreenAccessor {
@Accessor
@Accessor("x")
int getX();
@Accessor

@Accessor("y")
int getY();

@Accessor
int getBackgroundWidth();

@Accessor
int getBackgroundHeight();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;

public class ItemRegistry {
protected static final Path ITEM_LIST_DIR = NEURepo.LOCAL_REPO_DIR.resolve("items");
Expand Down Expand Up @@ -105,8 +106,12 @@ public static List<SkyblockCraftingRecipe> getRecipes(String internalName) {
return result;
}

public static List<SkyblockCraftingRecipe> getRecipes() {
return recipes;
public static Stream<SkyblockCraftingRecipe> getRecipesStream() {
return recipes.stream();
}

public static Stream<ItemStack> getRecipeResultsStream() {
return recipes.stream().map(SkyblockCraftingRecipe::getResult);
}

/**
Expand Down
10 changes: 10 additions & 0 deletions src/main/java/me/xmrvizzy/skyblocker/utils/ItemUtils.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package me.xmrvizzy.skyblocker.utils;

import com.mojang.brigadier.exceptions.CommandSyntaxException;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.StringNbtReader;
import net.minecraft.text.Text;

import java.util.ArrayList;
Expand Down Expand Up @@ -30,4 +32,12 @@ public static List<String> getTooltipStrings(ItemStack item) {

return list;
}

public static ItemStack getSkyblockerStack() {
try {
return ItemStack.fromNbt(StringNbtReader.parse("{id:\"minecraft:player_head\",Count:1,tag:{SkullOwner:{Id:[I;-300151517,-631415889,-1193921967,-1821784279],Properties:{textures:[{Value:\"e3RleHR1cmVzOntTS0lOOnt1cmw6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvZDdjYzY2ODc0MjNkMDU3MGQ1NTZhYzUzZTA2NzZjYjU2M2JiZGQ5NzE3Y2Q4MjY5YmRlYmVkNmY2ZDRlN2JmOCJ9fX0=\"}]}}}}"));
} catch (CommandSyntaxException e) {
throw new RuntimeException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void init() {
ScreenEvents.BEFORE_INIT.register((client, screen, scaledWidth, scaledHeight) -> {
if (Utils.isOnSkyblock() && screen instanceof GenericContainerScreen genericContainerScreen) {
ScreenEvents.afterRender(screen).register((screen1, context, mouseX, mouseY, delta) -> {
MatrixStack matrices = context.getMatrices();
MatrixStack matrices = context.getMatrices();
matrices.push();
matrices.translate(((HandledScreenAccessor) genericContainerScreen).getX(), ((HandledScreenAccessor) genericContainerScreen).getY(), 300);
onDraw(context, genericContainerScreen.getScreenHandler().slots.subList(0, genericContainerScreen.getScreenHandler().getRows() * 9));
Expand Down Expand Up @@ -117,8 +117,9 @@ public void onDraw(DrawContext context, List<Slot> slots) {

private Map<Integer, ItemStack> slotMap(List<Slot> slots) {
Map<Integer, ItemStack> slotMap = new TreeMap<>();
for (int i = 0; i < slots.size(); i++)
for (int i = 0; i < slots.size(); i++) {
slotMap.put(i, slots.get(i).getStack());
}
return slotMap;
}
}
4 changes: 3 additions & 1 deletion src/main/resources/assets/skyblocker/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -349,5 +349,7 @@

"skyblocker.quiverWarning.50Left": "You only have 50 Arrows left in your Quiver!",
"skyblocker.quiverWarning.10Left": "You only have 10 Arrows left in your Quiver!",
"skyblocker.quiverWarning.empty": "You don't have any more Arrows left in your Quiver!"
"skyblocker.quiverWarning.empty": "You don't have any more Arrows left in your Quiver!",

"emi.category.skyblocker.skyblock": "Skyblock"
}
7 changes: 5 additions & 2 deletions src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,13 @@
"dev.cbyrne.betterinject.BetterInject::initialize"
],
"modmenu": [
"me.xmrvizzy.skyblocker.config.modmenu.ModMenuEntry"
"me.xmrvizzy.skyblocker.compatibility.modmenu.ModMenuEntry"
],
"rei_client": [
"me.xmrvizzy.skyblocker.skyblock.rei.SkyblockerREIClientPlugin"
"me.xmrvizzy.skyblocker.compatibility.rei.SkyblockerREIClientPlugin"
],
"emi": [
"me.xmrvizzy.skyblocker.compatibility.emi.SkyblockerEMIPlugin"
]
},
"mixins": [
Expand Down