Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AnalyzerRecipe implements Recipe<SimpleContainer> {
- private final ResourceLocation id;
- //private final ResourceLocation output;
- private final NonNullList<Ingredient> recipeItems;
- public AnalyzerRecipe(ResourceLocation id,
- NonNullList<Ingredient> recipeItems) {
- this.id = id;
- //this.output = output;
- this.recipeItems = recipeItems;
- }
- @Override
- public boolean matches(SimpleContainer pContainer, Level pLevel) {
- return !recipeItems.isEmpty() && recipeItems.get(0).test(pContainer.getItem(1));
- }
- @Override
- public ItemStack assemble(SimpleContainer pContainer) {
- //This does nothing
- return ItemStack.EMPTY;
- }
- @Override
- public boolean canCraftInDimensions(int pWidth, int pHeight) {
- return true;
- }
- @Override
- public ItemStack getResultItem() {
- return ItemStack.EMPTY;
- }
- @Override
- public ResourceLocation getId() {
- return id;
- }
- @Override
- public RecipeSerializer<?> getSerializer() {
- return Serializer.INSTANCE;
- }
- @Override
- public RecipeType<?> getType() {
- return Type.INSTANCE;
- }
- public static class Type implements RecipeType<AnalyzerRecipe> {
- private Type() { }
- public static final Type INSTANCE = new Type();
- }
- @Override
- public NonNullList<Ingredient> getIngredients() {
- return recipeItems;
- }
- public static class Serializer implements RecipeSerializer<AnalyzerRecipe> {
- public static final Serializer INSTANCE = new Serializer();
- public static final ResourceLocation ID = new ResourceLocation(UnusualPrehistory.MODID,"analyzing");
- @Override
- public AnalyzerRecipe fromJson(ResourceLocation id, JsonObject json) {
- JsonArray ingredients = GsonHelper.getAsJsonArray(json, "ingredients");
- NonNullList<Ingredient> inputs = NonNullList.withSize(1, Ingredient.EMPTY);
- for (int i = 0; i < inputs.size(); i++) {
- inputs.set(i, Ingredient.fromJson(ingredients.get(i)));
- }
- return new AnalyzerRecipe(id, inputs);
- }
- @Override
- public AnalyzerRecipe fromNetwork(ResourceLocation id, FriendlyByteBuf buf) {
- NonNullList<Ingredient> inputs = NonNullList.withSize(buf.readInt(), Ingredient.EMPTY);
- for (int i = 0; i < inputs.size(); i++) {
- inputs.set(i, Ingredient.fromNetwork(buf));
- }
- ResourceLocation output = buf.readResourceLocation();
- return new AnalyzerRecipe(id, inputs);
- }
- @Override
- public void toNetwork(FriendlyByteBuf buf, AnalyzerRecipe recipe) {
- buf.writeInt(recipe.getIngredients().size());
- for (Ingredient ing : recipe.getIngredients()) {
- ing.toNetwork(buf);
- }
- }
- public RecipeSerializer<?> setRegistryName(ResourceLocation name) {
- return INSTANCE;
- }
- public ResourceLocation getRegistryName() {
- return ID;
- }
- public Class<RecipeSerializer<?>> getRegistryType() {
- return Serializer.castClass(RecipeSerializer.class);
- }
- @SuppressWarnings("unchecked") // Need this wrapper, because generics
- private static <G> Class<G> castClass(Class<?> cls) {
- return (Class<G>)cls;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement