From 4b76440fce90e64dd558261c2bf311da92fd7849 Mon Sep 17 00:00:00 2001 From: Flanks255 <32142731+Flanks255@users.noreply.github.com> Date: Tue, 12 Oct 2021 16:44:02 -0500 Subject: [PATCH] Fixed recipe class name to more align with previous class. --- .../mod/crafting/ActuallyRecipes.java | 2 +- .../mod/crafting/CopyNBTRecipeShaped.java | 92 ------------- .../mod/crafting/RecipeKeepDataShaped.java | 125 ++++++++++++------ 3 files changed, 89 insertions(+), 130 deletions(-) delete mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/crafting/CopyNBTRecipeShaped.java diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ActuallyRecipes.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ActuallyRecipes.java index 1651b9289..6aea6f7a2 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ActuallyRecipes.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/ActuallyRecipes.java @@ -14,5 +14,5 @@ public class ActuallyRecipes { RECIPE_TYPES.register(bus); } - public static final RegistryObject> NBT_COPY_RECIPE = RECIPE_TYPES.register(CopyNBTRecipeShaped.NAME, CopyNBTRecipeShaped.Serializer::new); + public static final RegistryObject> KEEP_DATA_SHAPED_RECIPE = RECIPE_TYPES.register(RecipeKeepDataShaped.NAME, RecipeKeepDataShaped.Serializer::new); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/CopyNBTRecipeShaped.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/CopyNBTRecipeShaped.java deleted file mode 100644 index 8938a85bd..000000000 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/CopyNBTRecipeShaped.java +++ /dev/null @@ -1,92 +0,0 @@ -package de.ellpeck.actuallyadditions.mod.crafting; - -import com.google.gson.JsonObject; -import net.minecraft.inventory.CraftingInventory; -import net.minecraft.item.ItemStack; -import net.minecraft.item.crafting.IRecipeSerializer; -import net.minecraft.item.crafting.Ingredient; -import net.minecraft.item.crafting.ShapedRecipe; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.NonNullList; -import net.minecraft.util.ResourceLocation; -import net.minecraftforge.registries.ForgeRegistryEntry; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; - -import javax.annotation.Nullable; - -public class CopyNBTRecipeShaped extends ShapedRecipe { - public static String NAME = "copy_nbt"; - public static final Logger LOGGER = LogManager.getLogger(); - public CopyNBTRecipeShaped(ResourceLocation idIn, String groupIn, int recipeWidthIn, int recipeHeightIn, NonNullList recipeItemsIn, ItemStack recipeOutputIn) { - super(idIn, groupIn, recipeWidthIn, recipeHeightIn, recipeItemsIn, recipeOutputIn); - } - - public CopyNBTRecipeShaped(ShapedRecipe shapedRecipe) { - super(shapedRecipe.getId(), shapedRecipe.getGroup(), shapedRecipe.getRecipeWidth(), shapedRecipe.getRecipeHeight(), shapedRecipe.getIngredients(), shapedRecipe.getResultItem()); - } - - @Override - public ItemStack assemble(CraftingInventory inv) { - final ItemStack craftingResult = super.assemble(inv); - TargetNBTIngredient donorIngredient = null; - ItemStack datasource = ItemStack.EMPTY; - NonNullList ingredients = getIngredients(); - for (Ingredient ingredient : ingredients) { - if (ingredient instanceof TargetNBTIngredient) { - donorIngredient = (TargetNBTIngredient) ingredient; - break; - } - } - if (donorIngredient != null && !inv.isEmpty()) { - for (int i = 0; i < inv.getContainerSize(); i++) { - final ItemStack item = inv.getItem(i); - if (!item.isEmpty() && donorIngredient.test(item)) { - datasource = item; - break; - } - } - } - - if (!datasource.isEmpty() && datasource.hasTag()) - craftingResult.setTag(datasource.getTag().copy()); - - return craftingResult; - } - - - @Override - public IRecipeSerializer getSerializer() { - return ActuallyRecipes.NBT_COPY_RECIPE.get(); - } - - public static class Serializer extends ForgeRegistryEntry> implements IRecipeSerializer { - @Nullable - @Override - public CopyNBTRecipeShaped fromNetwork(ResourceLocation recipeId, PacketBuffer buffer) { - return new CopyNBTRecipeShaped(IRecipeSerializer.SHAPED_RECIPE.fromNetwork(recipeId, buffer)); - } - - @Override - public CopyNBTRecipeShaped fromJson(ResourceLocation recipeId, JsonObject json) { - try { - return new CopyNBTRecipeShaped(IRecipeSerializer.SHAPED_RECIPE.fromJson(recipeId, json)); - } - catch (Exception exception) { - LOGGER.info("Error reading "+ NAME +" Recipe from packet: ", exception); - throw exception; - } - } - - @Override - public void toNetwork(PacketBuffer buffer, CopyNBTRecipeShaped recipe) { - try { - IRecipeSerializer.SHAPED_RECIPE.toNetwork(buffer, recipe); - } - catch (Exception exception) { - LOGGER.info("Error writing "+ NAME +" Recipe to packet: ", exception); - throw exception; - } - } - } -} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/RecipeKeepDataShaped.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/RecipeKeepDataShaped.java index 580a9054a..7cab1cc79 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/RecipeKeepDataShaped.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/RecipeKeepDataShaped.java @@ -1,41 +1,92 @@ -/* - * This file ("RecipeKeepDataShaped.java") is part of the Actually Additions mod for Minecraft. - * It is created and owned by Ellpeck and distributed - * under the Actually Additions License to be found at - * http://ellpeck.de/actaddlicense - * View the source code at https://github.com/Ellpeck/ActuallyAdditions - * - * © 2015-2017 Ellpeck - */ - package de.ellpeck.actuallyadditions.mod.crafting; -// TODO: [port] MOVE TO DATA_GENERATOR -@Deprecated -public class RecipeKeepDataShaped { //extends ShapedOreRecipe { - // - // private final ItemStack nbtCopyStack; - // - // public RecipeKeepDataShaped(ResourceLocation group, ItemStack result, ItemStack nbtCopyStack, Object... recipe) { - // super(group, result, recipe); - // this.nbtCopyStack = nbtCopyStack; - // - // RecipeHelper.addRecipe(group.getPath(), this); - // } - // - // @Override - // public ItemStack getCraftingResult(InventoryCrafting inventory) { - // ItemStack stack = super.getCraftingResult(inventory); - // if (StackUtil.isValid(stack)) { - // for (int i = 0; i < inventory.getSizeInventory(); i++) { - // ItemStack input = inventory.getStackInSlot(i); - // if (ItemUtil.areItemsEqual(this.nbtCopyStack, input, true)) { - // stack.setTagCompound(input.getTagCompound()); - // break; - // } - // } - // } - // return stack; - // } +import com.google.gson.JsonObject; +import net.minecraft.inventory.CraftingInventory; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipeSerializer; +import net.minecraft.item.crafting.Ingredient; +import net.minecraft.item.crafting.ShapedRecipe; +import net.minecraft.network.PacketBuffer; +import net.minecraft.util.NonNullList; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.registries.ForgeRegistryEntry; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import javax.annotation.Nullable; + +public class RecipeKeepDataShaped extends ShapedRecipe { + public static String NAME = "copy_nbt"; + public static final Logger LOGGER = LogManager.getLogger(); + public RecipeKeepDataShaped(ResourceLocation idIn, String groupIn, int recipeWidthIn, int recipeHeightIn, NonNullList recipeItemsIn, ItemStack recipeOutputIn) { + super(idIn, groupIn, recipeWidthIn, recipeHeightIn, recipeItemsIn, recipeOutputIn); + } + + public RecipeKeepDataShaped(ShapedRecipe shapedRecipe) { + super(shapedRecipe.getId(), shapedRecipe.getGroup(), shapedRecipe.getRecipeWidth(), shapedRecipe.getRecipeHeight(), shapedRecipe.getIngredients(), shapedRecipe.getResultItem()); + } + + @Override + public ItemStack assemble(CraftingInventory inv) { + final ItemStack craftingResult = super.assemble(inv); + TargetNBTIngredient donorIngredient = null; + ItemStack datasource = ItemStack.EMPTY; + NonNullList ingredients = getIngredients(); + for (Ingredient ingredient : ingredients) { + if (ingredient instanceof TargetNBTIngredient) { + donorIngredient = (TargetNBTIngredient) ingredient; + break; + } + } + if (donorIngredient != null && !inv.isEmpty()) { + for (int i = 0; i < inv.getContainerSize(); i++) { + final ItemStack item = inv.getItem(i); + if (!item.isEmpty() && donorIngredient.test(item)) { + datasource = item; + break; + } + } + } + + if (!datasource.isEmpty() && datasource.hasTag()) + craftingResult.setTag(datasource.getTag().copy()); + + return craftingResult; + } + + + @Override + public IRecipeSerializer getSerializer() { + return ActuallyRecipes.KEEP_DATA_SHAPED_RECIPE.get(); + } + + public static class Serializer extends ForgeRegistryEntry> implements IRecipeSerializer { + @Nullable + @Override + public RecipeKeepDataShaped fromNetwork(ResourceLocation recipeId, PacketBuffer buffer) { + return new RecipeKeepDataShaped(IRecipeSerializer.SHAPED_RECIPE.fromNetwork(recipeId, buffer)); + } + + @Override + public RecipeKeepDataShaped fromJson(ResourceLocation recipeId, JsonObject json) { + try { + return new RecipeKeepDataShaped(IRecipeSerializer.SHAPED_RECIPE.fromJson(recipeId, json)); + } + catch (Exception exception) { + LOGGER.info("Error reading "+ NAME +" Recipe from packet: ", exception); + throw exception; + } + } + + @Override + public void toNetwork(PacketBuffer buffer, RecipeKeepDataShaped recipe) { + try { + IRecipeSerializer.SHAPED_RECIPE.toNetwork(buffer, recipe); + } + catch (Exception exception) { + LOGGER.info("Error writing "+ NAME +" Recipe to packet: ", exception); + throw exception; + } + } + } }