diff options
| author | shedaniel <daniel@shedaniel.me> | 2021-11-21 11:49:06 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2021-11-21 19:05:46 +0800 |
| commit | 30eb93c91f00c6cf8a3809ff72fa9bedaaebbc92 (patch) | |
| tree | 70b0d086a0fef306250aeddc8197a464567e6d5a /default-plugin/src/main/java/me | |
| parent | 8203246cb37dff7ef0871ad03ab49b271727abfd (diff) | |
| download | RoughlyEnoughItems-30eb93c91f00c6cf8a3809ff72fa9bedaaebbc92.tar.gz RoughlyEnoughItems-30eb93c91f00c6cf8a3809ff72fa9bedaaebbc92.tar.bz2 RoughlyEnoughItems-30eb93c91f00c6cf8a3809ff72fa9bedaaebbc92.zip | |
Fix EnderStorage recipes
Diffstat (limited to 'default-plugin/src/main/java/me')
3 files changed, 96 insertions, 4 deletions
diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java index 779b21e0b..15c55430d 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/client/DefaultClientPlugin.java @@ -69,9 +69,8 @@ import me.shedaniel.rei.plugin.common.displays.brewing.DefaultBrewingDisplay; import me.shedaniel.rei.plugin.common.displays.cooking.DefaultBlastingDisplay; import me.shedaniel.rei.plugin.common.displays.cooking.DefaultSmeltingDisplay; import me.shedaniel.rei.plugin.common.displays.cooking.DefaultSmokingDisplay; +import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCraftingDisplay; import me.shedaniel.rei.plugin.common.displays.crafting.DefaultCustomDisplay; -import me.shedaniel.rei.plugin.common.displays.crafting.DefaultShapedDisplay; -import me.shedaniel.rei.plugin.common.displays.crafting.DefaultShapelessDisplay; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.Minecraft; @@ -236,8 +235,7 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin @Override public void registerDisplays(DisplayRegistry registry) { - registry.registerRecipeFiller(ShapelessRecipe.class, RecipeType.CRAFTING, DefaultShapelessDisplay::new); - registry.registerRecipeFiller(ShapedRecipe.class, RecipeType.CRAFTING, DefaultShapedDisplay::new); + registry.registerRecipeFiller(CraftingRecipe.class, RecipeType.CRAFTING, DefaultCraftingDisplay::of); registry.registerRecipeFiller(SmeltingRecipe.class, RecipeType.SMELTING, DefaultSmeltingDisplay::new); registry.registerRecipeFiller(SmokingRecipe.class, RecipeType.SMOKING, DefaultSmokingDisplay::new); registry.registerRecipeFiller(BlastingRecipe.class, RecipeType.BLASTING, DefaultBlastingDisplay::new); diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCraftingDisplay.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCraftingDisplay.java index 0a2234540..f37712c05 100644 --- a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCraftingDisplay.java +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCraftingDisplay.java @@ -23,6 +23,9 @@ package me.shedaniel.rei.plugin.common.displays.crafting; +import dev.architectury.injectables.annotations.ExpectPlatform; +import dev.architectury.injectables.annotations.PlatformOnly; +import me.shedaniel.architectury.platform.Platform; import me.shedaniel.rei.api.common.category.CategoryIdentifier; import me.shedaniel.rei.api.common.display.SimpleGridMenuDisplay; import me.shedaniel.rei.api.common.display.basic.BasicDisplay; @@ -33,13 +36,21 @@ import me.shedaniel.rei.api.common.transfer.info.MenuInfo; import me.shedaniel.rei.api.common.transfer.info.MenuSerializationContext; import me.shedaniel.rei.api.common.transfer.info.simple.SimpleGridMenuInfo; import me.shedaniel.rei.api.common.util.CollectionUtils; +import me.shedaniel.rei.api.common.util.EntryIngredients; import me.shedaniel.rei.plugin.common.BuiltinPlugin; +import net.minecraft.core.NonNullList; import net.minecraft.resources.ResourceLocation; import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Recipe; +import net.minecraft.world.item.crafting.ShapedRecipe; +import net.minecraft.world.item.crafting.ShapelessRecipe; +import org.apache.commons.lang3.tuple.Pair; +import org.jetbrains.annotations.Nullable; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Optional; @@ -51,6 +62,37 @@ public abstract class DefaultCraftingDisplay<C extends Recipe<?>> extends BasicD this.recipe = recipe; } + @Nullable + public static DefaultCraftingDisplay<?> of(Recipe<?> recipe) { + if (recipe instanceof ShapelessRecipe) { + return new DefaultShapelessDisplay((ShapelessRecipe) recipe); + } else if (recipe instanceof ShapedRecipe) { + return new DefaultShapedDisplay((ShapedRecipe) recipe); + } else if (!recipe.isSpecial()) { + NonNullList<Ingredient> ingredients = recipe.getIngredients(); + Pair<Integer, Integer> size = Platform.isFabric() ? null : getSize(recipe); + + if (!ingredients.isEmpty()) { + if (size == null) { + return new DefaultCustomDisplay(recipe, EntryIngredients.ofIngredients(recipe.getIngredients()), + Collections.singletonList(EntryIngredients.of(recipe.getResultItem()))); + } else { + return new DefaultCustomShapedDisplay(recipe, EntryIngredients.ofIngredients(recipe.getIngredients()), + Collections.singletonList(EntryIngredients.of(recipe.getResultItem())), + size.getLeft(), size.getRight()); + } + } + } + + return null; + } + + @ExpectPlatform + @PlatformOnly(PlatformOnly.FORGE) + private static Pair<Integer, Integer> getSize(Recipe<?> recipe) { + throw new AssertionError(); + } + @Override public CategoryIdentifier<?> getCategoryIdentifier() { return BuiltinPlugin.CRAFTING; diff --git a/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCustomShapedDisplay.java b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCustomShapedDisplay.java new file mode 100644 index 000000000..18296bd1e --- /dev/null +++ b/default-plugin/src/main/java/me/shedaniel/rei/plugin/common/displays/crafting/DefaultCustomShapedDisplay.java @@ -0,0 +1,52 @@ +/* + * This file is licensed under the MIT License, part of Roughly Enough Items. + * Copyright (c) 2018, 2019, 2020, 2021 shedaniel + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package me.shedaniel.rei.plugin.common.displays.crafting; + +import me.shedaniel.rei.api.common.entry.EntryIngredient; +import net.minecraft.world.item.crafting.Recipe; +import org.jetbrains.annotations.Nullable; + +import java.util.List; +import java.util.Optional; + +public class DefaultCustomShapedDisplay extends DefaultCraftingDisplay<Recipe<?>> { + private int width; + private int height; + + public DefaultCustomShapedDisplay(@Nullable Recipe<?> possibleRecipe, List<EntryIngredient> input, List<EntryIngredient> output, int width, int height) { + super(input, output, Optional.ofNullable(possibleRecipe)); + this.width = width; + this.height = height; + } + + @Override + public int getWidth() { + return width; + } + + @Override + public int getHeight() { + return height; + } +} |
