diff options
| author | shedaniel <daniel@shedaniel.me> | 2020-09-09 17:08:36 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2020-09-09 17:08:36 +0800 |
| commit | e3bbafaad49d15c7459ec0b38dd4268b4fd7e5ef (patch) | |
| tree | aad638798bc66a140ad6900fde438f5040952903 /RoughlyEnoughItems-default-plugin/src/main/java/me | |
| parent | afe32352abcef8d501acf7985d2e9b1f3fcb673e (diff) | |
| download | RoughlyEnoughItems-e3bbafaad49d15c7459ec0b38dd4268b4fd7e5ef.tar.gz RoughlyEnoughItems-e3bbafaad49d15c7459ec0b38dd4268b4fd7e5ef.tar.bz2 RoughlyEnoughItems-e3bbafaad49d15c7459ec0b38dd4268b4fd7e5ef.zip | |
Get rid of mixins, turn EntryStack methods turn an ImmutableList instead of ArrayList
Signed-off-by: shedaniel <daniel@shedaniel.me>
Diffstat (limited to 'RoughlyEnoughItems-default-plugin/src/main/java/me')
7 files changed, 112 insertions, 166 deletions
diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java index 3c1ef8c46..c5198bce1 100644 --- a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java +++ b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java @@ -23,9 +23,12 @@ package me.shedaniel.rei.plugin; +import com.google.common.collect.Iterators; import com.google.common.collect.Lists; -import com.google.common.collect.Maps; +import com.google.common.collect.Sets; import it.unimi.dsi.fastutil.objects.Object2FloatMap; +import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet; +import it.unimi.dsi.fastutil.objects.ReferenceSet; import me.shedaniel.math.Rectangle; import me.shedaniel.rei.api.*; import me.shedaniel.rei.api.fluid.FluidSupportProvider; @@ -79,10 +82,10 @@ import net.minecraft.resources.ResourceLocation; import net.minecraft.tags.BlockTags; import net.minecraft.tags.ItemTags; import net.minecraft.tags.Tag; -import net.minecraft.util.LazyLoadedValue; -import net.minecraft.util.Mth; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.item.*; +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.*; import net.minecraft.world.item.enchantment.Enchantment; @@ -123,8 +126,6 @@ public class DefaultPlugin implements REIPluginV0, BuiltinPlugin { public static final ResourceLocation INFO = BuiltinPlugin.INFO; private static final ResourceLocation DISPLAY_TEXTURE = new ResourceLocation("roughlyenoughitems", "textures/gui/display.png"); private static final ResourceLocation DISPLAY_TEXTURE_DARK = new ResourceLocation("roughlyenoughitems", "textures/gui/display_dark.png"); - private static final List<LazyLoadedValue<DefaultBrewingDisplay>> BREWING_DISPLAYS = Lists.newArrayList(); - private static final List<DefaultInformationDisplay> INFO_DISPLAYS = Lists.newArrayList(); public static ResourceLocation getDisplayTexture() { return REIHelper.getInstance().getDefaultDisplayTexture(); @@ -137,19 +138,19 @@ public class DefaultPlugin implements REIPluginV0, BuiltinPlugin { @Deprecated @ApiStatus.ScheduledForRemoval public static void registerBrewingDisplay(DefaultBrewingDisplay recipe) { - BREWING_DISPLAYS.add(new LazyLoadedValue<>(() -> recipe)); + RecipeHelper.getInstance().registerDisplay(recipe); } public static void registerBrewingRecipe(RegisteredBrewingRecipe recipe) { - BREWING_DISPLAYS.add(new LazyLoadedValue<>(() -> new DefaultBrewingDisplay(recipe.input, recipe.ingredient, recipe.output))); + RecipeHelper.getInstance().registerDisplay(new DefaultBrewingDisplay(recipe.input, recipe.ingredient, recipe.output)); } public static void registerInfoDisplay(DefaultInformationDisplay display) { - INFO_DISPLAYS.add(display); + RecipeHelper.getInstance().registerDisplay(display); } @Override - public void registerBrewingRecipe(ItemStack input, Ingredient ingredient, ItemStack output) { + public void registerBrewingRecipe(Ingredient input, Ingredient ingredient, ItemStack output) { registerBrewingRecipe(new RegisteredBrewingRecipe(input, ingredient, output)); } @@ -164,11 +165,6 @@ public class DefaultPlugin implements REIPluginV0, BuiltinPlugin { } @Override - public void preRegister() { - INFO_DISPLAYS.clear(); - } - - @Override public void registerEntries(EntryRegistry entryRegistry) { for (Item item : Registry.ITEM) { List<ItemStack> stacks = null; @@ -232,41 +228,36 @@ public class DefaultPlugin implements REIPluginV0, BuiltinPlugin { recipeHelper.registerRecipes(CAMPFIRE, CampfireCookingRecipe.class, DefaultCampfireDisplay::new); recipeHelper.registerRecipes(STONE_CUTTING, StonecutterRecipe.class, DefaultStoneCuttingDisplay::new); recipeHelper.registerRecipes(SMITHING, UpgradeRecipe.class, DefaultSmithingDisplay::new); - for (LazyLoadedValue<DefaultBrewingDisplay> display : BREWING_DISPLAYS) { - recipeHelper.registerDisplay(display.get()); - } for (Map.Entry<Item, Integer> entry : AbstractFurnaceBlockEntity.getFuel().entrySet()) { recipeHelper.registerDisplay(new DefaultFuelDisplay(EntryStack.create(entry.getKey()), entry.getValue())); } List<EntryStack> arrowStack = Collections.singletonList(EntryStack.create(Items.ARROW)); + ReferenceSet<Potion> registeredPotions = new ReferenceOpenHashSet<>(); EntryRegistry.getInstance().getEntryStacks().filter(entry -> entry.getItem() == Items.LINGERING_POTION).forEach(entry -> { - List<List<EntryStack>> input = new ArrayList<>(); - for (int i = 0; i < 4; i++) - input.add(arrowStack); - input.add(Collections.singletonList(EntryStack.create(entry.getItemStack()))); - for (int i = 0; i < 4; i++) - input.add(arrowStack); - ItemStack outputStack = new ItemStack(Items.TIPPED_ARROW, 8); - PotionUtils.setPotion(outputStack, PotionUtils.getPotion(entry.getItemStack())); - PotionUtils.setCustomEffects(outputStack, PotionUtils.getCustomEffects(entry.getItemStack())); - List<EntryStack> output = Collections.singletonList(EntryStack.create(outputStack).addSetting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE)); - recipeHelper.registerDisplay(new DefaultCustomDisplay(null, input, output)); + Potion potion = PotionUtils.getPotion(entry.getItemStack()); + if (registeredPotions.add(potion)) { + List<List<EntryStack>> input = new ArrayList<>(); + for (int i = 0; i < 4; i++) + input.add(arrowStack); + input.add(Collections.singletonList(EntryStack.create(entry.getItemStack()))); + for (int i = 0; i < 4; i++) + input.add(arrowStack); + ItemStack outputStack = new ItemStack(Items.TIPPED_ARROW, 8); + PotionUtils.setPotion(outputStack, potion); + PotionUtils.setCustomEffects(outputStack, PotionUtils.getCustomEffects(entry.getItemStack())); + List<EntryStack> output = Collections.singletonList(EntryStack.create(outputStack).addSetting(EntryStack.Settings.CHECK_TAGS, EntryStack.Settings.TRUE)); + recipeHelper.registerDisplay(new DefaultCustomDisplay(null, input, output)); + } }); - Map<ItemLike, Float> map = Maps.newLinkedHashMap(); if (ComposterBlock.COMPOSTABLES.isEmpty()) ComposterBlock.bootStrap(); - for (Object2FloatMap.Entry<ItemLike> entry : ComposterBlock.COMPOSTABLES.object2FloatEntrySet()) { - if (entry.getFloatValue() > 0) - map.put(entry.getKey(), entry.getFloatValue()); - } - List<ItemLike> stacks = Lists.newArrayList(map.keySet()); - stacks.sort(Comparator.comparing(map::get)); - for (int i = 0; i < stacks.size(); i += Mth.clamp(48, 1, stacks.size() - i)) { - List<ItemLike> thisStacks = Lists.newArrayList(); - for (int j = i; j < i + 48; j++) - if (j < stacks.size()) - thisStacks.add(stacks.get(j)); - recipeHelper.registerDisplay(new DefaultCompostingDisplay(Mth.floor(i / 48f), thisStacks, map, new ItemStack(Items.BONE_MEAL))); + Object2FloatMap<ItemLike> compostables = ComposterBlock.COMPOSTABLES; + int i = 0; + Iterator<List<Object2FloatMap.Entry<ItemLike>>> iterator = Iterators.partition(compostables.object2FloatEntrySet().stream().sorted(Map.Entry.comparingByValue()).iterator(), 48); + while (iterator.hasNext()) { + List<Object2FloatMap.Entry<ItemLike>> entries = iterator.next(); + recipeHelper.registerDisplay(new DefaultCompostingDisplay(i, entries, compostables, new ItemStack(Items.BONE_MEAL))); + i++; } DummyAxeItem.getStrippedBlocksMap().entrySet().stream().sorted(Comparator.comparing(b -> Registry.BLOCK.getKey(b.getKey()))).forEach(set -> { recipeHelper.registerDisplay(new DefaultStrippingDisplay(EntryStack.create(set.getKey()), EntryStack.create(set.getValue()))); @@ -279,12 +270,38 @@ public class DefaultPlugin implements REIPluginV0, BuiltinPlugin { }); recipeHelper.registerDisplay(new DefaultBeaconBaseDisplay(CollectionUtils.map(Lists.newArrayList(BlockTags.BEACON_BASE_BLOCKS.getValues()), ItemStack::new))); recipeHelper.registerDisplay(new DefaultBeaconPaymentDisplay(CollectionUtils.map(Lists.newArrayList(ItemTags.BEACON_PAYMENT_ITEMS.getValues()), ItemStack::new))); + Set<Potion> potions = Sets.newLinkedHashSet(); + for (Ingredient container : PotionBrewing.ALLOWED_CONTAINERS) { + for (PotionBrewing.Mix<Potion> mix : PotionBrewing.POTION_MIXES) { + Potion from = mix.from; + Ingredient ingredient = mix.ingredient; + Potion to = mix.to; + Ingredient base = Ingredient.of(Arrays.stream(container.getItems()) + .map(ItemStack::copy) + .map(stack -> PotionUtils.setPotion(stack, from))); + ItemStack output = Arrays.stream(container.getItems()) + .map(ItemStack::copy) + .map(stack -> PotionUtils.setPotion(stack, to)) + .findFirst().orElse(ItemStack.EMPTY); + registerBrewingRecipe(base, ingredient, output); + potions.add(from); + potions.add(to); + } + } + for (Potion potion : potions) { + for (PotionBrewing.Mix<Item> mix : PotionBrewing.CONTAINER_MIXES) { + Item from = mix.from; + Ingredient ingredient = mix.ingredient; + Item to = mix.to; + Ingredient base = Ingredient.of(PotionUtils.setPotion(new ItemStack(from), potion)); + ItemStack output = PotionUtils.setPotion(new ItemStack(to), potion); + registerBrewingRecipe(base, ingredient, output); + } + } } @Override public void postRegister() { - for (DefaultInformationDisplay display : INFO_DISPLAYS) - RecipeHelper.getInstance().registerDisplay(display); // TODO Turn this into an API // Sit tight! This will be a fast journey! long time = System.currentTimeMillis(); diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingDisplay.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingDisplay.java index 69537a9b6..a297ddfab 100644 --- a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingDisplay.java +++ b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingDisplay.java @@ -44,12 +44,18 @@ import java.util.List; @Environment(EnvType.CLIENT) public class DefaultBrewingDisplay implements RecipeDisplay { - private EntryStack input, output; - private List<EntryStack> reactant; + private EntryStack output; + private List<EntryStack> reactant, input; @ApiStatus.Internal - public DefaultBrewingDisplay(ItemStack input, Ingredient reactant, ItemStack output) { - this.input = EntryStack.create(input).setting(EntryStack.Settings.TOOLTIP_APPEND_EXTRA, stack -> Collections.singletonList(new TranslatableComponent("category.rei.brewing.input").withStyle(ChatFormatting.YELLOW))); + public DefaultBrewingDisplay(Ingredient input, Ingredient reactant, ItemStack output) { + ItemStack[] inputItems = input.getItems(); + this.input = new ArrayList<>(inputItems.length); + for (ItemStack inputItem : inputItems) { + EntryStack entryStack = EntryStack.create(inputItem); + entryStack.setting(EntryStack.Settings.TOOLTIP_APPEND_EXTRA, s -> Collections.singletonList(new TranslatableComponent("category.rei.brewing.input").withStyle(ChatFormatting.YELLOW))); + this.input.add(entryStack); + } ItemStack[] reactantStacks = reactant.getItems(); this.reactant = new ArrayList<>(reactantStacks.length); for (ItemStack stack : reactantStacks) { @@ -62,7 +68,7 @@ public class DefaultBrewingDisplay implements RecipeDisplay { @Override public @NotNull List<List<EntryStack>> getInputEntries() { - return Lists.newArrayList(Collections.singletonList(input), reactant); + return Lists.newArrayList(input, reactant); } @Override diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/RegisteredBrewingRecipe.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/RegisteredBrewingRecipe.java index 51c6e054b..e331a9253 100644 --- a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/RegisteredBrewingRecipe.java +++ b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/RegisteredBrewingRecipe.java @@ -28,11 +28,11 @@ import net.minecraft.world.item.crafting.Ingredient; public class RegisteredBrewingRecipe { - public final ItemStack input; + public final Ingredient input; public final Ingredient ingredient; public final ItemStack output; - public RegisteredBrewingRecipe(ItemStack input, Ingredient ingredient, ItemStack output) { + public RegisteredBrewingRecipe(Ingredient input, Ingredient ingredient, ItemStack output) { this.input = input; this.ingredient = ingredient; this.output = output; diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/composting/DefaultCompostingCategory.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/composting/DefaultCompostingCategory.java index 56447b60f..0b529a026 100644 --- a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/composting/DefaultCompostingCategory.java +++ b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/composting/DefaultCompostingCategory.java @@ -86,17 +86,19 @@ public class DefaultCompostingCategory implements RecipeCategory<DefaultComposti public @NotNull List<Widget> setupDisplay(DefaultCompostingDisplay display, Rectangle bounds) { List<Widget> widgets = Lists.newArrayList(); Point startingPoint = new Point(bounds.x + bounds.width - 55, bounds.y + 110); - List<EntryStack> stacks = new ArrayList<>(display.getRequiredEntries().get(0)); + List<List<EntryStack>> stacks = new ArrayList<>(display.getInputEntries()); int i = 0; for (int y = 0; y < 6; y++) for (int x = 0; x < 8; x++) { - EntryStack[] entryStack = {stacks.size() > i ? stacks.get(i) : EntryStack.empty()}; - if (!entryStack[0].isEmpty()) { - display.getInputMap().entrySet().parallelStream().filter(entry -> entry.getKey() != null && Objects.equals(entry.getKey().asItem(), entryStack[0].getItem())).findAny().map(Map.Entry::getValue).ifPresent(chance -> { - entryStack[0] = entryStack[0].setting(EntryStack.Settings.TOOLTIP_APPEND_EXTRA, s -> Collections.singletonList(new TranslatableComponent("text.rei.composting.chance", Mth.fastFloor(chance * 100)).withStyle(ChatFormatting.YELLOW))); + List<EntryStack> entryStack = stacks.size() > i ? stacks.get(i) : Collections.emptyList(); + if (!entryStack.isEmpty()) { + display.getInputMap().object2FloatEntrySet().stream().filter(entry -> entry.getKey() != null && Objects.equals(entry.getKey().asItem(), entryStack.get(0).getItem())).findAny().map(Map.Entry::getValue).ifPresent(chance -> { + for (EntryStack stack : entryStack) { + stack.setting(EntryStack.Settings.TOOLTIP_APPEND_EXTRA, s -> Collections.singletonList(new TranslatableComponent("text.rei.composting.chance", Mth.fastFloor(chance * 100)).withStyle(ChatFormatting.YELLOW))); + } }); } - widgets.add(Widgets.createSlot(new Point(bounds.getCenterX() - 72 + x * 18, bounds.y + 3 + y * 18)).entry(entryStack[0]).markInput()); + widgets.add(Widgets.createSlot(new Point(bounds.getCenterX() - 72 + x * 18, bounds.y + 3 + y * 18)).entries(entryStack).markInput()); i++; } widgets.add(Widgets.createArrow(new Point(startingPoint.x - 1, startingPoint.y + 7))); diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/composting/DefaultCompostingDisplay.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/composting/DefaultCompostingDisplay.java index f5f1df2f6..b764a00e5 100644 --- a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/composting/DefaultCompostingDisplay.java +++ b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/composting/DefaultCompostingDisplay.java @@ -23,10 +23,10 @@ package me.shedaniel.rei.plugin.composting; +import it.unimi.dsi.fastutil.objects.Object2FloatMap; import me.shedaniel.rei.api.EntryStack; import me.shedaniel.rei.api.RecipeDisplay; import me.shedaniel.rei.plugin.DefaultPlugin; -import me.shedaniel.rei.utils.CollectionUtils; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.resources.ResourceLocation; @@ -34,22 +34,30 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.level.ItemLike; import org.jetbrains.annotations.NotNull; +import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Map; @Environment(EnvType.CLIENT) public class DefaultCompostingDisplay implements RecipeDisplay { - private List<EntryStack> order; - private Map<ItemLike, Float> inputMap; - private List<EntryStack> output; + private List<List<EntryStack>> inputs; + private Object2FloatMap<ItemLike> inputMap; + private List<List<EntryStack>> output; private int page; - public DefaultCompostingDisplay(int page, List<ItemLike> order, Map<ItemLike, Float> inputMap, ItemStack output) { + public DefaultCompostingDisplay(int page, List<Object2FloatMap.Entry<ItemLike>> inputs, Object2FloatMap<ItemLike> map, ItemStack output) { this.page = page; - this.order = EntryStack.ofItems(order); - this.inputMap = inputMap; - this.output = EntryStack.ofItemStacks(Collections.singletonList(output)); + { + List<EntryStack>[] result = new List[inputs.size()]; + int i = 0; + for (Object2FloatMap.Entry<ItemLike> entry : inputs) { + result[i] = Collections.singletonList(EntryStack.create(entry.getKey())); + i++; + } + this.inputs = Arrays.asList(result); + } + this.inputMap = map; + this.output = Collections.singletonList(Collections.singletonList(EntryStack.create(output))); } public int getPage() { @@ -58,16 +66,16 @@ public class DefaultCompostingDisplay implements RecipeDisplay { @Override public @NotNull List<List<EntryStack>> getInputEntries() { - return CollectionUtils.map(order, Collections::singletonList); + return inputs; } - public Map<ItemLike, Float> getInputMap() { + public Object2FloatMap<ItemLike> getInputMap() { return inputMap; } @Override public @NotNull List<List<EntryStack>> getResultingEntries() { - return Collections.singletonList(output); + return output; } @Override @@ -77,6 +85,6 @@ public class DefaultCompostingDisplay implements RecipeDisplay { @Override public @NotNull List<List<EntryStack>> getRequiredEntries() { - return Collections.singletonList(order); + return inputs; } } diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultCustomDisplay.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultCustomDisplay.java index e8f650cdd..5bab62e7a 100644 --- a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultCustomDisplay.java +++ b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultCustomDisplay.java @@ -23,7 +23,7 @@ package me.shedaniel.rei.plugin.crafting; -import com.google.common.collect.Lists; +import com.google.common.collect.ImmutableList; import me.shedaniel.rei.api.EntryStack; import me.shedaniel.rei.utils.CollectionUtils; import net.fabricmc.api.EnvType; @@ -33,6 +33,7 @@ import net.minecraft.world.item.ItemStack; import net.minecraft.world.item.crafting.Recipe; import org.jetbrains.annotations.NotNull; +import java.util.BitSet; import java.util.Collections; import java.util.List; import java.util.Optional; @@ -50,21 +51,21 @@ public class DefaultCustomDisplay implements DefaultCraftingDisplay { } public DefaultCustomDisplay(Recipe<?> possibleRecipe, List<List<EntryStack>> input, List<EntryStack> output) { - this.input = input; - this.output = output; + this.input = ImmutableList.copyOf(input); + this.output = ImmutableList.copyOf(output); this.possibleRecipe = possibleRecipe; - List<Boolean> row = Lists.newArrayList(false, false, false); - List<Boolean> column = Lists.newArrayList(false, false, false); + BitSet row = new BitSet(3); + BitSet column = new BitSet(3); for (int i = 0; i < 9; i++) if (i < this.input.size()) { List<EntryStack> stacks = this.input.get(i); if (stacks.stream().anyMatch(stack -> !stack.isEmpty())) { - row.set((i - (i % 3)) / 3, true); - column.set(i % 3, true); + row.set((i - (i % 3)) / 3); + column.set(i % 3); } } - this.width = (int) column.stream().filter(Boolean::booleanValue).count(); - this.height = (int) row.stream().filter(Boolean::booleanValue).count(); + this.width = row.cardinality(); + this.height = column.cardinality(); } public DefaultCustomDisplay(List<List<ItemStack>> input, List<ItemStack> output) { diff --git a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/mixin/MixinPotionBrewing.java b/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/mixin/MixinPotionBrewing.java deleted file mode 100644 index 1c5250833..000000000 --- a/RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/mixin/MixinPotionBrewing.java +++ /dev/null @@ -1,88 +0,0 @@ -/* - * This file is licensed under the MIT License, part of Roughly Enough Items. - * Copyright (c) 2018, 2019, 2020 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.mixin; - -import com.google.common.collect.Lists; -import me.shedaniel.rei.plugin.DefaultPlugin; -import me.shedaniel.rei.plugin.brewing.BrewingRecipe; -import me.shedaniel.rei.plugin.brewing.RegisteredBrewingRecipe; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.minecraft.world.item.Item; -import net.minecraft.world.item.ItemStack; -import net.minecraft.world.item.PotionItem; -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 org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Unique; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; - -import java.util.List; - -@Mixin(PotionBrewing.class) -@Environment(EnvType.CLIENT) -public class MixinPotionBrewing { - - @Unique private static final List<BrewingRecipe> SELF_ITEM_RECIPES = Lists.newArrayList(); - @Unique private static final List<Potion> REGISTERED_POTION_TYPES = Lists.newArrayList(); - @Unique private static final List<Ingredient> SELF_POTION_TYPES = Lists.newArrayList(); - - @Inject(method = "addContainer", at = @At("RETURN")) - private static void addContainer(Item item_1, CallbackInfo ci) { - if (item_1 instanceof PotionItem) - SELF_POTION_TYPES.add(Ingredient.of(item_1)); - } - - @Inject(method = "addContainerRecipe", at = @At("RETURN")) - private static void addContainerRecipe(Item item_1, Item item_2, Item item_3, CallbackInfo ci) { - if (item_1 instanceof PotionItem && item_3 instanceof PotionItem) - SELF_ITEM_RECIPES.add(new BrewingRecipe(item_1, Ingredient.of(item_2), item_3)); - } - - @Inject(method = "addMix", at = @At("RETURN")) - private static void addMix(Potion potion_1, Item item_1, Potion potion_2, CallbackInfo ci) { - if (!REGISTERED_POTION_TYPES.contains(potion_1)) - rei_registerPotionType(potion_1); - if (!REGISTERED_POTION_TYPES.contains(potion_2)) - rei_registerPotionType(potion_2); - for (Ingredient type : SELF_POTION_TYPES) { - for (ItemStack stack : type.getItems()) { - DefaultPlugin.registerBrewingRecipe(new RegisteredBrewingRecipe(PotionUtils.setPotion(stack.copy(), potion_1), Ingredient.of(item_1), PotionUtils.setPotion(stack.copy(), potion_2))); - } - } - } - - @Unique - private static void rei_registerPotionType(Potion potion) { - REGISTERED_POTION_TYPES.add(potion); - for (BrewingRecipe recipe : SELF_ITEM_RECIPES) { - DefaultPlugin.registerBrewingRecipe(new RegisteredBrewingRecipe(PotionUtils.setPotion(recipe.input.getDefaultInstance(), potion), recipe.ingredient, PotionUtils.setPotion(recipe.output.getDefaultInstance(), potion))); - } - } - -} |
