2020-04-29 16:38:50 +02:00
|
|
|
package de.ellpeck.naturesaura.recipes;
|
|
|
|
|
|
|
|
import com.google.gson.JsonObject;
|
2020-09-28 01:50:17 +02:00
|
|
|
import de.ellpeck.naturesaura.NaturesAura;
|
2020-04-29 16:38:50 +02:00
|
|
|
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
|
|
|
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
|
2020-09-28 01:50:17 +02:00
|
|
|
import de.ellpeck.naturesaura.items.ItemAuraBottle;
|
|
|
|
import de.ellpeck.naturesaura.items.ModItems;
|
2021-12-04 19:17:21 +01:00
|
|
|
import net.minecraft.network.FriendlyByteBuf;
|
2022-06-27 15:24:04 +02:00
|
|
|
import net.minecraft.network.chat.Component;
|
2021-12-04 19:17:21 +01:00
|
|
|
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 IAuraType requiredType;
|
|
|
|
public final Ingredient catalyst;
|
|
|
|
public final int aura;
|
|
|
|
public final int time;
|
|
|
|
|
|
|
|
public AltarRecipe(ResourceLocation name, Ingredient input, ItemStack output, IAuraType requiredType, Ingredient catalyst, int aura, int time) {
|
|
|
|
super(name);
|
|
|
|
this.input = input;
|
|
|
|
this.output = output;
|
|
|
|
this.requiredType = requiredType;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2020-09-28 01:50:17 +02:00
|
|
|
public ItemStack getDimensionBottle() {
|
2021-12-15 16:30:22 +01:00
|
|
|
var bottle = ItemAuraBottle.setType(new ItemStack(ModItems.AURA_BOTTLE), this.requiredType);
|
2022-06-27 15:24:04 +02:00
|
|
|
bottle.setHoverName(Component.translatable("info." + NaturesAura.MOD_ID + ".required_aura_type." + this.requiredType.getName()));
|
2020-09-28 01:50:17 +02:00
|
|
|
return bottle;
|
|
|
|
}
|
|
|
|
|
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),
|
|
|
|
NaturesAuraAPI.AURA_TYPES.get(new ResourceLocation(json.get("aura_type").getAsString())),
|
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(),
|
2020-04-29 16:38:50 +02:00
|
|
|
NaturesAuraAPI.AURA_TYPES.get(buffer.readResourceLocation()),
|
2021-12-04 19:17:21 +01:00
|
|
|
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);
|
2020-04-29 16:38:50 +02:00
|
|
|
buffer.writeResourceLocation(recipe.requiredType.getName());
|
2021-12-04 19:17:21 +01:00
|
|
|
recipe.catalyst.toNetwork(buffer);
|
2020-04-29 16:38:50 +02:00
|
|
|
buffer.writeInt(recipe.aura);
|
|
|
|
buffer.writeInt(recipe.time);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|