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

70 lines
2.2 KiB
Java
Raw Normal View History

2020-04-29 16:38:50 +02:00
package de.ellpeck.naturesaura.recipes;
2024-03-10 15:54:58 +01:00
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
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.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 javax.annotation.Nullable;
public class OfferingRecipe extends ModRecipe {
public final Ingredient input;
public final Ingredient startItem;
public final ItemStack output;
2024-03-10 15:54:58 +01:00
public OfferingRecipe(Ingredient input, Ingredient startItem, ItemStack output) {
2020-04-29 16:38:50 +02:00
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
2024-03-10 15:54:58 +01:00
private static final Codec<OfferingRecipe> CODEC = RecordCodecBuilder.create(i -> i.group(
Ingredient.CODEC.fieldOf("input").forGetter(r -> r.input),
Ingredient.CODEC.fieldOf("start_item").forGetter(r -> r.startItem),
ItemStack.CODEC.fieldOf("output").forGetter(r -> r.output)
).apply(i, OfferingRecipe::new));
2020-04-29 16:38:50 +02:00
@Override
2024-03-10 15:54:58 +01:00
public Codec<OfferingRecipe> codec() {
return Serializer.CODEC;
2020-04-29 16:38:50 +02:00
}
@Nullable
@Override
2024-03-10 15:54:58 +01:00
public OfferingRecipe fromNetwork(FriendlyByteBuf buffer) {
return new OfferingRecipe(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
}
2024-03-10 15:54:58 +01:00
2020-04-29 16:38:50 +02:00
}
2024-03-10 15:54:58 +01:00
2020-04-29 16:38:50 +02:00
}