From b657842bcddcb65fb658d4cd9835e7fa15e1c236 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Sun, 16 May 2021 17:45:22 +0800 Subject: Update JEI API to 7.6.4 & Fix #520 --- .../client/forge/DefaultClientPluginImpl.java | 71 ++++++++++++++++++++++ 1 file changed, 71 insertions(+) create mode 100644 forge/src/main/java/me/shedaniel/rei/plugin/client/forge/DefaultClientPluginImpl.java (limited to 'forge/src') diff --git a/forge/src/main/java/me/shedaniel/rei/plugin/client/forge/DefaultClientPluginImpl.java b/forge/src/main/java/me/shedaniel/rei/plugin/client/forge/DefaultClientPluginImpl.java new file mode 100644 index 000000000..7c47d1c84 --- /dev/null +++ b/forge/src/main/java/me/shedaniel/rei/plugin/client/forge/DefaultClientPluginImpl.java @@ -0,0 +1,71 @@ +/* + * 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.client.forge; + +import com.google.common.collect.Sets; +import me.shedaniel.rei.api.client.registry.display.DisplayRegistry; +import me.shedaniel.rei.plugin.client.BuiltinClientPlugin; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.alchemy.Potion; +import net.minecraft.world.item.alchemy.PotionBrewing; +import net.minecraft.world.item.alchemy.PotionUtils; +import net.minecraft.world.item.crafting.Ingredient; +import net.minecraftforge.registries.IRegistryDelegate; + +import java.util.Arrays; +import java.util.Set; + +public class DefaultClientPluginImpl { + public static void registerForgePotions(DisplayRegistry registry, BuiltinClientPlugin clientPlugin) { + Set potions = Sets.newLinkedHashSet(); + for (Ingredient container : PotionBrewing.ALLOWED_CONTAINERS) { + for (PotionBrewing.Mix mix : PotionBrewing.POTION_MIXES) { + IRegistryDelegate from = mix.from; + Ingredient ingredient = mix.ingredient; + IRegistryDelegate to = mix.to; + Ingredient base = Ingredient.of(Arrays.stream(container.getItems()) + .map(ItemStack::copy) + .map(stack -> PotionUtils.setPotion(stack, from.get()))); + ItemStack output = Arrays.stream(container.getItems()) + .map(ItemStack::copy) + .map(stack -> PotionUtils.setPotion(stack, to.get())) + .findFirst().orElse(ItemStack.EMPTY); + clientPlugin.registerBrewingRecipe(base, ingredient, output); + potions.add(from.get()); + potions.add(to.get()); + } + } + for (Potion potion : potions) { + for (PotionBrewing.Mix mix : PotionBrewing.CONTAINER_MIXES) { + IRegistryDelegate from = mix.from; + Ingredient ingredient = mix.ingredient; + IRegistryDelegate to = mix.to; + Ingredient base = Ingredient.of(PotionUtils.setPotion(new ItemStack(from.get()), potion)); + ItemStack output = PotionUtils.setPotion(new ItemStack(to.get()), potion); + clientPlugin.registerBrewingRecipe(base, ingredient, output); + } + } + } +} -- cgit