Added cover recipes

This commit is contained in:
Buuz135
2021-09-11 20:05:35 +02:00
parent 3fa1fbb272
commit a6884690d4
9 changed files with 380 additions and 6 deletions

View File

@@ -0,0 +1,84 @@
package com.refinedmods.refinedstorage.integration.jei;
import com.refinedmods.refinedstorage.RSItems;
import com.refinedmods.refinedstorage.apiimpl.network.node.cover.CoverManager;
import com.refinedmods.refinedstorage.item.CoverItem;
import com.refinedmods.refinedstorage.recipe.CoverRecipe;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.category.extensions.vanilla.crafting.ICraftingCategoryExtension;
import mezz.jei.api.recipe.category.extensions.vanilla.crafting.ICustomCraftingCategoryExtension;
import net.minecraft.block.Block;
import net.minecraft.block.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.Tags;
import net.minecraftforge.common.util.Size2i;
import net.minecraftforge.registries.ForgeRegistries;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class CoverCraftingCategoryExtension implements ICustomCraftingCategoryExtension {
@Override
public void setIngredients(IIngredients ingredients) {
List<ItemStack> input = new ArrayList<>();
List<ItemStack> output = new ArrayList<>();
for (Block block : ForgeRegistries.BLOCKS.getValues()) {
Item item = Item.getItemFromBlock(block);
if (item == Items.AIR) {
continue;
}
NonNullList<ItemStack> subBlocks = NonNullList.create();
block.fillItemGroup(ItemGroup.SEARCH, subBlocks);
for (ItemStack subBlock : subBlocks) {
if (CoverManager.isValidCover(subBlock)) {
input.add(subBlock);
ItemStack stack = new ItemStack(RSItems.COVER.get());
CoverItem.setItem(stack, subBlock);
output.add(stack);
}
}
}
ingredients.setInputLists(VanillaTypes.ITEM, Arrays.asList(Tags.Items.NUGGETS_IRON.getAllElements().stream().map(ItemStack::new).collect(Collectors.toList()), input));
ingredients.setOutputs(VanillaTypes.ITEM, output);
}
@Nullable
@Override
public Size2i getSize() {
return new Size2i(2, 1);
}
@Nullable
@Override
public ResourceLocation getRegistryName() {
return CoverRecipe.SERIALIZER.getRegistryName();
}
@Override
public void setRecipe(IRecipeLayout recipeLayout, IIngredients ingredients) {
ItemStack stack = recipeLayout.getFocus(VanillaTypes.ITEM).getValue();
if (stack.getItem() instanceof CoverItem){
recipeLayout.getIngredientsGroup(VanillaTypes.ITEM).set(4, Tags.Items.NUGGETS_IRON.getAllElements().stream().map(ItemStack::new).collect(Collectors.toList()));
recipeLayout.getIngredientsGroup(VanillaTypes.ITEM).set(5, CoverItem.getItem(stack));
recipeLayout.getIngredientsGroup(VanillaTypes.ITEM).set(0, stack);
}else {
recipeLayout.getIngredientsGroup(VanillaTypes.ITEM).set(4, Tags.Items.NUGGETS_IRON.getAllElements().stream().map(ItemStack::new).collect(Collectors.toList()));
recipeLayout.getIngredientsGroup(VanillaTypes.ITEM).set(5, stack);
ItemStack output = new ItemStack(RSItems.COVER.get());
CoverItem.setItem(output, stack);
recipeLayout.getIngredientsGroup(VanillaTypes.ITEM).set(0, output);
}
}
}

View File

