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

81 lines
2.6 KiB
Java
Raw Normal View History

2020-04-29 16:38:50 +02:00
package de.ellpeck.naturesaura.recipes;
import com.google.gson.JsonObject;
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 AltarRecipe extends ModRecipe {
public final Ingredient input;
public final ItemStack output;
public final Ingredient catalyst;
public final int aura;
public final int time;
public AltarRecipe(ResourceLocation name, Ingredient input, ItemStack output, Ingredient catalyst, int aura, int time) {
2020-04-29 16:38:50 +02:00
super(name);
this.input = input;
this.output = output;
this.catalyst = catalyst;
this.aura = aura;
this.time = time;
}
@Override
2021-12-04 19:17:21 +01:00
public ItemStack getResultItem() {
2020-04-29 16:38:50 +02:00
return this.output;
}
@Override
2021-12-04 19:17:21 +01:00
public RecipeSerializer<?> getSerializer() {
2022-06-27 15:24:04 +02:00
return ModRecipes.ALTAR_SERIALIZER;
2020-04-29 16:38:50 +02:00
}
@Override
2021-12-04 19:17:21 +01:00
public RecipeType<?> getType() {
2020-04-29 16:38:50 +02:00
return ModRecipes.ALTAR_TYPE;
}
2022-06-27 15:24:04 +02:00
public static class Serializer implements RecipeSerializer<AltarRecipe> {
2020-04-29 16:38:50 +02:00
@Override
2021-12-04 19:17:21 +01:00
public AltarRecipe fromJson(ResourceLocation recipeId, JsonObject json) {
2020-04-29 16:38:50 +02:00
return new AltarRecipe(
recipeId,
2021-12-04 19:17:21 +01:00
Ingredient.fromJson(json.getAsJsonObject("input")),
2020-04-29 16:38:50 +02:00
CraftingHelper.getItemStack(json.getAsJsonObject("output"), true),
2021-12-04 19:17:21 +01:00
json.has("catalyst") ? Ingredient.fromJson(json.getAsJsonObject("catalyst")) : Ingredient.EMPTY,
2020-04-29 16:38:50 +02:00
json.get("aura").getAsInt(),
json.get("time").getAsInt());
}
@Nullable
@Override
2021-12-04 19:17:21 +01:00
public AltarRecipe fromNetwork(ResourceLocation recipeId, FriendlyByteBuf buffer) {
2020-04-29 16:38:50 +02:00
return new AltarRecipe(
recipeId,
2021-12-04 19:17:21 +01:00
Ingredient.fromNetwork(buffer),
buffer.readItem(),
Ingredient.fromNetwork(buffer),
2020-04-29 16:38:50 +02:00
buffer.readInt(),
buffer.readInt());
}
@Override
2021-12-04 19:17:21 +01:00
public void toNetwork(FriendlyByteBuf buffer, AltarRecipe recipe) {
recipe.input.toNetwork(buffer);
buffer.writeItem(recipe.output);
recipe.catalyst.toNetwork(buffer);
2020-04-29 16:38:50 +02:00
buffer.writeInt(recipe.aura);
buffer.writeInt(recipe.time);
}
}
}