aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshedaniel <daniel@shedaniel.me>2020-09-09 17:08:36 +0800
committershedaniel <daniel@shedaniel.me>2020-09-09 17:08:36 +0800
commite3bbafaad49d15c7459ec0b38dd4268b4fd7e5ef (patch)
treeaad638798bc66a140ad6900fde438f5040952903
parentafe32352abcef8d501acf7985d2e9b1f3fcb673e (diff)
downloadRoughlyEnoughItems-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>
-rw-r--r--RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/BuiltinPlugin.java6
-rw-r--r--RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ConfigObject.java2
-rw-r--r--RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryStack.java65
-rw-r--r--RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/DefaultPlugin.java103
-rw-r--r--RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/DefaultBrewingDisplay.java16
-rw-r--r--RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/brewing/RegisteredBrewingRecipe.java4
-rw-r--r--RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/composting/DefaultCompostingCategory.java14
-rw-r--r--RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/composting/DefaultCompostingDisplay.java34
-rw-r--r--RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/crafting/DefaultCustomDisplay.java19
-rw-r--r--RoughlyEnoughItems-default-plugin/src/main/java/me/shedaniel/rei/plugin/mixin/MixinPotionBrewing.java88
-rw-r--r--RoughlyEnoughItems-default-plugin/src/main/resources/fabric.mod.json3
-rw-r--r--RoughlyEnoughItems-default-plugin/src/main/resources/mixin.roughlyenoughitems-default-plugin.json13
-rw-r--r--RoughlyEnoughItems-default-plugin/src/main/resources/roughlyenoughitems-default-plugin.accessWidener7
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/EntryListWidget.java12
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/gui/widget/FavoritesListWidget.java12
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/AbstractEntryStack.java43
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ConfigObjectImpl.java3
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/EntryRegistryImpl.java2
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/FluidEntryStack.java6
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ItemEntryStack.java19
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/ItemStackHook.java31
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/impl/RecipeHelperImpl.java10
-rw-r--r--RoughlyEnoughItems-runtime/src/main/java/me/shedaniel/rei/mixin/MixinItemStack.java48
-rw-r--r--RoughlyEnoughItems-runtime/src/main/resources/fabric.mod.json3
-rw-r--r--RoughlyEnoughItems-runtime/src/main/resources/mixin.roughlyenoughitems-runtime.json13
-rwxr-xr-xbuild.gradle239
-rw-r--r--gradle.properties2
27 files changed, 486 insertions, 331 deletions
diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/BuiltinPlugin.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/BuiltinPlugin.java
index ca9c60085..057ac2613 100644
--- a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/BuiltinPlugin.java
+++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/BuiltinPlugin.java
@@ -56,7 +56,11 @@ public interface BuiltinPlugin {
return Internals.getBuiltinPlugin();
}
- void registerBrewingRecipe(ItemStack input, Ingredient ingredient, ItemStack output);
+ default void registerBrewingRecipe(ItemStack input, Ingredient ingredient, ItemStack output) {
+ registerBrewingRecipe(Ingredient.of(input), ingredient, output);
+ }
+
+ void registerBrewingRecipe(Ingredient input, Ingredient ingredient, ItemStack output);
void registerInformation(List<EntryStack> entryStacks, Component name, UnaryOperator<List<Component>> textBuilder);
diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ConfigObject.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ConfigObject.java
index 044b5e659..e7b2bf1a5 100644
--- a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ConfigObject.java
+++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/ConfigObject.java
@@ -59,6 +59,8 @@ public interface ConfigObject {
boolean isToastDisplayedOnCopyIdentifier();
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval
boolean doesRenderEntryEnchantmentGlint();
boolean isEntryListWidgetScrolled();
diff --git a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryStack.java b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryStack.java
index e1ff44c24..98ef1533e 100644
--- a/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryStack.java
+++ b/RoughlyEnoughItems-api/src/main/java/me/shedaniel/rei/api/EntryStack.java
@@ -23,9 +23,12 @@
package me.shedaniel.rei.api;
+import com.google.common.collect.ImmutableList;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.mojang.blaze3d.vertex.PoseStack;
+import it.unimi.dsi.fastutil.shorts.Short2ObjectMap;
+import it.unimi.dsi.fastutil.shorts.Short2ObjectOpenHashMap;
import me.shedaniel.math.Point;
import me.shedaniel.math.Rectangle;
import me.shedaniel.rei.api.fluid.FluidSupportProvider;
@@ -85,36 +88,57 @@ public interface EntryStack extends TextRepresentable {
}
static List<EntryStack> ofItems(Collection<ItemLike> stacks) {
- List<EntryStack> result = new ArrayList<>(stacks.size());
+ if (stacks.size() == 0) return Collections.emptyList();
+ if (stacks.size() == 1) return Collections.singletonList(create(stacks.iterator().next()));
+ EntryStack[] result = new EntryStack[stacks.size()];
+ int i = 0;
for (ItemLike stack : stacks) {
- result.add(create(stack));
+ result[i] = create(stack);
+ i++;
}
- return result;
+ return Arrays.asList(result);
}
static List<EntryStack> ofItemStacks(Collection<ItemStack> stacks) {
+ if (stacks.size() == 0) return Collections.emptyList();
+ if (stacks.size() == 1) {
+ ItemStack stack = stacks.iterator().next();
+ if (stack.isEmpty()) return Collections.emptyList();
+ return Collections.singletonList(create(stack));
+ }
List<EntryStack> result = new ArrayList<>(stacks.size());
for (ItemStack stack : stacks) {
result.add(create(stack));
}
- return result;
+ return ImmutableList.copyOf(result);
}
static List<EntryStack> ofIngredient(Ingredient ingredient) {
+ if (ingredient.isEmpty()) return Collections.emptyList();
ItemStack[] matchingStacks = ingredient.getItems();
+ if (matchingStacks.length == 0) return Collections.emptyList();
+ if (matchingStacks.length == 1) return Collections.singletonList(create(matchingStacks[0]));
List<EntryStack> result = new ArrayList<>(matchingStacks.length);
for (ItemStack matchingStack : matchingStacks) {
- result.add(create(matchingStack));
+ if (!matchingStack.isEmpty())
+ result.add(create(matchingStack));
}
- return result;
+ return ImmutableList.copyOf(result);
}
static List<List<EntryStack>> ofIngredients(List<Ingredient> ingredients) {
+ if (ingredients.size() == 0) return Collections.emptyList();
+ if (ingredients.size() == 1) {
+ Ingredient ingredient = ingredients.get(0);
+ if (ingredient.isEmpty()) return Collections.emptyList();
+ return Collections.singletonList(ofIngredient(ingredient));
+ }
List<List<EntryStack>> result = new ArrayList<>(ingredients.size());
for (Ingredient ingredient : ingredients) {
- result.add(ofIngredient(ingredient));
+ if (!ingredient.isEmpty())
+ result.add(ofIngredient(ingredient));
}
- return result;
+ return ImmutableList.copyOf(result);
}
@Deprecated
@@ -246,6 +270,11 @@ public interface EntryStack extends TextRepresentable {
EntryStack copy();
+ @ApiStatus.Internal
+ default EntryStack rewrap() {
+ return copy();
+ }
+
Object getObject();
boolean equals(EntryStack stack, boolean ignoreTags, boolean ignoreAmount);
@@ -335,6 +364,9 @@ public interface EntryStack extends TextRepresentable {
}
class Settings<T> {
+ @ApiStatus.Internal
+ private static final Short2ObjectMap<Settings<?>> ID_TO_SETTINGS = new Short2ObjectOpenHashMap<>();
+
public static final Supplier<Boolean> TRUE = () -> true;
public static final Supplier<Boolean> FALSE = () -> false;
public static final Settings<Supplier<Boolean>> RENDER = new Settings<>(TRUE);
@@ -346,17 +378,34 @@ public interface EntryStack extends TextRepresentable {
public static final Settings<Function<EntryStack, List<Component>>> TOOLTIP_APPEND_EXTRA = new Settings<>(stack -> Collections.emptyList());
public static final Settings<Function<EntryStack, String>> COUNTS = new Settings<>(stack -> null);
+ private static short nextId;
private T defaultValue;
+ private short id;
+ @ApiStatus.Internal
public Settings(T defaultValue) {
this.defaultValue = defaultValue;
+ this.id = nextId++;
+ ID_TO_SETTINGS.put(this.id, this);
+ }
+
+ @ApiStatus.Internal
+ public static <T> Settings<T> getById(short id) {
+ return (Settings<T>) ID_TO_SETTINGS.get(id);
}
public T getDefaultValue() {
return defaultValue;
}
+ @ApiStatus.Internal
+ public short getId() {
+ return id;
+ }
+
public static class Item {
+ @Deprecated
+ @ApiStatus.ScheduledForRemoval
public static final Settings<Supplier<Boolean>> RENDER_ENCHANTMENT_GLINT = new Settings<>(TRUE);
private Item() {
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 in