Covers JEI integration.

This commit is contained in:
raoulvdberge
2018-07-07 00:07:38 +02:00
parent 7fc99b5547
commit 34b0735050
6 changed files with 199 additions and 2 deletions

View File

@@ -7,7 +7,7 @@ import javax.annotation.Nullable;
import java.awt.*; import java.awt.*;
import java.util.List; import java.util.List;
public class GuiHandlerGrid implements IAdvancedGuiHandler<GuiGrid> { public class AdvancedGuiHandlerGrid implements IAdvancedGuiHandler<GuiGrid> {
@Override @Override
public Class<GuiGrid> getGuiContainerClass() { public Class<GuiGrid> getGuiContainerClass() {
return GuiGrid.class; return GuiGrid.class;

View File

@@ -17,7 +17,10 @@ public class RSJEIPlugin implements IModPlugin {
registry.getRecipeTransferRegistry().addUniversalRecipeTransferHandler(new RecipeTransferHandlerGrid()); registry.getRecipeTransferRegistry().addUniversalRecipeTransferHandler(new RecipeTransferHandlerGrid());
registry.addAdvancedGuiHandlers(new GuiHandlerGrid()); registry.addAdvancedGuiHandlers(new AdvancedGuiHandlerGrid());
registry.addRecipeRegistryPlugin(new RecipeRegistryPluginCover());
registry.addRecipeRegistryPlugin(new RecipeRegistryPluginHollowCover());
} }
@Override @Override

View File

@@ -0,0 +1,59 @@
package com.raoulvdberge.refinedstorage.integration.jei;
import com.raoulvdberge.refinedstorage.RSItems;
import com.raoulvdberge.refinedstorage.apiimpl.network.node.cover.CoverManager;
import com.raoulvdberge.refinedstorage.item.ItemCover;
import mezz.jei.api.recipe.*;
import net.minecraft.item.ItemStack;
import java.util.Collections;
import java.util.List;
public class RecipeRegistryPluginCover implements IRecipeRegistryPlugin {
@Override
public <V> List<String> getRecipeCategoryUids(IFocus<V> focus) {
if (focus.getValue() instanceof ItemStack) {
ItemStack stack = (ItemStack) focus.getValue();
if (focus.getMode() == IFocus.Mode.INPUT) {
if (CoverManager.isValidCover(stack)) {
return Collections.singletonList(VanillaRecipeCategoryUid.CRAFTING);
}
} else if (focus.getMode() == IFocus.Mode.OUTPUT) {
if (stack.getItem() == RSItems.COVER) {
return Collections.singletonList(VanillaRecipeCategoryUid.CRAFTING);
}
}
}
return Collections.emptyList();
}
@Override
public <T extends IRecipeWrapper, V> List<T> getRecipeWrappers(IRecipeCategory<T> recipeCategory, IFocus<V> focus) {
if (focus.getValue() instanceof ItemStack) {
ItemStack stack = (ItemStack) focus.getValue();
if (focus.getMode() == IFocus.Mode.INPUT) {
if (CoverManager.isValidCover(stack)) {
ItemStack cover = new ItemStack(RSItems.COVER);
ItemCover.setItem(cover, stack);
return Collections.singletonList((T) new RecipeWrapperCover(stack, cover));
}
} else if (focus.getMode() == IFocus.Mode.OUTPUT) {
if (stack.getItem() == RSItems.COVER) {
return Collections.singletonList((T) new RecipeWrapperCover(ItemCover.getItem(stack), stack));
}
}
}
return Collections.emptyList();
}
@Override
public <T extends IRecipeWrapper> List<T> getRecipeWrappers(IRecipeCategory<T> recipeCategory) {
return Collections.emptyList();
}
}

View File

@@ -0,0 +1,63 @@
package com.raoulvdberge.refinedstorage.integration.jei;
import com.raoulvdberge.refinedstorage.RSItems;
import com.raoulvdberge.refinedstorage.apiimpl.network.node.cover.CoverManager;
import com.raoulvdberge.refinedstorage.item.ItemCover;
import mezz.jei.api.recipe.*;
import net.minecraft.item.ItemStack;
import java.util.Collections;
import java.util.List;
public class RecipeRegistryPluginHollowCover implements IRecipeRegistryPlugin {
@Override
public <V> List<String> getRecipeCategoryUids(IFocus<V> focus) {
if (focus.getValue() instanceof ItemStack) {
ItemStack stack = (ItemStack) focus.getValue();
if (focus.getMode() == IFocus.Mode.INPUT) {
if (stack.getItem() == RSItems.COVER && CoverManager.isValidCover(ItemCover.getItem(stack))) {
return Collections.singletonList(VanillaRecipeCategoryUid.CRAFTING);
}
} else if (focus.getMode() == IFocus.Mode.OUTPUT) {
if (stack.getItem() == RSItems.HOLLOW_COVER) {
return Collections.singletonList(VanillaRecipeCategoryUid.CRAFTING);
}
}
}
return Collections.emptyList();
}
@Override
public <T extends IRecipeWrapper, V> List<T> getRecipeWrappers(IRecipeCategory<T> recipeCategory, IFocus<V> focus) {
if (focus.getValue() instanceof ItemStack) {
ItemStack stack = (ItemStack) focus.getValue();
if (focus.getMode() == IFocus.Mode.INPUT) {
if (stack.getItem() == RSItems.COVER && CoverManager.isValidCover(ItemCover.getItem(stack))) {
ItemStack hollowCover = new ItemStack(RSItems.HOLLOW_COVER);
ItemCover.setItem(hollowCover, ItemCover.getItem(stack));
return Collections.singletonList((T) new RecipeWrapperHollowCover(stack, hollowCover));
}
} else if (focus.getMode() == IFocus.Mode.OUTPUT) {
if (stack.getItem() == RSItems.HOLLOW_COVER) {
ItemStack cover = new ItemStack(RSItems.COVER);
ItemCover.setItem(cover, ItemCover.getItem(stack));
return Collections.singletonList((T) new RecipeWrapperHollowCover(cover, stack));
}
}
}
return Collections.emptyList();
}
@Override
public <T extends IRecipeWrapper> List<T> getRecipeWrappers(IRecipeCategory<T> recipeCategory) {
return Collections.emptyList();
}
}

View File

@@ -0,0 +1,31 @@
package com.raoulvdberge.refinedstorage.integration.jei;
import com.raoulvdberge.refinedstorage.RSItems;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.wrapper.ICraftingRecipeWrapper;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.ItemHandlerHelper;
import java.util.ArrayList;
import java.util.List;
public class RecipeWrapperCover implements ICraftingRecipeWrapper {
private ItemStack stack;
private ItemStack cover;
public RecipeWrapperCover(ItemStack stack, ItemStack cover) {
this.stack = ItemHandlerHelper.copyStackWithSize(stack, 1);
this.cover = ItemHandlerHelper.copyStackWithSize(cover, 6);
}
@Override
public void getIngredients(IIngredients ingredients) {
List<ItemStack> inputs = new ArrayList<>();
inputs.add(new ItemStack(RSItems.CUTTING_TOOL));
inputs.add(stack);
ingredients.setInputs(ItemStack.class, inputs);
ingredients.setOutput(ItemStack.class, cover);
}
}

View File

@@ -0,0 +1,41 @@
package com.raoulvdberge.refinedstorage.integration.jei;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.wrapper.IShapedCraftingRecipeWrapper;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.ItemHandlerHelper;
import java.util.ArrayList;
import java.util.List;
public class RecipeWrapperHollowCover implements IShapedCraftingRecipeWrapper {
private ItemStack cover;
private ItemStack hollowCover;
public RecipeWrapperHollowCover(ItemStack cover, ItemStack hollowCover) {
this.cover = ItemHandlerHelper.copyStackWithSize(cover, 1);
this.hollowCover = ItemHandlerHelper.copyStackWithSize(hollowCover, 8);
}
@Override
public void getIngredients(IIngredients ingredients) {
List<ItemStack> inputs = new ArrayList<>();
for (int i = 0; i < 9; ++i) {
inputs.add(i == 4 ? ItemStack.EMPTY : cover);
}
ingredients.setInputs(ItemStack.class, inputs);
ingredients.setOutput(ItemStack.class, hollowCover);
}
@Override
public int getWidth() {
return 3;
}
@Override
public int getHeight() {
return 3;
}
}