Fixed recipe class name to more align with previous class.

This commit is contained in:
Flanks255 2021-10-12 16:44:02 -05:00
parent 0e31e1e19f
commit 4b76440fce
3 changed files with 89 additions and 130 deletions

View file

@ -14,5 +14,5 @@ public class ActuallyRecipes {
RECIPE_TYPES.register(bus); RECIPE_TYPES.register(bus);
} }
public static final RegistryObject<IRecipeSerializer<?>> NBT_COPY_RECIPE = RECIPE_TYPES.register(CopyNBTRecipeShaped.NAME, CopyNBTRecipeShaped.Serializer::new); public static final RegistryObject<IRecipeSerializer<?>> KEEP_DATA_SHAPED_RECIPE = RECIPE_TYPES.register(RecipeKeepDataShaped.NAME, RecipeKeepDataShaped.Serializer::new);
} }

View file

@ -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<Ingredient> 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<Ingredient> 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<IRecipeSerializer<?>> implements IRecipeSerializer<CopyNBTRecipeShaped> {
@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;
}
}
}
}

View file

@ -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; package de.ellpeck.actuallyadditions.mod.crafting;
// TODO: [port] MOVE TO DATA_GENERATOR import com.google.gson.JsonObject;
@Deprecated import net.minecraft.inventory.CraftingInventory;
public class RecipeKeepDataShaped { //extends ShapedOreRecipe { import net.minecraft.item.ItemStack;
// import net.minecraft.item.crafting.IRecipeSerializer;
// private final ItemStack nbtCopyStack; import net.minecraft.item.crafting.Ingredient;
// import net.minecraft.item.crafting.ShapedRecipe;
// public RecipeKeepDataShaped(ResourceLocation group, ItemStack result, ItemStack nbtCopyStack, Object... recipe) { import net.minecraft.network.PacketBuffer;
// super(group, result, recipe); import net.minecraft.util.NonNullList;
// this.nbtCopyStack = nbtCopyStack; import net.minecraft.util.ResourceLocation;
// import net.minecraftforge.registries.ForgeRegistryEntry;
// RecipeHelper.addRecipe(group.getPath(), this); import org.apache.logging.log4j.LogManager;
// } import org.apache.logging.log4j.Logger;
//
// @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 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<Ingredient> 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<Ingredient> 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<IRecipeSerializer<?>> implements IRecipeSerializer<RecipeKeepDataShaped> {
@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;
}
}
}
} }