2021-10-12 23:19:47 +02:00
|
|
|
package de.ellpeck.actuallyadditions.mod.crafting;
|
|
|
|
|
|
|
|
import com.google.gson.JsonObject;
|
2024-03-02 21:23:08 +01:00
|
|
|
import net.minecraft.data.recipes.FinishedRecipe;
|
|
|
|
import net.minecraft.resources.ResourceLocation;
|
|
|
|
import net.minecraft.world.item.crafting.RecipeSerializer;
|
2024-03-04 20:21:48 +01:00
|
|
|
import net.neoforged.neoforge.registries.BuiltInRegistries;
|
2021-10-12 23:19:47 +02:00
|
|
|
|
|
|
|
import javax.annotation.Nullable;
|
|
|
|
import java.util.function.Consumer;
|
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
public class WrappedRecipe implements FinishedRecipe {
|
|
|
|
FinishedRecipe inner;
|
|
|
|
RecipeSerializer<?> serializerOverride;
|
2021-10-12 23:19:47 +02:00
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
public WrappedRecipe(FinishedRecipe innerIn) {
|
2021-10-12 23:19:47 +02:00
|
|
|
inner = innerIn;
|
|
|
|
}
|
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
public WrappedRecipe(FinishedRecipe innerIn, RecipeSerializer<?> serializerOverrideIn) {
|
2021-10-12 23:19:47 +02:00
|
|
|
inner = innerIn;
|
|
|
|
serializerOverride = serializerOverrideIn;
|
|
|
|
}
|
|
|
|
|
2024-03-02 21:23:08 +01:00
|
|
|
public static Consumer<FinishedRecipe> Inject(Consumer<FinishedRecipe> consumer, RecipeSerializer<?> serializer) {
|
2021-10-12 23:19:47 +02:00
|
|
|
return iFinishedRecipe -> consumer.accept(new WrappedRecipe(iFinishedRecipe, serializer));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void serializeRecipeData(JsonObject json) {
|
|
|
|
inner.serializeRecipeData(json);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public JsonObject serializeRecipe() {
|
|
|
|
JsonObject jsonObject = new JsonObject();
|
|
|
|
|
|
|
|
if (serializerOverride != null)
|
2024-03-04 20:21:48 +01:00
|
|
|
jsonObject.addProperty("type", BuiltInRegistries.RECIPE_SERIALIZERS.getKey(serializerOverride).toString());
|
2021-10-12 23:19:47 +02:00
|
|
|
else
|
2024-03-04 20:21:48 +01:00
|
|
|
jsonObject.addProperty("type", BuiltInRegistries.RECIPE_SERIALIZERS.getKey(inner.getType()).toString());
|
2021-10-12 23:19:47 +02:00
|
|
|
serializeRecipeData(jsonObject);
|
|
|
|
return jsonObject;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public ResourceLocation getId() {
|
|
|
|
return inner.getId();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-03-02 21:23:08 +01:00
|
|
|
public RecipeSerializer<?> getType () {
|
2021-10-12 23:19:47 +02:00
|
|
|
return serializerOverride != null? serializerOverride:inner.getType();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public JsonObject serializeAdvancement() {
|
|
|
|
return inner.serializeAdvancement();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Nullable
|
|
|
|
@Override
|
|
|
|
public ResourceLocation getAdvancementId() {
|
|
|
|
return inner.getAdvancementId();
|
|
|
|
}
|
|
|
|
}
|