diff options
| author | shedaniel <daniel@shedaniel.me> | 2021-04-12 21:30:18 +0800 |
|---|---|---|
| committer | shedaniel <daniel@shedaniel.me> | 2021-04-12 21:30:18 +0800 |
| commit | 5467c2f08da6f3c6dae7ae603e3708d4f6eb1638 (patch) | |
| tree | cd923542890f062bf270b51e586270795ca9c260 | |
| parent | 513347f841a401391f59b4c9fe3cbcb4f554f86d (diff) | |
| download | RoughlyEnoughItems-5467c2f08da6f3c6dae7ae603e3708d4f6eb1638.tar.gz RoughlyEnoughItems-5467c2f08da6f3c6dae7ae603e3708d4f6eb1638.tar.bz2 RoughlyEnoughItems-5467c2f08da6f3c6dae7ae603e3708d4f6eb1638.zip | |
Fix #502 and Fix #499
Signed-off-by: shedaniel <daniel@shedaniel.me>
9 files changed, 52 insertions, 35 deletions
diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/category/CategoryRegistry.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/category/CategoryRegistry.java index 90abba478..254d0b5fd 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/category/CategoryRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/category/CategoryRegistry.java @@ -58,8 +58,8 @@ public interface CategoryRegistry extends Reloadable<REIClientPlugin>, Iterable< * * @param category the category to register */ - default <T extends Display> void register(DisplayCategory<T> category) { - register(category, config -> {}); + default <T extends Display> void add(DisplayCategory<T> category) { + add(category, config -> {}); } /** @@ -68,16 +68,16 @@ public interface CategoryRegistry extends Reloadable<REIClientPlugin>, Iterable< * @param category the category to register * @param configurator the consumer for configuring the attributes of the category */ - <T extends Display> void register(DisplayCategory<T> category, Consumer<CategoryConfiguration<T>> configurator); + <T extends Display> void add(DisplayCategory<T> category, Consumer<CategoryConfiguration<T>> configurator); /** * Registers the categories supplied. * * @param categories the categories to register */ - default <T extends Display> void register(Iterable<DisplayCategory<? extends T>> categories) { + default <T extends Display> void add(Iterable<DisplayCategory<? extends T>> categories) { for (DisplayCategory<?> category : categories) { - register(category); + add(category); } } @@ -86,9 +86,9 @@ public interface CategoryRegistry extends Reloadable<REIClientPlugin>, Iterable< * * @param categories the categories to register */ - default <T extends Display> void register(DisplayCategory<? extends T>... categories) { + default <T extends Display> void add(DisplayCategory<? extends T>... categories) { for (DisplayCategory<?> category : categories) { - register(category); + add(category); } } diff --git a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java index 65bdb9460..7535645a5 100644 --- a/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java +++ b/api/src/main/java/me/shedaniel/rei/api/client/registry/display/DisplayRegistry.java @@ -62,22 +62,22 @@ public interface DisplayRegistry extends RecipeManagerContext<REIClientPlugin> { * * @param display the recipe display */ - void registerDisplay(Display display); + void add(Display display); /** * Returns an unmodifiable map of displays visible to the player * * @return an unmodifiable map of displays */ - Map<CategoryIdentifier<?>, List<Display>> getAllDisplays(); + Map<CategoryIdentifier<?>, List<Display>> getAll(); /** * Returns the list of displays visible to the player for a category * * @return the list of displays */ - default <D extends Display> List<D> getDisplays(CategoryIdentifier<D> categoryId) { - return (List<D>) getAllDisplays().getOrDefault(categoryId, Collections.emptyList()); + default <D extends Display> List<D> get(CategoryIdentifier<D> categoryId) { + return (List<D>) getAll().getOrDefault(categoryId, Collections.emptyList()); } /** diff --git a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java index 99dbf1014..7288ca97a 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/entry/EntryStack.java @@ -49,6 +49,9 @@ import java.util.function.BiFunction; import java.util.function.Function; import java.util.function.Supplier; +/** + * @see me.shedaniel.rei.api.common.util.EntryStacks + */ public interface EntryStack<T> extends TextRepresentable, Renderer { static EntryStack<Unit> empty() { return Internals.getEntryStackProvider().empty(); diff --git a/api/src/main/java/me/shedaniel/rei/api/common/util/EntryStacks.java b/api/src/main/java/me/shedaniel/rei/api/common/util/EntryStacks.java index c8b1b86e9..46e601f37 100644 --- a/api/src/main/java/me/shedaniel/rei/api/common/util/EntryStacks.java +++ b/api/src/main/java/me/shedaniel/rei/api/common/util/EntryStacks.java @@ -148,6 +148,18 @@ public final class EntryStacks { } /** + * Hash Code of the {@code context} context. + * + * @param stack the stack to hash code + * @param context the context to use + * @param <T> the type of the stack + * @return the hash code of the {@code context} context + */ + public static <T> long hash(EntryStack<T> stack, ComparisonContext context) { + return stack.getDefinition().hash(stack, stack.getValue(), context); + } + + /** * Hash Code of the {@link ComparisonContext#EXACT} context, stacks with the same hash code should share the same normalized stack. * <p> * For example, enchantment books of different enchantments will not receive the same hash code under this context. @@ -156,9 +168,10 @@ public final class EntryStacks { * @param stack the stack to hash code * @param <T> the type of the stack * @return the hash code of the {@link ComparisonContext#EXACT} context + * @see #hash(EntryStack, ComparisonContext) */ public static <T> long hashExact(EntryStack<T> stack) { - return stack.getDefinition().hash(stack, stack.getValue(), ComparisonContext.EXACT); + return hash(stack, ComparisonContext.EXACT); } /** @@ -170,13 +183,9 @@ public final class EntryStacks { * @param stack the stack to hash code * @param <T> the type of the stack * @return the hash code of the {@link ComparisonContext#FUZZY} context + * @see #hash(EntryStack, ComparisonContext) */ public static <T> long hashFuzzy(EntryStack<T> stack) { - return stack.getDefinition().hash(stack, stack.getValue(), ComparisonContext.FUZZY); - } - - public static EntryStack<FluidStack> simplifyAmount(EntryStack<FluidStack> stack) { - stack.getValue().setAmount(stack.getValue().getAmount().simplify()); - return stack; + return hash(stack, ComparisonContext.FUZZY); } } 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 9e609e3ce..3c44e982f 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 @@ -110,12 +110,12 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin @Override public void registerBrewingRecipe(Ingredient input, Ingredient ingredient, ItemStack output) { - DisplayRegistry.getInstance().registerDisplay(new DefaultBrewingDisplay(new BrewingRecipe(input, ingredient, output))); + DisplayRegistry.getInstance().add(new DefaultBrewingDisplay(new BrewingRecipe(input, ingredient, output))); } @Override public void registerInformation(EntryIngredient ingredient, Component name, UnaryOperator<List<Component>> textBuilder) { - DisplayRegistry.getInstance().registerDisplay(DefaultInformationDisplay.createFromEntries(ingredient, name).lines(textBuilder.apply(Lists.newArrayList()))); + DisplayRegistry.getInstance().add(DefaultInformationDisplay.createFromEntries(ingredient, name).lines(textBuilder.apply(Lists.newArrayList()))); } @Override @@ -137,7 +137,7 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin @Override public void registerCategories(CategoryRegistry registry) { - registry.register( + registry.add( new DefaultCraftingCategory(), new DefaultCookingCategory(SMELTING, EntryStacks.of(Items.FURNACE), "category.rei.smelting"), new DefaultCookingCategory(SMOKING, EntryStacks.of(Items.SMOKER), "category.rei.smoking"), @@ -222,7 +222,7 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin registry.registerFiller(UpgradeRecipe.class, DefaultSmithingDisplay::new); registry.registerFiller(BrewingRecipe.class, DefaultBrewingDisplay::new); for (Map.Entry<Item, Integer> entry : AbstractFurnaceBlockEntity.getFuel().entrySet()) { - registry.registerDisplay(new DefaultFuelDisplay(Collections.singletonList(EntryIngredients.of(entry.getKey())), Collections.emptyList(), entry.getValue())); + registry.add(new DefaultFuelDisplay(Collections.singletonList(EntryIngredients.of(entry.getKey())), Collections.emptyList(), entry.getValue())); } EntryIngredient arrowStack = EntryIngredient.of(EntryStacks.of(Items.ARROW)); ReferenceSet<Potion> registeredPotions = new ReferenceOpenHashSet<>(); @@ -240,7 +240,7 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin PotionUtils.setPotion(outputStack, potion); PotionUtils.setCustomEffects(outputStack, PotionUtils.getCustomEffects(itemStack)); EntryIngredient output = EntryIngredients.of(outputStack); - registry.registerDisplay(new DefaultCustomDisplay(null, input, Collections.singletonList(output))); + registry.add(new DefaultCustomDisplay(null, input, Collections.singletonList(output))); } }); if (ComposterBlock.COMPOSTABLES.isEmpty()) { @@ -250,19 +250,19 @@ public class DefaultClientPlugin implements REIClientPlugin, BuiltinClientPlugin Iterator<List<Object2FloatMap.Entry<ItemLike>>> iterator = Iterators.partition(ComposterBlock.COMPOSTABLES.object2FloatEntrySet().stream().sorted(Map.Entry.comparingByValue()).iterator(), 48); while (iterator.hasNext()) { List<Object2FloatMap.Entry<ItemLike>> entries = iterator.next(); - registry.registerDisplay(DefaultCompostingDisplay.of(entries, Collections.singletonList(EntryIngredients.of(new ItemStack(Items.BONE_MEAL))), page++)); + registry.add(DefaultCompostingDisplay.of(entries, Collections.singletonList(EntryIngredients.of(new ItemStack(Items.BONE_MEAL))), page++)); } DummyAxeItem.getStrippedBlocksMap().entrySet().stream().sorted(Comparator.comparing(b -> Registry.BLOCK.getKey(b.getKey()))).forEach(set -> { - registry.registerDisplay(new DefaultStrippingDisplay(EntryStacks.of(set.getKey()), EntryStacks.of(set.getValue()))); + registry.add(new DefaultStrippingDisplay(EntryStacks.of(set.getKey()), EntryStacks.of(set.getValue()))); }); DummyHoeItem.getTilledBlocksMap().entrySet().stream().sorted(Comparator.comparing(b -> Registry.BLOCK.getKey(b.getKey()))).forEach(set -> { - registry.registerDisplay(new DefaultTillingDisplay(EntryStacks.of(set.getKey()), EntryStacks.of(set.getValue().getBlock()))); + registry.add(new DefaultTillingDisplay(EntryStacks.of(set.getKey()), EntryStacks.of(set.getValue().getBlock()))); }); DummyShovelItem.getPathBlocksMap().entrySet().stream().sorted(Comparator.comparing(b -> Registry.BLOCK.getKey(b.getKey()))).forEach(set -> { - registry.registerDisplay(new DefaultPathingDisplay(EntryStacks.of(set.getKey()), EntryStacks.of(set.getValue().getBlock()))); + registry.add(new DefaultPathingDisplay(EntryStacks.of(set.getKey()), EntryStacks.of(set.getValue().getBlock()))); }); - registry.registerDisplay(new DefaultBeaconBaseDisplay(CollectionUtils.map(Lists.newArrayList(BlockTags.BEACON_BASE_BLOCKS.getValues()), ItemStack::new))); - registry.registerDisplay(new DefaultBeaconPaymentDisplay(CollectionUtils.map(Lists.newArrayList(ItemTags.BEACON_PAYMENT_ITEMS.getValues()), ItemStack::new))); + registry.add(new DefaultBeaconBaseDisplay(CollectionUtils.map(Lists.newArrayList(BlockTags.BEACON_BASE_BLOCKS.getValues()), ItemStack::new))); + registry.add(new DefaultBeaconPaymentDisplay(CollectionUtils.map(Lists.newArrayList(ItemTags.BEACON_PAYMENT_ITEMS.getValues()), ItemStack::new))); if (Platform.isFabric()) { Set<Potion> potions = Sets.newLinkedHashSet(); for (Ingredient container : PotionBrewing.ALLOWED_CONTAINERS) { diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/category/CategoryRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/category/CategoryRegistryImpl.java index 3fac9255f..f2acf7bdc 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/category/CategoryRegistryImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/category/CategoryRegistryImpl.java @@ -67,7 +67,7 @@ public class CategoryRegistryImpl implements CategoryRegistry { } @Override - public <T extends Display> void register(DisplayCategory<T> category, Consumer<CategoryConfiguration<T>> configurator) { + public <T extends Display> void add(DisplayCategory<T> category, Consumer<CategoryConfiguration<T>> configurator) { Configuration<T> configuration = new Configuration<>(category); this.categories.put(category.getCategoryIdentifier(), configuration); configurator.accept(configuration); diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java index 04f44839f..c08e2ac38 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/registry/display/DisplayRegistryImpl.java @@ -65,7 +65,7 @@ public class DisplayRegistryImpl extends RecipeManagerContextImpl<REIClientPlugi } @Override - public void registerDisplay(Display display) { + public void add(Display display) { displays.computeIfAbsent(display.getCategoryIdentifier(), location -> new ArrayList<>()) .add(display); displayCount.increment(); @@ -78,7 +78,7 @@ public class DisplayRegistryImpl extends RecipeManagerContextImpl<REIClientPlugi } @Override - public Map<CategoryIdentifier<?>, List<Display>> getAllDisplays() { + public Map<CategoryIdentifier<?>, List<Display>> getAll() { return Collections.unmodifiableMap(displays); } diff --git a/runtime/src/main/java/me/shedaniel/rei/impl/client/view/ViewsImpl.java b/runtime/src/main/java/me/shedaniel/rei/impl/client/view/ViewsImpl.java index fe0fd0453..31a667a34 100644 --- a/runtime/src/main/java/me/shedaniel/rei/impl/client/view/ViewsImpl.java +++ b/runtime/src/main/java/me/shedaniel/rei/impl/client/view/ViewsImpl.java @@ -60,7 +60,7 @@ public class ViewsImpl implements Views { for (CategoryRegistry.CategoryConfiguration<?> categoryConfiguration : CategoryRegistry.getInstance()) { DisplayCategory<?> category = categoryConfiguration.getCategory(); CategoryIdentifier<?> categoryId = categoryConfiguration.getCategoryIdentifier(); - List<Display> allRecipesFromCategory = DisplayRegistry.getInstance().getDisplays((CategoryIdentifier<Display>) categoryId); + List<Display> allRecipesFromCategory = DisplayRegistry.getInstance().get((CategoryIdentifier<Display>) categoryId); Set<Display> set = Sets.newLinkedHashSet(); if (categories.contains(categoryId)) { @@ -184,7 +184,7 @@ public class ViewsImpl implements Views { @Override public Collection<EntryStack<?>> findCraftableEntriesByMaterials(Iterable<? extends EntryStack<?>> inventoryItems) { Set<EntryStack<?>> craftables = new HashSet<>(); - for (List<Display> displays : DisplayRegistry.getInstance().getAllDisplays().values()) { + for (List<Display> displays : DisplayRegistry.getInstance().getAll().values()) { for (Display display : displays) { int slotsCraftable = 0; List<EntryIngredient> requiredInput = display.getRequiredEntries(); diff --git a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java index eadb3f947..9344eb9e8 100644 --- a/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java +++ b/runtime/src/main/java/me/shedaniel/rei/plugin/client/entry/FluidEntryDefinition.java @@ -212,7 +212,7 @@ public class FluidEntryDefinition implements EntryDefinition<FluidStack>, EntryS List<Component> toolTip = Lists.newArrayList(entry.asFormattedText()); Fraction amount = entry.getValue().getAmount(); if (!amount.isLessThan(Fraction.zero())) { - String amountTooltip = I18n.get(FLUID_AMOUNT, EntryStacks.simplifyAmount(entry).getValue().getAmount()); + String amountTooltip = I18n.get(FLUID_AMOUNT, simplifyAmount(entry).getValue().getAmount()); if (amountTooltip != null) { toolTip.addAll(Stream.of(amountTooltip.split("\n")).map(TextComponent::new).collect(Collectors.toList())); } @@ -224,4 +224,9 @@ public class FluidEntryDefinition implements EntryDefinition<FluidStack>, EntryS return Tooltip.create(toolTip); } } + + public static EntryStack<FluidStack> simplifyAmount(EntryStack<FluidStack> stack) { + stack.getValue().setAmount(stack.getValue().getAmount().simplify()); + return stack; + } } |