@@ -0,0 +1,67 @@
package com.refinedmods.refinedstorage.integration.jei;
import com.refinedmods.refinedstorage.RSItems;
import com.refinedmods.refinedstorage.apiimpl.network.node.cover.CoverManager;
import com.refinedmods.refinedstorage.item.CoverItem;
import com.refinedmods.refinedstorage.recipe.CoverRecipe;
import com.refinedmods.refinedstorage.recipe.HollowCoverRecipe;
import mezz.jei.api.constants.VanillaTypes;
import mezz.jei.api.gui.IRecipeLayout;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.category.extensions.vanilla.crafting.ICustomCraftingCategoryExtension;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.NonNullList;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.Tags;
import net.minecraftforge.common.util.Size2i;
import net.minecraftforge.registries.ForgeRegistries;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class HollowCoverCraftingCategoryExtension implements ICustomCraftingCategoryExtension {
@Override
public void setIngredients(IIngredients ingredients) {
ingredients.setInput(VanillaTypes.ITEM, new ItemStack(RSItems.COVER.get()));
ingredients.setOutput(VanillaTypes.ITEM, new ItemStack(RSItems.HOLLOW_COVER.get()));
}
@Nullable
@Override
public Size2i getSize() {
return new Size2i(2, 1);
}
@Nullable
@Override
public ResourceLocation getRegistryName() {
return HollowCoverRecipe.SERIALIZER.getRegistryName();
}
@Override
public void setRecipe(IRecipeLayout recipeLayout, IIngredients ingredients) {
ItemStack stack = recipeLayout.getFocus(VanillaTypes.ITEM).getValue();
if (stack.getItem() == RSItems.COVER.get()){
recipeLayout.getIngredientsGroup(VanillaTypes.ITEM).set(5, stack);
ItemStack output = new ItemStack(RSItems.HOLLOW_COVER.get());
CoverItem.setItem(output, CoverItem.getItem(stack));
recipeLayout.getIngredientsGroup(VanillaTypes.ITEM).set(0, output);
}else {
ItemStack input = new ItemStack(RSItems.COVER.get());
CoverItem.setItem(input, CoverItem.getItem(stack));
recipeLayout.getIngredientsGroup(VanillaTypes.ITEM).set(5, input);
recipeLayout.getIngredientsGroup(VanillaTypes.ITEM).set(0, stack);
}
}
}

View File

