mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-11-16 21:13:11 +01:00
67 lines
2 KiB
Java
67 lines
2 KiB
Java
package de.ellpeck.actuallyadditions.mod.crafting;
|
|
|
|
import com.google.gson.JsonObject;
|
|
import net.minecraft.data.recipes.FinishedRecipe;
|
|
import net.minecraft.resources.ResourceLocation;
|
|
import net.minecraft.world.item.crafting.RecipeSerializer;
|
|
import net.neoforged.neoforge.registries.BuiltInRegistries;
|
|
|
|
import javax.annotation.Nullable;
|
|
import java.util.function.Consumer;
|
|
|
|
public class WrappedRecipe implements FinishedRecipe {
|
|
FinishedRecipe inner;
|
|
RecipeSerializer<?> serializerOverride;
|
|
|
|
public WrappedRecipe(FinishedRecipe innerIn) {
|
|
inner = innerIn;
|
|
}
|
|
|
|
public WrappedRecipe(FinishedRecipe innerIn, RecipeSerializer<?> serializerOverrideIn) {
|
|
inner = innerIn;
|
|
serializerOverride = serializerOverrideIn;
|
|
}
|
|
|
|
public static Consumer<FinishedRecipe> Inject(Consumer<FinishedRecipe> consumer, RecipeSerializer<?> serializer) {
|
|
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)
|
|
jsonObject.addProperty("type", BuiltInRegistries.RECIPE_SERIALIZERS.getKey(serializerOverride).toString());
|
|
else
|
|
jsonObject.addProperty("type", BuiltInRegistries.RECIPE_SERIALIZERS.getKey(inner.getType()).toString());
|
|
serializeRecipeData(jsonObject);
|
|
return jsonObject;
|
|
}
|
|
|
|
@Override
|
|
public ResourceLocation getId() {
|
|
return inner.getId();
|
|
}
|
|
|
|
@Override
|
|
public RecipeSerializer<?> getType () {
|
|
return serializerOverride != null? serializerOverride:inner.getType();
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public JsonObject serializeAdvancement() {
|
|
return inner.serializeAdvancement();
|
|
}
|
|
|
|
@Nullable
|
|
@Override
|
|
public ResourceLocation getAdvancementId() {
|
|
return inner.getAdvancementId();
|
|
}
|
|
}
|