NaturesAura/src/main/java/de/ellpeck/naturesaura/recipes/OfferingRecipe.java

72 lines
2.3 KiB
Java
Raw Normal View History

2020-04-29 16:38:50 +02:00
package de.ellpeck.naturesaura.recipes;
import com.google.gson.JsonObject;
2023-07-08 12:32:27 +02:00
import net.minecraft.core.RegistryAccess;
2021-12-04 19:17:21 +01:00
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.minecraft.world.item.crafting.RecipeType;
2020-04-29 16:38:50 +02:00
import net.minecraftforge.common.crafting.CraftingHelper;
import javax.annotation.Nullable;
public class OfferingRecipe extends ModRecipe {
public final Ingredient input;
public final Ingredient startItem;
public final ItemStack output;
public OfferingRecipe(ResourceLocation name, Ingredient input, Ingredient startItem, ItemStack output) {
super(name);
this.input = input;
this.startItem = startItem;
this.output = output;
}
@Override
2023-07-08 12:32:27 +02:00
public ItemStack getResultItem(RegistryAccess access) {
2020-04-29 16:38:50 +02:00
return this.output;
}
@Override
2021-12-04 19:17:21 +01:00
public RecipeSerializer<?> getSerializer() {
2020-04-29 16:38:50 +02:00
return ModRecipes.OFFERING_SERIALIZER;
}
@Override
2021-12-04 19:17:21 +01:00
public RecipeType<?> getType() {
2020-04-29 16:38:50 +02:00
return ModRecipes.OFFERING_TYPE;
}
2022-06-27 15:24:04 +02:00
public static class Serializer implements RecipeSerializer<OfferingRecipe> {
2021-12-04 19:17:21 +01:00
2020-04-29 16:38:50 +02:00
@Override
2021-12-04 19:17:21 +01:00
public OfferingRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
2020-04-29 16:38:50 +02:00
return new OfferingRecipe(
recipeId,
2021-12-04 19:17:21 +01:00
Ingredient.fromJson(json.get("input")),
Ingredient.fromJson(json.get("start_item")),
2020-04-29 16:38:50 +02:00
CraftingHelper.getItemStack(json.getAsJsonObject("output"), true));
}
@Nullable
@Override
2021-12-04 19:17:21 +01:00
public OfferingRecipe fromNetwork(ResourceLocation recipeId, FriendlyByteBuf buffer) {
2020-04-29 16:38:50 +02:00
return new OfferingRecipe(
recipeId,
2021-12-04 19:17:21 +01:00
Ingredient.fromNetwork(buffer),
Ingredient.fromNetwork(buffer),
buffer.readItem());
2020-04-29 16:38:50 +02:00
}
@Override
2021-12-04 19:17:21 +01:00
public void toNetwork(FriendlyByteBuf buffer, OfferingRecipe recipe) {
recipe.input.toNetwork(buffer);
recipe.startItem.toNetwork(buffer);
buffer.writeItem(recipe.output);
2020-04-29 16:38:50 +02:00
}
}
}