@@ -2,15 +2,18 @@ package com.refinedmods.refinedstorage.integration.jei;
import com.refinedmods.refinedstorage.RS;
import com.refinedmods.refinedstorage.RSItems;
import com.refinedmods.refinedstorage.recipe.CoverRecipe;
import com.refinedmods.refinedstorage.recipe.HollowCoverRecipe;
import com.refinedmods.refinedstorage.screen.BaseScreen;
import mezz.jei.api.IModPlugin;
import mezz.jei.api.JeiPlugin;
import mezz.jei.api.registration.IGuiHandlerRegistration;
import mezz.jei.api.registration.IRecipeTransferRegistration;
import mezz.jei.api.registration.ISubtypeRegistration;
import mezz.jei.api.constants.VanillaRecipeCategoryUid;
import mezz.jei.api.registration.*;
import mezz.jei.api.runtime.IJeiRuntime;
import net.minecraft.util.ResourceLocation;
import java.util.Collections;
@JeiPlugin
public class RSJeiPlugin implements IModPlugin {
private static final ResourceLocation ID = new ResourceLocation(RS.ID, "plugin");
@@ -46,4 +49,10 @@ public class RSJeiPlugin implements IModPlugin {
public void registerItemSubtypes(ISubtypeRegistration registration) {
registration.useNbtForSubtypes(RSItems.COVER.get(), RSItems.HOLLOW_COVER.get());
}
@Override
public void registerVanillaCategoryExtensions(IVanillaCategoryExtensionRegistration registration) {
registration.getCraftingCategory().addCategoryExtension(CoverRecipe.class, (cover) -> new CoverCraftingCategoryExtension());
registration.getCraftingCategory().addCategoryExtension(HollowCoverRecipe.class, (cover) -> new HollowCoverCraftingCategoryExtension());
}
}

View File

@@ -21,6 +21,8 @@ import net.minecraft.util.Direction;
import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponent;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.client.model.ModelDataManager;
@@ -45,8 +47,9 @@ public class CoverItem extends Item {
if (!cover.hasTag()) {
cover.setTag(new CompoundNBT());
}
cover.getTag().put(NBT_ITEM, item.serializeNBT());
ItemStack result = item.copy();
result.setCount(1);
cover.getTag().put(NBT_ITEM, result.serializeNBT());
}
@Nonnull
@@ -64,7 +67,7 @@ public class CoverItem extends Item {
ItemStack item = getItem(stack);
if (!item.isEmpty()) {
tooltip.add(item.getItem().getDisplayName(item));
tooltip.add(((TextComponent)item.getItem().getDisplayName(item)).mergeStyle(TextFormatting.GRAY));
}
}

View File

@@ -0,0 +1,111 @@
package com.refinedmods.refinedstorage.recipe;
import com.google.common.collect.Lists;
import com.refinedmods.refinedstorage.RSItems;
import com.refinedmods.refinedstorage.apiimpl.network.node.cover.Cover;
import com.refinedmods.refinedstorage.apiimpl.network.node.cover.CoverManager;
import com.refinedmods.refinedstorage.item.CoverItem;
import com.refinedmods.refinedstorage.item.WrenchItem;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.item.crafting.SpecialRecipe;
import net.minecraft.item.crafting.SpecialRecipeSerializer;
import net.minecraft.tags.ItemTags;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.common.Tags;
import java.util.List;
public class CoverRecipe extends SpecialRecipe {
public static IRecipeSerializer<CoverRecipe> SERIALIZER = new SpecialRecipeSerializer<>(CoverRecipe::new);
public CoverRecipe(ResourceLocation idIn) {
super(idIn);
}
public static boolean stackMatches(ItemStack first) {
return CoverManager.isValidCover(first);
}
public static boolean matches(List<ItemStack> list) {
return list.size() == 2;
}
public static ItemStack getResult(List<ItemStack> list) {
if (list.size() == 2) {
ItemStack first = list.get(0);
ItemStack second = list.get(1);
return getResult(first, second);
}
return ItemStack.EMPTY;
}
public static ItemStack getResult(ItemStack first, ItemStack second){
if (first.getItem().isIn(Tags.Items.NUGGETS_IRON)){
ItemStack stack = new ItemStack(RSItems.COVER.get());
CoverItem.setItem(stack, second);
stack.setCount(6);
return stack;
}
if (second.getItem().isIn(Tags.Items.NUGGETS_IRON)){
ItemStack stack = new ItemStack(RSItems.COVER.get());
CoverItem.setItem(stack, first);
stack.setCount(6);
return stack;
}
return ItemStack.EMPTY;
}
@Override
public boolean matches(CraftingInventory inv, World worldIn) {
List<ItemStack> list = Lists.newArrayList();
int ingots = 0;
for (int i = 0; i < inv.getSizeInventory(); ++i) {
ItemStack itemstack = inv.getStackInSlot(i);
if (!itemstack.isEmpty()) {
list.add(itemstack);
if (itemstack.getItem().isIn(Tags.Items.NUGGETS_IRON)){
++ingots;
} else if (!stackMatches(itemstack)){
return false;
}
}
}
return matches(list) && ingots == 1;
}
@Override
public ItemStack getCraftingResult(CraftingInventory inv) {
List<ItemStack> list = Lists.newArrayList();
int ingots = 0;
for (int i = 0; i < inv.getSizeInventory(); ++i) {
ItemStack itemstack = inv.getStackInSlot(i);
if (!itemstack.isEmpty()) {
list.add(itemstack);
if (itemstack.getItem().isIn(Tags.Items.NUGGETS_IRON)){
++ingots;
} else if (!stackMatches(itemstack)){
return ItemStack.EMPTY;
}
}
}
if (ingots > 1){
return ItemStack.EMPTY;
}
return getResult(list);
}
@Override
public boolean canFit(int width, int height) {
return width * height >= 2;
}
@Override
public IRecipeSerializer<?> getSerializer() {
return SERIALIZER;
}
}

View File

@@ -0,0 +1,89 @@
package com.refinedmods.refinedstorage.recipe;
import com.google.common.collect.Lists;
import com.refinedmods.refinedstorage.RSItems;
import com.refinedmods.refinedstorage.apiimpl.network.node.cover.CoverManager;
import com.refinedmods.refinedstorage.item.CoverItem;
import net.minecraft.inventory.CraftingInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.item.crafting.SpecialRecipe;
import net.minecraft.item.crafting.SpecialRecipeSerializer;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.minecraftforge.common.Tags;
import java.util.List;
public class HollowCoverRecipe extends SpecialRecipe {
public static IRecipeSerializer<HollowCoverRecipe> SERIALIZER = new SpecialRecipeSerializer<>(HollowCoverRecipe::new);
public HollowCoverRecipe(ResourceLocation idIn) {
super(idIn);
}
public static boolean stackMatches(ItemStack first) {
return first.getItem() == RSItems.COVER.get();
}
public static boolean matches(List<ItemStack> list) {
return list.size() == 1;
}
public static ItemStack getResult(List<ItemStack> list) {
if (list.size() == 1) {
ItemStack first = list.get(0);
return getResult(first);
}
return ItemStack.EMPTY;
}
public static ItemStack getResult(ItemStack first){
ItemStack stack = CoverItem.getItem(first);
ItemStack result = new ItemStack(RSItems.HOLLOW_COVER.get());
CoverItem.setItem(result, stack);
return result;
}
@Override
public boolean matches(CraftingInventory inv, World worldIn) {
List<ItemStack> list = Lists.newArrayList();
for (int i = 0; i < inv.getSizeInventory(); ++i) {
ItemStack itemstack = inv.getStackInSlot(i);
if (!itemstack.isEmpty()) {
list.add(itemstack);
if (!stackMatches(itemstack)){
return false;
}
}
}
return matches(list);
}
@Override
public ItemStack getCraftingResult(CraftingInventory inv) {
List<ItemStack> list = Lists.newArrayList();
for (int i = 0; i < inv.getSizeInventory(); ++i) {
ItemStack itemstack = inv.getStackInSlot(i);
if (!itemstack.isEmpty()) {
list.add(itemstack);
if (!stackMatches(itemstack)){
return ItemStack.EMPTY;
}
}
}
return getResult(list);
}
@Override
public boolean canFit(int width, int height) {
return width * height >= 2;
}
@Override
public IRecipeSerializer<?> getSerializer() {
return SERIALIZER;
}
}

View File

@@ -35,6 +35,8 @@ import com.refinedmods.refinedstorage.container.factory.*;
import com.refinedmods.refinedstorage.integration.craftingtweaks.CraftingTweaksIntegration;
import com.refinedmods.refinedstorage.integration.inventorysorter.InventorySorterIntegration;
import com.refinedmods.refinedstorage.item.blockitem.PortableGridBlockItem;
import com.refinedmods.refinedstorage.recipe.CoverRecipe;
import com.refinedmods.refinedstorage.recipe.HollowCoverRecipe;
import com.refinedmods.refinedstorage.recipe.UpgradeWithEnchantedBookRecipeSerializer;
import com.refinedmods.refinedstorage.tile.*;
import com.refinedmods.refinedstorage.tile.craftingmonitor.CraftingMonitorTile;
@@ -46,6 +48,7 @@ import net.minecraft.item.crafting.IRecipeSerializer;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityType;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.extensions.IForgeContainerType;
import net.minecraftforge.event.RegistryEvent;
@@ -141,6 +144,8 @@ public class CommonSetup {
@SubscribeEvent
public void onRegisterRecipeSerializers(RegistryEvent.Register<IRecipeSerializer<?>> e) {
e.getRegistry().register(new UpgradeWithEnchantedBookRecipeSerializer().setRegistryName(RS.ID, "upgrade_with_enchanted_book"));
e.getRegistry().register(CoverRecipe.SERIALIZER.setRegistryName(new ResourceLocation(RS.ID, "cover_recipe")));
e.getRegistry().register(HollowCoverRecipe.SERIALIZER.setRegistryName(new ResourceLocation(RS.ID, "hollow_cover_recipe")));
}
@SubscribeEvent

View File

@@ -0,0 +1,3 @@
{
"type": "refinedstorage:cover_recipe"
}

View File

@@ -0,0 +1,3 @@
{
"type": "refinedstorage:hollow_cover_recipe"
}